Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Created January 16, 2018 23:24
Show Gist options
  • Save ayamflow/c06bc0c8a64f985dd431bd0ac5b557cd to your computer and use it in GitHub Desktop.
Save ayamflow/c06bc0c8a64f985dd431bd0ac5b557cd 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)
@BerryOnGit
Copy link

<3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment