Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GL_ES
- precision highp float;
- #endif
- uniform vec2 resolution;
- uniform float time;
- //UTIL START
- vec2 ObjUnion(in vec2 obj0,in vec2 obj1){
- if (obj0.x<obj1.x)
- return obj0;
- else
- return obj1;
- }
- //UTIL END
- //SCENE START
- //OBJ0
- vec2 obj0(in vec3 p){
- return vec2(p.y+3.0,0);
- }
- //OBJ0 COLOR
- vec3 obj0_c(in vec3 p){
- if (fract(p.x*.5)>.5)
- if (fract(p.z*.5)>.5)
- return vec3(0,0,0);
- else
- return vec3(1,1,1);
- else
- if (fract(p.z*.5)>.5)
- return vec3(1,1,1);
- else
- return vec3(0,0,0);
- }
- //OBJ1
- vec2 obj1(in vec3 p){
- p.x=p.x+sin(p.y*4.0+time*8.0)*0.3+sin(p.z*4.0-time)*0.3;
- return vec2(distance(p,vec3(0,0,0))-1.9,1);
- }
- //OBJ1 COLOR
- vec3 obj1_c(in vec3 p){
- return vec3(1.0,0.5,0.2);
- }
- //OBJ
- vec2 inObj(in vec3 p){
- return ObjUnion(obj0(p),obj1(p));
- }
- //SCENE END
- void main(void){
- vec2 vPos=-1.0+2.0*gl_FragCoord.xy/resolution.xy;
- //Camera animation
- vec3 vuv=vec3(0,1,0);//view up vector
- vec3 vrp=vec3(0,0,0); //view reference point
- vec3 prp=vec3(-sin(time)*8.0,4,cos(time)*8.0); //camera position
- //Camera setup
- vec3 vpn=normalize(vrp-prp);
- vec3 u=normalize(cross(vuv,vpn));
- vec3 v=cross(vpn,u);
- vec3 vcv=(prp+vpn);
- vec3 scrCoord=vcv+vPos.x*u*resolution.x/resolution.y+vPos.y*v;
- vec3 scp=normalize(scrCoord-prp);
- //Raymarching
- const vec3 e=vec3(0.1,0,0);
- const float maxd=200.0;
- vec2 s=vec2(0.1,0);
- vec3 c,p,n;
- float f=1.0;
- for(int i=0;i<256;i++){
- if (abs(s.x)<.01||f>maxd) break;
- f+=s.x;
- p=prp+scp*f;
- s=inObj(p);
- }
- if (f<maxd){
- if (s.y==0.0)
- c=obj0_c(p);
- else
- c=obj1_c(p);
- n=normalize(
- vec3(s.x-inObj(p-e.xyy).x,
- s.x-inObj(p-e.yxy).x,
- s.x-inObj(p-e.yyx).x));
- float b=dot(n,normalize(prp-p));
- gl_FragColor=vec4((b*c+pow(b,54.0))*(1.0-f*.005),1.0);
- }
- else gl_FragColor=vec4(0,0,0,1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement