Created
January 16, 2018 23:24
-
-
Save ayamflow/c06bc0c8a64f985dd431bd0ac5b557cd to your computer and use it in GitHub Desktop.
Rotate UV in GLSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Compute cos()/sin() once.
vec2 rotateUV(vec2 uv, float rotation)
{
float mid = 0.5;
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
return vec2(
cosAngle * (uv.x - mid) + sinAngle * (uv.y - mid) + mid,
cosAngle * (uv.y - mid) - sinAngle * (uv.x - mid) + mid
);
}
vec2 rotateUV(vec2 uv, float rotation, vec2 mid)
{
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
return vec2(
cosAngle * (uv.x - mid.x) + sinAngle * (uv.y - mid.y) + mid.x,
cosAngle * (uv.y - mid.y) - sinAngle * (uv.x - mid.x) + mid.y
);
}
vec2 rotateUV(vec2 uv, float rotation, float mid)
{
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
return vec2(
cosAngle * (uv.x - mid) + sinAngle * (uv.y - mid) + mid,
cosAngle * (uv.y - mid) - sinAngle * (uv.x - mid) + mid
);
}
#pragma glslify: export(rotateUV)
<3
<3
<3
<3
<3
👍
<3
🙏
<3
<3
<3
♡
<3
<3
<3
<3
❤️
Compute cos()/sin() once.
vec2 rotateUV(vec2 uv, float rotation) { float mid = 0.5; float cosAngle = cos(rotation); float sinAngle = sin(rotation); return vec2( cosAngle * (uv.x - mid) + sinAngle * (uv.y - mid) + mid, cosAngle * (uv.y - mid) - sinAngle * (uv.x - mid) + mid ); } vec2 rotateUV(vec2 uv, float rotation, vec2 mid) { float cosAngle = cos(rotation); float sinAngle = sin(rotation); return vec2( cosAngle * (uv.x - mid.x) + sinAngle * (uv.y - mid.y) + mid.x, cosAngle * (uv.y - mid.y) - sinAngle * (uv.x - mid.x) + mid.y ); } vec2 rotateUV(vec2 uv, float rotation, float mid) { float cosAngle = cos(rotation); float sinAngle = sin(rotation); return vec2( cosAngle * (uv.x - mid) + sinAngle * (uv.y - mid) + mid, cosAngle * (uv.y - mid) - sinAngle * (uv.x - mid) + mid ); }
Compute point once:
vec2 rotateUV(vec2 uv, float rotation)
{
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
vec2 p = uv - vec2(0.5);
return vec2(
cosAngle * p.x + sinAngle * p.y + 0.5,
cosAngle * p.y - sinAngle * p.x + 0.5
);
}
vec2 rotateUV(vec2 uv, float rotation, vec2 mid)
{
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
vec2 p = uv - mid;
return vec2(
cosAngle * p.x + sinAngle * p.y + mid.x,
cosAngle * p.y - sinAngle * p.x + mid.y
);
}
vec2 rotateUV(vec2 uv, float rotation, float mid)
{
float cosAngle = cos(rotation);
float sinAngle = sin(rotation);
vec2 p = uv - vec2(mid);
return vec2(
cosAngle * p.x + sinAngle * p.y + mid,
cosAngle * p.y - sinAngle * p.x + mid
);
}
#pragma glslify: export(rotateUV)
💙
<3
<3
<3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3