Skip to content

Commit 6650f32

Browse files
committed
More optimization.
1 parent 8bf6fc8 commit 6650f32

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

assets/frag.glsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ vec4 col_scene(vec4 p) {
201201

202202
//A faster formula to find the gradient/normal direction of the DE(the w component is the average DE)
203203
//credit to http://www.iquilezles.org/www/articles/normalsSDF/normalsSDF.htm
204-
vec3 calcGrad(vec4 p, float dx) {
204+
vec3 calcNormal(vec4 p, float dx) {
205205
const vec3 k = vec3(1,-1,0);
206-
return (k.xyy*DE(p + k.xyyz*dx) +
207-
k.yyx*DE(p + k.yyxz*dx) +
208-
k.yxy*DE(p + k.yxyz*dx) +
209-
k.xxx*DE(p + k.xxxz*dx)) / vec3(4*dx,4*dx,4*dx);
206+
return normalize(k.xyy*DE(p + k.xyyz*dx) +
207+
k.yyx*DE(p + k.yyxz*dx) +
208+
k.yxy*DE(p + k.yxyz*dx) +
209+
k.xxx*DE(p + k.xxxz*dx));
210210
}
211211

212212
//find the average color of the fractal in a radius dx in plane s1-s2
@@ -261,7 +261,7 @@ vec4 scene(inout vec4 p, inout vec4 ray, float vignette) {
261261
float min_dist = max(FOVperPixel*td, MIN_DIST);
262262
if (d < min_dist) {
263263
//Get the surface normal
264-
vec3 n = normalize(calcGrad(p,min_dist*0.5));
264+
vec3 n = calcNormal(p, min_dist*0.5);
265265

266266
//find closest surface point, without this we get weird coloring artifacts
267267
p.xyz -= n*d;

0 commit comments

Comments
 (0)