-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Screen texture alpha of transparent viewport is always 1.0 when sampled in shaders #78207
Comments
OK, went down a rabbit hole first looking at this logic in the 3D pipeline, which works as advertised. This issue is in the 2D pipeline and looks intentional. The offending code is in
Note all the default parameters being passed so However seeing this effort is done my conclusion is that there must be a reason to set alpha to 1, possibly so the gaussian blur logic works correctly when populating the miplevels (which are used for various effects that also use the back buffer). So fixing this may have negative flow on effects. We'll need to investigate why alpha is removed here to ensure this is fixed in a way that we can retain our alpha values. cc @clayjohn |
We probably need to add explicit support for a transparent viewport to all the screen effects. That's what we ended up doing in 3.x, but we did it after the split between 3.x and 4.x so not everything got carried over |
I had the same problem, how did you solve it? |
In this particular use case, I solved it by using 2 alternating viewports instead of a single one. |
Do note that this behavior is completely fine when using the opengl renderer, the vulkan one is the one with the issues |
This is still an issue in v4.3.dev6.mono.official [89850d5]. I'm attempting to have a screen-reading shader applied to all embedded subwindows (so tooltips can receive the shader as well), and alpha is always 1. This means that when I apply the shader to tooltips (for example), they will end up having black corners: Recording.2024-05-02.210727.mp4 |
Godot version
Godot 4.0.3, Forward+
System information
Windows 10 64 bits NVIDIA GeForce GTX 1060
Issue description
I use a transparent viewport in which I need to read all 4 components of the previously rendered frame. I do this by sampling a
uniform sampler2D u_screen_texture : hint_screen_texture;
in a shader.But even though the viewport is transparent, the alpha I get from the screen texture is always 1.0. I expected the alpha component to not be cleared.
Note:
In my project, the viewport renders twice or more and never clears. The first render draws something transparent, and the second render draws something else that makes use of the screen texture.
The image I get just after the first render with
viewport.get_texture().get_image()
has correct alpha (I did not include that in the MRP, needs more work), but the result of the second render shows that this alpha hasn't been preserved in the screen texture.Steps to reproduce
Render a 3D scene that would normally render transparent, and add a sprite on top with a shader that renders the screen texture. It should not show a difference, but currently it makes the environment "appear" while it should not have (and should never have been rendered to begin with, but was rendered anyways, perhaps a different problem).
Note: in my project I don't use 3D, but the problem is the same.
Minimal reproduction project
ScreenTextureAlpha.zip
The text was updated successfully, but these errors were encountered: