Skip to content

Instantly share code, notes, and snippets.

@floz
Forked from ayamflow/rotate-uv.glsl
Created January 12, 2021 08:26
Show Gist options
  • Save floz/27550c65b5c2a30ab9455e54f74c29c5 to your computer and use it in GitHub Desktop.
Save floz/27550c65b5c2a30ab9455e54f74c29c5 to your computer and use it in GitHub Desktop.
Rotate UV in GLSL
vec2 rotateUV(vec2 uv, float rotation)
{
float mid = 0.5;
return vec2(
cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,
cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid
);
}
vec2 rotateUV(vec2 uv, float rotation, vec2 mid)
{
return vec2(
cos(rotation) * (uv.x - mid.x) + sin(rotation) * (uv.y - mid.y) + mid.x,
cos(rotation) * (uv.y - mid.y) - sin(rotation) * (uv.x - mid.x) + mid.y
);
}
vec2 rotateUV(vec2 uv, float rotation, float mid)
{
return vec2(
cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,
cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid
);
}
#pragma glslify: export(rotateUV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment