Skip to content

Commit

Permalink
Simplify sphere rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Aug 20, 2024
1 parent ec7ae0d commit 37f18fa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ void main() {
float r = length(vPosition.xy);
float theta = atan(vPosition.y, vPosition.x);

// Rotate with time
theta += 2.0 * M_PI * t/PERIOD_ROTATE;

// If we're outside a disk of radius 1, leave pixel transparent
if (r >= 1.0) {
gl_FragColor = vec4(0.0);
Expand All @@ -33,13 +36,12 @@ void main() {
// on a sphere
r = asin(r);

// Pattern zoom
r = r / ZOOM;

// Convert back to cartesian
vec2 p = vec2(r * cos(theta), r * sin(theta));

// Rotate
float a = 2.0 * M_PI * t/PERIOD_ROTATE;
p *= 1.0/ZOOM * mat2(cos(a), -sin(a), sin(a), cos(a));

// delta in the animation found empirically (though with known period)
float delta = 2.095 + 0.030 * sin(t * 2.0 * M_PI / PERIOD_SHAPE);

Expand All @@ -64,7 +66,7 @@ void main() {

// Add subtle shading
// (light in top-left and dark in bottom right)
rgb -= cos(theta + M_PI/4.0) * r / 15.0;
rgb -= cos(atan(vPosition.y, vPosition.x) + M_PI/4.0) * r / 15.0;

gl_FragColor = vec4(alpha * rgb, alpha);
}

0 comments on commit 37f18fa

Please sign in to comment.