Build GLSL shaders with natural language

Favorites

    History

      Explore

      • organic motion background
      • a kaledioscope effect with trippy patterns and colors
      • dreamscape with chromatic abberation effect where mouse is
      • dreamscape
      • isometric vector art grid
      • sun
      • smoke mist turbulent
      • a smooth rainbow gradient with colors gently flowing into eachother
      • soft rainbow gradients flowing into eachother gently
      • morphing madness
      • gentle rainbow gradient
      • swirling
      • displacement shader on image with distortion centered around the mouse. add chromatic aberration effect which grows stronger at the edges
      Explore more
      precision mediump float;
      
      uniform float u_time;
      uniform vec2 u_mouse;
      uniform vec2 u_resolution;
      varying vec2 v_uv;
      
      float smin(float a, float b, float k) {
          float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
          return mix(b, a, h) - k * h * (1.0 - h);
      }
      
      float sdSphere(vec3 p, float r) {
          return length(p) - r;
      }
      
      float noise(vec3 p) {
          return sin(p.x) * sin(p.y) * sin(p.z);
      }
      
      float map(vec3 p) {
          vec3 p1 = p;
          p1.xz *= mat2(cos(u_time * 0.5), sin(u_time * 0.5), -sin(u_time * 0.5), cos(u_time * 0.5));
          
          float mouseDist = length(u_mouse - vec2(0.5));
          float size = 0.8 + mouseDist * 0.4;
          
          float d1 = sdSphere(p1, size);
          float d2 = sdSphere(p1 + vec3(sin(u_time), cos(u_time * 0.7), 0.0), 0.7);
          float d3 = sdSphere(p1 + vec3(cos(u_time * 0.8), sin(u_time * 1.1), 0.0), 0.6);
          
          float dist = smin(d1, d2, 0.5);
          dist = smin(dist, d3, 0.5);
          
          return dist + noise(p * 3.0) * 0.1;
      }
      
      vec3 getNormal(vec3 p) {
          vec2 e = vec2(0.01, 0.0);
          return normalize(vec3(
              map(p + e.xyy) - map(p - e.xyy),
              map(p + e.yxy) - map(p - e.yxy),
              map(p + e.yyx) - map(p - e.yyx)
          ));
      }
      
      vec3 palette(float t) {
          vec3 a = vec3(0.3, 0.5, 0.5);
          vec3 b = vec3(0.3, 0.5, 0.5);
          vec3 c = vec3(0.8, 1.0, 1.0);
          vec3 d = vec3(0.4, 0.2, 0.2);
          return a + b * cos(6.28318 * (c * t + d));
      }
      
      void main() {
          vec2 uv = (v_uv - 0.5) * 2.0;
          uv.x *= u_resolution.x/u_resolution.y;
          
          vec3 ro = vec3(0.0, 0.0, -2.8);
          vec3 rd = normalize(vec3(uv, 1.0));
          
          float t = 0.0;
          float steps = 50.0;
          
          for(float i = 0.0; i < steps; i++) {
              vec3 p = ro + rd * t;
              float d = map(p);
              if(d < 0.01) break;
              t += d;
              if(t > 10.0) break;
          }
          
          vec3 col = vec3(0.0, 0.2, 0.8);
          
          if(t < 10.0) {
              vec3 p = ro + rd * t;
              vec3 n = getNormal(p);
              vec3 ref = reflect(rd, n);
              
              float fresnel = pow(1.0 - max(0.0, dot(-rd, n)), 4.0);
              vec3 objCol = palette(length(p) * 0.2 + u_time * 0.1);
              
              col = mix(objCol, vec3(1.0), fresnel * 0.7);
              col *= 1.0 - t * 0.1;
          }
          
          gl_FragColor = vec4(col, 1.0);
          
          #include <colorspace_fragment>
      }