Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GL_ES
- precision highp float;
- #endif
- uniform float time;
- uniform vec2 resolution;
- uniform vec4 mouse;
- struct rayHit {
- vec3 lv; vec3 rv; vec3 cv; vec3 norm;
- };
- float getMBv(vec3 ball, vec3 sp) {
- return 1./(pow(ball.x-sp.x, 2.)+pow(ball.y-sp.y, 2.));
- }
- void main()
- {
- vec2 p = -2.0 + 4.0 * gl_FragCoord.xy / resolution;
- p.x *= resolution.x/resolution.y;
- vec3 camera = vec3(p, -1.0);
- vec3 r = camera;
- vec3 col = vec3(0., 0., 0.1);
- vec3 cc = vec3(cos(time), sin(time), 0.);
- vec3 cc2 = cc+vec3(-cos(time*6.), -sin(time*8.), 0.);
- vec3 lightpos = vec3(0.,0., 1.+cos(time)*1.22222);
- bool hit = false;
- float d = distance(camera.xy, cc.xy);
- float d2 = distance(camera.xy, cc2.xy);
- float th = getMBv(cc, camera);
- float th2 = getMBv(cc2, camera);
- rayHit rh;
- if (th+th2 > 3.) {
- hit = true;
- col = vec3(0., 0., 1.);
- d =d/.5;
- d2 =d2/.5;
- r = vec3(p, ((1.-1./th+1.-1./th2)/2.));
- }
- if (hit) {
- vec3 lv = lightpos-r;
- lv = normalize(lv);
- vec3 norm = ((cc-r)+(cc2-r));
- norm = normalize(norm);
- vec3 cv = camera-r;
- cv = normalize(cv);
- vec3 rv = reflect(lv, norm);
- rv = normalize(rv);
- float i = clamp(dot(lv, norm), 0., 1.);
- col += i*vec3(1.,0., 0.);
- i = pow(clamp(dot(cv, rv), 0., 1.), 2.0);
- col += i *vec3(0., 1., 0.);
- }
- gl_FragColor = vec4(col,1.0);
- }
Add Comment
Please, Sign In to add comment