I think it will be better, why not use same floating point number in common.glsl.js
--- a/src/renderers/shaders/ShaderChunk/common.glsl.js
+++ b/src/renderers/shaders/ShaderChunk/common.glsl.js
@@ -1,9 +1,9 @@
export default /* glsl */`
#define PI 3.14159265359
#define PI2 6.28318530718
-#define PI_HALF 1.5707963267949
+#define PI_HALF 1.570796326795
#define RECIPROCAL_PI 0.31830988618
-#define RECIPROCAL_PI2 0.15915494
+#define RECIPROCAL_PI2 0.15915494309
#define LOG2 1.442695
Well, for consistency reasons it's of course better to follow a common approach for decimal places. At least for the PI constants.
@WestLangley any preferences?
Not really. @linbingquan can file a PR and fix it.
It looks like LOG2 is poorly-named. Maybe it is not used and can be removed here.
#define LOG2 1.442695041 // 1 / ln( 2 )
@WestLangley I don't know RECIPROCAL_PI what does it relationship with PI.
In the Chrome83, the Math.PI value is 3.141592653589793, I want to use it.
And I removed LOG2.
--- a/src/renderers/shaders/ShaderChunk/common.glsl.js
+++ b/src/renderers/shaders/ShaderChunk/common.glsl.js
@@ -1,10 +1,9 @@
export default /* glsl */`
-#define PI 3.14159265359
-#define PI2 6.28318530718
-#define PI_HALF 1.5707963267949
+#define PI 3.141592653589793
+#define PI2 6.283185307179586
+#define PI_HALF 1.5707963267948966
#define RECIPROCAL_PI 0.31830988618
-#define RECIPROCAL_PI2 0.15915494
-#define LOG2 1.442695
+#define RECIPROCAL_PI2 0.15915494309
#define EPSILON 1e-6
RECIPROCAL_PI = 1 / PI
@WestLangley Excuse me, I don't know EPSILON, why it define 1e-6, does it has relationship with Number.EPSILON, shall we change other high precision value, like 1e-7 or 1e-8, etc.
In the shaders, EPSILON is not based on the hardware precision. It has been used to avoid instabilities in the calculation. Perhaps it should be defined only where is it used.
/ping @bhouston for 2nd opinion
Just remember that glsl currently is precision limited to float32 or lower, where as JavaScript uses doubles for all mathematical calculations. Thus JavaScript's Math.PI and other math constants will have more precision than needed for GLSL. Probably don't hurt though as GLSL probably just truncates.
I am okay with removing EPSILON. I had a friend in university who could analyze any floating point calculation and tell you the exact epsilon you should use in that case. But it is a lot of work to do that on a per mathematical equation basis.