diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-10-22 17:23:45 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-10-22 17:53:06 +0400 |
commit | d2d1b19170c5790b2ef971f5d825d3c36e008513 (patch) | |
tree | 6f72ebf7152740c2bf3390418d2762fa6655c745 /intern/cycles | |
parent | c24698a37e1382c6f2ee3c8da935a3399a7836b4 (diff) |
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.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/blender/addon/properties.py | 19 | ||||
-rw-r--r-- | intern/cycles/blender/addon/ui.py | 2 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/geom/geom_volume.h | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_compat_cpu.h | 8 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_types.h | 16 | ||||
-rw-r--r-- | intern/cycles/render/shader.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/render/shader.h | 1 |
8 files changed, 54 insertions, 9 deletions
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 597ac1a9ce0..05a6f70d423 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 8743aa445be..6a08b47b01f 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 33c7bf5f859..97f2ecc1a6c 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 33a20494966..3cb6d168f80 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 e00caf5a720..37cba03ff97 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 ca1210f2d80..e49a6c6669e 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 d8925852c21..b960dfa3861 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 368496fd188..0eef62a1c61 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; |