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.
This commit is contained in:
@@ -114,6 +114,11 @@ enum_volume_sampling = (
|
|||||||
('MULTIPLE_IMPORTANCE', "Multiple Importance", "Combine distance and equi-angular sampling for volumes where neither method is ideal"),
|
('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):
|
class CyclesRenderSettings(bpy.types.PropertyGroup):
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -617,6 +622,13 @@ class CyclesMaterialSettings(bpy.types.PropertyGroup):
|
|||||||
default='DISTANCE',
|
default='DISTANCE',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cls.volume_interpolation = EnumProperty(
|
||||||
|
name="Volume Interpolation",
|
||||||
|
description="Interpolation method to use for volumes",
|
||||||
|
items=enum_volume_interpolation,
|
||||||
|
default='LINEAR',
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unregister(cls):
|
def unregister(cls):
|
||||||
del bpy.types.Material.cycles
|
del bpy.types.Material.cycles
|
||||||
@@ -693,6 +705,13 @@ class CyclesWorldSettings(bpy.types.PropertyGroup):
|
|||||||
default='EQUIANGULAR',
|
default='EQUIANGULAR',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cls.volume_interpolation = EnumProperty(
|
||||||
|
name="Volume Interpolation",
|
||||||
|
description="Interpolation method to use for volumes",
|
||||||
|
items=enum_volume_interpolation,
|
||||||
|
default='LINEAR',
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def unregister(cls):
|
def unregister(cls):
|
||||||
del bpy.types.World.cycles
|
del bpy.types.World.cycles
|
||||||
|
@@ -936,6 +936,7 @@ class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
|
|||||||
sub = col.column()
|
sub = col.column()
|
||||||
sub.active = use_cpu(context)
|
sub.active = use_cpu(context)
|
||||||
sub.prop(cworld, "volume_sampling", text="")
|
sub.prop(cworld, "volume_sampling", text="")
|
||||||
|
sub.prop(cworld, "volume_interpolation", text="")
|
||||||
col.prop(cworld, "homogeneous_volume", text="Homogeneous")
|
col.prop(cworld, "homogeneous_volume", text="Homogeneous")
|
||||||
|
|
||||||
|
|
||||||
@@ -1040,6 +1041,7 @@ class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
|
|||||||
sub = col.column()
|
sub = col.column()
|
||||||
sub.active = use_cpu(context)
|
sub.active = use_cpu(context)
|
||||||
sub.prop(cmat, "volume_sampling", text="")
|
sub.prop(cmat, "volume_sampling", text="")
|
||||||
|
col.prop(cmat, "volume_interpolation", text="")
|
||||||
col.prop(cmat, "homogeneous_volume", text="Homogeneous")
|
col.prop(cmat, "homogeneous_volume", text="Homogeneous")
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1015,6 +1015,7 @@ void BlenderSync::sync_materials(bool update_all)
|
|||||||
shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
|
shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
|
||||||
shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
|
shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
|
||||||
shader->volume_sampling_method = RNA_enum_get(&cmat, "volume_sampling");
|
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->set_graph(graph);
|
||||||
shader->tag_update(scene);
|
shader->tag_update(scene);
|
||||||
@@ -1045,6 +1046,7 @@ void BlenderSync::sync_world(bool update_all)
|
|||||||
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
|
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
|
||||||
shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
|
shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
|
||||||
shader->volume_sampling_method = RNA_enum_get(&cworld, "volume_sampling");
|
shader->volume_sampling_method = RNA_enum_get(&cworld, "volume_sampling");
|
||||||
|
shader->volume_interpolation_method = RNA_enum_get(&cworld, "volume_interpolation");
|
||||||
}
|
}
|
||||||
else if(b_world) {
|
else if(b_world) {
|
||||||
ShaderNode *closure, *out;
|
ShaderNode *closure, *out;
|
||||||
|
@@ -52,7 +52,11 @@ ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd,
|
|||||||
#ifdef __KERNEL_GPU__
|
#ifdef __KERNEL_GPU__
|
||||||
float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
if(dx) *dx = 0.0f;
|
if(dx) *dx = 0.0f;
|
||||||
@@ -68,7 +72,11 @@ ccl_device float3 volume_attribute_float3(KernelGlobals *kg, const ShaderData *s
|
|||||||
#ifdef __KERNEL_GPU__
|
#ifdef __KERNEL_GPU__
|
||||||
float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
|
if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f);
|
||||||
|
@@ -150,6 +150,13 @@ template<typename T> struct texture_image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ccl_always_inline float4 interp_3d(float x, float y, float z, bool periodic = false)
|
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))
|
if(UNLIKELY(!data))
|
||||||
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
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_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(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(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)
|
#define kernel_data (kg->__data)
|
||||||
|
|
||||||
|
@@ -616,18 +616,20 @@ enum ShaderDataFlag {
|
|||||||
SD_HAS_BSSRDF_BUMP = 65536, /* bssrdf normal uses bump */
|
SD_HAS_BSSRDF_BUMP = 65536, /* bssrdf normal uses bump */
|
||||||
SD_VOLUME_EQUIANGULAR = 131072, /* use equiangular sampling */
|
SD_VOLUME_EQUIANGULAR = 131072, /* use equiangular sampling */
|
||||||
SD_VOLUME_MIS = 262144, /* use multiple importance 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_SHADER_FLAGS = (SD_USE_MIS|SD_HAS_TRANSPARENT_SHADOW|SD_HAS_VOLUME|
|
||||||
SD_HAS_ONLY_VOLUME|SD_HETEROGENEOUS_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 */
|
/* object flags */
|
||||||
SD_HOLDOUT_MASK = 524288, /* holdout for camera rays */
|
SD_HOLDOUT_MASK = 1048576, /* holdout for camera rays */
|
||||||
SD_OBJECT_MOTION = 1048576, /* has object motion blur */
|
SD_OBJECT_MOTION = 2097152, /* has object motion blur */
|
||||||
SD_TRANSFORM_APPLIED = 2097152, /* vertices have transform applied */
|
SD_TRANSFORM_APPLIED = 4194304, /* vertices have transform applied */
|
||||||
SD_NEGATIVE_SCALE_APPLIED = 4194304, /* vertices have negative scale applied */
|
SD_NEGATIVE_SCALE_APPLIED = 8388608, /* vertices have negative scale applied */
|
||||||
SD_OBJECT_HAS_VOLUME = 8388608, /* object has a volume shader */
|
SD_OBJECT_HAS_VOLUME = 16777216, /* object has a volume shader */
|
||||||
SD_OBJECT_INTERSECTS_VOLUME = 16777216, /* object intersects AABB of an object with 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_OBJECT_FLAGS = (SD_HOLDOUT_MASK|SD_OBJECT_MOTION|SD_TRANSFORM_APPLIED|
|
||||||
SD_NEGATIVE_SCALE_APPLIED|SD_OBJECT_HAS_VOLUME|
|
SD_NEGATIVE_SCALE_APPLIED|SD_OBJECT_HAS_VOLUME|
|
||||||
|
@@ -139,6 +139,7 @@ Shader::Shader()
|
|||||||
use_transparent_shadow = true;
|
use_transparent_shadow = true;
|
||||||
heterogeneous_volume = true;
|
heterogeneous_volume = true;
|
||||||
volume_sampling_method = 0;
|
volume_sampling_method = 0;
|
||||||
|
volume_interpolation_method = 0;
|
||||||
|
|
||||||
has_surface = false;
|
has_surface = false;
|
||||||
has_surface_transparent = false;
|
has_surface_transparent = false;
|
||||||
@@ -356,6 +357,8 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
|
|||||||
flag |= SD_VOLUME_EQUIANGULAR;
|
flag |= SD_VOLUME_EQUIANGULAR;
|
||||||
if(shader->volume_sampling_method == 2)
|
if(shader->volume_sampling_method == 2)
|
||||||
flag |= SD_VOLUME_MIS;
|
flag |= SD_VOLUME_MIS;
|
||||||
|
if(shader->volume_interpolation_method == 1)
|
||||||
|
flag |= SD_VOLUME_CUBIC;
|
||||||
|
|
||||||
/* regular shader */
|
/* regular shader */
|
||||||
shader_flag[i++] = flag;
|
shader_flag[i++] = flag;
|
||||||
|
@@ -69,6 +69,7 @@ public:
|
|||||||
bool use_transparent_shadow;
|
bool use_transparent_shadow;
|
||||||
bool heterogeneous_volume;
|
bool heterogeneous_volume;
|
||||||
int volume_sampling_method;
|
int volume_sampling_method;
|
||||||
|
int volume_interpolation_method;
|
||||||
|
|
||||||
/* synchronization */
|
/* synchronization */
|
||||||
bool need_update;
|
bool need_update;
|
||||||
|
Reference in New Issue
Block a user