Page MenuHome

Fix T87194: Attribute Node not working with Cycles Volume
ClosedPublic

Authored by Kévin Dietrich (kevindietrich) on Jun 28 2021, 5:40 PM.

Details

Summary

Custom properties defined on objects are not accessible from the
attribute node when rendering a volume in Cycles. This appears to be
caused by ShaderData.type not being setup in shader_eval_volume,
which makes primitive_surface_attribute_float4 return a zero value.
(Object attributes are always of type float4 as the code in
blender_object.cpp does not attempt to discriminate the actual type.)

To fix this, I added a primitive type for volumes (PRIMITIVE_VOLUME)
which is used to initialized ShaderData.type.
primitive_surface_attribute_float4 then uses this information to
dispatch a call to volume_attribute_float4 which will then check
the attribute element type to choose the lookup function.

This may have some slight performance penalties, as checking the
attribute element type will be done multiple times, every existing
calls to volume_attribute_float4 already check if we have
ATTR_ELEM_VOXEL. I haven't checked this.

Diff Detail

Repository
rB Blender
Branch
fix_t87194 (branched from master)
Build Status
Buildable 15468
Build 15468: arc lint + arc unit

Event Timeline

Kévin Dietrich (kevindietrich) requested review of this revision.Jun 28 2021, 5:40 PM
Kévin Dietrich (kevindietrich) created this revision.
Brecht Van Lommel (brecht) requested changes to this revision.Jun 28 2021, 6:29 PM
Brecht Van Lommel (brecht) added inline comments.
intern/cycles/kernel/geom/geom_primitive.h
122–132

Adding this should be avoided, on the GPU having multiple such calls to volume attribute lookup leads to poor performance. Not sure why it's needed anyway.

152

Can we change this to return sd->prim == PRIMITIVE_VOLUME now?

Since all potential attributes are handled by volume_attribute_float4, so no need to check desc.element here.

intern/cycles/kernel/geom/geom_volume.h
75

This should also check for ATTR_ELEMENT_MESH.

This revision now requires changes to proceed.Jun 28 2021, 6:29 PM
Kévin Dietrich (kevindietrich) marked 3 inline comments as done.
  • Address requested changes.
intern/cycles/kernel/geom/geom_primitive.h
122–132

I added this because it wasn't handled through the code path taken when primitive_is_volume_attribute is true. But making primitive_is_volume_attribute return true with sd->type == PRIMITIVE_VOLUME will handle it.

This revision is now accepted and ready to land.Jun 28 2021, 6:55 PM