提交 80c63992 编写于 作者: M Mr.doob

Merge pull request #7271 from mkkellogg/dev

Fix for #7260: PointLight shadows work properly only if shadow is applied to first light added to the scene.
......@@ -1989,6 +1989,11 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( light instanceof THREE.PointLight ) {
// for point lights we set the shadow matrix to be a translation-only matrix
// equal to inverse of the light's position
_vector3.setFromMatrixPosition( light.matrixWorld ).negate();
light.shadowMatrix.identity().setPosition( _vector3 );
// for point lights we set the sign of the shadowDarkness uniform to be negative
uniforms.shadowDarkness.value[ j ] = - light.shadowDarkness;
......
......@@ -101,30 +101,6 @@
}
// gsdXX = grid sampling disk XX
// these values are used when rendering PCF shadow maps for point lights
const vec3 gsd0 = vec3( 1, 1, 1 );
const vec3 gsd1 = vec3( 1, - 1, 1 );
const vec3 gsd2 = vec3( - 1, - 1, 1 );
const vec3 gsd3 = vec3( - 1, 1, 1 );
const vec3 gsd4 = vec3( 1, 1, - 1 );
const vec3 gsd5 = vec3( 1, - 1, - 1 );
const vec3 gsd6 = vec3( - 1, - 1, - 1 );
const vec3 gsd7 = vec3( -1, 1, - 1 );
const vec3 gsd8 = vec3( 1, 1, 0 );
const vec3 gsd9 = vec3( 1, - 1, 0 );
const vec3 gsd10 = vec3( - 1, - 1, 0 );
const vec3 gsd11 = vec3( - 1, 1, 0 );
const vec3 gsd12 = vec3( 1, 0, 1 );
const vec3 gsd13 = vec3( - 1, 0, 1 );
const vec3 gsd14 = vec3( 1, 0, - 1 );
const vec3 gsd15 = vec3( - 1, 0, - 1 );
const vec3 gsd16 = vec3( 0, 1, 1 );
const vec3 gsd17 = vec3( 0, - 1, 1 );
const vec3 gsd18 = vec3( 0, - 1, - 1 );
const vec3 gsd19 = vec3( 0, 1, - 1 );
#endif
#endif
......@@ -2,40 +2,8 @@
for( int i = 0; i < MAX_SHADOWS; i ++ ) {
#if defined(POINT_LIGHT_SHADOWS)
// if shadowDarkness[ i ] < 0.0, that means we have a point light with a cube
// shadow map
if( shadowDarkness[ i ] < 0.0 ) {
// calculate vector from light to vertex in view space
vec3 fromLight = mvPosition.xyz - pointLightPosition[ i ];
// Transform 'fromLight' into world space by multiplying it on the left
// side of 'viewMatrix'. This is equivalent to multiplying it on the right
// side of the transpose of 'viewMatrix'. Since 'viewMatrix' is orthogonal,
// its transpose is the same as its inverse.
fromLight = fromLight * mat3( viewMatrix );
// We repurpose vShadowCoord to hold the distance in world space from the
// light to the vertex. This value will be interpolated correctly in the fragment shader.
vShadowCoord[ i ] = vec4( fromLight, 1.0 );
} else {
vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;
}
#else
vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;
#endif
}
#endif
\ No newline at end of file
......@@ -100,27 +100,15 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
var faceCount, isPointLight;
if ( scope.enabled === false ) return;
if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
// set GL state for depth map
if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
// Set GL state for depth map.
_gl.clearColor( 1, 1, 1, 1 );
_state.disable( _gl.BLEND );
_state.enable( _gl.CULL_FACE );
_gl.frontFace( _gl.CCW );
if ( scope.cullFace === THREE.CullFaceFront ) {
_gl.cullFace( _gl.FRONT );
} else {
_gl.cullFace( _gl.BACK );
}
_state.setDepthTest( true );
_gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
_state.setDepthTest( true );
// save the existing viewport so it can be restored later
_renderer.getViewport( _vector4 );
......@@ -131,6 +119,8 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
var light = _lights[ i ];
if ( ! light.castShadow ) continue;
if ( light instanceof THREE.PointLight ) {
faceCount = 6;
......@@ -172,8 +162,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
if ( ! light.castShadow ) continue;
if ( ! light.shadowMap ) {
var shadowFilter = THREE.LinearFilter;
......@@ -321,15 +309,17 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
_renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
//We must call _renderer.resetGLState() at the end of each iteration of
// the light loop in order to force material updates for each light.
_renderer.resetGLState();
}
// restore GL state
_renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
// Restore GL state.
var clearColor = _renderer.getClearColor(),
clearAlpha = _renderer.getClearAlpha();
_renderer.setClearColor( clearColor, clearAlpha );
_state.enable( _gl.BLEND );
......@@ -339,7 +329,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
_renderer.resetGLState();
_renderer.resetGLState();
scope.needsUpdate = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册