Godot Version
4.5.1-stable
Question
This has me genuinely baffled so any help is immensely appreciated.
I have a texture which is a white square for the sake of testing, on which I have the following shader;
shader_type canvas_item;
render_mode unshaded;
uniform float area_start : hint_range(0.0, 1.0, 0.01) = 0.0;
uniform float area_end : hint_range(0.0, 1.0, 0.01) = 1.0;
void vertex() {
float y = 1.0 - UV.y;
bool inside_region = y >= area_start && y <= area_end;
if (inside_region) {
VERTEX.x += 50.0;
}
}
How I would expect this to work is as follows:
- Get ‘y’ from the UV and invert it, so the bottom of the texture should be 0.0 and the top 1.0.
- ‘inside_region’ should return True only if ‘y’ is within the values between ‘area_start’ and ‘area_end’
- If ‘inside_region’ is True, then offset the texture 50 units to the right.
However, when running this I get the following results:
This is when ‘area_start’ is 0.0 and ‘area_end’ is 1.0.
When ‘area_end’ is any non-one value and ‘area_start’ is 0.0.
When ‘area_end’ is 1.0 and ‘area_start’ is any non-zero value;
And finally, when both ‘area_start’ is not zero and ‘area_end’ is not one.
Now, to me, this makes no sense. How is it sheering gradually when it should be being increased by a fixed amount based on a boolean value? I even tried using the VERTEX.y value alongside a uniform for the node size to get what should be the UV.y value in the case it was wrong inside the vertex() function, but it was the same result as I both did and didn’t expect.
As said at the top of this post this has left me genuinely baffled, I have spent over an hour trying to figure out how this is causing this result and came up empty.
The thing is, when running some simmilar code inside the fragment() function I get what I expect, though I had to invert the UV.y as seen below;
COLOR.r = float(1.0 - UV.y > area_start && 1.0 - UV.y < area_end)
This results in a movable (Based off of ‘area_start’ and ‘area_end’) region which is white while the rest is blue. Why is the vertex() any different?
I want the vertex to apply the offset under the same conditions as the above.
Thanks.




