flame.glsl Full Listing

flame.glsl
1// Flame by XT95
2// Source : https://www.shadertoy.com/view/MdX3zr
3
4float noise(vec3 p) //Thx to Las^Mercury
5{
6 vec3 i = floor(p);
7 vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.);
8 vec3 f = cos((p-i)*acos(-1.))*(-.5)+.5;
9 a = mix(sin(cos(a)*a),sin(cos(1.+a)*(1.+a)), f.x);
10 a.xy = mix(a.xz, a.yw, f.y);
11 return mix(a.x, a.y, f.z);
12}
13
14float sphere(vec3 p, vec4 spr)
15{
16 return length(spr.xyz-p) - spr.w;
17}
18
19float flame(vec3 p)
20{
21 float d = sphere(p*vec3(1.,.5,1.), vec4(.0,-1.,.0,1.));
22 return d + (noise(p+vec3(.0,iTime*2.,.0)) + noise(p*3.)*.5)*.25*(p.y) ;
23}
24
25float scene(vec3 p)
26{
27 return min(100.-length(p) , abs(flame(p)) );
28}
29
30vec4 raymarch(vec3 org, vec3 dir)
31{
32 float d = 0.0, glow = 0.0, eps = 0.02;
33 vec3 p = org;
34 bool glowed = false;
35
36 for(int i=0; i<64; i++)
37 {
38 d = scene(p) + eps;
39 p += d * dir;
40 if( d>eps )
41 {
42 if(flame(p) < .0)
43 glowed=true;
44 if(glowed)
45 glow = float(i)/64.;
46 }
47 }
48 return vec4(p,glow);
49}
50
51void mainImage( out vec4 fragColor, in vec2 fragCoord )
52{
53 vec2 v = -1.0 + 2.0 * fragCoord.xy / iResolution.xy;
54 v.x *= iResolution.x/iResolution.y;
55
56 vec3 org = vec3(0., -2., 4.);
57 vec3 dir = normalize(vec3(v.x*1.6, -v.y, -1.5));
58
59 vec4 p = raymarch(org, dir);
60 float glow = p.w;
61
62 vec4 col = mix(vec4(1.,.5,.1,1.), vec4(0.1,.5,1.,1.), p.y*.02+.4);
63
64 fragColor = mix(vec4(0.), col, pow(glow*2.,4.));
65 //fragColor = mix(vec4(1.), mix(vec4(1.,.5,.1,1.),vec4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));
66
67}
68