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
Incorrect texture UV for Label #23210
Comments
I get 404 on the example project |
Probably because some form of texture caching or a texture atlas (character map) is implemented in which case this would be expected. |
UV is used to determine which character to draw. So UV value for fonts corresponds to a particular color. This issue will be fixed by #32861 |
Still valid in 6c173e2 |
Considering text is drawn as many rectangles of various sizes, I'm not sure if
So I think adding more information to text shaders would make this is an enhancement rather than a bug. |
I'm having this issue as well; are there any known workarounds? |
Other than using a separate Viewport and applying a shader on the viewport, I can't think of any. |
You don't always need UVs do make a drop shadow. The problem you have is different. With labels, the target rectangle in the world used to draw each letter does not bleed further than the letters area. To do what you want with a shader, it requires a larger drawing area, like a margin, which is probably not possible because you risk drawing parts of different letters from the characters atlas. You might be able to extend the drawing area with the shader (assuming you can tell which vertices of the quad belong to which corner, not sure how you can do that), but at this point you would have to instruct the font importer to put more empty space between characters of the atlas (there are options for extra spacing on DynamicFont but they dont seem to do that). Another way to do drop shadow is to just duplicate the label with a dark color behind the first label. I also see options for "shadow" in the Label's "custom constants" but I have no idea how they work, they don't seem to do anything. But that would be a better option than duplicating. |
In the Label's Custom Constants section, you need to set Shadow Offset X and/or Y to non-zero values, then in the Custom Colors section, set a shadow color with an alpha component greater than 0. Shadow As Outline should be kept to 0 (it's a legacy outline system that will likely be removed in 4.0). This gives you the same visual ressult as using a second Label node, but it doesn't require you to update the position/text of both nodes manually. |
Now I understand why even with the changes of this pull #32861 my shader doesn't work, even if I can get the whole label uv, the shader will work only inside this rectangles. I will assume this thing was designed with optimization in mind (draw only on character size), but this thing makes impossible to do very cool shaders not only the dropshadow, outline shaders based too. I confess I don't understand anything about how texts are rendered in game engines but I'll ask, make a proposal to have a different text node having one rectangle for all text focused to receive shaders like this is ridiculous? |
Outlines are supported natively in DynamicFont, so you don't need a shader to draw one 🙂 If you need more than one outline, see godotengine/godot-proposals#2564. It may be possible to use two Label nodes, one with a different DynamicFont each (each with its own outline style).
This may be achievable with the CanvasGroup node in Godot 4.0. |
You don't have to use an opaque color for the shadow. You can use a translucent color with alpha < 1.0. It will still be a hard shadow, but it will look softer and less harsh overall. |
inspired by #32861 (comment), you can do: varying vec2 full_uv;
void vertex () {
full_uv = VERTEX.xy;
}
void fragment() {
COLOR.a = texture(TEXTURE, UV).a;
COLOR.g = full_uv.x / 20.0;
} with the caveat that the size of the rect needs to be passed in the shader (via an uniform): |
I'm on 4.2 and VERTEX.xy only provides (0,0) in the vertex function. Am I missing something, or does this workaround no longer work? |
Godot version:
3.0.6
OS/device:
Windows 8.1, Toshiba Satellite
Issue description:
For shaders attached to Labels, UV is not as expected. If you attach a shader to a Label and try to do a simple vertical gradient on it, UV.y = 1.0 does not correspond to the bottom of the Label.
Steps to reproduce:
Minimal reproduction project:
ExampleProject.zip
The text was updated successfully, but these errors were encountered: