UNPKG

903 BJavaScriptView Raw
1import { Color } from '../math/Color.js';
2import { Vector3 } from '../math/Vector3.js';
3import { LightProbe } from './LightProbe.js';
4
5class HemisphereLightProbe extends LightProbe {
6
7 constructor( skyColor, groundColor, intensity = 1 ) {
8
9 super( undefined, intensity );
10
11 const color1 = new Color().set( skyColor );
12 const color2 = new Color().set( groundColor );
13
14 const sky = new Vector3( color1.r, color1.g, color1.b );
15 const ground = new Vector3( color2.r, color2.g, color2.b );
16
17 // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
18 const c0 = Math.sqrt( Math.PI );
19 const c1 = c0 * Math.sqrt( 0.75 );
20
21 this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
22 this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
23
24 }
25
26}
27
28HemisphereLightProbe.prototype.isHemisphereLightProbe = true;
29
30export { HemisphereLightProbe };