40
40
#define SUN_SHARPNESS 2.0
41
41
#define SUN_SIZE 0.004
42
42
#define VIGNETTE_STRENGTH 0.5
43
- #define FRACTAL_ITER 16
43
+ #define FRACTAL_ITER 14
44
+ #define ENABLE_FILTERING 1
44
45
45
46
uniform mat4 iMat;
46
47
uniform vec2 iResolution;
@@ -198,7 +199,7 @@ vec4 col_scene(vec4 p) {
198
199
// Main code
199
200
// ##########################################
200
201
201
- // A faster formula to find the gradient/normal diraction of the DE(the w component is the average DE)
202
+ // A faster formula to find the gradient/normal direction of the DE(the w component is the average DE)
202
203
// credit to http://www.iquilezles.org/www/articles/normalsSDF/normalsSDF.htm
203
204
vec4 calcGrad(vec4 p, float dx)
204
205
{
@@ -209,6 +210,16 @@ vec4 calcGrad(vec4 p, float dx)
209
210
k.xxxx* DE(p + k.xxxz* dx)) / vec4 (4 * dx,4 * dx,4 * dx,4 );
210
211
}
211
212
213
+ // find the average color of the fractal in a radius dx
214
+ vec4 smoothColor(vec4 p, float dx)
215
+ {
216
+ const vec3 k = vec3 (1 ,- 1 ,0 );
217
+ return (COL(p + k.xyyz* dx) +
218
+ COL(p + k.yyxz* dx) +
219
+ COL(p + k.yxyz* dx) +
220
+ COL(p + k.xxxz* dx))/ 4 ;
221
+ }
222
+
212
223
vec4 ray_march(inout vec4 p, vec4 ray, float sharpness) {
213
224
// March the ray
214
225
float d = DE(p);
@@ -222,8 +233,8 @@ vec4 ray_march(inout vec4 p, vec4 ray, float sharpness) {
222
233
for (; s < MAX_MARCHES; s += 1.0 ) {
223
234
// if the distance from the surface is less than the distance per pixel we stop
224
235
float min_dist = max (FOVperPixel* td, MIN_DIST);
225
- if (d < min_dist ) {
226
- s += 0.14 * d / min_dist ;
236
+ if (d < min_dist) {
237
+ s += 0.1 * d / min_dist;
227
238
break ;
228
239
} else if (td > MAX_DIST) {
229
240
break ;
@@ -245,21 +256,24 @@ vec4 scene(inout vec4 p, inout vec4 ray, float vignette) {
245
256
246
257
// Determine the color for this pixel
247
258
vec4 col = vec4 (0.0 );
248
-
249
259
float min_dist = max (FOVperPixel* td, MIN_DIST);
250
260
if (d < min_dist) {
251
261
// Get the surface normal
252
- vec4 grad = calcGrad(p,td * FOVperPixel * 0.2 );
262
+ vec4 grad = calcGrad(p,min_dist * 0.5 );
253
263
vec3 n = normalize (grad.xyz);
254
264
255
265
// find closest surface point, without this we get weird coloring artifacts
256
266
p.xyz -= n* d;
257
-
258
- vec3 reflected = ray.xyz - 2.0 * dot (ray.xyz, n) * n;
259
267
268
+ vec3 reflected = ray.xyz - 2.0 * dot (ray.xyz, n) * n;
269
+
260
270
// Get coloring
261
- vec4 orig_col = clamp (COL(p), 0.0 , 1.0 );
262
- col.w = orig_col.w;
271
+ #if ENABLE_FILTERING
272
+ vec4 orig_col = clamp (smoothColor(p, min_dist* 0.5 ), 0.0 , 1.0 );
273
+ #else
274
+ vec4 orig_col = clamp (COL(p), 0.0 , 1.0 );
275
+ #endif
276
+ col.w = orig_col.w;
263
277
264
278
// Get if this point is in shadow
265
279
float k = 1.0 ;
@@ -325,7 +339,7 @@ void main() {
325
339
vec2 screen_pos = (gl_FragCoord .xy + delta) / iResolution.xy;
326
340
327
341
// Calculate the view angle per pixel
328
- FOVperPixel = 90 * PI/ (180 * iResolution.x);
342
+ FOVperPixel = 1 * 90 * PI/ (180 * iResolution.x);
329
343
330
344
vec2 uv = 2 * screen_pos - 1 ;
331
345
uv.x *= iResolution.x / iResolution.y;
0 commit comments