Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rxadmin opened this issue Jun 23, 2018 · 4 comments

Comments

@rxadmin
Copy link

rxadmin commented Jun 23, 2018

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
Copy link
Member

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

@clayjohn
Copy link
Member

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
Copy link
Member

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

@clayjohn
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants