- Home /
Basic Fragment Shader UV offset
I'm trying to get a handle on the basic of working with texture UVs in a fragment shader. I have the following code:
float4 frag (v2f i) : SV_Target
{
float new_UV_value = (uv.x) * offsetValue;
uv.x -= new_UV_value;
return uv.x;
}
Now, offsetValue is a property on the shader, and has the range from -1 to 0. When offsetValue is 0, the resulting image looks like this, a nice smooth gradient.
As offsetValue gets decreased to -1, I assumed that the entire gradient would be squeezed into the left side of the square.
However, when the shader evaluates offsetValue at -1, I get this instead.
So I know I'm doing something wrong, and I assume it's how I'm working with the uv coordinates. Any suggestions on how to fix this would be greatly appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172044im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how can i catch the sky box and do a reflection in object 0 Answers
Why does my shader only shade objects based on their normals in the X axis? 1 Answer
Get distance to camera from CameraDepthTexture 1 Answer
How can I achieve this kind of shading? 1 Answer
Change fragment output color depending on pixel overlaps. 1 Answer