[Bf-blender-cvs] [d2d1b19] master: Cycles: Expose volume voxel data interpolation to the interface

Sergey Sharybin noreply at git.blender.org
Wed Oct 22 15:54:57 CEST 2014


Commit: d2d1b19170c5790b2ef971f5d825d3c36e008513
Author: Sergey Sharybin
Date:   Wed Oct 22 19:23:45 2014 +0600
Branches: master
https://developer.blender.org/rBd2d1b19170c5790b2ef971f5d825d3c36e008513

Cycles: Expose volume voxel data interpolation to the interface

It is per-material setting which could be found under the Volume settings
in the material and world context buttons.

There could still be some code-wise improvements, like using variable-size
macro for interp3d instead of having interp3d_ex to which you can pass the
interpolation method.

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

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/kernel/geom/geom_volume.h
M	intern/cycles/kernel/kernel_compat_cpu.h
M	intern/cycles/kernel/kernel_types.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 597ac1a..05a6f70 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -114,6 +114,11 @@ enum_volume_sampling = (
     ('MULTIPLE_IMPORTANCE', "Multiple Importance", "Combine distance and equi-angular sampling for volumes where neither method is ideal"),
     )
 
+enum_volume_interpolation = (
+    ('LINEAR', "Linear", "Good smoothness and speed"),
+    ('CUBIC', 'Cubic', 'Smoothed high quality interpolation, but slower')
+    )
+
 
 class CyclesRenderSettings(bpy.types.PropertyGroup):
     @classmethod
@@ -617,6 +622,13 @@ class CyclesMaterialSettings(bpy.types.PropertyGroup):
                 default='DISTANCE',
                 )
 
+        cls.volume_interpolation = EnumProperty(
+                name="Volume Interpolation",
+                description="Interpolation method to use for volumes",
+                items=enum_volume_interpolation,
+                default='LINEAR',
+                )
+
     @classmethod
     def unregister(cls):
         del bpy.types.Material.cycles
@@ -693,6 +705,13 @@ class CyclesWorldSettings(bpy.types.PropertyGroup):
                 default='EQUIANGULAR',
                 )
 
+        cls.volume_interpolation = EnumProperty(
+                name="Volume Interpolation",
+                description="Interpolation method to use for volumes",
+                items=enum_volume_interpolation,
+                default='LINEAR',
+                )
+
     @classmethod
     def unregister(cls):
         del bpy.types.World.cycles
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 8743aa4..6a08b47 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -936,6 +936,7 @@ class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
         sub = col.column()
         sub.active = use_cpu(context)
         sub.prop(cworld, "volume_sampling", text="")
+        sub.prop(cworld, "volume_interpolation", text="")
         col.prop(cworld, "homogeneous_volume", text="Homogeneous")
 
 
@@ -1040,6 +1041,7 @@ class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
         sub = col.column()
         sub.active = use_cpu(context)
         sub.prop(cmat, "volume_sampling", text="")
+        col.prop(cmat, "volume_interpolation", text="")
         col.prop(cmat, "homogeneous_volume", text="Homogeneous")
 
 
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 33c7bf5..97f2ecc 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1015,6 +1015,7 @@ void BlenderSync::sync_materials(bool update_all)
 			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
 			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
 			shader->volume_sampling_method = RNA_enum_get(&cmat, "volume_sampling");
+			shader->volume_interpolation_method = RNA_enum_get(&cmat, "volume_interpolation");
 
 			shader->set_graph(graph);
 			shader->tag_update(scene);
@@ -1045,6 +1046,7 @@ void BlenderSync::sync_world(bool update_all)
 			PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
 			shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
 			shader->volume_sampling_method = RNA_enum_get(&cworld, "volume_sampling");
+			shader->volume_interpolation_method = RNA_enum_get(&cworld, "volume_interpolation");
 		}
 		else if(b_world) {
 			ShaderNode *closure, *out;
diff --git a/intern/cycles/kernel/geom/geom_volume.h b/intern/cycles/kernel/geom/geom_volume.h
index 33a2049..3cb6d16 100644
--- a/intern/cycles/kernel/geom/geom_volume.h
+++ b/intern/cycles/kernel/geom/geom_volume.h
@@ -52,7 +52,11 @@ ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd,
 #ifdef __KERNEL_GPU__
 	float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 #else
-	float4 r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
+	float4 r;
+	if(sd->flag & SD_VOLUME_CUBIC)
+		r = kernel_tex_image_interp_3d_ex(id, P.x, P.y, P.z, INTERPOLATION_CUBIC);
+	else
+		r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
 #endif
 
 	if(dx) *dx = 0.0f;
@@ -68,7 +72,11 @@ ccl_device float3 volume_attribute_float3(KernelGlobals *kg, const ShaderData *s
 #ifdef __KERNEL_GPU__
 	float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 #else
-	float4 r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
+	float4 r;
+	if(sd->flag & SD_VOLUME_CUBIC)
+		r = kernel_tex_image_interp_3d_ex(id, P.x, P.y, P.z, INTERPOLATION_CUBIC);
+	else
+		r = kernel_tex_image_interp_3d(id, P.x, P.y, P.z);
 #endif
 
 	if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h
index e00caf5..37cba03 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -151,6 +151,13 @@ template<typename T> struct texture_image  {
 
 	ccl_always_inline float4 interp_3d(float x, float y, float z, bool periodic = false)
 	{
+		return interp_3d_ex(x, y, z, interpolation, periodic);
+	}
+
+	ccl_always_inline float4 interp_3d_ex(float x, float y, float z,
+	                                      int interpolation = INTERPOLATION_LINEAR,
+	                                      bool periodic = false)
+	{
 		if(UNLIKELY(!data))
 			return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
 
@@ -331,6 +338,7 @@ typedef texture_image<uchar4> texture_image_uchar4;
 #define kernel_tex_lookup(tex, t, offset, size) (kg->tex.lookup(t, offset, size))
 #define kernel_tex_image_interp(tex, x, y) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp(x, y) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp(x, y))
 #define kernel_tex_image_interp_3d(tex, x, y, z) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp_3d(x, y, z) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp_3d(x, y, z))
+#define kernel_tex_image_interp_3d_ex(tex, x, y, z, interpolation) ((tex < MAX_FLOAT_IMAGES) ? kg->texture_float_images[tex].interp_3d_ex(x, y, z, interpolation) : kg->texture_byte_images[tex - MAX_FLOAT_IMAGES].interp_3d_ex(x, y, z, interpolation))
 
 #define kernel_data (kg->__data)
 
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index ca1210f..e49a6c6 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -616,18 +616,20 @@ enum ShaderDataFlag {
 	SD_HAS_BSSRDF_BUMP = 65536,			/* bssrdf normal uses bump */
 	SD_VOLUME_EQUIANGULAR = 131072,		/* use equiangular sampling */
 	SD_VOLUME_MIS = 262144,				/* use multiple importance sampling */
+	SD_VOLUME_CUBIC = 524288,
 
 	SD_SHADER_FLAGS = (SD_USE_MIS|SD_HAS_TRANSPARENT_SHADOW|SD_HAS_VOLUME|
 	                   SD_HAS_ONLY_VOLUME|SD_HETEROGENEOUS_VOLUME|
-					   SD_HAS_BSSRDF_BUMP|SD_VOLUME_EQUIANGULAR|SD_VOLUME_MIS),
+	                   SD_HAS_BSSRDF_BUMP|SD_VOLUME_EQUIANGULAR|SD_VOLUME_MIS|
+	                   SD_VOLUME_CUBIC),
 
 	/* object flags */
-	SD_HOLDOUT_MASK = 524288,			/* holdout for camera rays */
-	SD_OBJECT_MOTION = 1048576,			/* has object motion blur */
-	SD_TRANSFORM_APPLIED = 2097152,		/* vertices have transform applied */
-	SD_NEGATIVE_SCALE_APPLIED = 4194304,	/* vertices have negative scale applied */
-	SD_OBJECT_HAS_VOLUME = 8388608,		/* object has a volume shader */
-	SD_OBJECT_INTERSECTS_VOLUME = 16777216, /* object intersects AABB of an object with volume shader */
+	SD_HOLDOUT_MASK = 1048576,			/* holdout for camera rays */
+	SD_OBJECT_MOTION = 2097152,			/* has object motion blur */
+	SD_TRANSFORM_APPLIED = 4194304,		/* vertices have transform applied */
+	SD_NEGATIVE_SCALE_APPLIED = 8388608,	/* vertices have negative scale applied */
+	SD_OBJECT_HAS_VOLUME = 16777216,		/* object has a volume shader */
+	SD_OBJECT_INTERSECTS_VOLUME = 33554432, /* object intersects AABB of an object with volume shader */
 
 	SD_OBJECT_FLAGS = (SD_HOLDOUT_MASK|SD_OBJECT_MOTION|SD_TRANSFORM_APPLIED|
 	                   SD_NEGATIVE_SCALE_APPLIED|SD_OBJECT_HAS_VOLUME|
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index d892585..b960dfa 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -139,6 +139,7 @@ Shader::Shader()
 	use_transparent_shadow = true;
 	heterogeneous_volume = true;
 	volume_sampling_method = 0;
+	volume_interpolation_method = 0;
 
 	has_surface = false;
 	has_surface_transparent = false;
@@ -356,6 +357,8 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
 			flag |= SD_VOLUME_EQUIANGULAR;
 		if(shader->volume_sampling_method == 2)
 			flag |= SD_VOLUME_MIS;
+		if(shader->volume_interpolation_method == 1)
+			flag |= SD_VOLUME_CUBIC;
 
 		/* regular shader */
 		shader_flag[i++] = flag;
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index 368496f..0eef62a 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -69,6 +69,7 @@ public:
 	bool use_transparent_shadow;
 	bool heterogeneous_volume;
 	int volume_sampling_method;
+	int volume_interpolation_method;
 
 	/* synchronization */
 	bool need_update;




More information about the Bf-blender-cvs mailing list