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

Subviewport is duplicating itself when screen shader is used #92058

Closed
starblinky opened this issue May 17, 2024 · 1 comment
Closed

Subviewport is duplicating itself when screen shader is used #92058

starblinky opened this issue May 17, 2024 · 1 comment

Comments

@starblinky
Copy link

starblinky commented May 17, 2024

Tested versions

Reproducible in v4.2.2.stable.official [15073af] and v4.3 -dev6 beta

System information

Mac OS Sonoma 14.4.1 (23E224)

Issue description

When using a screen-shader in a SubViewPort there is a double image. The SubViewPort will draw the original texture (pre-shader) and then draw AGAIN with the shader effect on top.

Screenshot 2024-05-17 at 12 09 30 PM

If you select "Transparent Background" the original texture (pre-shader) no longer shows. But now the background is no longer transparent. I can work around this by setting the grey colour alpha to 0 within a shader, but this isn't ideal solution for me.

Steps to reproduce

Screenshot 2024-05-17 at 12 03 00 PM

Shader code:

shader_type canvas_item;

uniform sampler2D tex : repeat_enable;
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap;
void fragment() {

	vec4 noiseTex = texture(tex, UV + TIME * 0.2);
	vec4 mainTex = texture(SCREEN_TEXTURE, SCREEN_UV + noiseTex.r);

	COLOR = mainTex;
}

Create a Noise Texture for the shader:

Screenshot 2024-05-17 at 12 20 13 PM

Minimal reproduction project (MRP)

DuplicationBug for Github.zip

@clayjohn
Copy link
Member

clayjohn commented Jun 8, 2024

Thank you for your report. I have tested locally and confirmed that this is the expected behaviour for what you are doing.

Screen reading textures simply copy the screen below them. When you use them to draw, they are just drawing over top the thing they just copied. Godot doesn't clear the area underneath.

When you use an opaque viewport with this shader you can obscure the old texture with the background color. But when using a transparent background, it is more obvious that the second sprite is simply drawing over the first sprite.

If you change your background to something other than flat gray, you would notice this same problem even using an opaque viewport.

Based on your description, it sounds like what you actually need is a second Viewport. Instead of using a screen reading shader you can pass the results of the Viewport to a custom shader using a ViewportTexture.

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

No branches or pull requests

3 participants