提交 867baa06 编写于 作者: M Mr.doob

WebGLRenderer: More shadow collection refactoring. See #8379.

上级 c2824abf
......@@ -106,7 +106,7 @@
color: 0xff0000,
shininess: 150,
specular: 0x222222,
shading: THREE.SmoothShading,
shading: THREE.SmoothShading
} );
torusKnot = new THREE.Mesh( geometry, material );
......
......@@ -139,8 +139,7 @@ THREE.WebGLRenderer = function ( parameters ) {
pointShadowMatrix: [],
hemi: [],
shadows: 0,
shadowsPointLight: 0
shadows: []
},
......@@ -303,7 +302,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// shadow map
var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
this.shadowMap = shadowMap;
......@@ -1160,6 +1159,8 @@ THREE.WebGLRenderer = function ( parameters ) {
//
setupShadows( lights );
shadowMap.render( scene, camera );
setupLights( lights, camera );
......@@ -1625,7 +1626,8 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( materialProperties.lightsHash !== _lights.hash ) {
if ( materialProperties.lightsHash !== undefined &&
materialProperties.lightsHash !== _lights.hash ) {
material.needsUpdate = true;
......@@ -2588,6 +2590,26 @@ THREE.WebGLRenderer = function ( parameters ) {
}
function setupShadows ( lights ) {
var lightShadowsLength = 0;
for ( var i = 0, l = lights.length; i < l; i ++ ) {
var light = lights[ i ];
if ( light.castShadow ) {
_lights.shadows[ lightShadowsLength ++ ] = light;
}
}
_lights.shadows.length = lightShadowsLength;
}
function setupLights ( lights, camera ) {
var l, ll, light,
......@@ -2603,9 +2625,6 @@ THREE.WebGLRenderer = function ( parameters ) {
spotLength = 0,
hemiLength = 0;
_lights.shadows = 0;
_lights.shadowsPointLight = 0;
for ( l = 0, ll = lights.length; l < ll; l ++ ) {
light = lights[ l ];
......@@ -2638,8 +2657,6 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.shadowRadius = light.shadow.radius;
uniforms.shadowMapSize = light.shadow.mapSize;
_lights.shadows ++;
}
_lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
......@@ -2673,8 +2690,6 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.shadowRadius = light.shadow.radius;
uniforms.shadowMapSize = light.shadow.mapSize;
_lights.shadows ++;
}
_lights.spotShadowMap[ spotLength ] = light.shadow.map;
......@@ -2700,8 +2715,6 @@ THREE.WebGLRenderer = function ( parameters ) {
uniforms.shadowRadius = light.shadow.radius;
uniforms.shadowMapSize = light.shadow.mapSize;
_lights.shadows ++;
}
_lights.pointShadowMap[ pointLength ] = light.shadow.map;
......@@ -2745,7 +2758,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_lights.point.length = pointLength;
_lights.hemi.length = hemiLength;
_lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows;
_lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
}
......
......@@ -418,7 +418,6 @@ THREE.WebGLProgram = ( function () {
parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
......@@ -520,7 +519,6 @@ THREE.WebGLProgram = ( function () {
parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
......
......@@ -23,8 +23,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
"maxBones", "useVertexTexture", "morphTargets", "morphNormals",
"maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
"numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
"shadowMapEnabled", "pointLightShadows", "toneMapping", 'physicallyCorrectLights',
"shadowMapType",
"shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
"alphaTest", "doubleSided", "flipSided"
];
......@@ -170,9 +169,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
numSpotLights: lights.spot.length,
numHemiLights: lights.hemi.length,
pointLightShadows: lights.shadowsPointLight,
shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows > 0,
shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
shadowMapType: renderer.shadowMap.type,
toneMapping: renderer.toneMapping,
......
......@@ -10,7 +10,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
_frustum = new THREE.Frustum(),
_projScreenMatrix = new THREE.Matrix4(),
_lightShadows = [],
_lightShadows = _lights.shadows,
_shadowMapSize = new THREE.Vector2(),
......@@ -97,25 +97,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
if ( scope.enabled === false ) return;
if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
// Collect lights with shadows
var lightShadowsLength = 0;
for ( var i = 0, l = _lights.length; i < l; i ++ ) {
var light = _lights[ i ];
if ( light.castShadow ) {
_lightShadows[ lightShadowsLength ++ ] = light;
}
}
if ( lightShadowsLength === 0 ) return;
_lightShadows.length = lightShadowsLength;
if ( _lightShadows.length === 0 ) return;
// Set GL state for depth map.
_state.clearColor( 1, 1, 1, 1 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册