[Bf-blender-cvs] [889d77e] master: Cycles Volume Render: heterogeneous (textured) volumes support.

Brecht Van Lommel noreply at git.blender.org
Mon Dec 30 00:05:47 CET 2013


Commit: 889d77e6f67e8da70a7cd7dcec6eec12bd996d9f
Author: Brecht Van Lommel
Date:   Sun Dec 29 22:19:38 2013 +0100
https://developer.blender.org/rB889d77e6f67e8da70a7cd7dcec6eec12bd996d9f

Cycles Volume Render: heterogeneous (textured) volumes support.

Volumes can now have textured colors and density. There is a Volume Sampling
panel in the Render properties with these settings:

* Step size: distance between volume shader samples when rendering the volume.
  Lower values give more accurate and detailed results but also increased render
  time.
* Max steps: maximum number of steps through the volume before giving up, to
  protect from extremely long render times with big objects or small step sizes.

This is much more compute intensive than homogeneous volume, so when you are not
using a texture you should enable the Homogeneous Volume option in the material
or world for faster rendering.

One important missing feature is that Generated texture coordinates are not yet
working in volumes, and they are the default coordinates for nearly all texture
nodes. So until that works you need to plug in object texture coordinates or a
world space position.

This is work by "storm", Stuart Broadfoot, Thomas Dinges and myself.

===================================================================

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/kernel/kernel_path.h
M	intern/cycles/kernel/kernel_path_state.h
M	intern/cycles/kernel/kernel_random.h
M	intern/cycles/kernel/kernel_shadow.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/kernel_volume.h
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/integrator.h
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h

===================================================================

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index e446e47..6ee7939 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -302,6 +302,20 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
                 default=True,
                 )
 
+        cls.volume_step_size = FloatProperty(
+                name="Step Size",
+                description="Distance between volume shader samples when rendering the volume. Lower values give more accurate and detailed results but also increased render time.",
+                default=0.1,
+                min=0.0000001, max=100000.0
+                )
+
+        cls.volume_max_steps = IntProperty(
+                name="Max Steps",
+                description="Maximum number of steps through the volume before giving up, to protect from extremely long render times with big objects or small step sizes.",
+                default=1024,
+                min=2, max=65536
+                )
+
         cls.film_exposure = FloatProperty(
                 name="Exposure",
                 description="Image brightness scale",
@@ -509,8 +523,8 @@ class CyclesMaterialSettings(bpy.types.PropertyGroup):
                 )
         cls.homogeneous_volume = BoolProperty(
                 name="Homogeneous Volume",
-                description="When using volume rendering, assume volume has the same density everywhere, "
-                            "for faster rendering",
+                description="When using volume rendering, assume volume has the same density everywhere"
+                            "(not using any textures), for faster rendering",
                 default=False,
                 )
 
@@ -579,8 +593,8 @@ class CyclesWorldSettings(bpy.types.PropertyGroup):
                 )
         cls.homogeneous_volume = BoolProperty(
                 name="Homogeneous Volume",
-                description="When using volume rendering, assume volume has the same density everywhere, "
-                            "for faster rendering",
+                description="When using volume rendering, assume volume has the same density everywhere"
+                            "(not using any textures), for faster rendering",
                 default=False,
                 )
 
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 02d1dfb..969f130 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -152,6 +152,21 @@ class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
         draw_samples_info(layout, cscene)
 
 
+class CyclesRender_PT_volume_sampling(CyclesButtonsPanel, Panel):
+    bl_label = "Volume Sampling"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        scene = context.scene
+        cscene = scene.cycles
+
+        split = layout.split()
+        split.prop(cscene, "volume_step_size")
+        split.prop(cscene, "volume_max_steps")
+
+
 class CyclesRender_PT_light_paths(CyclesButtonsPanel, Panel):
     bl_label = "Light Paths"
     bl_options = {'DEFAULT_CLOSED'}
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 6ec72c3..ed00e88 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -921,7 +921,7 @@ void BlenderSync::sync_materials(bool update_all)
 			PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles");
 			shader->use_mis = get_boolean(cmat, "sample_as_light");
 			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
-			shader->homogeneous_volume = get_boolean(cmat, "homogeneous_volume");
+			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
 
 			shader->set_graph(graph);
 			shader->tag_update(scene);
@@ -958,7 +958,7 @@ void BlenderSync::sync_world(bool update_all)
 			graph->connect(closure->output("Background"), out->input("Surface"));
 
 			PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
-			shader->homogeneous_volume = get_boolean(cworld, "homogeneous_volume");
+			shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
 		}
 
 		if(b_world) {
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index a349ddc..826402c 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -171,6 +171,9 @@ void BlenderSync::sync_integrator()
 	integrator->transparent_min_bounce = get_int(cscene, "transparent_min_bounces");
 	integrator->transparent_shadows = get_boolean(cscene, "use_transparent_shadows");
 
+	integrator->volume_max_steps = get_int(cscene, "volume_max_steps");
+	integrator->volume_step_size = get_float(cscene, "volume_step_size");
+
 	integrator->no_caustics = get_boolean(cscene, "no_caustics");
 	integrator->filter_glossy = get_float(cscene, "blur_glossy");
 
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index 204f782..ee56dbd 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -94,8 +94,9 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg, RNG *rng, int sample, Ra
 #ifdef __VOLUME__
 		/* volume attenuation, emission, scatter */
 		if(state.volume_stack[0].shader != SHADER_NO_ID) {
-			ray.t = (hit)? isect.t: FLT_MAX;
-			kernel_volume_integrate(kg, &state, &ray, L, &throughput);
+			Ray volume_ray = ray;
+			volume_ray.t = (hit)? isect.t: FLT_MAX;
+			kernel_volume_integrate(kg, &state, &volume_ray, L, &throughput);
 		}
 #endif
 
@@ -462,7 +463,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
 	int num_samples = 0;
 #endif
 
-	path_state_init(kg, &state);
+	path_state_init(kg, &state, rng, sample);
 
 	/* path iteration */
 	for(;; rng_offset += PRNG_BOUNCE_NUM) {
@@ -515,8 +516,9 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
 #ifdef __VOLUME__
 		/* volume attenuation, emission, scatter */
 		if(state.volume_stack[0].shader != SHADER_NO_ID) {
-			ray.t = (hit)? isect.t: FLT_MAX;
-			kernel_volume_integrate(kg, &state, &ray, &L, &throughput);
+			Ray volume_ray = ray;
+			volume_ray.t = (hit)? isect.t: FLT_MAX;
+			kernel_volume_integrate(kg, &state, &volume_ray, &L, &throughput);
 		}
 #endif
 
@@ -988,7 +990,7 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
 	int aa_samples = 0;
 #endif
 
-	path_state_init(kg, &state);
+	path_state_init(kg, &state, rng, sample);
 
 	for(;; rng_offset += PRNG_BOUNCE_NUM) {
 		/* intersect scene */
@@ -1018,8 +1020,9 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
 #ifdef __VOLUME__
 		/* volume attenuation, emission, scatter */
 		if(state.volume_stack[0].shader != SHADER_NO_ID) {
-			ray.t = (hit)? isect.t: FLT_MAX;
-			kernel_volume_integrate(kg, &state, &ray, &L, &throughput);
+			Ray volume_ray = ray;
+			volume_ray.t = (hit)? isect.t: FLT_MAX;
+			kernel_volume_integrate(kg, &state, &volume_ray, &L, &throughput);
 		}
 #endif
 
diff --git a/intern/cycles/kernel/kernel_path_state.h b/intern/cycles/kernel/kernel_path_state.h
index afca28f..3e0ad81 100644
--- a/intern/cycles/kernel/kernel_path_state.h
+++ b/intern/cycles/kernel/kernel_path_state.h
@@ -16,7 +16,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-ccl_device_inline void path_state_init(KernelGlobals *kg, PathState *state)
+ccl_device_inline void path_state_init(KernelGlobals *kg, PathState *state, RNG *rng, int sample)
 {
 	state->flag = PATH_RAY_CAMERA|PATH_RAY_SINGULAR|PATH_RAY_MIS_SKIP;
 	state->bounce = 0;
@@ -26,7 +26,15 @@ ccl_device_inline void path_state_init(KernelGlobals *kg, PathState *state)
 	state->transparent_bounce = 0;
 
 #ifdef __VOLUME__
-	kernel_volume_stack_init(kg, state->volume_stack);
+	if(kernel_data.integrator.use_volumes) {
+		/* initialize volume stack with volume we are inside of */
+		kernel_volume_stack_init(kg, state->volume_stack);
+		/* seed RNG for cases where we can't use stratified samples */
+		state->rng_congruential = lcg_init(*rng + sample*0x51633e2d);
+	}
+	else {
+		state->volume_stack[0].shader = SHADER_NO_ID;
+	}
 #endif
 }
 
diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h
index 69e7b43..c435c27 100644
--- a/intern/cycles/kernel/kernel_random.h
+++ b/intern/cycles/kernel/kernel_random.h
@@ -18,8 +18,6 @@
 
 CCL_NAMESPACE_BEGIN
 
-typedef uint RNG;
-
 #ifdef __SOBOL__
 
 /* skip initial numbers that are not as well distributed, especially the
@@ -192,10 +190,6 @@ ccl_device void path_rng_end(KernelGlobals *kg, ccl_global uint *rng_state, RNG
 
 /* Linear Congruential Generator */
 
-ccl_device float path_rng(KernelGlobals *kg, RNG& rng, int sample, int dimension)
-{
-}
-
 ccl_device_inline float path_rng_1D(KernelGlobals *kg, RNG& rng, int sample, int num_samples, int dimension)
 {
 	/* implicit mod 2^32 */
diff --git a/intern/cycles/kernel/kernel_shadow.h b/intern/cycles/kernel/kernel_shadow.h
index 4bf063e..9b015c9 100644
--- a/intern/cycles/kernel/kernel_shadow.h
+++ b/intern/cycles/kernel/kernel_shadow.h
@@ -74,7 +74,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
 #ifdef __VOLUME__
 					/* attenuation for last line segment towards light */
 					if(ps.volume_stack[0].shader != SHADER_NO_ID)
-						kernel_volume_get_shadow_attenuation(kg, &ps, ray, &throughput);
+						kernel_volume_shadow(kg, &ps, ray, &throughput);
 #endif
 
 					*shadow *= throughput;
@@ -89,7 +89,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
 				if(ps.volume_stack[0].shader != SHADER_NO_ID) {
 					Ray segment_ray = *ray;
 					segment_ray.t = isect.t;
-					kernel_volume_get_shadow_attenuation(kg, &ps, &segment_ray, &throughput);
+					kernel_volume_shadow(kg, &ps, &segment_ray, &throughput);
 				}
 #endif
 
@@ -120,7 +120,7 @@ ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *
 #ifdef __VOLUME__
 	else if(!result && state->volume_stack[0].shader != SHADER_NO_ID) {
 		/* apply attenuation from current volume s

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list