Get Transform Position not Vertex Position in Shader?

This kinda feels like a dumb question…

but lets say I have a mesh with a custom material, with that material I am offsetting the mesh in the vertex shader but it is relative to that meshes transform position.

Is there a way to decompose the matrices coming in to just get the transforms position not the vertex buffer/attribute positions?

I feel like I know how to do this but am brain dead right now.

Wouldn’t it be something simple like:

vec4 transformPos = finalWorld*vec4(vec3(0.0),1.0);

… yes that does work.

Is there a better way though?

I’m pretty sure you can grab the translation straight from the matrix like this. :slight_smile:

vec3 transformPos = vec3(finalWorld[3][0], finalWorld[3][1], finalWorld[3][2]);
1 Like

Thought so, I just have so many numbers being swizzled I did not want to assume. Thank you.


Looks to work.

1 Like