Guest User

Untitled

a guest
Oct 6th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4.  
  5. uniform float time;
  6. uniform vec2 resolution;
  7. uniform vec4 mouse;
  8.  
  9. struct rayHit {
  10.    vec3 lv; vec3 rv; vec3 cv; vec3 norm;
  11. };
  12.  
  13. float getMBv(vec3 ball, vec3 sp) {
  14.    return 1./(pow(ball.x-sp.x, 2.)+pow(ball.y-sp.y, 2.));
  15. }
  16.  
  17. void main()
  18. {
  19.     vec2 p = -2.0 + 4.0 * gl_FragCoord.xy / resolution;
  20.     p.x *= resolution.x/resolution.y;
  21.  
  22.     vec3 camera = vec3(p, -1.0);
  23.     vec3 r = camera;
  24.     vec3 col = vec3(0., 0., 0.1);
  25.    
  26.     vec3 cc = vec3(cos(time), sin(time), 0.);
  27.     vec3 cc2 = cc+vec3(-cos(time*6.), -sin(time*8.), 0.);
  28.     vec3 lightpos = vec3(0.,0., 1.+cos(time)*1.22222);
  29.  
  30.     bool hit = false;
  31.     float d = distance(camera.xy, cc.xy);
  32.     float d2 = distance(camera.xy, cc2.xy);
  33.     float th = getMBv(cc, camera);
  34.     float th2 = getMBv(cc2, camera);
  35.  
  36.     rayHit rh;
  37.     if (th+th2 > 3.) {
  38.        hit = true;
  39.         col = vec3(0., 0., 1.);
  40.         d =d/.5;
  41.         d2 =d2/.5;
  42.         r = vec3(p, ((1.-1./th+1.-1./th2)/2.));
  43.     }
  44.  
  45.     if (hit) {
  46.     vec3 lv = lightpos-r;
  47.     lv = normalize(lv);
  48.     vec3 norm = ((cc-r)+(cc2-r));
  49.     norm = normalize(norm);
  50.  
  51.     vec3 cv = camera-r;
  52.     cv = normalize(cv);
  53.     vec3 rv = reflect(lv, norm);
  54.     rv = normalize(rv);
  55.  
  56.     float i = clamp(dot(lv, norm), 0., 1.);
  57.     col += i*vec3(1.,0., 0.);
  58.  
  59.     i = pow(clamp(dot(cv, rv), 0., 1.), 2.0);
  60.     col += i *vec3(0., 1., 0.);
  61.  
  62.     }
  63.     gl_FragColor = vec4(col,1.0);
  64. }
Add Comment
Please, Sign In to add comment