fractal_pyramid.glsl Full Listing#

../../_images/fractal_pyramid.png
fractal_pyramid.glsl#
 1// Fractal Pyramid by bradjamesgrant
 2// Source : https://www.shadertoy.com/view/tsXBzS
 3
 4vec3 palette(float d){
 5	return mix(vec3(0.2,0.7,0.9),vec3(1.,0.,1.),d);
 6}
 7
 8vec2 rotate(vec2 p,float a){
 9	float c = cos(a);
10    float s = sin(a);
11    return p*mat2(c,s,-s,c);
12}
13
14float map(vec3 p){
15    for( int i = 0; i<8; ++i){
16        float t = iTime*0.2;
17        p.xz =rotate(p.xz,t);
18        p.xy =rotate(p.xy,t*1.89);
19        p.xz = abs(p.xz);
20        p.xz-=.5;
21	}
22	return dot(sign(p),p)/5.;
23}
24
25vec4 rm (vec3 ro, vec3 rd){
26    float t = 0.;
27    vec3 col = vec3(0.);
28    float d;
29    for(float i =0.; i<64.; i++){
30		vec3 p = ro + rd*t;
31        d = map(p)*.5;
32        if(d<0.02){
33            break;
34        }
35        if(d>100.){
36        	break;
37        }
38        //col+=vec3(0.6,0.8,0.8)/(400.*(d));
39        col+=palette(length(p)*.1)/(400.*(d));
40        t+=d;
41    }
42    return vec4(col,1./(d*100.));
43}
44void mainImage( out vec4 fragColor, in vec2 fragCoord )
45{
46    vec2 uv = (fragCoord-(iResolution.xy/2.))/iResolution.x;
47	vec3 ro = vec3(0.,0.,-50.);
48    ro.xz = rotate(ro.xz,iTime);
49    vec3 cf = normalize(-ro);
50    vec3 cs = normalize(cross(cf,vec3(0.,1.,0.)));
51    vec3 cu = normalize(cross(cf,cs));
52
53    vec3 uuv = ro+cf*3. + uv.x*cs + uv.y*cu;
54
55    vec3 rd = normalize(uuv-ro);
56
57    vec4 col = rm(ro,rd);
58
59
60    fragColor = col;
61}
62
63/** SHADERDATA
64{
65	"title": "fractal pyramid",
66	"description": "",
67	"model": "car"
68}
69*/