Skip to content

Instantly share code, notes, and snippets.

@simonecesano
Created October 7, 2021 16:44
Show Gist options
  • Save simonecesano/f4c2d2acecf5a8b7a0277b0431dc1384 to your computer and use it in GitHub Desktop.
Save simonecesano/f4c2d2acecf5a8b7a0277b0431dc1384 to your computer and use it in GitHub Desktop.
uniform sampler2D texture;
uniform vec2 texSize;
varying vec2 texCoord;
uniform float degrees;
const float PI = 3.1415926535897932384626433832795;
const vec2 HALF = vec2(0.5);
float deg2rad(float deg){ return deg * PI / 180.0; }
void main() {
vec2 coord = texCoord.xy;
float aspect = texSize.x / texSize.y;
float sin_factor = sin(deg2rad(degrees));
float cos_factor = cos(deg2rad(degrees));
mat2 rotMat = mat2(cos_factor, sin_factor, -sin_factor, cos_factor);
mat2 scaleMat = mat2(aspect, 0.0, 0.0, 1.0);
mat2 scaleMatInv = mat2(1.0 / aspect, 0.0, 0.0, 1.0);
vec2 tc = coord;
coord -= HALF.xy;
coord = scaleMatInv * rotMat * scaleMat * coord;
coord += HALF.xy;
vec4 color = texture2D(texture, coord);
float grey = 0.299 * color.r + 0.587 * color.g + 0.114 * color.b;
gl_FragColor = vec4(color);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment