Star_nest.glsl完整列表#

star_nest.glsl#
1// Star Nest by Pablo Roman Andrioli
2// This content is under the MIT License.
3// Source : https://www.shadertoy.com/view/XlfGRj
4
5#define iterations 17
6#define formuparam 0.53
7
8#define volsteps 20
9#define stepsize 0.1
10
11#define zoom 0.800
12#define tile 0.850
13#define speed 0.010
14
15#define brightness 0.0015
16#define darkmatter 0.300
17#define distfading 0.730
18#define saturation 0.850
19
20void mainImage( out vec4 fragColor, in vec2 fragCoord )
21{
22 //get coords and direction
23 vec2 uv=fragCoord.xy/iResolution.xy-.5;
24 uv.y*=iResolution.y/iResolution.x;
25 vec3 dir=vec3(uv*zoom,1.);
26 float time=iTime*speed+.25;
27
28 //mouse rotation
29 float a1=.5+iMouse.x/iResolution.x*2.;
30 float a2=.8+iMouse.y/iResolution.y*2.;
31 mat2 rot1=mat2(cos(a1),sin(a1),-sin(a1),cos(a1));
32 mat2 rot2=mat2(cos(a2),sin(a2),-sin(a2),cos(a2));
33 dir.xz*=rot1;
34 dir.xy*=rot2;
35 vec3 from=vec3(1.,.5,0.5);
36 from+=vec3(time*2.,time,-2.);
37 from.xz*=rot1;
38 from.xy*=rot2;
39
40 //volumetric rendering
41 float s=0.1,fade=1.;
42 vec3 v=vec3(0.);
43 for (int r=0; r<volsteps; r++) {
44 vec3 p=from+s*dir*.5;
45 p = abs(vec3(tile)-mod(p,vec3(tile*2.))); // tiling fold
46 float pa,a=pa=0.;
47 for (int i=0; i<iterations; i++) {
48 p=abs(p)/dot(p,p)-formuparam; // the magic formula
49 a+=abs(length(p)-pa); // absolute sum of average change
50 pa=length(p);
51 }
52 float dm=max(0.,darkmatter-a*a*.001); //dark matter
53 a*=a*a; // add contrast
54 if (r>6) fade*=1.-dm; // dark matter, don't render near
55 //v+=vec3(dm,dm*.5,0.);
56 v+=fade;
57 v+=vec3(s,s*s,s*s*s*s)*a*brightness*fade; // coloring based on distance
58 fade*=distfading; // distance fading
59 s+=stepsize;
60 }
61 v=mix(vec3(length(v)),v,saturation); //color adjust
62 fragColor = vec4(v*.01,1.);
63}