godotengine / godotengine/godot

CanvasGroup custom shaders are always clipped to screen size because of screen texture

Open
#89,341 0 comments 1 reaction 0 assignees View on GitHub
enhancement feature proposal topic:rendering
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.2.2 rc1

### System information

Windows 10, amd rx 480 gpu

### Issue description

When writing a custom material shader for a CanvasGroup, it's not possible to access texels outside of the screen. Trying to do so results in reading edge-clamped data, because the screen texture is mapped to the screen rather than the calculated area of the CanvasGroup's children.

The margin properties don't help here.

This could be fixed by https://github.com/godotengine/godot-proposals/issues/6506 ("Allow canvas groups to be used as textures"). However, because it makes certain full-screen custom shaders on CanvasGroups impossible, I think this is a bug or design mistake that needs to be fixed rather than a feature request.

### Steps to reproduce

Create a CanvasGroup with contents extending outside of the screen and add a custom shader material that zooms out. The edges will be clamped. For example:

```glsl
shader_type canvas_item;
uniform sampler2D screen_texture : hint_screen_texture, repeat_enable;
void fragment() {
vec2 uv = SCREEN_UV;
uv -= vec2(0.5);
uv *= 2.0;
uv += vec2(0.5);
vec4 tex = textureLod(screen_texture, uv, 0);
tex.a = 1.0;
COLOR = tex * COLOR;
}
```

![Godot_v4 2 2-rc1_win64_2024-03-09_18-34-13](https://github.com/godotengine/godot/assets/585488/8c9124fa-116d-4551-b7e0-73ded6f8d4d7)

### Minimal reproduction project (MRP)

[CanvasRepro.zip](https://github.com/godotengine/godot/files/14548148/CanvasRepro.zip)
![Godot_v4 2 2-rc1_win64_2024-03-09_18-44-14](https://github.com/godotengine/godot/assets/585488/00c9f4b8-76f3-4da7-a60e-057a6396230f)

Contributor guide

Open the contributing guide

Research direction

Start by opening the attached CanvasRepro.zip in Godot and run the reported CanvasGroup shader reproduction. Inspect the screen-texture behavior for content extending beyond the viewport; done means the shader can sample outside the screen without edge-clamped results.

Written by the indexing model from the issue text.

Assessment

Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.