Cycles Volume Render: support for rendering of homogeneous volume with absorption.

This is the simplest possible volume rendering case, constant density inside
the volume and no scattering or emission. My plan is to tweak, verify and commit
more volume rendering effects one by one, doing it all at once makes it
difficult to verify correctness and track down bugs.

Documentation is here:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Materials/Volume

Currently this hooks into path tracing in 3 ways, which should get us pretty
far until we add more advanced light sampling. These 3 hooks are repeated in
the path tracing, branched path tracing and transparent shadow code:

* Determine active volume shader at start of the path
* Change active volume shader on transmission through a surface
* Light attenuation over line segments between camera, surfaces and background

This is work by "storm", Stuart Broadfoot, Thomas Dinges and myself.
This commit is contained in:
Brecht Van Lommel
2013-12-28 16:56:19 +01:00
parent 133f770ab3
commit e369a5c485
15 changed files with 532 additions and 134 deletions

View File

@@ -22,7 +22,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
if(ray->t == 0.0f)
return false;
Intersection isect;
#ifdef __HAIR__
bool result = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f);
@@ -45,6 +45,10 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
float3 Pend = ray->P + ray->D*ray->t;
int bounce = state->transparent_bounce;
#ifdef __VOLUME__
int volume_shader = state->volume_shader;
#endif
for(;;) {
if(bounce >= kernel_data.integrator.transparent_max_bounce) {
return true;
@@ -67,6 +71,13 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
#else
if(!scene_intersect(kg, ray, PATH_RAY_SHADOW_TRANSPARENT, &isect)) {
#endif
#ifdef __VOLUME__
/* attenuation for last line segment towards light */
if(volume_shader != SHADER_NO_ID)
throughput *= kernel_volume_get_shadow_attenuation(kg, state, ray, volume_shader);
#endif
*shadow *= throughput;
return false;
}
@@ -74,20 +85,48 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
if(!shader_transparent_shadow(kg, &isect))
return true;
#ifdef __VOLUME__
/* attenuation between last surface and next surface */
if(volume_shader != SHADER_NO_ID) {
Ray segment_ray = *ray;
segment_ray.t = isect.t;
throughput *= kernel_volume_get_shadow_attenuation(kg, state, &segment_ray, volume_shader);
}
#endif
/* setup shader data at surface */
ShaderData sd;
shader_setup_from_ray(kg, &sd, &isect, ray, state->bounce+1);
shader_eval_surface(kg, &sd, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
throughput *= shader_bsdf_transparency(kg, &sd);
/* attenuation from transparent surface */
if(!(sd.flag & SD_HAS_ONLY_VOLUME)) {
shader_eval_surface(kg, &sd, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
throughput *= shader_bsdf_transparency(kg, &sd);
}
/* move ray forward */
ray->P = ray_offset(sd.P, -sd.Ng);
if(ray->t != FLT_MAX)
ray->D = normalize_len(Pend - ray->P, &ray->t);
#ifdef __VOLUME__
/* exit/enter volume */
if(sd.flag & SD_BACKFACING)
volume_shader = kernel_data.background.volume_shader;
else
volume_shader = (sd.flag & SD_HAS_VOLUME)? sd.shader: SHADER_NO_ID;
#endif
bounce++;
}
}
}
#ifdef __VOLUME__
else if(!result && state->volume_shader != SHADER_NO_ID) {
/* apply attenuation from current volume shader */
*shadow *= kernel_volume_get_shadow_attenuation(kg, state, ray, state->volume_shader);
}
#endif
#endif
return result;