Page MenuHome

Fix T93179: geonodes UVs and Vertex colors do not work in EEVEE
ClosedPublic

Authored by Kévin Dietrich (kevindietrich) on Jan 4 2022, 12:32 PM.

Details

Summary

Overwriting UV map or vertex color data in Geometry nodes will move the
layers to another CustomData channel, and as such, will make attribute
lookup fail from the UVMap and Vertex Color nodes in EEVEE as the
CustomDataType will also be modified (i.e. no longer CD_MTFACE or
CD_MCOL).

As discussed in T93179, the solution is to use CD_PROP_AUTO_FROM_NAME
so that the render engine is able to find the attributes. This also makes
EEVEE emulate Cycles behaviour in this regard.

Apparently it is enough to just modify the CustomDataType parameter in
calls to GPU_attribute, as the rest of the draw code is already
handling CD_PROP_AUTO_FROM_NAME cases and already properly alias
attribute names. CD_MTFACE and CD_MCOL may still be used for default
layers (with no names) so their handling in the draw code was not
removed.

Demo files downloaded from blender.org, as well as some selected
production files from the Blender Cloud, are still rendering fine.
However, this change might introduce some rendering issues due to name
collision between UV maps and Vertex colors.

Diff Detail

Repository
rB Blender

Event Timeline

Kévin Dietrich (kevindietrich) requested review of this revision.Jan 4 2022, 12:32 PM
Kévin Dietrich (kevindietrich) created this revision.

However, this change might introduce some rendering issues due to name collision between UV maps and Vertex colors.

This is my main concern. It partially defeat the purpose of having different nodes for accessing the Custom Data. The only real benefit after that is that the lists are correctly populated. Maybe we should prevent name clashing in the naming operators itself. But that means patching old files too, which is not great.

Brecht Van Lommel (brecht) requested changes to this revision.Jan 5 2022, 1:44 PM

I think this is fine but would then replace CD_MTFACE, CD_MCOL and CD_PROP_COLOR with CD_AUTO_FROM_NAME in all shader nodes, to make it fully consistent with Cycles.

However, this change might introduce some rendering issues due to name collision between UV maps and Vertex colors.

This is my main concern. It partially defeat the purpose of having different nodes for accessing the Custom Data. The only real benefit after that is that the lists are correctly populated. Maybe we should prevent name clashing in the naming operators itself. But that means patching old files too, which is not great.

Populating the list was the main motivation for adding those nodes. Personally I think it's fine to just have the name clashing problem for now, it's already been there for a long time with Cycles and we haven't really seen user complaints.

I think we can move towards a future where geometry nodes and renderers don't necessarily care about the type of attribute and just use a name as identifier.

This revision now requires changes to proceed.Jan 5 2022, 1:44 PM

Use CD_AUTO_FROM_NAME for all nodes.

This also removes CD_MCOL and CD_PROP_COLOR from the GPU codegen attribute
prefix generation routine. VBOs have been updated to use the "a" attribute
prefix instead of "c" in those cases.

CD_MTFACE remains for the prefix selection as it is the fallback custom
data type used when the attribute name is empty and the type is
CD_AUTO_FROM_NAME.

c prefix is for colors. You would need to remove the u prefix for uvs too.

Remove "u" prefix as well. This also removes the CD_MTFACE fallback from
gpu_node_graph_add_attribute as it was only used for prefixing. The various
attribute lookup functions are still defaulting to UVs if the name is empty.

Clément Foucault (fclem) requested changes to this revision.Apr 28 2022, 8:34 PM

This does need to be updated to the new codegen. I'm not opposed to simplification to this system. I'll accept after it is updated.

This revision now requires changes to proceed.Apr 28 2022, 8:34 PM

Rebase on master.

The node_uvmap GLSL function was modified to take a vec4 as input.

This removes attr_load_uv and attr_load_color from all shaders as
the generic attribute code is always used now.

source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
51

Does that mean we get any attribute type if not using any name on a UV node? Why do color attrib keep the c but uvs do not keep the u?

You might have to remove the attr_load_color and attr_load_uv from eevee_next too now. You can do that during commit.

source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
51

I see now:

/* Fall back to the UV layer, which matches old behavior. */
 if (type == CD_AUTO_FROM_NAME && name[0] == '\0') {
   type = CD_MTFACE;
 }

Not an issue then.

This revision is now accepted and ready to land.May 2 2022, 9:40 AM

You might have to remove the attr_load_color and attr_load_uv from eevee_next too now. You can do that during commit.

I guess this should be done in tmp-eevee-next-merge?

I guess this should be done in tmp-eevee-next-merge?

Nope. Do it in master or the release branch. The changes have been merged already.

I commited the fix in the release without changes to`eevee_next` as attr_load_uv and attr_load_color are also used for the grease pencil which uses a couple of global variables (g_uvs and g_color). These globals are set via another shader, so I am not really sure what should be done here. I haven't looked deeply at the surrounding code, so maybe there is an easy solution I have missed.

I commited the fix in the release without changes to`eevee_next` as attr_load_uv and attr_load_color are also used for the grease pencil which uses a couple of global variables (g_uvs and g_color). These globals are set via another shader, so I am not really sure what should be done here. I haven't looked deeply at the surrounding code, so maybe there is an easy solution I have missed.

To be fair, the Grease Pencil object rendering is turned off for now until we have a per object option to use the render engine.
I am not sure how gpencil will be able to identify its attributes since they are nameless. Maybe we should have some builtin names to access them? Just like density for volume grids.