forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CandleFlame.osl
98 lines (89 loc) · 2.51 KB
/
CandleFlame.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// OSL Shader by Tomás Atria based on http://glslsandbox.com/ examples
// Modified by Saul Espinosa 7/15/2021 for Redshift 3d
float fract(float x)
{
return (x - floor(x));
}
shader candle_flame
[[ string help = "Candle Flame for 2D Cards",
string label = "Candle Flame" ]]
(
point Po = point(u,v,0),
float Time = 1.0
[[ string label = "Time", float min = 0.0, float max = 1000.0]],
int aces = 0
[[ string widget = "checkBox",
string label = "ACES",
int connectable = 0 ]],
output vector outColor = 0,
)
{
point pos = Po;
//NEW
pos = ( pos ) * 7.7-point(4.,5.,0.);
pos[1] = (pos[1]/.88);
if(pos[1]>-2.*4.2)
{
for(float baud = 1.; baud < 9.; baud += 1.)
{
pos[1] += 0.2*sin(4.20*Time/(1.+baud))/(1.+baud);
pos[0] += 0.1*cos(pos[1]/4.20+2.40*Time/(1.+baud))/(1.+baud);
//NEW
//pos[1] += 3.2*sin(16.*4.555*Time/(1.+baud))/(1.+baud*32);
//pos[0] += 0.03*cos(2.*Time/(1.+0.01*baud*cos(baud*baud)+pos[0]/4e3))/(1.+baud);
}
//pos[1] += 0.04*fract(sin(Time*60.));
//NEW
pos[0] += 0.04*mod((sin(Time*60.)),1.0);
}
vector col = vector(0.,0.,0.);
float p =.004;
float y = -pow(abs(pos[0]), 4.2)/p;
float dir = abs(pos[1] - y)*sin(.3);
//float dir = abs(pos[1] - y)*(0.01*sin(Time)+0.07);
if(dir < 0.7)
{
//color.rg += smoothstep(0.,1.,.75-dir);
//color.g /=2.4;
col[0] += smoothstep(0.0,1.,.75-dir);
col[1] += smoothstep(0.0,1.,.75-dir);
col[1] /=2.4;
}
// ACES sRGB Transform
matrix aces_tm = matrix(
0.6131, 0.0701, 0.0206, 0,
0.3395, 0.9164, 0.1096, 0,
0.0474, 0.0135, 0.8698, 0,
0, 0, 0, 1);
col *= (0.2 + abs(pos[1]/4.2 + 4.2)/4.2);
col += pow(col[0], 1.1);
col *= cos(-0.5+pos[1]*0.4);
pos[1] += 1.5;
vector dolor = vector(0.,0.,0.0);
y = -pow(abs(pos[0]), 4.2)/(4.2*p)*4.2;
dir = abs(pos[1] - y)*sin(1.1);
if(dir < 0.7)
{
//dolor.bg += smoothstep(0., 1., .75-dir);
//dolor.g /=2.4;
dolor[2] += smoothstep(.0,1.,.75-dir);
dolor[1] += smoothstep(.0,1.,.75-dir);
dolor[1] /= 2.4;
}
dolor *= (0.2 + abs((pos[1]/4.2+4.2))/4.2);
dolor += pow(col[2],1.1);
dolor *= cos(-0.6+pos[1]*0.4);
dolor -= pow(length(dolor)/16., 0.5);
//col = (col+dolor)/2.;
//NEW
col = (col*0.6+dolor)/1.5;
vector Out = vector(col);
float r = Out[0], g = Out[1], b = Out[2];
// ACES Output
if (aces == 0)
outColor = Out;
else
{
outColor = transform(aces_tm, vector(r,g,b));
}
}