godotengine / godot

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

shader on gui element is applied to geometry and text - probably missing z value #19736

Open rxadmin opened 6 years ago

rxadmin commented 6 years ago

Godot version: 3.0.3

OS/device including version: Windows, 7, 32-bit, Intel HD graphics (coming with Lenovo L570).

Issue description: In 2D: added a ShaderMaterial to a button. The shader code is below. This creates a red rectangle on the left of the button. However, some characters in on the button text also had a red rectangle. Experimenting with different text strings I noticed it was always on the same characters. Changing to a different font I noticed it was on different characters. My best guess here is that the characters showing this effect had the required UV.x value, that is, they were locate on the left edge of the corresponding bitmap holding th characters.

/// code shader_type canvas_item;

void fragment() { vec4 c = texture(TEXTURE, UV); if ((UV.x < 0.1)) { COLOR.rgba = vec4(1.0, 0.0, 0.0, 1.0); } else { COLOR = c; } }

expected behaviour To the minimum: it should be possible to distinguish in the shader between the various layers that make up a gui element - in the sample project, I used a button with som text so the expected behaviour here would be to have the text on a different layer than the button geometry - so a z-value should be needed.

Better would be to allow for different shaders on gui elements. It makes sense to do this since you can then apply different effects on gui background and the gui front.

Minimal reproduction project:

shadertest.zip

akien-mga commented 5 years ago

Still reproducible in the current master branch, but I'm not sure if it's a bug or intended behaviour. CC @clayjohn

clayjohn commented 5 years ago

This is intended behaviour. I agree it is not ideal, I have been frustrated in the past trying to write a custom shader for text. But right now this is just a limitation of the engine.

akien-mga commented 4 years ago

@clayjohn I guess we should just document it then to close this issue?

clayjohn commented 4 years ago

I'm not sure. I guess we should for 3.2.

The issue arises because we hijack UV1 to use for text, a better solution would be for text to have an optional TEXT_UV. I don't know how the 2D API has changed in 4.0. this may already be fixed, or it may be easy to fix.