-
Notifications
You must be signed in to change notification settings - Fork 5
/
Fire_Emitter.osl
83 lines (54 loc) · 1.56 KB
/
Fire_Emitter.osl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// GLSL code by unknown
// OSL compiled, ported 4 vector to floats - By Mads Drøschler
// 5.6.2018
// License CC3.0
float fract(float x)
{
return x - floor(x);
}
vector fract(vector x)
{
return x - floor(x);
}
float Snoise(vector uv, float res)
{
vector s = vector(1e0, 1e2, 1e3);
uv *= res;
vector uv0 = floor(mod(uv, res))*s;
vector uv1 = floor(mod(uv+vector(1.), res))*s;
vector f = fract(uv);
f = f*f*(3.0-2.0*f);
float a = uv0[0]+uv0[1]+uv0[2];
float b = uv1[0]+uv0[1]+uv0[2];
float c = uv0[0]+uv1[1]+uv0[2];
float d = uv1[0]+uv1[1]+uv0[2];
float ra = fract(sin(a*1e-1)*1e3);
float rb = fract(sin(b*1e-1)*1e3);
float rc = fract(sin(c*1e-1)*1e3);
float rd = fract(sin(d*1e-1)*1e3);
float r0 = mix(mix(ra, rb, f[0]), mix(rc, rd, f[0]), f[1]);
float raa = fract(sin((a + uv1[2] - uv0[2])*1e-1)*1e3);
float rbb = fract(sin((b + uv1[2] - uv0[2])*1e-1)*1e3);
float rcc = fract(sin((c + uv1[2] - uv0[2])*1e-1)*1e3);
float rdd = fract(sin((d + uv1[2] - uv0[2])*1e-1)*1e3);
float r1 = mix(mix(raa, rbb, f[0]), mix(rcc, rdd, f[0]), f[1]);
return mix(r0, r1, f[2])*2.-1.;
}
shader Fire_Emitter
(
point Po = P,
float Time = 1.0,
output vector Out = 0,
)
{
vector p = Po;
p[0] *= 1.0;
float Color = 3.0 - (5.*length(2.*p));
vector coord = vector(atan2(p[0],p[1])/(2*M_PI)+.5, length(p)*.4, .5);
for(int i = 1; i <= 8; i++)
{
float power = pow(2.0, float(i));
Color += (1.5 / power) * Snoise(coord + vector(0.,-Time*.05, Time*.01), power*16.);
}
Out = vector( Color, pow(max(Color,0.),2.)*0.4, pow(max(Color,0.),3.)*0.15);
}