HemisphereLightProbe.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @author WestLangley / http://github.com/WestLangley
  3. */
  4. import { Color } from '../math/Color.js';
  5. import { Vector3 } from '../math/Vector3.js';
  6. import { LightProbe } from './LightProbe.js';
  7. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  8. LightProbe.call( this, undefined, intensity );
  9. var color1 = new Color().set( skyColor );
  10. var color2 = new Color().set( groundColor );
  11. var sky = new Vector3( color1.r, color1.g, color1.b );
  12. var ground = new Vector3( color2.r, color2.g, color2.b );
  13. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  14. var c0 = Math.sqrt( Math.PI );
  15. var c1 = c0 * Math.sqrt( 0.75 );
  16. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  17. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  18. }
  19. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  20. constructor: HemisphereLightProbe,
  21. isHemisphereLightProbe: true,
  22. copy: function ( source ) { // modifying colors not currently supported
  23. LightProbe.prototype.copy.call( this, source );
  24. return this;
  25. },
  26. toJSON: function ( meta ) {
  27. var data = LightProbe.prototype.toJSON.call( this, meta );
  28. // data.sh = this.sh.toArray(); // todo
  29. return data;
  30. }
  31. } );
  32. export { HemisphereLightProbe };
粤ICP备19079148号