Advertisement
Guest User

WebGL2.0 fix

a guest
Mar 24th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define STEPS 80
  2. #define LIGHTPASSES 2
  3. const vec3 wallColor=vec3(1.,1.,1.);
  4. /*by Olivier de Schaetzen (citiral)
  5. haven't really seen anything like this before, so either I don't check enough shaders or I might have made something original once ;)
  6. */
  7. float rand(vec2 n){ //random function not by me, found it somewhere on the internet!
  8.     return 1.*fract(sin(dot(n.xy,vec2(12.9898,78.233)))*43758.5453);
  9. }
  10. vec3 getColor(vec2 p){ 
  11.     if(p.x>=.1&&p.x<=.19&&p.y>=.1&&p.y<=.19){
  12.         return wallColor;
  13.     }
  14.     p.x+=sin(iTime)*.1;
  15.     p.y+=cos(iTime)*.1;
  16.     if(length(p-vec2(.5,.5*iResolution.y/iResolution.x))<=.05){
  17.         return wallColor;
  18.     }
  19.     return vec3(.3,.3,.3);
  20. }
  21. vec3 getLighting(vec2 p,vec2 lp){
  22.     vec2 sp=p;
  23.     vec2 v=(lp-p)/float(STEPS);
  24.     for(int i=0;i<STEPS;i++){
  25.         if(getColor(sp)==wallColor){
  26.             return length(p-lp)/vec3(1.,1.,1.)+1./length(p-lp)*.075*vec3(1.0,.5*(sin(iTime)+1.),.6);
  27.         }
  28.         sp+=v;
  29.     }
  30.     return vec3(1.0,1.0,1.0)+1./length(p-lp)*.075*vec3(1.0,.5*(sin(iTime)+1.),.6);
  31. }
  32. vec3 blendLighting(vec2 p,vec2 lp){
  33.     vec2 r;
  34.     vec3 c=vec3(0.,0.,0.);
  35.     for(int i=1;i<=LIGHTPASSES;i++) {
  36.         r=vec2(rand(sin(iTime*float(i))+p.xy)*.03-.015,rand(cos(iTime*float(i))+p.yx)*.03-.015);
  37.         c+=getLighting(p,lp+r)/float(LIGHTPASSES);
  38.     }
  39.     return c;
  40. }
  41. void mainImage(out vec4 fragColor,in vec2 fragCoord){
  42.     vec2 p=fragCoord.xy/iResolution.xy;
  43.     vec2 lp=iMouse.xy/iResolution.xy;
  44.     p.y*=iResolution.y/iResolution.x;
  45.     lp.y*=iResolution.y/iResolution.x; 
  46.     fragColor=vec4(getColor(p)*blendLighting(p,lp),1.);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement