diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index ffda6114c18bfbae64ab656df2199f959294ffed..112394d85c0d0e65e490e06c5ccd8688631c4923 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -284,12 +284,9 @@ THREE.WebGLRenderer = function ( parameters ) { // shadow map - this.shadowMap = new THREE.WebGLShadowMap( this, lights, _webglObjects, _webglObjectsImmediate ); - this.shadowMapEnabled = false; - this.shadowMapType = THREE.PCFShadowMap; - this.shadowMapCullFace = THREE.CullFaceFront; - this.shadowMapDebug = false; - this.shadowMapCascade = false; + var shadowMap = new THREE.WebGLShadowMap( this, lights, _webglObjects, _webglObjectsImmediate ); + + this.shadowMap = shadowMap; // GPU capabilities @@ -1890,7 +1887,7 @@ THREE.WebGLRenderer = function ( parameters ) { // - this.shadowMap.render( scene, camera ); + shadowMap.render( scene, camera ); // @@ -2718,10 +2715,10 @@ THREE.WebGLRenderer = function ( parameters ) { maxHemiLights: maxLightCount.hemi, maxShadows: maxShadows, - shadowMapEnabled: _this.shadowMapEnabled && object.receiveShadow && maxShadows > 0, - shadowMapType: _this.shadowMapType, - shadowMapDebug: _this.shadowMapDebug, - shadowMapCascade: _this.shadowMapCascade, + shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0, + shadowMapType: shadowMap.type, + shadowMapDebug: shadowMap.debug, + shadowMapCascade: shadowMap.cascade, alphaTest: material.alphaTest, metal: material.metal, @@ -4780,4 +4777,52 @@ THREE.WebGLRenderer = function ( parameters ) { }; + Object.defineProperties( this, { + shadowMapEnabled: { + get: function () { + return this.shadowMap.enabled; + }, + set: function ( value ) { + THREE.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' ); + this.shadowMap.enabled = value; + } + }, + shadowMapType: { + get: function () { + return this.shadowMap.type; + }, + set: function ( value ) { + THREE.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' ); + this.shadowMap.type = value; + } + }, + shadowMapCullFace: { + get: function () { + return this.shadowMap.cullFace; + }, + set: function ( value ) { + THREE.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' ); + this.shadowMap.cullFace = value; + } + }, + shadowMapDebug: { + get: function () { + return this.shadowMap.debug; + }, + set: function ( value ) { + THREE.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' ); + this.shadowMap.debug = value; + } + }, + shadowMapCascade: { + get: function () { + return this.shadowMap.cascade; + }, + set: function ( value ) { + THREE.warn( 'THREE.WebGLRenderer: .shadowMapCascade is now .shadowMap.cascade.' ); + this.shadowMap.cascade = value; + } + } + } ); + }; diff --git a/src/renderers/webgl/WebGLShadowMap.js b/src/renderers/webgl/WebGLShadowMap.js index 7052b2ea495b67a80c8aba2da2ce945dc5a4388e..e5c0da1a62b70e83212fac23e7cb98c6cfb3cc19 100644 --- a/src/renderers/webgl/WebGLShadowMap.js +++ b/src/renderers/webgl/WebGLShadowMap.js @@ -5,10 +5,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjectsImmediate ) { - var _gl = _renderer.context; - - var _depthMaterial, _depthMaterialMorph, _depthMaterialSkin, _depthMaterialMorphSkin, - + var _gl = _renderer.context, _frustum = new THREE.Frustum(), _projScreenMatrix = new THREE.Matrix4(), @@ -24,27 +21,27 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjec var depthShader = THREE.ShaderLib[ "depthRGBA" ]; var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms ); - _depthMaterial = new THREE.ShaderMaterial( { + var _depthMaterial = new THREE.ShaderMaterial( { uniforms: depthUniforms, vertexShader: depthShader.vertexShader, fragmentShader: depthShader.fragmentShader } ); - _depthMaterialMorph = new THREE.ShaderMaterial( { + var _depthMaterialMorph = new THREE.ShaderMaterial( { uniforms: depthUniforms, vertexShader: depthShader.vertexShader, fragmentShader: depthShader.fragmentShader, morphTargets: true } ); - _depthMaterialSkin = new THREE.ShaderMaterial( { + var _depthMaterialSkin = new THREE.ShaderMaterial( { uniforms: depthUniforms, vertexShader: depthShader.vertexShader, fragmentShader: depthShader.fragmentShader, skinning: true } ); - _depthMaterialMorphSkin = new THREE.ShaderMaterial( { + var _depthMaterialMorphSkin = new THREE.ShaderMaterial( { uniforms: depthUniforms, vertexShader: depthShader.vertexShader, fragmentShader: depthShader.fragmentShader, @@ -57,9 +54,19 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjec _depthMaterialSkin._shadowPass = true; _depthMaterialMorphSkin._shadowPass = true; + // + + var scope = this; + + this.enabled = false; + this.type = THREE.PCFShadowMap; + this.cullFace = THREE.CullFaceFront; + this.debug = false; + this.cascade = false; + this.render = function ( scene, camera ) { - if ( _renderer.shadowMapEnabled === false ) return; + if ( scope.enabled === false ) return; var i, il, j, jl, n, @@ -80,7 +87,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjec _gl.enable( _gl.CULL_FACE ); _gl.frontFace( _gl.CCW ); - if ( _renderer.shadowMapCullFace === THREE.CullFaceFront ) { + if ( scope.cullFace === THREE.CullFaceFront ) { _gl.cullFace( _gl.FRONT ); @@ -157,7 +164,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjec var shadowFilter = THREE.LinearFilter; - if ( _renderer.shadowMapType === THREE.PCFSoftShadowMap ) { + if ( scope.type === THREE.PCFSoftShadowMap ) { shadowFilter = THREE.NearestFilter; @@ -339,7 +346,7 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _webglObjects, _webglObjec _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha ); _gl.enable( _gl.BLEND ); - if ( _renderer.shadowMapCullFace === THREE.CullFaceFront ) { + if ( scope.cullFace === THREE.CullFaceFront ) { _gl.cullFace( _gl.BACK );