Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLShadowMap: fix directional light shadow updating #11314

Merged
merged 1 commit into from
May 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions src/renderers/webgl/WebGLShadowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {

// render depth map

var faceCount, isPointLight;
var faceCount;

for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {

var light = _lightShadows[ i ];
var shadow = light.shadow;
var isPointLight = light && light.isPointLight;

if ( shadow === undefined ) {

Expand All @@ -134,25 +135,12 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {

}

if ( shadow.isSpotLightShadow ) {

shadow.update( light );

}

var shadowCamera = shadow.camera;
var shadowMatrix = shadow.matrix;

_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
shadowCamera.position.copy( _lightPositionWorld );

_shadowMapSize.copy( shadow.mapSize );
_shadowMapSize.min( _maxShadowMapSize );

if ( light && light.isPointLight ) {

faceCount = 6;
isPointLight = true;
if ( isPointLight ) {

var vpWidth = _shadowMapSize.x;
var vpHeight = _shadowMapSize.y;
Expand Down Expand Up @@ -186,6 +174,34 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
_shadowMapSize.x *= 4.0;
_shadowMapSize.y *= 2.0;

}

if ( shadow.map === null ) {

var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };

shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap";

shadowCamera.updateProjectionMatrix();

}

if ( shadow.isSpotLightShadow ) {

shadow.update( light );

}

var shadowMap = shadow.map;
var shadowMatrix = shadow.matrix;

_lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
shadowCamera.position.copy( _lightPositionWorld );

if ( isPointLight ) {

faceCount = 6;

// for point lights we set the shadow matrix to be a translation-only matrix
// equal to inverse of the light's position
Expand All @@ -195,7 +211,6 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {
} else {

faceCount = 1;
isPointLight = false;

_lookTarget.setFromMatrixPosition( light.target.matrixWorld );
shadowCamera.lookAt( _lookTarget );
Expand All @@ -216,19 +231,6 @@ function WebGLShadowMap( _renderer, _lights, _objects, capabilities ) {

}

if ( shadow.map === null ) {

var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };

shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
shadow.map.texture.name = light.name + ".shadowMap";

shadowCamera.updateProjectionMatrix();

}

var shadowMap = shadow.map;

_renderer.setRenderTarget( shadowMap );
_renderer.clear();

Expand Down