forked from rodrigomas/DCTLs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flame.dctl
282 lines (244 loc) · 5.15 KB
/
Flame.dctl
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Flame DCTL
__DEVICE__ float3 add(float3 A, float B)
{
float3 C;
C.x = A.x + B;
C.y = A.y + B;
C.z = A.z + B;
return C;
}
__DEVICE__ float3 add(float3 A, float3 B)
{
float3 C;
C.x = A.x + B.x;
C.y = A.y + B.y;
C.z = A.z + B.z;
return C;
}
__DEVICE__ float4 add(float A, float4 B)
{
float4 C;
C.x = A + B.x;
C.y = A + B.y;
C.z = A + B.z;
C.w = A + B.w;
return C;
}
__DEVICE__ float3 cos(float3 A)
{
float3 B;
B.x = _cosf(A.x);
B.y = _cosf(A.y);
B.z = _cosf(A.z);
return B;
}
__DEVICE__ float4 cos(float4 A)
{
float4 B;
B.x = _cosf(A.x);
B.y = _cosf(A.y);
B.z = _cosf(A.z);
B.w = _cosf(A.w);
return B;
}
__DEVICE__ float dot(float2 A, float2 B)
{
float C = A.x * B.x + A.y * B.y;
return C;
}
__DEVICE__ float dot(float3 A, float3 B)
{
float C = A.x * B.x + A.y * B.y + A.z * B.z;
return C;
}
__DEVICE__ float3 floor(float3 A)
{
float3 B;
B.x = _floor(A.x);
B.y = _floor(A.y);
B.z = _floor(A.z);
return B;
}
__DEVICE__ float length(float2 A)
{
float B = _sqrtf(A.x * A.x + A.y * A.y);
return B;
}
__DEVICE__ float length(float3 A)
{
float B = _sqrtf(A.x * A.x + A.y * A.y + A.z * A.z);
return B;
}
__DEVICE__ float4 make_float4(float3 A, float B)
{
float4 C = make_float4(A.x, A.y, A.z, B);
return C;
}
__DEVICE__ float3 minus(float A, float3 B)
{
float3 C;
C.x = A - B.x;
C.y = A - B.y;
C.z = A - B.z;
return C;
}
__DEVICE__ float3 minus(float3 A, float3 B)
{
float3 C;
C.x = A.x - B.x;
C.y = A.y - B.y;
C.z = A.z - B.z;
return C;
}
__DEVICE__ float mix(float A, float B, float C)
{
float D = A * (1.0f - C) + B * C;
return D;
}
__DEVICE__ float2 mix(float2 A, float2 B, float C)
{
float2 D;
D.x = A.x * (1.0f - C) + B.x * C;
D.y = A.y * (1.0f - C) + B.y * C;
return D;
}
__DEVICE__ float3 mix(float3 A, float3 B, float C)
{
float3 D;
D.x = A.x * (1.0f - C) + B.x * C;
D.y = A.y * (1.0f - C) + B.y * C;
D.z = A.z * (1.0f - C) + B.z * C;
return D;
}
__DEVICE__ float4 mix(float4 A, float4 B, float C)
{
float4 D;
D.x = A.x * (1.0f - C) + B.x * C;
D.y = A.y * (1.0f - C) + B.y * C;
D.z = A.z * (1.0f - C) + B.z * C;
D.w = A.w * (1.0f - C) + B.w * C;
return D;
}
__DEVICE__ float3 multi(float A, float3 B)
{
float3 C;
C.x = A * B.x;
C.y = A * B.y;
C.z = A * B.z;
return C;
}
__DEVICE__ float3 multi(float3 A, float B)
{
float3 C;
C.x = A.x * B;
C.y = A.y * B;
C.z = A.z * B;
return C;
}
__DEVICE__ float3 multi(float3 A, float3 B)
{
float3 C;
C.x = A.x * B.x;
C.y = A.y * B.y;
C.z = A.z * B.z;
return C;
}
__DEVICE__ float4 multi(float4 A, float B)
{
float4 C;
C.x = A.x * B;
C.y = A.y * B;
C.z = A.z * B;
C.w = A.w * B;
return C;
}
__DEVICE__ float4 multi(float4 A, float4 B)
{
float4 C;
C.x = A.x * B.x;
C.y = A.y * B.y;
C.z = A.z * B.z;
C.w = A.w * B.w;
return C;
}
__DEVICE__ float3 normalize(float3 A)
{
float3 B;
float C = _sqrtf((A.x * A.x) + (A.y * A.y) + (A.z * A.z));
B.x = A.x / C;
B.y = A.y / C;
B.z = A.z / C;
return B;
}
__DEVICE__ float4 sin(float4 A)
{
float4 B;
B.x = _sinf(A.x);
B.y = _sinf(A.y);
B.z = _sinf(A.z);
B.w = _sinf(A.w);
return B;
}
__DEVICE__ float noise(float3 p)
{
float3 i = floor(p);
float4 a = add(dot(i, make_float3(1.0f, 57.0f, 21.0f)), make_float4(0.0f, 57.0f, 21.0f, 78.0f));
float3 f = add(multi(cos(multi(minus(p, i), _acosf(-1.0f))), -0.5f), 0.5f);
a = mix(sin(multi(cos(a), a)), sin(multi(cos(add(1.0f, a)), (add(1.0f, a)))), f.x);
float2 axy = mix(make_float2(a.x, a.z), make_float2(a.y, a.w), f.y);
a.x = axy.x;
a.y = axy.y;
return mix(a.x, a.y, f.z);
}
__DEVICE__ float sphere(float3 p, float4 spr)
{
return length(minus(make_float3(spr.x, spr.y, spr.z), p)) - spr.w;
}
__DEVICE__ float flame(float3 p, float iTime)
{
float d = sphere(multi(p, make_float3(1.0f, 0.5f, 1.0f)), make_float4(0.0f, -1.0f, 0.0f, 1.0f));
return d + (noise(add(p, make_float3(0.0f, iTime * 2.0f, 0.0f))) + noise(multi(p, 3.0f)) * 0.5f) * 0.25 * (p.y);
}
__DEVICE__ float scene(float3 p, float iTime)
{
return _fminf(100.0f - length(p) , _fabs(flame(p, iTime)) );
}
__DEVICE__ float4 raymarch(float3 org, float3 dir, float iTime)
{
float d = 0.0f, glow = 0.0f, eps = 0.02f;
float3 p = org;
bool glowed = false;
for(int i=0; i<64; i++)
{
d = scene(p, iTime) + eps;
p = add(p, multi(d, dir));
if( d>eps )
{
if(flame(p, iTime) < 0.0f)
glowed=true;
if(glowed)
glow = float(i)/64.0f;
}
}
return make_float4(p,glow);
}
__DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, __TEXTURE__ p_TexR, __TEXTURE__ p_TexG, __TEXTURE__ p_TexB)
{
//float iTime = _tex2D(p_TexR, 500, 500) / 24.0f;
float iTime = _tex2D(p_TexR, 500, 500) * 20.0f;
float X = (float)p_X;
float Y = (float)(p_Height - p_Y);
float2 resolution = make_float2((float)p_Width, (float)p_Height);
float2 v;
v.x = -1.0f + 2.0f * X / resolution.x;
v.y = -1.0f + 2.0f * Y / resolution.y;
v.x *= resolution.x/resolution.y;
float3 org = make_float3(0.0f, -2.0f, 4.0f);
float3 dir = normalize(make_float3(v.x * 1.6f, -v.y, -1.5f));
float4 p = raymarch(org, dir, iTime);
float glow = p.w;
float4 col = mix(make_float4(1.0, 0.5f, 0.1f, 1.0f), make_float4(0.1f, 0.5f, 1.0f, 1.0f), p.y * 0.02f + 0.4f);
float4 Col = mix(make_float4(0.0f, 0.0f, 0.0f, 0.0f), col, _powf(glow * 2.0f, 4.0f));
//fragColor = mix(make_float4(1.), mix(make_float4(1.,.5,.1,1.),make_float4(0.1,.5,1.,1.),p.y*.02+.4), pow(glow*2.,4.));
return make_float3(Col.x, Col.y, Col.z);
}