No, I don't misunderstand how this works and how a vertex is interpolated from vertex to fragment shader but still a good explanation.
But I finally got what you actually trying to tell me and I think we are talking past each other so let me clearify some things:
I know that I can't alter the value of a varying sent (and interpolated) from vertex to fragment shader.
I also know that you can't modify the position of a fragment.
But I can interpret a specific fragment how I like, for example, manipulate it's color, lighting, shadow etc.
And that's exactly what I want to achieve, I want to tell the code being executed after my custom shader what position it should use for the shadow calculations.
I don't want to modify the vertex varying, I'm just searching a way to tell the shader what my raymarching algrithm calculated.
So what I basically want is a POSITION parameter which can be read and written to, like this:
// Code before custom shader function
vec3 vertex = vertex_interp;
vec3 view = -normalize(vertex);
#if POSITION_USED
vec3 position = vertex_interp;
#endif
// custom shader function
vec3 displacedPos = raymarch(...);
POSITION = displacedPos;
// Code after custom shader:
#if POSITION_USED
view = -normalize(position);
#endif
// shadow calculation
float shadow = 1.0;
if (directional_lights.data[i].shadow_opacity > 0.001) {
float depth_z = -position.z; // <-- use position here instead of vertex
vec3 light_dir = directional_lights.data[i].direction;
// this also looks fishy as the fragment shader allows to write to NORMAL but uses normal_interp here
vec3 base_normal_bias = normalize(normal_interp) * (1.0 - max(0.0, dot(light_dir, -normalize(normal_interp))));
I hope I made it crystal clear now what I want to achieve and what my problem actually is.
I'm not good at explaining things in an academic way, I'm better at practially showing what I want to do via code and images, so that may be the reason why my intentions where not good to understand.
P.S.: VERTEX is still being directly replaced with vertex so what I'm actually writing to after transpiling is the vec3 vertex
variable, not the vertex_interp
varying coming from the vertex stage.