#(Godot4) Sampling GradientTexture1D at UV.x = 0 seemingly results in wrapped value from UV.x = 1

14 messages · Page 1 of 1 (latest)

quiet aurora
#

Hello, was working on a color ramp for toon shading and realized an issue I was having was because a call to texture(gradient1D, vec2) where vec2 was (0, 0) was resulting in seemingly the last value in the ramp instead of the first as I was expecting

a simple MeshInstance3D Plane with a ShaderMaterial with the following shader code

shader_type spatial;
render_mode unshaded;

uniform sampler2D ramp;

void fragment() {
    float ramp_value = texture(ramp, vec2(0.0, 1)).r;
    ALBEDO = vec3(ramp_value);
}

Here, sampling at 0.0 results in the entire Plane being white though I would expect it to be black.

I wanted to post here in case I had a misunderstanding on how things are working with Godot 4 or if this is perhaps a bug, I didn't find anything on the issue tracker. the same setup in godot 3.5 produces the result I expect.

#

using UV.x in the texture sample results in a white line where I assume UV.x is Zero

#
shader_type spatial;
render_mode unshaded;

uniform sampler2D ramp;

void fragment() {
   
    float ramp_value = texture(ramp, vec2(UV.x, 0)).r;
    ALBEDO = vec3(ramp_value);
}
#

Best I could do to work around this was clamp the x input to 0.001

#
    float clamped_x = clamp(UV.x, 0.001, 1);
    float ramp_value = texture(ramp, vec2(clamped_x, 0)).r;
#

(Godot4) Sampling GradientTexture1D at UV.x = 0 seemingly results in wrapped value from UV.x = 1

sly rain
#

Looks like a bug, but I am unaware of how this feature works so I couldn't say for sure

quiet aurora
#

Whoops, figured it out, good thing I decided to sleep on it, it seems GradientTextures are set to repeat by default now and can be fixed with a shader hint

#

The expected result, all is right with the world

#

probably should have tried this before the clamping strat but I guess I'm still learning lol

sly rain
#

Nice, you should mark this as solved