Fix T87194: custom attributes not accessible with Cycles Volume
Custom properties defined on objects are not accessible from the attribute node when rendering a volume in Cycles. This is because this case is not handled. To handle it, added a primitive type for volumes in the kernel, which is then used in the initialization of ShaderData and to check whether an attribute lookup is for a volume. `volume_attribute_float4` is also now checking the attribute element type to dispatch to the right lookup function. Reviewed By: #cycles, brecht Maniphest Tasks: T87194 Differential Revision: https://developer.blender.org/D11728
This commit is contained in:
parent
afb17552e1
commit
a5ed075110
Notes:
blender-bot
2023-02-14 11:34:30 +01:00
Referenced by issue #87194, Attribute Node not working with Cycles Volume
|
@ -138,7 +138,7 @@ ccl_device_inline float4 primitive_surface_attribute_float4(KernelGlobals *kg,
|
|||
ccl_device_inline bool primitive_is_volume_attribute(const ShaderData *sd,
|
||||
const AttributeDescriptor desc)
|
||||
{
|
||||
return (sd->object != OBJECT_NONE && desc.element == ATTR_ELEMENT_VOXEL);
|
||||
return sd->type == PRIMITIVE_VOLUME;
|
||||
}
|
||||
|
||||
ccl_device_inline float primitive_volume_attribute_float(KernelGlobals *kg,
|
||||
|
|
|
@ -72,14 +72,22 @@ ccl_device float4 volume_attribute_float4(KernelGlobals *kg,
|
|||
const ShaderData *sd,
|
||||
const AttributeDescriptor desc)
|
||||
{
|
||||
/* todo: optimize this so we don't have to transform both here and in
|
||||
* kernel_tex_image_interp_3d when possible. Also could optimize for the
|
||||
* common case where transform is translation/scale only. */
|
||||
float3 P = sd->P;
|
||||
object_inverse_position_transform(kg, sd, &P);
|
||||
InterpolationType interp = (sd->flag & SD_VOLUME_CUBIC) ? INTERPOLATION_CUBIC :
|
||||
INTERPOLATION_NONE;
|
||||
return kernel_tex_image_interp_3d(kg, desc.offset, P, interp);
|
||||
if (desc.element & (ATTR_ELEMENT_OBJECT | ATTR_ELEMENT_MESH)) {
|
||||
return kernel_tex_fetch(__attributes_float3, desc.offset);
|
||||
}
|
||||
else if (desc.element == ATTR_ELEMENT_VOXEL) {
|
||||
/* todo: optimize this so we don't have to transform both here and in
|
||||
* kernel_tex_image_interp_3d when possible. Also could optimize for the
|
||||
* common case where transform is translation/scale only. */
|
||||
float3 P = sd->P;
|
||||
object_inverse_position_transform(kg, sd, &P);
|
||||
InterpolationType interp = (sd->flag & SD_VOLUME_CUBIC) ? INTERPOLATION_CUBIC :
|
||||
INTERPOLATION_NONE;
|
||||
return kernel_tex_image_interp_3d(kg, desc.offset, P, interp);
|
||||
}
|
||||
else {
|
||||
return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1268,6 +1268,7 @@ ccl_device_inline void shader_eval_volume(KernelGlobals *kg,
|
|||
sd->num_closure_left = max_closures;
|
||||
sd->flag = 0;
|
||||
sd->object_flag = 0;
|
||||
sd->type = PRIMITIVE_VOLUME;
|
||||
|
||||
for (int i = 0; stack[i].shader != SHADER_NONE; i++) {
|
||||
/* setup shaderdata from stack. it's mostly setup already in
|
||||
|
|
|
@ -694,17 +694,20 @@ typedef enum PrimitiveType {
|
|||
*/
|
||||
PRIMITIVE_LAMP = (1 << 6),
|
||||
|
||||
PRIMITIVE_VOLUME = (1 << 7),
|
||||
|
||||
PRIMITIVE_ALL_TRIANGLE = (PRIMITIVE_TRIANGLE | PRIMITIVE_MOTION_TRIANGLE),
|
||||
PRIMITIVE_ALL_CURVE = (PRIMITIVE_CURVE_THICK | PRIMITIVE_MOTION_CURVE_THICK |
|
||||
PRIMITIVE_CURVE_RIBBON | PRIMITIVE_MOTION_CURVE_RIBBON),
|
||||
PRIMITIVE_ALL_VOLUME = (PRIMITIVE_VOLUME),
|
||||
PRIMITIVE_ALL_MOTION = (PRIMITIVE_MOTION_TRIANGLE | PRIMITIVE_MOTION_CURVE_THICK |
|
||||
PRIMITIVE_MOTION_CURVE_RIBBON),
|
||||
PRIMITIVE_ALL = (PRIMITIVE_ALL_TRIANGLE | PRIMITIVE_ALL_CURVE),
|
||||
PRIMITIVE_ALL = (PRIMITIVE_ALL_TRIANGLE | PRIMITIVE_ALL_CURVE | PRIMITIVE_ALL_VOLUME),
|
||||
|
||||
/* Total number of different traceable primitives.
|
||||
* NOTE: This is an actual value, not a bitflag.
|
||||
*/
|
||||
PRIMITIVE_NUM_TOTAL = 6,
|
||||
PRIMITIVE_NUM_TOTAL = 7,
|
||||
} PrimitiveType;
|
||||
|
||||
#define PRIMITIVE_PACK_SEGMENT(type, segment) ((segment << PRIMITIVE_NUM_TOTAL) | (type))
|
||||
|
|
Loading…
Reference in New Issue