Below is a GLSL fragment shader written in Shadertoy syntax. This shader generates a realistic, animated cloud effect that appears to grow over time. I've incorporated a baroque-inspired color palette, drawing from rich, dramatic colors like deep blues, purples, golds, and warm pinks to give it an ornate, artistic feel.
Key Features:
- Cloud Simulation: Uses fractal Brownian motion (fBm) based on a simple 2D noise function to create fluffy, volumetric clouds. The noise is animated and scaled over time to simulate growth.
- Animation and Growth: The clouds evolve by offsetting and scaling the noise input with
iTime, making them expand outward from the center while subtly moving.
- Baroque Color Palette: The noise value is mapped to a gradient inspired by baroque art. Low densities blend into dark, moody blues (like a dramatic sky), mid-densities shift to rich purples and crimsons, and high densities peak at golden and pinkish hues for a luxurious, ornate effect.
- Realism Enhancements: Adds basic lighting and density thresholding to make the clouds look more volumetric and soft-edged.
To use this in Shadertoy:
- Copy the code into the Shadertoy editor.
- Run it to see the effect. The clouds will grow and animate over time.
// Shadertoy-compatible GLSL fragment shader
// Hash function for generating pseudo-random noise
float hash(vec2 p) {
return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
}
// 2D noise function based on hash
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f); // Smoothstep for interpolation
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
// Fractal Brownian Motion (fBm) for cloud-like noise
float fbm(vec2 p) {
float value = 0.0;
float amplitude = 0.5;
for(int i = 0; i < 6; i++) { // 6 octaves for detailed clouds
value += amplitude * noise(p);
p *= 2.0; // Increase frequency
amplitude *= 0.5; // Decrease amplitude
}
return value * 0.5 + 0.5; // Normalize to [0, 1]
}
// Baroque-inspired color palette function
vec3 baroquePalette(float t) {
// t is in [0, 1]
// Gradient: Dark blue (sky) -> Purple/crimson -> Gold/pink
vec3 color1 = vec3(0.05, 0.1, 0.3); // Deep, moody blue
vec3 color2 = vec3(0.4, 0.1, 0.4); // Rich purple
vec3 color3 = vec3(0.9, 0.7, 0.2); // Golden hue
vec3 color4 = vec3(1.0, 0.6, 0.7); // Warm pink for highlights
if (t < 0.33) return mix(color1, color2, t / 0.33); // Blue to purple
if (t < 0.66) return mix(color2, color3, (t - 0.33) / 0.33); // Purple to gold
return mix(color3, color4, (t - 0.66) / 0.34); // Gold to pink
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// Normalized and centered UV coordinates
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float time = iTime * 0.2; // Slow animation speed
// Add growth effect: Scale and offset UV based on time
float growthScale = 1.0 + time * 0.1; // Gradually increase scale for growth
vec2 animatedUV = uv * growthScale + vec2(sin(time * 0.5), cos(time * 0.5)) * 0.1; // Offset for subtle movement
// Sample fBm noise with animation
float noiseVal = fbm(animatedUV + vec2(time * 0.05)); // Time-based offset for animation
// Add simple lighting for realism: Fake a light direction
vec2 grad = vec2(
fbm(animatedUV + vec2(0.01, 0.0)) - fbm(animatedUV - vec2(0.01, 0.0)),
fbm(animatedUV + vec2(0.0, 0.01)) - fbm(animatedUV - vec2(0.0, 0.01))
);
float lighting = dot(grad, vec2(0.5, 0.5)); // Simple diffuse lighting
lighting = 0.5 + 0.5 * lighting; // Normalize to [0, 1]
// Threshold noise for cloud density and apply lighting
float density = smoothstep(0.3, 0.7, noiseVal); // Clouds only where noise is sufficiently high
density *= lighting; // Modulate by lighting for volume
// Map density to baroque palette
vec3 cloudColor = baroquePalette(density);
// Blend with a baroque-inspired background (e.g., a dark, dramatic sky)
vec3 backgroundColor = vec3(0.02, 0.05, 0.1); // Very dark blue for contrast
vec3 finalColor = mix(backgroundColor, cloudColor, density); // Blend based on density
fragColor = vec4(finalColor, 1.0);
}
Explanation:
- Noise and fBm: The
noise function generates basic 2D noise, and fbm layers it to create the fractal patterns typical of clouds. This results in soft, turbulent shapes.
- Animation and Growth:
growthScale increases with iTime, making the UV coordinates scale up, which simulates clouds expanding from the center.
- An offset based on sine and cosine functions adds gentle, swirling movement.
- Color Mapping: The
baroquePalette function interpolates between a custom gradient of colors. This ensures the clouds have a rich, dramatic appearance rather than plain white.
- Realism Touches:
- Density Thresholding: Only areas with sufficient noise value are rendered as clouds, creating defined shapes with soft edges.
- Lighting: A simple gradient-based normal approximation adds shading, making the clouds look more 3D and volumetric.
- Performance: This shader uses a moderate number of octaves in fBm (6) to balance detail and speed. If it's too slow on your hardware, reduce it to 4 or 5.
When you run this in Shadertoy, you'll see clouds that start small and grow while shifting colors in a baroque style. Feel free to tweak parameters like the animation speed or color gradients to refine it further!