File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ export default /* glsl */`
19
19
#include "floatAsUintPS"
20
20
#endif
21
21
22
+ // Fast approximate e^x based on https://nic.schraudolph.org/pubs/Schraudolph99.pdf
23
+ const float EXP_A = 12102203.0; // ≈ 2^23 / ln(2)
24
+ const int EXP_BC_RMS = 1064866808; // (127 << 23) - 60801 * 8
25
+ float fastExp(float x) {
26
+ int i = int(EXP_A * x) + EXP_BC_RMS;
27
+ return intBitsToFloat(i);
28
+ }
29
+
22
30
varying mediump vec2 gaussianUV;
23
31
varying mediump vec4 gaussianColor;
24
32
@@ -29,7 +37,7 @@ void main(void) {
29
37
}
30
38
31
39
// evaluate alpha
32
- mediump float alpha = exp (-A * 4.0) * gaussianColor.a;
40
+ mediump float alpha = fastExp (-A * 4.0) * gaussianColor.a;
33
41
34
42
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
35
43
if (alpha < alphaClip) {
Original file line number Diff line number Diff line change @@ -19,6 +19,14 @@ export default /* wgsl */`
19
19
#include "floatAsUintPS"
20
20
#endif
21
21
22
+ // Fast approximate e^x based on https://nic.schraudolph.org/pubs/Schraudolph99.pdf
23
+ const EXP_A: f32 = 12102203.0; // ≈ 2^23 / ln(2)
24
+ const EXP_BC_RMS: i32 = 1064866808; // (127 << 23) - 60801 * 8
25
+ fn fastExp(x: f32) -> f32 {
26
+ var i: i32 = i32(EXP_A * x) + EXP_BC_RMS;
27
+ return bitcast<f32>(i);
28
+ }
29
+
22
30
varying gaussianUV: vec2f;
23
31
varying gaussianColor: vec4f;
24
32
@@ -33,7 +41,7 @@ fn fragmentMain(input: FragmentInput) -> FragmentOutput {
33
41
}
34
42
35
43
// evaluate alpha
36
- var alpha: f32 = exp (-A * 4.0) * gaussianColor.a;
44
+ var alpha: f32 = fastExp (-A * 4.0) * gaussianColor.a;
37
45
38
46
#if defined(SHADOW_PASS) || defined(PICK_PASS) || defined(PREPASS_PASS)
39
47
if (alpha < uniform.alphaClip) {
You can’t perform that action at this time.
0 commit comments