|
@@ -102,6 +102,12 @@ function UniformsCache() {
|
|
|
|
|
|
var nextVersion = 0;
|
|
|
|
|
|
+var shadowCastingLightsFirst = function ( lightA, lightB ) {
|
|
|
+
|
|
|
+ return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
function WebGLLights() {
|
|
|
|
|
|
var cache = new UniformsCache();
|
|
@@ -116,7 +122,10 @@ function WebGLLights() {
|
|
|
spotLength: - 1,
|
|
|
rectAreaLength: - 1,
|
|
|
hemiLength: - 1,
|
|
|
- shadowsLength: - 1,
|
|
|
+
|
|
|
+ numDirectionalShadows: - 1,
|
|
|
+ numPointShadows: - 1,
|
|
|
+ numSpotShadows: - 1,
|
|
|
},
|
|
|
|
|
|
ambient: [ 0, 0, 0 ],
|
|
@@ -131,7 +140,11 @@ function WebGLLights() {
|
|
|
point: [],
|
|
|
pointShadowMap: [],
|
|
|
pointShadowMatrix: [],
|
|
|
- hemi: []
|
|
|
+ hemi: [],
|
|
|
+
|
|
|
+ numDirectionalShadows: - 1,
|
|
|
+ numPointShadows: - 1,
|
|
|
+ numSpotShadows: - 1
|
|
|
|
|
|
};
|
|
|
|
|
@@ -153,8 +166,14 @@ function WebGLLights() {
|
|
|
var rectAreaLength = 0;
|
|
|
var hemiLength = 0;
|
|
|
|
|
|
+ var numDirectionalShadows = 0;
|
|
|
+ var numPointShadows = 0;
|
|
|
+ var numSpotShadows = 0;
|
|
|
+
|
|
|
var viewMatrix = camera.matrixWorldInverse;
|
|
|
|
|
|
+ lights.sort( shadowCastingLightsFirst );
|
|
|
+
|
|
|
for ( var i = 0, l = lights.length; i < l; i ++ ) {
|
|
|
|
|
|
var light = lights[ i ];
|
|
@@ -199,10 +218,13 @@ function WebGLLights() {
|
|
|
uniforms.shadowRadius = shadow.radius;
|
|
|
uniforms.shadowMapSize = shadow.mapSize;
|
|
|
|
|
|
+ state.directionalShadowMap[ directionalLength ] = shadowMap;
|
|
|
+ state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
|
|
|
+
|
|
|
+ numDirectionalShadows ++;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- state.directionalShadowMap[ directionalLength ] = shadowMap;
|
|
|
- state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
|
|
|
state.directional[ directionalLength ] = uniforms;
|
|
|
|
|
|
directionalLength ++;
|
|
@@ -236,10 +258,13 @@ function WebGLLights() {
|
|
|
uniforms.shadowRadius = shadow.radius;
|
|
|
uniforms.shadowMapSize = shadow.mapSize;
|
|
|
|
|
|
+ state.spotShadowMap[ spotLength ] = shadowMap;
|
|
|
+ state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
|
|
|
+
|
|
|
+ numSpotShadows ++;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- state.spotShadowMap[ spotLength ] = shadowMap;
|
|
|
- state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
|
|
|
state.spot[ spotLength ] = uniforms;
|
|
|
|
|
|
spotLength ++;
|
|
@@ -299,10 +324,13 @@ function WebGLLights() {
|
|
|
uniforms.shadowCameraNear = shadow.camera.near;
|
|
|
uniforms.shadowCameraFar = shadow.camera.far;
|
|
|
|
|
|
+ state.pointShadowMap[ pointLength ] = shadowMap;
|
|
|
+ state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
|
|
|
+
|
|
|
+ numPointShadows ++;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- state.pointShadowMap[ pointLength ] = shadowMap;
|
|
|
- state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
|
|
|
state.point[ pointLength ] = uniforms;
|
|
|
|
|
|
pointLength ++;
|
|
@@ -337,7 +365,9 @@ function WebGLLights() {
|
|
|
hash.spotLength !== spotLength ||
|
|
|
hash.rectAreaLength !== rectAreaLength ||
|
|
|
hash.hemiLength !== hemiLength ||
|
|
|
- hash.shadowsLength !== shadows.length ) {
|
|
|
+ hash.numDirectionalShadows !== numDirectionalShadows ||
|
|
|
+ hash.numPointShadows !== numPointShadows ||
|
|
|
+ hash.numSpotShadows !== numSpotShadows ) {
|
|
|
|
|
|
state.directional.length = directionalLength;
|
|
|
state.spot.length = spotLength;
|
|
@@ -345,12 +375,22 @@ function WebGLLights() {
|
|
|
state.point.length = pointLength;
|
|
|
state.hemi.length = hemiLength;
|
|
|
|
|
|
+ state.directionalShadowMap.length = numDirectionalShadows;
|
|
|
+ state.pointShadowMap.length = numPointShadows;
|
|
|
+ state.spotShadowMap.length = numSpotShadows;
|
|
|
+ state.directionalShadowMatrix.length = numDirectionalShadows;
|
|
|
+ state.pointShadowMatrix.length = numPointShadows;
|
|
|
+ state.spotShadowMatrix.length = numSpotShadows;
|
|
|
+
|
|
|
hash.directionalLength = directionalLength;
|
|
|
hash.pointLength = pointLength;
|
|
|
hash.spotLength = spotLength;
|
|
|
hash.rectAreaLength = rectAreaLength;
|
|
|
hash.hemiLength = hemiLength;
|
|
|
- hash.shadowsLength = shadows.length;
|
|
|
+
|
|
|
+ hash.numDirectionalShadows = numDirectionalShadows;
|
|
|
+ hash.numPointShadows = numPointShadows;
|
|
|
+ hash.numSpotShadows = numSpotShadows;
|
|
|
|
|
|
state.version = nextVersion ++;
|
|
|
|