Lerping normals in a vertex shader. Is it possible?

Godot Version



Hey. I have some grass swaying in the wind. And for this I’ve manually pointed the normals of the grass straight upwards, to make it fit the ground better.

like so:

//Pointing normals upwards manually
	NORMAL = vec3(0.0,1.0,0.0);
	//Cant believe this worked!

But now i figure i want to point the normals as is from the mesh at the top of the quads.

Obviously I would just lerp it i guess, but it seems that is not a thing in the vertex part of the shader!

I’ve tried naturally stupid stuff like:

vec3 up_n = vec3(0.0,1.0,0.0);
NORMAL = vec3.lerp(NORMAL,up_n,UV.y);
//Ofcourse not!

Then to my surprise, this does a thing (doesnt cast any errors!)

vec3 up_normal = vec3(0.0,1.0,0.0);
	NORMAL = NORMAL + (up_normal * (1.0 - UV.y));

(But does it make any sense???)

Anyone know how to do this properly?

mix is lerp, not sure this is the effect you are looking for either though.

vec3 up_n = vec3(0.0,1.0,0.0);
NORMAL = mix(NORMAL,up_n,UV.y);
1 Like

But can I use mix in the vertex stage though? :thinking::thinking:

Seems mix is not part of the vertex stage though. :confused:

It is. Is there an error showing up?

1 Like

Mix is listed here in 4.0, always accessable


I must try this again. Not very good at this shader stuff might have mistaken something something. Thanks for the answer! :palms_up_together::palms_up_together::palms_up_together:

based on your other posts it’s looking fantastic!

1 Like

Thanks. Trying. Next is conform to terrain3d. :sob::sob::sob::sob: