How to get normalized VERTEX coordinates in spatial_shader

Godot Version

4.3.stable

Question

How do I get the normalized VERTEX coordinates in local space such that they go from [-1, 1].:
x: [-1, 1]
y: [-1, 1]
z: [-1, 1]

Here’s an example where you can see that VERTEX.x is [-3, 3] since the width of the model is 6m.

The vertex shader will not know the bounds of the model, as vertex data can extend to any value. You will have to add a uniform specifying the size of the mesh.

If your mesh was size 1x1 and scaled up, you might be able to use the MODEL_MATRIX to invert the transformation back to a 0-1 scale.

2 Likes