@@ -26,6 +26,16 @@ import { Fn, float, vec2, vec3, acos, add, mul, clamp, cos, dot, exp, max, mix,
2626 * scene.add( sky );
2727 * ```
2828 *
29+ * It can be useful to hide the sun disc when generating an environment map to avoid artifacts
30+ *
31+ * ```js
32+ * // disable before rendering environment map
33+ * sky.showSunDisc.value = false;
34+ * // ...
35+ * // re-enable before scene sky box rendering
36+ * sky.showSunDisc.value = true;
37+ * ```
38+ *
2939 * @augments Mesh
3040 * @three_import import { SkyMesh } from 'three/addons/objects/SkyMesh.js';
3141 */
@@ -117,6 +127,13 @@ class SkyMesh extends Mesh {
117127 */
118128 this . cloudElevation = uniform ( 0.5 ) ;
119129
130+ /**
131+ * Whether to render the solar disc.
132+ *
133+ * @type {UniformNode<float> }
134+ */
135+ this . showSunDisc = uniform ( 1 ) ;
136+
120137 /**
121138 * This flag can be used for type testing.
122139 *
@@ -146,8 +163,8 @@ class SkyMesh extends Mesh {
146163 const vertexNode = /*@__PURE__ */ Fn ( ( ) => {
147164
148165 // constants for atmospheric scattering
149- const e = float ( 2.71828182845904523536028747135266249775724709369995957 ) ;
150- // const pi = float( 3.141592653589793238462643383279502884197169 );
166+ const e = float ( 2.718281828459045 ) ;
167+ // const pi = float( 3.141592653589793 );
151168
152169 // wavelength of used primaries, according to preetham
153170 // const lambda = vec3( 680E-9, 550E-9, 450E-9 );
@@ -211,13 +228,13 @@ class SkyMesh extends Mesh {
211228 const colorNode = /*@__PURE__ */ Fn ( ( ) => {
212229
213230 // constants for atmospheric scattering
214- const pi = float ( 3.141592653589793238462643383279502884197169 ) ;
231+ const pi = float ( 3.141592653589793 ) ;
215232
216233 // optical length at zenith for molecules
217234 const rayleighZenithLength = float ( 8.4E3 ) ;
218235 const mieZenithLength = float ( 1.25E3 ) ;
219236 // 66 arc seconds -> degrees, and the cosine of that
220- const sunAngularDiameterCos = float ( 0.999956676946448443553574619906976478926848692873900859324 ) ;
237+ const sunAngularDiameterCos = float ( 0.9999566769464484 ) ;
221238
222239 // 3.0 / ( 16.0 * pi )
223240 const THREE_OVER_SIXTEENPI = float ( 0.05968310365946075 ) ;
@@ -262,8 +279,8 @@ class SkyMesh extends Mesh {
262279 const L0 = vec3 ( 0.1 ) . mul ( Fex ) ;
263280
264281 // composition + solar disc
265- const sundisk = smoothstep ( sunAngularDiameterCos , sunAngularDiameterCos . add ( 0.00002 ) , cosTheta ) ;
266- L0 . addAssign ( vSunE . mul ( 19000.0 ) . mul ( Fex ) . mul ( sundisk ) ) ;
282+ const sundisc = smoothstep ( sunAngularDiameterCos , sunAngularDiameterCos . add ( 0.00002 ) , cosTheta ) . mul ( this . showSunDisc ) ;
283+ L0 . addAssign ( vSunE . mul ( 19000.0 ) . mul ( Fex ) . mul ( sundisc ) ) ;
267284
268285 const texColor = add ( Lin , L0 ) . mul ( 0.04 ) . add ( vec3 ( 0.0 , 0.0003 , 0.00075 ) ) . toVar ( ) ;
269286
0 commit comments