|
@@ -199,7 +199,7 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
const matrix4 = new Matrix4();
|
|
|
const matrix42 = new Matrix4();
|
|
|
|
|
|
- function setup( lights, shadows, camera ) {
|
|
|
+ function setup( lights ) {
|
|
|
|
|
|
let r = 0, g = 0, b = 0;
|
|
|
|
|
@@ -215,8 +215,6 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
let numPointShadows = 0;
|
|
|
let numSpotShadows = 0;
|
|
|
|
|
|
- const viewMatrix = camera.matrixWorldInverse;
|
|
|
-
|
|
|
lights.sort( shadowCastingLightsFirst );
|
|
|
|
|
|
for ( let i = 0, l = lights.length; i < l; i ++ ) {
|
|
@@ -248,10 +246,6 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
const uniforms = cache.get( light );
|
|
|
|
|
|
uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
|
|
|
- uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
- vector3.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
- uniforms.direction.sub( vector3 );
|
|
|
- uniforms.direction.transformDirection( viewMatrix );
|
|
|
|
|
|
if ( light.castShadow ) {
|
|
|
|
|
@@ -281,16 +275,10 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
const uniforms = cache.get( light );
|
|
|
|
|
|
uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
- uniforms.position.applyMatrix4( viewMatrix );
|
|
|
|
|
|
uniforms.color.copy( color ).multiplyScalar( intensity );
|
|
|
uniforms.distance = distance;
|
|
|
|
|
|
- uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
- vector3.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
- uniforms.direction.sub( vector3 );
|
|
|
- uniforms.direction.transformDirection( viewMatrix );
|
|
|
-
|
|
|
uniforms.coneCos = Math.cos( light.angle );
|
|
|
uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
|
|
|
uniforms.decay = light.decay;
|
|
@@ -328,24 +316,9 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
// (b) intensity is the brightness of the light
|
|
|
uniforms.color.copy( color ).multiplyScalar( intensity );
|
|
|
|
|
|
- uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
- uniforms.position.applyMatrix4( viewMatrix );
|
|
|
-
|
|
|
- // extract local rotation of light to derive width/height half vectors
|
|
|
- matrix42.identity();
|
|
|
- matrix4.copy( light.matrixWorld );
|
|
|
- matrix4.premultiply( viewMatrix );
|
|
|
- matrix42.extractRotation( matrix4 );
|
|
|
-
|
|
|
uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
|
|
|
uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
|
|
|
|
|
|
- uniforms.halfWidth.applyMatrix4( matrix42 );
|
|
|
- uniforms.halfHeight.applyMatrix4( matrix42 );
|
|
|
-
|
|
|
- // TODO (abelnation): RectAreaLight distance?
|
|
|
- // uniforms.distance = distance;
|
|
|
-
|
|
|
state.rectArea[ rectAreaLength ] = uniforms;
|
|
|
|
|
|
rectAreaLength ++;
|
|
@@ -354,9 +327,6 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
|
|
|
const uniforms = cache.get( light );
|
|
|
|
|
|
- uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
- uniforms.position.applyMatrix4( viewMatrix );
|
|
|
-
|
|
|
uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
|
|
|
uniforms.distance = light.distance;
|
|
|
uniforms.decay = light.decay;
|
|
@@ -390,10 +360,6 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
|
|
|
const uniforms = cache.get( light );
|
|
|
|
|
|
- uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
- uniforms.direction.transformDirection( viewMatrix );
|
|
|
- uniforms.direction.normalize();
|
|
|
-
|
|
|
uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
|
|
|
uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
|
|
|
|
|
@@ -485,8 +451,94 @@ function WebGLLights( extensions, capabilities ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function setupView( lights, camera ) {
|
|
|
+
|
|
|
+ let directionalLength = 0;
|
|
|
+ let pointLength = 0;
|
|
|
+ let spotLength = 0;
|
|
|
+ let rectAreaLength = 0;
|
|
|
+ let hemiLength = 0;
|
|
|
+
|
|
|
+ const viewMatrix = camera.matrixWorldInverse;
|
|
|
+
|
|
|
+ for ( let i = 0, l = lights.length; i < l; i ++ ) {
|
|
|
+
|
|
|
+ const light = lights[ i ];
|
|
|
+
|
|
|
+ if ( light.isDirectionalLight ) {
|
|
|
+
|
|
|
+ const uniforms = state.directional[ directionalLength ];
|
|
|
+
|
|
|
+ uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ vector3.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
+ uniforms.direction.sub( vector3 );
|
|
|
+ uniforms.direction.transformDirection( viewMatrix );
|
|
|
+
|
|
|
+ directionalLength ++;
|
|
|
+
|
|
|
+ } else if ( light.isSpotLight ) {
|
|
|
+
|
|
|
+ const uniforms = state.spot[ spotLength ];
|
|
|
+
|
|
|
+ uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ uniforms.position.applyMatrix4( viewMatrix );
|
|
|
+
|
|
|
+ uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ vector3.setFromMatrixPosition( light.target.matrixWorld );
|
|
|
+ uniforms.direction.sub( vector3 );
|
|
|
+ uniforms.direction.transformDirection( viewMatrix );
|
|
|
+
|
|
|
+ spotLength ++;
|
|
|
+
|
|
|
+ } else if ( light.isRectAreaLight ) {
|
|
|
+
|
|
|
+ const uniforms = state.rectArea[ rectAreaLength ];
|
|
|
+
|
|
|
+ uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ uniforms.position.applyMatrix4( viewMatrix );
|
|
|
+
|
|
|
+ // extract local rotation of light to derive width/height half vectors
|
|
|
+ matrix42.identity();
|
|
|
+ matrix4.copy( light.matrixWorld );
|
|
|
+ matrix4.premultiply( viewMatrix );
|
|
|
+ matrix42.extractRotation( matrix4 );
|
|
|
+
|
|
|
+ uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
|
|
|
+ uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
|
|
|
+
|
|
|
+ uniforms.halfWidth.applyMatrix4( matrix42 );
|
|
|
+ uniforms.halfHeight.applyMatrix4( matrix42 );
|
|
|
+
|
|
|
+ rectAreaLength ++;
|
|
|
+
|
|
|
+ } else if ( light.isPointLight ) {
|
|
|
+
|
|
|
+ const uniforms = state.point[ pointLength ];
|
|
|
+
|
|
|
+ uniforms.position.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ uniforms.position.applyMatrix4( viewMatrix );
|
|
|
+
|
|
|
+ pointLength ++;
|
|
|
+
|
|
|
+ } else if ( light.isHemisphereLight ) {
|
|
|
+
|
|
|
+ const uniforms = state.hemi[ hemiLength ];
|
|
|
+
|
|
|
+ uniforms.direction.setFromMatrixPosition( light.matrixWorld );
|
|
|
+ uniforms.direction.transformDirection( viewMatrix );
|
|
|
+ uniforms.direction.normalize();
|
|
|
+
|
|
|
+ hemiLength ++;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
setup: setup,
|
|
|
+ setupView: setupView,
|
|
|
state: state
|
|
|
};
|
|
|
|