1+ void mainImage( out vec4 fragColor, in vec2 fragCoord )
2+ {
3+ // Correct aspect ratio
4+ vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
5+
6+ // Background gradient
7+ vec3 col = mix(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 0.4), uv.y * 0.5 + 0.5);
8+
9+ // Light source direction
10+ vec3 lightDir = normalize(vec3(-10.0, -10.0, 20.0));
11+
12+ // Sphere properties
13+ float sphereRadius = 0.20;
14+ vec3 sphereColors[3] = vec3[](vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
15+
16+ // Time factor for rotation
17+ float time = iTime * 0.5;
18+
19+ // Draw each sphere
20+ for(int i = 0; i < 3; i++) {
21+ float angle = time + float(i) * 2.0944; // 120 degrees apart
22+ vec2 position = vec2(sin(angle), cos(angle)) * sphereRadius * 2;
23+
24+ // Sphere shading
25+ float dist = length(uv - position);
26+ if(dist < sphereRadius) {
27+ float diff = dot(lightDir, normalize(vec3(position - uv, sqrt(sphereRadius * sphereRadius - dist * dist))));
28+ diff = clamp(diff, 0.0, 1.0);
29+
30+ // Combine sphere color with light intensity and background
31+ col = mix(col, sphereColors[i] * diff, smoothstep(sphereRadius, sphereRadius - 0.03, dist));
32+ }
33+ }
34+
35+ // Output to screen
36+ fragColor = vec4(col,1.0);
37+ }
0 commit comments