godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.56k stars 21.09k forks source link

Vulkan: Sky not blurred by textureLod shader #61969

Open bramreth opened 2 years ago

bramreth commented 2 years ago

Godot version

4.0.a9

System information

Windows 10, NVidia 2070 Super, Vulkan

Issue description

When blurring the screen with a textureLod shader I noticed the sky wasn't blurring with the rest of the meshes in my scene as of alpha 9.

image

The attached projects works as expected in alpha 8, but not in alpha 9.

blur

Steps to reproduce

Add a world environment and camera to a scene, point the camera at a mesh so the background environment is visible.

Add a TextureRect that covers the screen and add a shader that uses the textureLod function to blur the screen.

shader_type canvas_item;

void fragment() {
    vec4 t = textureLod(SCREEN_TEXTURE, SCREEN_UV, 4.0);
    // I also darken it to make the changes more visible
    t.rgb *= 0.5;
    COLOR = t;
}

Minimal reproduction project

BrokenBlur.zip

Calinou commented 2 years ago

cc @clayjohn

clayjohn commented 2 years ago

Looks like it is caused by https://github.com/godotengine/godot/pull/61109

CC @Chaosus and @BastiaanOlij

The BackBuffer somehow ends up with an alpha of 0 so when applied over the original scene it adds nothing.

A temporary workaround until this bug is fixed is to ignore the alpha channel in your shader. i.e. add COLOR.a = 1.0 at the end.

Chaosus commented 2 years ago

I don't know yet how to fix this bug but my intuition say me that #61109 is correct and the problem is somewhere else (it only make it visible).

clayjohn commented 2 years ago

I don't know yet how to fix this bug but my intuition say me that #61109 is correct and the problem is somewhere else (it only make it visible).

The trouble is that during the main rendering pass, we allow writing to the alpha channel of the backbuffer texture It is just ignored later on if transparent background is disabled. We had the same issue in the 3.x branch and I ended up fixing by adding an IGNORE_ALPHA shader version that would be used when transparent background is disabled.

The other solution is to do a comprehensive audit of our alpha rendering pass and ensure that alpha is not written to when transparent background is disabled

clayjohn commented 1 year ago

This is still a problem in RC3. We need to disable copying the alpha channel of the 3D buffer to the 2D buffer when the viewport is not transparent