Skip to content

Ensure that depth write state is updated before transparent pass in OpenGL3 renderer#75968

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
clayjohn:GL-depth-write
Apr 12, 2023
Merged

Ensure that depth write state is updated before transparent pass in OpenGL3 renderer#75968
akien-mga merged 1 commit into
godotengine:masterfrom
clayjohn:GL-depth-write

Conversation

@clayjohn

Copy link
Copy Markdown
Member

Fixes: #75063

The core of the issue comes from here:

glDepthMask(GL_TRUE);
scene_state.current_depth_test = GLES3::SceneShaderData::DEPTH_TEST_ENABLED;
scene_state.current_depth_draw = GLES3::SceneShaderData::DEPTH_DRAW_OPAQUE;

and here:

if (scene_state.current_depth_draw != shader->depth_draw) {
switch (shader->depth_draw) {
case GLES3::SceneShaderData::DEPTH_DRAW_OPAQUE: {
glDepthMask(p_pass_mode == PASS_MODE_COLOR);
} break;
case GLES3::SceneShaderData::DEPTH_DRAW_ALWAYS: {
glDepthMask(GL_TRUE);
} break;
case GLES3::SceneShaderData::DEPTH_DRAW_DISABLED: {
glDepthMask(GL_FALSE);
} break;
}
scene_state.current_depth_draw = shader->depth_draw;
}

The behaviour of DEPTH_DRAW_OPAQUE changes depending on if we are in the transparent pass or in the Opaque pass. Further, the setting doesn't get updated unless another depth draw type is used.

#75063 is fixed just by setting the default depth draw mode to DEPTH_DRAW_ALWAYS before the opaque pass. However, a similar issue would arise if there were opaque objects in the scene. Therefore, the full solution is to ensure that the depth mode defaults to DEPTH_DRAW_DISABLED before the transparent pass so the glMask() state is correctly set regardless of what states were used in the opaque pass.

This PR also removes a check for the depth test state that was totally unnecessary as the state was set immediately after.

@clayjohn clayjohn added this to the 4.1 milestone Apr 12, 2023
@clayjohn clayjohn requested a review from a team as a code owner April 12, 2023 04:22
@akien-mga akien-mga merged commit 6e0c7d6 into godotengine:master Apr 12, 2023
@akien-mga

Copy link
Copy Markdown
Member

Thanks!

@YuriSizov

Copy link
Copy Markdown
Contributor

Cherry-picked for 4.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sorting is broken in compatibility pipeline

4 participants