I am trying to understand spatial shaders in Godot and have a simple vertex shader:
shader_type spatial;
void vertex(){
VERTEX.y -= VERTEX.x;
}
I applied it to a sphere with this result:
So it does work but I am a bit confused about the values that I am getting: Is the range going from -0.5 to +0.5 on the every axis? I am coming form 2D shaders where the origin point is basically always the topleft so I am a bit confused.
It will depend on your input, in this case your sphere’s radius in the settings pane. But yes, the origin point in 3D is [0,0,0]
.
Example: a default plane that is 2 units wide will have a radius along the XZ axes of ±1 unit; vertices at [-1,0,-1],[-1,0,1],[1,0,1],[1,0,-1]
. If you scale/transform this object, that won’t change how the vertex shader operates, as the transform of the object & transform of the shader “keep pace” (unless you tell it not to by using global coordinates, e.g.). However, if you edit the object, e.g. by setting the width of your plane to 4, your vertices would be at [-2,0,-2],[-2,0,2],[2,0,2],[2,0,-2]
, and so your vertex shader would change.
Worth noting if you’re importing anything from modelling software rather than using Godot primitives that -Z is (typically) your “FORWARD” direction, which might help you orient yourself 🙂