|
@@ -29,11 +29,6 @@ function UniformsCache() {
|
|
|
uniforms = {
|
|
|
direction: new Vector3(),
|
|
|
color: new Color(),
|
|
|
-
|
|
|
- shadow: false,
|
|
|
- shadowBias: 0,
|
|
|
- shadowRadius: 1,
|
|
|
- shadowMapSize: new Vector2()
|
|
|
};
|
|
|
break;
|
|
|
|
|
@@ -46,11 +41,6 @@ function UniformsCache() {
|
|
|
coneCos: 0,
|
|
|
penumbraCos: 0,
|
|
|
decay: 0,
|
|
|
-
|
|
|
- shadow: false,
|
|
|
- shadowBias: 0,
|
|
|
- shadowRadius: 1,
|
|
|
- shadowMapSize: new Vector2()
|
|
|
};
|
|
|
break;
|
|
|
|
|
@@ -60,13 +50,6 @@ function UniformsCache() {
|
|
|
color: new Color(),
|
|
|
distance: 0,
|
|
|
decay: 0,
|
|
|
-
|
|
|
- shadow: false,
|
|
|
- shadowBias: 0,
|
|
|
- shadowRadius: 1,
|
|
|
- shadowMapSize: new Vector2(),
|
|
|
- shadowCameraNear: 1,
|
|
|
- shadowCameraFar: 1000
|
|
|
};
|
|
|
break;
|
|
|
|
|
@@ -84,7 +67,6 @@ function UniformsCache() {
|
|
|
position: new Vector3(),
|
|
|
halfWidth: new Vector3(),
|
|
|
halfHeight: new Vector3()
|
|
|
- // TODO (abelnation): set RectAreaLight shadow uniforms
|
|
|
};
|
|
|
break;
|
|
|
|
|
@@ -100,6 +82,66 @@ 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 = {
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2()
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'SpotLight':
|
|
|
+ uniforms = {
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2()
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'PointLight':
|
|
|
+ uniforms = {
|
|
|
+ shadowBias: 0,
|
|
|
+ shadowRadius: 1,
|
|
|
+ shadowMapSize: new Vector2(),
|
|
|
+ shadowCameraNear: 1,
|
|
|
+ shadowCameraFar: 1000
|
|
|
+ };
|
|
|
+ break;
|
|
|
+
|
|
|
+ // TODO (abelnation): set RectAreaLight shadow uniforms
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ lights[ light.id ] = uniforms;
|
|
|
+
|
|
|
+ return uniforms;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
var nextVersion = 0;
|
|
|
|
|
|
function shadowCastingLightsFirst( lightA, lightB ) {
|
|
@@ -112,6 +154,8 @@ function WebGLLights() {
|
|
|
|
|
|
var cache = new UniformsCache();
|
|
|
|
|
|
+ var shadowCache = ShadowUniformsCache();
|
|
|
+
|
|
|
var state = {
|
|
|
|
|
|
version: 0,
|
|
@@ -131,13 +175,16 @@ function WebGLLights() {
|
|
|
ambient: [ 0, 0, 0 ],
|
|
|
probe: [],
|
|
|
directional: [],
|
|
|
+ directionalShadow: [],
|
|
|
directionalShadowMap: [],
|
|
|
directionalShadowMatrix: [],
|
|
|
spot: [],
|
|
|
+ spotShadow: [],
|
|
|
spotShadowMap: [],
|
|
|
spotShadowMatrix: [],
|
|
|
rectArea: [],
|
|
|
point: [],
|
|
|
+ pointShadow: [],
|
|
|
pointShadowMap: [],
|
|
|
pointShadowMatrix: [],
|
|
|
hemi: []
|
|
@@ -204,16 +251,17 @@ function WebGLLights() {
|
|
|
uniforms.direction.sub( vector3 );
|
|
|
uniforms.direction.transformDirection( viewMatrix );
|
|
|
|
|
|
- uniforms.shadow = light.castShadow;
|
|
|
-
|
|
|
if ( light.castShadow ) {
|
|
|
|
|
|
var shadow = light.shadow;
|
|
|
|
|
|
- uniforms.shadowBias = shadow.bias;
|
|
|
- uniforms.shadowRadius = shadow.radius;
|
|
|
- uniforms.shadowMapSize = shadow.mapSize;
|
|
|
+ var shadowUniforms = shadowCache.get( light );
|
|
|
+
|
|
|
+ shadowUniforms.shadowBias = shadow.bias;
|
|
|
+ shadowUniforms.shadowRadius = shadow.radius;
|
|
|
+ shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
|
|
|
|
+ state.directionalShadow[ directionalLength ] = shadowUniforms;
|
|
|
state.directionalShadowMap[ directionalLength ] = shadowMap;
|
|
|
state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
|
|
|
|
|
@@ -244,16 +292,17 @@ function WebGLLights() {
|
|
|
uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
|
|
|
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;
|
|
|
+ var shadowUniforms = shadowCache.get( light );
|
|
|
+
|
|
|
+ shadowUniforms.shadowBias = shadow.bias;
|
|
|
+ shadowUniforms.shadowRadius = shadow.radius;
|
|
|
+ shadowUniforms.shadowMapSize = shadow.mapSize;
|
|
|
|
|
|
+ state.spotShadow[ spotLength ] = shadowUniforms;
|
|
|
state.spotShadowMap[ spotLength ] = shadowMap;
|
|
|
state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
|
|
|
|
|
@@ -308,18 +357,19 @@ 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.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;
|
|
|
|
|
@@ -371,8 +421,11 @@ function WebGLLights() {
|
|
|
state.point.length = pointLength;
|
|
|
state.hemi.length = hemiLength;
|
|
|
|
|
|
+ state.directionalShadow.length = numDirectionalShadows;
|
|
|
state.directionalShadowMap.length = numDirectionalShadows;
|
|
|
+ state.pointShadow.length = numPointShadows;
|
|
|
state.pointShadowMap.length = numPointShadows;
|
|
|
+ state.spotShadow.length = numSpotShadows;
|
|
|
state.spotShadowMap.length = numSpotShadows;
|
|
|
state.directionalShadowMatrix.length = numDirectionalShadows;
|
|
|
state.pointShadowMatrix.length = numPointShadows;
|