|
@@ -60,13 +60,6 @@ function UniformsCache() {
|
|
|
color: new Color(),
|
|
|
distance: 0,
|
|
|
decay: 0,
|
|
|
-
|
|
|
- shadow: false,
|
|
|
- shadowBias: 0,
|
|
|
- shadowRadius: 1,
|
|
|
- shadowMapSize: new Vector2(),
|
|
|
- shadowCameraNear: 1,
|
|
|
- shadowCameraFar: 1000
|
|
|
};
|
|
|
break;
|
|
|
|
|
@@ -100,6 +93,67 @@ function UniformsCache() {
|
|
|
|
|
|
}
|
|
|
|
|
|
+function ShadowUniformsCache() {
|
|
|
+
|
|
|
+ var lights = {};
|
|
|
+
|
|
|
+ return {
|
|
|
+
|
|
|
+ get: function ( light ) {
|
|
|
+
|
|
|
+ if ( lights[ light.id ] !== undefined ) {
|
|
|
+
|
|
|
+ return lights[ light.id ];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var uniforms;
|
|
|
+
|
|
|
+ switch ( light.type ) {
|
|
|
+
|
|
|
+ case 'DirectionalLight':
|
|
|
+ uniforms = {
|
|
|
+ shadow: false,
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2()
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'SpotLight':
|
|
|
+ uniforms = {
|
|
|
+ shadow: false,
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2()
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'PointLight':
|
|
|
+ uniforms = {
|
|
|
+ shadow: false,
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2(),
|
|
|
+ shadowCameraNear: 1,
|
|
|
+ shadowCameraFar: 1000
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ lights[ light.id ] = uniforms;
|
|
|
+
|
|
|
+ return uniforms;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var nextVersion = 0;
|
|
|
|
|
|
function shadowCastingLightsFirst( lightA, lightB ) {
|
|
@@ -112,6 +166,8 @@ function WebGLLights() {
|
|
|
|
|
|
var cache = new UniformsCache();
|
|
|
|
|
|
+ var shadowCache = ShadowUniformsCache();
|
|
|
+
|
|
|
var state = {
|
|
|
|
|
|
version: 0,
|
|
@@ -138,6 +194,7 @@ function WebGLLights() {
|
|
|
spotShadowMatrix: [],
|
|
|
rectArea: [],
|
|
|
point: [],
|
|
|
+ pointShadow: [],
|
|
|
pointShadowMap: [],
|
|
|
pointShadowMatrix: [],
|
|
|
hemi: []
|
|
@@ -308,18 +365,20 @@ function WebGLLights() {
|
|
|
uniforms.distance = light.distance;
|
|
|
uniforms.decay = light.decay;
|
|
|
|
|
|
- uniforms.shadow = light.castShadow;
|
|
|
-
|
|
|
if ( light.castShadow ) {
|
|
|
|
|
|
var shadow = light.shadow;
|
|
|
|
|
|
- uniforms.shadowBias = shadow.bias;
|
|
|
- uniforms.shadowRadius = shadow.radius;
|
|
|
- uniforms.shadowMapSize = shadow.mapSize;
|
|
|
- uniforms.shadowCameraNear = shadow.camera.near;
|
|
|
- uniforms.shadowCameraFar = shadow.camera.far;
|
|
|
+ var shadowUniforms = shadowCache.get( light );
|
|
|
+
|
|
|
+ shadowUniforms.shadow = light.castShadow;
|
|
|
+ shadowUniforms.shadowBias = shadow.bias;
|
|
|
+ shadowUniforms.shadowRadius = shadow.radius;
|
|
|
+ shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
|
+ shadowUniforms.shadowCameraNear = shadow.camera.near;
|
|
|
+ shadowUniforms.shadowCameraFar = shadow.camera.far;
|
|
|
|
|
|
+ state.pointShadow[ pointLength ] = shadowUniforms;
|
|
|
state.pointShadowMap[ pointLength ] = shadowMap;
|
|
|
state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
|
|
|
|
|
@@ -372,6 +431,7 @@ function WebGLLights() {
|
|
|
state.hemi.length = hemiLength;
|
|
|
|
|
|
state.directionalShadowMap.length = numDirectionalShadows;
|
|
|
+ state.pointShadow.length = numPointShadows;
|
|
|
state.pointShadowMap.length = numPointShadows;
|
|
|
state.spotShadowMap.length = numSpotShadows;
|
|
|
state.directionalShadowMatrix.length = numDirectionalShadows;
|