- Edited
lunatix I think you're misunderstanding how VERTEX works in Godot's shading language. Although it has the same name, it's not the same thing in vertex()
function and in fragment()
function.
In vertex()
it can be read from and written to. In fragment()
you can only read it. Its initial input value you get in the vertex()
function is vertex position in object space. You can choose to alter it or not.
Between the execution of your vertex()
and fragment()
functions, Godot will transform it from object space to camera space. It will also interpolate this value for each pixel, between three vertices that comprise currently rasterized triangle. It makes no sense to modify this value in fragment()
. It's the result of interpolation of values that fragment shader can't even read, let alone alter.
You also can't affect the position of a pixel. Shaders simply don't operate this way. The pixel is always fixed and the fragment()
function is executed in isolation per each fixed pixel, with no knowledge whatsoever of any other pixel.
In pre GLSL 1.5 terminology, VERTEX is a varying, or in modern terminology it's out in vertex shader and in in fragment shader. And the name is completely appropriate.