FRAGCOORD needs to be used differently in 4.3

Hi! The blog post Introducing Reverse Z (AKA I'm sorry for breaking your shader) mentions that “if you run into a situation where your shader breaks and it’s not covered here, please consider making a post on the Godot Forum”. So that’s why I’m here :slight_smile:

Our game uses fractal texturing, which requires reading the fragment depth in the fragment shader. Previously we have used:

void fragment() {
	float depth = FRAGCOORD.z / FRAGCOORD.w;

	// ...
}

With Godot 4.3 and reverse-Z, we had to change this to:

void fragment() {
	float depth = (1.0 - FRAGCOORD.z) / FRAGCOORD.w;

	// ...
}

Might be useful to mention this somewhere in case others run into the same problem.

3 Likes