Help with a visual bug in a water vertex shader

godot 4

4

Question

I’m creating a vertex shader to apply a wave effect to a subdivided plane, but strange artifacts are appearing, is like the sea is divided I think it’s due to the draw order. Do you know how to fix it?

This is the current shader code it simply applies the wave() function, which is a sine wave.


float wave(float position_x, float position_z, float magnitude) {
	float returner = sin(TIME + position_x + position_z);
	returner *= magnitude;
	return returner;
}


void vertex() {
	
	
	sea_level = VERTEX.y;
	
	float y_offset = 0.0;
	
	y_offset += 2.0 * wave(VERTEX.x * 0.3, VERTEX.z * 0.1, 0.6);
	y_offset += 1.0 * wave(VERTEX.x * -0.8, VERTEX.z * 0.6, -1.0);
	y_offset += 2.0 * wave(VERTEX.x * 0.5, VERTEX.z * -0.3, 0.4);
	y_offset += 20.0 * wave(VERTEX.x * 0.1, VERTEX.z * -0.3, 0.1);
	
	
	y_offset *= 0.4;
	
	VERTEX.y += y_offset;
}

Are you writing to ALPHA in the fragment function? What happens if you don’t write to it?

it fix it, thanks! I was setting it to 1.0, so I didn’t think it would matter