Roating Linear UV Gradients

Decided to do some exploration this morning into linearly accurate rotating uv gradients so that when we rotate the value’s displayed across the quad are normalized correctly between 0 and 1 from every corner.

Traditionally, if we rotate the UVs we end up with values outside of 0-1 in the corners. This method takes the dot product of a cardinal vector2 and the uv value and garuantees scaled linear output. the cardinal vector2 is calculated using a pingpong function for x and y values based on a rotation input.

I plan to use this for future interpolations in uv space

Graph:

Outputs:


r = 0

r = 135

r=200

PingPong function:

void PingPong_float(float input, float maxValue, out float output)
{
    if (maxValue == 0.0)
    {
        output = 0.0f;
    }
    else
    {
        output = abs(frac((input - maxValue) / (maxValue * 2.0)) * maxValue * 2.0 - maxValue);
    }
}

Demos:

6 Likes