About This Animation
This page demonstrates an animated gradient background created with Three.js and GLSL shaders. The animation uses layered noise patterns to create a dynamic, moody atmosphere.
How It Works
The background uses:
- WebGL through Three.js for GPU-accelerated rendering
- Custom GLSL fragment shaders for the gradient effect
- Fractal Brownian Motion (FBM) for natural-looking noise patterns
- Color blending between four moody color palettes
Press c
to toggle the animation controls and adjust parameters.
Original Prompt
Generate a full-screen Three.js scene featuring a seamlessly looping animated gradient designed for GPU efficiency. The gradient should transition through a spectrum of at least four distinct and vibrant colours in a non-linear and unpredictable way, avoiding simple linear interpolation.
Add it to a standalone HTML page. Use dark moody colors.
Utilise a single plane geometry that fills the viewport and apply a custom ShaderMaterial directly to it to implement this effect. The vertex shader should perform minimal operations, primarily passing through vertex positions. The fragment shader should:
- Use a noise function (such as Perlin or Simplex noise) modulated by a
time
uniform to influence the colour mixing at each pixel, creating a sense of organic flow and subtle visual变化. The noise should introduce unexpected swirls and patterns within the gradient without requiring complex iterative calculations per pixel. - Incorporate a
time
uniform to drive the animation of the gradient, ensuring the colours shift and evolve continuously without repeating obviously. The animation should be achieved through modifications of the noise function or colour mixing based on this uniform, rather than CPU-based updates. The speed and complexity of the animation should be easily adjustable parameters. - Blend between the chosen colours based on a combination of the pixel's screen position and the noise function's output. Aim for a minimal number of texture lookups (ideally none, as the colours are intended to be defined directly in the shader or as uniforms). Experiment with using different noise octaves or combining multiple noise functions with varying frequencies and amplitudes for added complexity, but be mindful of the computational cost per fragment.
- Aim for an aesthetic that evokes a sense of fluidity and subtle chaos, like swirling cosmic gases or shifting auroral displays. The colour transitions should be smooth yet surprising, avoiding harsh lines and predictable cycles. Prioritise mathematical functions and noise for colour generation over complex texture sampling.
- Include comments in the shader code explaining the logic behind the colour mixing and animation, with specific notes on how the design choices contribute to GPU efficiency. The scene should be set up with an orthographic camera to ensure the plane fills the entire screen without perspective distortion. Ensure the animation starts automatically when the scene loads and loops indefinitely. Consider adding basic controls (e.g., via the console) to adjust the animation speed and the intensity of the noise influence via uniforms, minimising CPU-GPU data transfer during animation. Specify the use of low-precision variables in the fragment shader where visually acceptable to reduce GPU load.
Implementation Results
Key Features
- GPU-Efficient Design: The fragment shader does all the heavy lifting while the vertex shader is minimal.
- Four Moody Colors: The gradient transitions between 4 colors in a non-linear way.
- Simplex Noise Implementation: Custom implementation of simplex noise directly in the shader, avoiding external textures.
- Fractal Brownian Motion (FBM): Multiple octaves of noise combined for complex, organic patterns.
- Time-Based Animation: The time uniform drives continuous evolution of the gradient.
- No Texture Lookups: All colors are defined as uniforms in the shader.
Technical Details
Shader Efficiency:
- Uses medium precision where possible (
precision mediump float
) - Parameterized complexity (adjust number of noise octaves)
- Limited iterations in FBM algorithm
Non-Linear Transitions:
- Uses smoothstep for easing between colors
- Multiple noise layers with different parameters
- Coordinate distortion for unpredictable flow
Interactive Controls:
- Press 'c' to show/hide controls
- Adjust animation speed, noise strength, and complexity in real-time