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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues with blend modes in OpenGL 3 renderer #77409

Merged
merged 1 commit into from
May 24, 2023

Conversation

allenwp
Copy link
Contributor

@allenwp allenwp commented May 23, 2023

Added uses_blend_alpha = true for ADD, SUBTRACT, and MULTIPLY blend modes to match the other renderers.

Fixes #76334

@allenwp allenwp requested a review from a team as a code owner May 23, 2023 20:25
@akien-mga akien-mga added this to the 4.1 milestone May 23, 2023
drivers/gles3/storage/material_storage.cpp Outdated Show resolved Hide resolved
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
glBlendEquation(GL_FUNC_SUBTRACT);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this. In Godot BLEND_MODE_SUB means that the color from the pixel shader is subtracted from the color behind it. That corresponds to GL_FUNC_REVERSE_SUBTRACT. GL_FUNC_SUBTRACT subtracts the background color from the pixel shader color and returns that value.

I.e. if you want to write a white pixel to a grey background with GL_FUNC_REVERSE_SUBTRACT you get (0.5, 0.5, 0.5) - (1, 1, 1,) = (0, 0, 0) while with GL_FUNC_SUBTRACT you get (1, 1, 1) - (0.5, 0.5, 0.5) = (0.5, 0.5, 0.5)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I see that the OpenGL renderer has always used GL_FUNC_REVERSE_SUBTRACT for BLEND_MODE_SUB. Thanks for pointing this out! I will remove this from the PR.

The reason that I initially made this change was to match the behaviour of the other two renderers in Godot 4 which use BLEND_OP_SUBTRACT instead of BLEND_OP_REVERSE_SUBTRACT:

blend_attachment.alpha_blend_op = RD::BLEND_OP_SUBTRACT;
blend_attachment.color_blend_op = RD::BLEND_OP_SUBTRACT;

blend_attachment.alpha_blend_op = RD::BLEND_OP_SUBTRACT;
blend_attachment.color_blend_op = RD::BLEND_OP_SUBTRACT;

attachment.alpha_blend_op = RD::BLEND_OP_SUBTRACT;
attachment.color_blend_op = RD::BLEND_OP_SUBTRACT;

I will open a different issue sometime later regarding the inconsistency of BLEND_MODE_SUB when using different renderers in Godot 4.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good catch. So it seems the RD backends are reversed. That actually explains some things

@clayjohn
Copy link
Member

Thanks for taking a look at this. It is super helpful to have others working on the opengl backend

@allenwp
Copy link
Contributor Author

allenwp commented May 24, 2023

Thanks for taking a look at this. It is super helpful to have others working on the opengl backend

I appreciate this! There's always some challenge with approaching a new open source project, so this feels good to hear. I also believe that one of the top 2 or maybe the top value of a game engine is portability across all devices, including old ones, so the OpenGL backend remains very important.

Added uses_blend_alpha = true for ADD, SUBTRACT, and MULTIPLY blend modes to match the other renderers

Fixes godotengine#76334
@akien-mga akien-mga merged commit 2ab0f17 into godotengine:master May 24, 2023
@akien-mga
Copy link
Member

akien-mga commented May 24, 2023

Thanks! And congrats for your first merged Godot contribution 🎉

@allenwp allenwp deleted the OpenGL3-Blend-Issue76334 branch May 24, 2023 16:48
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.

OpenGL: Blend modes other than Mix don't work unless Depth Draw Mode is set to Never
4 participants