Skip to content

Spatial shader with Next Pass does not perform depth testing correctly #95419

Description

@KiSetsuFu-PuLiN

Tested versions

  • Reproducible in v4.2.1.stable.official [b09f793]

System information

Windows 10 - Godot v4.2.1.stable.official - Forward+

Issue description

I wrote a shader as follows:

shader_type spatial;
render_mode cull_disabled, depth_draw_always;
uniform float z;
uniform float alpha: hint_range(0.0, 1.0);
void vertex(){
	MODELVIEW_MATRIX += mat4(
		vec4(0,0,0,0),
		vec4(0,0,0,0),
		vec4(0,0,0,0),
		vec4(0,0,z,0)
	);
}
void fragment() {
	ALPHA = alpha;
}

The shader turns on depth writing, and can control the distance from the model to the camera through z, and control the transparency of the shading through alpha.

I shaded a model twice with different materials from the same shader, and set the Z value in the NextPass to be slightly smaller, so that the model is farther away from my screen when shaded the second time. In theory, the second shading will never be displayed because it is blocked by the depth write of the first shading.

However, in this MRP, when the camera is adjusted to certain specific angles (generally when the negative z axis of model is facing the camera), the depth test does not prevent the second shading from being displayed.

image
image

This is sometimes good and sometimes bad. In most cases, it will be as described above. In a few cases, restarting Godot will return to normal or the depth test will not work at any camera angle.

Steps to reproduce

Open main.tscn in MRP, and then freely control the editor's camera to rotate around the model to observe.

Minimal reproduction project (MRP)

Non-Overlapping Transprancy.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions