浏览代码

Merge pull request #16298 from WestLangley/dev-ambient_hemi_light_probes

Added AmbientLightProbe and HemisphereLightProbe
Mr.doob 6 年之前
父节点
当前提交
513eceb0fe
共有 4 个文件被更改,包括 100 次插入3 次删除
  1. 2 0
      src/Three.js
  2. 45 0
      src/lights/AmbientLightProbe.js
  3. 53 0
      src/lights/HemisphereLightProbe.js
  4. 0 3
      src/lights/LightProbe.js

+ 2 - 0
src/Three.js

@@ -55,9 +55,11 @@ export { SpotLight } from './lights/SpotLight.js';
 export { PointLight } from './lights/PointLight.js';
 export { RectAreaLight } from './lights/RectAreaLight.js';
 export { HemisphereLight } from './lights/HemisphereLight.js';
+export { HemisphereLightProbe } from './lights/HemisphereLightProbe.js';
 export { DirectionalLightShadow } from './lights/DirectionalLightShadow.js';
 export { DirectionalLight } from './lights/DirectionalLight.js';
 export { AmbientLight } from './lights/AmbientLight.js';
+export { AmbientLightProbe } from './lights/AmbientLightProbe.js';
 export { LightShadow } from './lights/LightShadow.js';
 export { Light } from './lights/Light.js';
 export { LightProbe } from './lights/LightProbe.js';

+ 45 - 0
src/lights/AmbientLightProbe.js

@@ -0,0 +1,45 @@
+/**
+ * @author WestLangley / http://github.com/WestLangley
+ */
+
+import { Color } from '../math/Color.js';
+import { LightProbe } from './LightProbe.js';
+
+function AmbientLightProbe( color, intensity ) {
+
+	LightProbe.call( this, undefined, intensity );
+
+	var color1 = new Color().set( color );
+
+	// without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
+	this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
+
+}
+
+AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
+
+	constructor: AmbientLightProbe,
+
+	isAmbientLightProbe: true,
+
+	copy: function ( source ) { // modifying color not currently supported
+
+		LightProbe.prototype.copy.call( this, source );
+
+		return this;
+
+	},
+
+	toJSON: function ( meta ) {
+
+		var data = LightProbe.prototype.toJSON.call( this, meta );
+
+		// data.sh = this.sh.toArray(); // todo
+
+		return data;
+
+	}
+
+} );
+
+export { AmbientLightProbe };

+ 53 - 0
src/lights/HemisphereLightProbe.js

@@ -0,0 +1,53 @@
+/**
+ * @author WestLangley / http://github.com/WestLangley
+ */
+
+import { Color } from '../math/Color.js';
+import { LightProbe } from './LightProbe.js';
+
+function HemisphereLightProbe( skyColor, groundColor, intensity ) {
+
+	LightProbe.call( this, undefined, intensity );
+
+	var color1 = new Color().set( skyColor );
+	var color2 = new Color().set( groundColor );
+
+	var sky = new THREE.Vector3( color1.r, color1.g, color1.b );
+	var ground = new THREE.Vector3( color2.r, color2.g, color2.b );
+
+	// without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
+	var c0 = Math.sqrt( Math.PI );
+	var c1 = c0 * Math.sqrt( 0.75 );
+
+	this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
+	this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
+
+}
+
+HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
+
+	constructor: HemisphereLightProbe,
+
+	isHemisphereLightProbe: true,
+
+	copy: function ( source ) { // modifying colors not currently supported
+
+		LightProbe.prototype.copy.call( this, source );
+
+		return this;
+
+	},
+
+	toJSON: function ( meta ) {
+
+		var data = LightProbe.prototype.toJSON.call( this, meta );
+
+		// data.sh = this.sh.toArray(); // todo
+
+		return data;
+
+	}
+
+} );
+
+export { HemisphereLightProbe };

+ 0 - 3
src/lights/LightProbe.js

@@ -4,9 +4,6 @@
  * A LightProbe is a source of indirect-diffuse light
  */
 
-import { _Math } from '../math/Math.js';
-import { Vector3 } from '../math/Vector3.js';
-import { Color } from '../math/Color.js';
 import { SphericalHarmonics3 } from '../math/SphericalHarmonics3.js';
 import { Light } from './Light.js';