Skip to content

Commit 899fbfd

Browse files
committed
Reduce nesting
1 parent 63f3dfc commit 899fbfd

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/materials/shaders/convolution.bokeh.frag

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,61 +34,60 @@ void main() {
3434

3535
// Skip blurring.
3636
out_Color = texture(inputBuffer, vUv);
37+
return;
3738

38-
} else {
39-
40-
#ifdef FOREGROUND
39+
}
4140

42-
// Use far CoC to avoid weak blurring around foreground objects.
43-
vec2 step = resolution.zw * max(cocNearFar.x, cocNearFar.y);
41+
#ifdef FOREGROUND
4442

45-
#else
43+
// Use far CoC to avoid weak blurring around foreground objects.
44+
vec2 step = resolution.zw * max(cocNearFar.x, cocNearFar.y);
4645

47-
vec2 step = resolution.zw * coc;
46+
#else
4847

49-
#endif
48+
vec2 step = resolution.zw * coc;
5049

51-
#if PASS == 1
50+
#endif
5251

53-
vec4 acc = vec4(0.0);
52+
#if PASS == 1
5453

55-
// Each vector contains two sampling points (64 in total).
56-
for(int i = 0; i < 32; ++i) {
54+
vec4 acc = vec4(0.0);
5755

58-
vec4 kernel = kernel64[i];
56+
// Each vector contains two sampling points (64 in total).
57+
for(int i = 0; i < 32; ++i) {
5958

60-
vec2 uv = step * kernel.xy + vUv;
61-
acc += texture(inputBuffer, uv);
59+
vec4 kernel = kernel64[i];
6260

63-
uv = step * kernel.zw + vUv;
64-
acc += texture(inputBuffer, uv);
61+
vec2 uv = step * kernel.xy + vUv;
62+
acc += texture(inputBuffer, uv);
6563

66-
}
64+
uv = step * kernel.zw + vUv;
65+
acc += texture(inputBuffer, uv);
6766

68-
out_Color = acc / 64.0;
67+
}
6968

70-
#else
69+
out_Color = acc / 64.0;
7170

72-
vec4 maxValue = texture(inputBuffer, vUv);
71+
#else
7372

74-
// Each vector contains two sampling points (16 in total).
75-
for(int i = 0; i < 8; ++i) {
73+
vec4 maxValue = texture(inputBuffer, vUv);
7674

77-
vec4 kernel = kernel16[i];
75+
// Each vector contains two sampling points (16 in total).
76+
for(int i = 0; i < 8; ++i) {
7877

79-
vec2 uv = step * kernel.xy + vUv;
80-
maxValue = max(texture(inputBuffer, uv), maxValue);
78+
vec4 kernel = kernel16[i];
8179

82-
uv = step * kernel.zw + vUv;
83-
maxValue = max(texture(inputBuffer, uv), maxValue);
80+
vec2 uv = step * kernel.xy + vUv;
81+
maxValue = max(texture(inputBuffer, uv), maxValue);
8482

83+
uv = step * kernel.zw + vUv;
84+
maxValue = max(texture(inputBuffer, uv), maxValue);
8585

86-
}
8786

88-
out_Color = maxValue;
87+
}
8988

90-
#endif
89+
out_Color = maxValue;
9190

92-
}
91+
#endif
9392

9493
}

0 commit comments

Comments
 (0)