How to get vert normal before transform from skinning/animation/posing, or how to reproduce same transforms in shader?

Godot Version

v4.2.1.stable.mono.official [b09f793f5]

Question

The value of NORMAL in the vertex function of a spatial shader has already been transformed according to rotations applied by the pose of a skeleton. In my material, I need the original, unmodified vertex normal, within the vertex shader. How can I get this value?

This should cache the pre-transformed vertex normals, and here I am just drawing them on the ALBEDO.

varying vec3 vert_normals;

void vertex() 
{
	vert_normals = NORMAL;
}

void fragment() 
{
	ALBEDO = vert_normals;
}

No, this doesn’t work for me. The NORMAL value has already been transformed upon assignment to vert_normals in that example. I am not talking about model*view transformation. I am talking about transformation from skeletal animation. When the vertex is influenced by one or more bones, and those bones have been moved from the rest position, it is not clear how to obtain the original vertex normal already within the vertex function, because NORMAL was already transformed according to the pose.

Anyway, I should note that for my use case, it would also/alternatively be helpful if I could have access to whatever matrix or other data was used to transform NORMAL from whatever was baked into the vertex attribute to whatever is finally received in the vertex shader. Really, what I need to do for the material I’m currently working on, is apply the same transformation to custom vertex data.

I think I could achieve what I’m trying to, if I knew how to access bone_transforms here in the vertex shader. (The docs already mention BONE_INDICES and BONE_WEIGHTS, just no way I see to get the transforms.)

Can you show what you are seeing, and an example of what you are after? Like if you have a rigged character standing there, and you grab the arm and rotate it down or play and animation, what are the normal vertex values expected to do, like if you drew them in the albedo.

After a lot more investigation, I realized that what I wanted to do is apparently just not possible right now.

Technically, I was in fact able to get the normals before bone transforms by baking it into extra UV layers. This lets me check UV2 and CUSTOM0 in the vertex shader to get the original, unmodified vertex normal, before transforms from posing. So at least that strictly solves the original question I asked. But this didn’t solve the actual problem that I was having, like I expected it to.

I made a feature proposal to expose a BONE_TRANSFORM in vertex shaders.

In the meantime I figured out a janky workaround involving creating a second mesh and cramming the data I need transformed with bones into that mesh’s normals.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.