Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define STEPS 80
- #define LIGHTPASSES 2
- const vec3 wallColor=vec3(1.,1.,1.);
- /*by Olivier de Schaetzen (citiral)
- haven't really seen anything like this before, so either I don't check enough shaders or I might have made something original once ;)
- */
- float rand(vec2 n){ //random function not by me, found it somewhere on the internet!
- return 1.*fract(sin(dot(n.xy,vec2(12.9898,78.233)))*43758.5453);
- }
- vec3 getColor(vec2 p){
- if(p.x>=.1&&p.x<=.19&&p.y>=.1&&p.y<=.19){
- return wallColor;
- }
- p.x+=sin(iTime)*.1;
- p.y+=cos(iTime)*.1;
- if(length(p-vec2(.5,.5*iResolution.y/iResolution.x))<=.05){
- return wallColor;
- }
- return vec3(.3,.3,.3);
- }
- vec3 getLighting(vec2 p,vec2 lp){
- vec2 sp=p;
- vec2 v=(lp-p)/float(STEPS);
- for(int i=0;i<STEPS;i++){
- if(getColor(sp)==wallColor){
- return length(p-lp)/vec3(1.,1.,1.)+1./length(p-lp)*.075*vec3(1.0,.5*(sin(iTime)+1.),.6);
- }
- sp+=v;
- }
- return vec3(1.0,1.0,1.0)+1./length(p-lp)*.075*vec3(1.0,.5*(sin(iTime)+1.),.6);
- }
- vec3 blendLighting(vec2 p,vec2 lp){
- vec2 r;
- vec3 c=vec3(0.,0.,0.);
- for(int i=1;i<=LIGHTPASSES;i++) {
- r=vec2(rand(sin(iTime*float(i))+p.xy)*.03-.015,rand(cos(iTime*float(i))+p.yx)*.03-.015);
- c+=getLighting(p,lp+r)/float(LIGHTPASSES);
- }
- return c;
- }
- void mainImage(out vec4 fragColor,in vec2 fragCoord){
- vec2 p=fragCoord.xy/iResolution.xy;
- vec2 lp=iMouse.xy/iResolution.xy;
- p.y*=iResolution.y/iResolution.x;
- lp.y*=iResolution.y/iResolution.x;
- fragColor=vec4(getColor(p)*blendLighting(p,lp),1.);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement