godotengine / godotengine/godot
CanvasGroup custom shaders are always clipped to screen size because of screen texture
- 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;
}
```

### Minimal reproduction project (MRP)
[CanvasRepro.zip](https://github.com/godotengine/godot/files/14548148/CanvasRepro.zip)

Contributor 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