godotengine / godot

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

Glitch in shader when using screen_texture and Compatibility mode: pink gridded lines #79914

Open fguillen opened 1 year ago

fguillen commented 1 year ago

Godot version

4.1.1.stable

System information

MacOS - Ventura 13.1 - Godot 4.1.1.stable

Issue description

When in a shader I use screen_texture:

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

and Compatibility mode. In many cases, a gridded pink lines appear:

Screenshot 2023-07-26 at 08 07 41

In Forward+ mode: Screenshot 2023-07-26 at 08 01 03

In Mobile mode: Screenshot 2023-07-26 at 08 01 31

In Compatibility mode: Screenshot 2023-07-26 at 08 01 55

Steps to reproduce

Add this shader to a ColorRect in an independent CanvasLayer:

shader_type canvas_item;

uniform int amount = 40;
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

void fragment()
{
    vec2 grid_uv = round(SCREEN_UV * float(amount)) / float(amount);
    vec4 text = texture(screen_texture, grid_uv);
    COLOR = text;
}

Minimal reproduction project

TestingShaderGlitch.zip

TZer0 commented 10 months ago

Also applies to v4.1.3.stable.mono.official [f06b6836a] (only compatibility mode, Forward works fine)

This is a very strange bug as it stops happening in the scene view in the editor if you turn off filter_nearest for a moment and then turn it back on. The bug is always visible in the material view.

pirey0 commented 4 months ago

As a workaround: Using vec4 text = textureLod(screen_texture, grid_uv ,0.0) instead of vec4 text = texture(screen_texture, grid_uv) fixes the issue for me on v4.2.2

clayjohn commented 1 month ago

I can only reproduce this in 4.1.4 (I tested 4.3, 4.2.2, 4.2.1, 4.2.0, and 4.1.1)

Given the nature of the issue though, I'm not convinced that it is necessarily fixed. I have a feeling that https://github.com/godotengine/godot/pull/96502 may fix it though