-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Fixed issues with blend modes in OpenGL 3 renderer #77409
Conversation
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); | ||
glBlendEquation(GL_FUNC_SUBTRACT); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
:
godot/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
Lines 221 to 222 in b7032b5
blend_attachment.alpha_blend_op = RD::BLEND_OP_SUBTRACT; | |
blend_attachment.color_blend_op = RD::BLEND_OP_SUBTRACT; |
godot/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
Lines 210 to 211 in b7032b5
blend_attachment.alpha_blend_op = RD::BLEND_OP_SUBTRACT; | |
blend_attachment.color_blend_op = RD::BLEND_OP_SUBTRACT; |
godot/servers/rendering/renderer_rd/renderer_canvas_render_rd.cpp
Lines 2124 to 2125 in b7032b5
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.
There was a problem hiding this comment.
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
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
9b5a28c
to
51f0e36
Compare
Thanks! And congrats for your first merged Godot contribution 🎉 |
Added uses_blend_alpha = true for ADD, SUBTRACT, and MULTIPLY blend modes to match the other renderers.
Fixes #76334