Jupiter

Jupiter

Shader loading...

View Source Code
precision highp float;
precision highp int;

uniform float u_time;        // Elapsed time in seconds
uniform vec2 u_resolution;   // Canvas resolution (width, height)
uniform vec2 u_mouse;        // Mouse position in pixels

// Three.js compatible uniforms
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat3 normalMatrix;

varying vec2 vUv;            // UV coordinates (0-1)

#define PI 3.1415926535897932384626433832795


const float SPEED = 0.15;
const float SCALE = 2.0;
const float COMPLEXITY = 2.0;
const float INTENSITY = 1.5;
const int OCTAVES = 4;
const float FLUID_VISCOSITY = 0.8;
const float FLUID_FORCE = 2.5;

float hash(vec2 p) {
    p = fract(p * vec2(123.34, 456.21));
    p += dot(p, p + 45.32);
    return fract(p.x * p.y);
}

float noise(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f);
    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));
    
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}

float fbm(vec2 p) {
    float value = 0.0;
    float amplitude = 0.5;
    float frequency = 1.0;
    
    for (int i = 0; i < OCTAVES; i++) {
        value += amplitude * noise(p * frequency);
        amplitude *= 0.5;
        frequency *= 2.0;
    }
    
    return value;
}

vec3 palette(float t) {
    vec3 a = vec3(0.5, 0.5, 0.5);
    vec3 b = vec3(0.5, 0.5, 0.5);
    vec3 c = vec3(1.0, 1.0, 1.0);
    vec3 d = vec3(0.3, 0.2, 0.2);
    return a + b * cos(6.28318 * (c * t + d));
}

vec2 fluidInfluence(vec2 uv, vec2 mousePos, float strength) {
    vec2 diff = mousePos - uv;
    float dist = length(diff);
    float falloff = 1.0 / (1.0 + dist * FLUID_VISCOSITY);

    vec2 perpendicular = vec2(-diff.y, diff.x) / (dist + 0.0001);
    vec2 force = diff * falloff * strength;
    return force + perpendicular * falloff * strength * 0.5;
}

void main() {
    vec2 uv = gl_FragCoord.xy / u_resolution.xy;
    vec2 uvNorm = uv * 2.0 - 1.0;
    uvNorm.x *= u_resolution.x / u_resolution.y;
    vec2 mousePos = u_mouse.xy / u_resolution.xy;
    mousePos = mousePos * 2.0 - 1.0;
    mousePos.x *= u_resolution.x / u_resolution.y;
    vec2 fluidMotion = fluidInfluence(uvNorm, mousePos, FLUID_FORCE);
    vec2 distortedUV = uvNorm + fluidMotion * (0.1 + sin(u_time * 0.2) * 0.05);
    vec2 p = distortedUV * SCALE;
    p += u_time * SPEED;
    float angle = fbm(p) * 6.28318 + u_time * 0.2;
    vec2 flow = vec2(cos(angle), sin(angle)) * 0.4;
    float noiseField1 = fbm(p + flow + fluidMotion * 0.3);
    float noiseField2 = fbm(p - flow * 0.6 + fluidMotion * 0.2);
    float finalNoise = fbm(p + vec2(noiseField1, noiseField2) * COMPLEXITY);
    vec3 color = palette(finalNoise + u_time * 0.1);
    float glow = smoothstep(0.3, 0.7, finalNoise) * INTENSITY;
    color = mix(color, palette(finalNoise * 1.5 + u_time * 0.15), glow * 0.5);
    color = pow(color, vec3(0.9));  // Slight gamma adjustment for smoother appearance
    gl_FragColor = vec4(color, 1.0);
}