0.00
60.0 fps

Log in to post a comment.

#version 300 es
precision highp float;

int MAX_STEPS=80;

uniform float iTime;
uniform vec2  iResolution;

out vec4 fragColor;

uniform float mouseX; // value=142., min=-1.0, max=600.0, step=1.0
uniform float mouseY; // value=87., min=-1.0, max=180.0, step=1.0

float sdSphere(vec3 p,float s){
  return length(p)-s;
}

float sdBox(vec3 p,vec3 size){
  vec3 d=abs(p)-size;
  return length(max(d,0.))+min(max(d.x,max(d.y,d.z)),0.);
}

float sdTorus(vec3 p,float majorRadius,float minorRadius){
  vec2 q=vec2(length(p.xz)-majorRadius,p.y);
  return length(q)-minorRadius;
}

float smin(float a,float b,float k){
  float h=clamp(.5+.5*(b-a)/k,0.,1.);
  return mix(b,a,h)-k*h*(1.-h);
}

mat2 rot2D(float a){
  return mat2(cos(a),-sin(a),sin(a),cos(a));
}

float map(vec3 p){
  vec3 spherePos=vec3(tan(iTime)*3.,0,0);
  float sphere=sdSphere(p-spherePos,2.);
  
  vec3 q=p;
  q.xy*=rot2D(iTime*3.);
  q.yz*=rot2D(-iTime);
  
  vec3 boxPos=vec3(-8,0,0);
  float box=sdBox(q-boxPos,vec3(sin(iTime)*-2.));
  
  q.xy*=rot2D(iTime*1.);
  vec3 torusPos=vec3(2.,0,0);
  float torus=sdTorus(q-torusPos,2.5,.75);
  
  float ground=p.y+.2;
  float shapes=smin(sphere,box,3.);
  
  return smin(smin(ground,shapes,.2),torus,1.4);
}


void main() {
  vec2 iMouse = vec2(mouseX, mouseY);
    
  vec2 uv=(gl_FragCoord.xy*2.-iResolution.xy)/iResolution.y;
  vec2 m=(iMouse.xy-iResolution.xy*.5)/iResolution.y;

  vec3 ro=vec3(0.,0.,-8.);
  vec3 rd=normalize(vec3(uv,1));
  vec3 color=vec3(0.);
  
  float t=0.;// total distance traveled
  
  ro.yz*=rot2D(-m.y);
  rd.yz*=rot2D(-m.y*-3.);
  ro.xz*=rot2D(-m.x);
  rd.xy*=rot2D(m.x*-3.);
  
  int i=0;
  for(i;i<MAX_STEPS;i++){
    vec3 p=ro+rd*t;// current position along the ray
    
    p.xy*=rot2D(t*.15*m.x);
    p.y+=sin(t*(m.y+1.)*.5)*.35;// wiggle ray
    
    float d=map(p);// current distance
    t+=d;
    
    color=vec3(i)/float(MAX_STEPS);// color based on the number of steps taken
    
    if(d<.001||t>100.)break;
  }
  
  color=vec3(t*.02,0.,t*.1);
  fragColor = vec4(color,1.);
}