Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix fragcolor write locations in scene shaders #92070

Merged
merged 1 commit into from
May 20, 2024

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented May 18, 2024

This will need careful checking by @clayjohn as I'm not super familiar with all the parts of the scene shaders.

Fixes #91967

Discussion

In retrospect, I'm not totally surprised I got these in slightly the wrong place, the #ifdef arrangements especially in the scene shaders are very difficult to follow (manually). I would welcome suggestions for glsl editor that will follow them sensibly, geany can identify from opening, but not from closing. Other than that I'm relying on find_in_files.

What makes things particularly difficult is that the comments in the scene shaders appear to be out of sync:

// scene.glsl line 2464
#endif //RENDER_DEPTH //ubershader-runtime

presumably should be not RENDER_DEPTH.

This appears to have happened several times in the shaders because files originally contained e.g.

#ifdef RENDER_DEPTH
#endif // RENDER_DEPTH

then an #else was inserted, and the ending comment became incorrect.

I suspect these shaders could do with a second pass PR correcting these comments (I haven't done in the same PR as it seems two different problems).

Additionally, I worked out that RENDER_DEPTH seems actually for the z pre-pass and shadow maps. If so perhaps a better define would be RENDER_DEPTH_ONLY, because depth is also rendered during normal passes, so the define is confusing.

Also, //ubershader-runtime seems to be put on every closing #endif, and I have no idea why, perhaps I can figure out from the ubershader PR. 馃榿

// Use a temporary in the rest of the shader.
// This is for drivers that have a performance drop
// when the output is read during the shader.
gl_FragColor = frag_color;
Copy link
Member Author

@lawnjelly lawnjelly May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this because it turns out RENDER_DEPTH is actually depth only pass, and we don't want to write to color in depth only pass.

(TURNS OUT - unless we are using RGBA shadows 馃榾 ).

// Write to the final output once and only once.
// Use a temporary in the rest of the shader.
// This is for drivers that have a performance drop
// when the output is read during the shader.
frag_color_final = frag_color;

#endif //USE_MULTIPLE_RENDER_TARGETS //ubershader-runtime
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment may be incorrect, should be // not USE_MULTIPLE_RENDER_TARGETS...

// Write to the final output once and only once.
// Use a temporary in the rest of the shader.
// This is for drivers that have a performance drop
// when the output is read during the shader.
frag_color_final = frag_color;

#endif //USE_MULTIPLE_RENDER_TARGETS //ubershader-runtime

#endif //RENDER_DEPTH //ubershader-runtime
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems incorrect, should be // not RENDER_DEPTH_ONLY.

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. The problem comes from here where we define diffuse_buffer to be frag_color:

#define diffuse_buffer frag_color

So the main output of the shader ultimately writes to frag_color (our intermediate color value). Accordingly, we need to assign it to frag_color_final outside the branch

@lawnjelly
Copy link
Member Author

Fixed one last tweak neither of us noticed - the GLES2 change would have broken RGBA shadows because it never wrote to glFragColor in the very last section 馃槉 .

Have fixed this.

@lawnjelly lawnjelly merged commit 6c2870d into godotengine:3.x May 20, 2024
14 checks passed
@lawnjelly lawnjelly deleted the fix_fragcolor_write branch May 20, 2024 19:46
@lawnjelly
Copy link
Member Author

Thanks!

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.

None yet

2 participants