提交 b07f8b94 编写于 作者: T tschw 提交者: Mr.doob

Shadowing / Culling

* Removed useless and outdated ShadowMapPlugin docs.

* Consistified WebGLState, added culling.

* Let WebGLShadowMap set culling through WebGLState.

* WebGLShadowMap: Removed redundant state setup.

* WebGLRenderer: Removed needless factorization.

* Removed cull state mess from WebGLShadowMap.

- Instead flip .side on the depth material with the same effect.
- See #8760.

* Updated builds.
上级 fa8f62de
......@@ -26368,7 +26368,12 @@ THREE.WebGLRenderer = function ( parameters ) {
function setMaterial( material ) {
setMaterialFaces( material );
if ( material.side !== THREE.DoubleSide )
state.enable( _gl.CULL_FACE );
else
state.disable( _gl.CULL_FACE );
state.setFlipSided( material.side === THREE.BackSide );
if ( material.transparent === true ) {
......@@ -26388,13 +26393,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
function setMaterialFaces( material ) {
material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
state.setFlipSided( material.side === THREE.BackSide );
}
function setProgram( camera, fog, material, object ) {
_usedTextureUnits = 0;
......@@ -27261,39 +27259,8 @@ THREE.WebGLRenderer = function ( parameters ) {
this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
if ( cullFace === THREE.CullFaceNone ) {
state.disable( _gl.CULL_FACE );
} else {
if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
_gl.frontFace( _gl.CW );
} else {
_gl.frontFace( _gl.CCW );
}
if ( cullFace === THREE.CullFaceBack ) {
_gl.cullFace( _gl.BACK );
} else if ( cullFace === THREE.CullFaceFront ) {
_gl.cullFace( _gl.FRONT );
} else {
_gl.cullFace( _gl.FRONT_AND_BACK );
}
state.enable( _gl.CULL_FACE );
}
state.setCullFace( cullFace );
state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
};
......@@ -30163,8 +30130,8 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
this.needsUpdate = false;
this.type = THREE.PCFShadowMap;
this.cullFace = THREE.CullFaceFront;
this.flipSidedFaces = true;
this.allowDoubleSided = false;
this.render = function ( scene, camera ) {
......@@ -30177,9 +30144,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
// Set GL state for depth map.
_state.clearColor( 1, 1, 1, 1 );
_state.disable( _gl.BLEND );
_state.enable( _gl.CULL_FACE );
_gl.frontFace( _gl.CCW );
_gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
_state.setDepthTest( true );
_state.setScissorTest( false );
......@@ -30359,14 +30323,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
clearAlpha = _renderer.getClearAlpha();
_renderer.setClearColor( clearColor, clearAlpha );
_state.enable( _gl.BLEND );
if ( scope.cullFace === THREE.CullFaceFront ) {
_gl.cullFace( _gl.BACK );
}
scope.needsUpdate = false;
};
......@@ -30440,9 +30396,15 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
result.visible = material.visible;
result.wireframe = material.wireframe;
result.side = scope.allowDoubleSided ? material.side : THREE.FrontSide;
var side = material.side;
if ( ! scope.allowDoubleSided ) side &= 1;
if ( scope.flipSidedFaces && side < 2 ) side ^= 1;
result.side = side;
result.clipShadows = material.clipShadows;
result.clippingPlanes = material.clippingPlanes;
result.wireframeLinewidth = material.wireframeLinewidth;
result.linewidth = material.linewidth;
......@@ -30487,6 +30449,27 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
Object.defineProperty( this, 'cullFace', {
set: function( cullFace ) {
var flipSided = ( cullFace !== THREE.CullFaceBack );
console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. " +
" Set .shadowMap.flipSidedFaces to " + flipSided + "." );
this.flipSidedFaces = flipSided;
},
get: function() {
return this.flipSidedFaces ? THREE.CullFaceFront : THREE.CullFaceBack;
}
} );
};
// File:src/renderers/webgl/WebGLState.js
......@@ -30533,6 +30516,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
var currentStencilZPass = null;
var currentFlipSided = null;
var currentCullFace = null;
var currentLineWidth = null;
......@@ -30560,15 +30544,14 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.clearStencil( 0 );
this.enable( gl.DEPTH_TEST );
gl.depthFunc( gl.LEQUAL );
this.setDepthFunc( THREE.LessEqualDepth );
gl.frontFace( gl.CCW );
gl.cullFace( gl.BACK );
this.setFlipSided( false );
this.setCullFace( THREE.CullFaceBack );
this.enable( gl.CULL_FACE );
this.enable( gl.BLEND );
gl.blendEquation( gl.FUNC_ADD );
gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
this.setBlending( THREE.NormalBlending );
};
......@@ -30626,7 +30609,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.disableUnusedAttributes = function () {
for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
......@@ -30689,13 +30672,15 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
if ( blending === THREE.NoBlending ) {
if ( blending !== THREE.NoBlending ) {
this.disable( gl.BLEND );
this.enable( gl.BLEND );
} else {
this.enable( gl.BLEND );
this.disable( gl.BLEND );
currentBlending = blending; // no blending, that is
return;
}
......@@ -30988,6 +30973,40 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
};
this.setCullFace = function ( cullFace ) {
if ( cullFace !== THREE.CullFaceNone ) {
this.enable( gl.CULL_FACE );
if ( cullFace !== currentCullFace ) {
if ( cullFace === THREE.CullFaceBack ) {
gl.cullFace( gl.BACK );
} else if ( cullFace === THREE.CullFaceFront ) {
gl.cullFace( gl.FRONT );
} else {
gl.cullFace( gl.FRONT_AND_BACK );
}
}
} else {
this.disable( gl.CULL_FACE );
}
currentCullFace = cullFace;
};
this.setLineWidth = function ( width ) {
if ( width !== currentLineWidth ) {
......@@ -31006,18 +31025,18 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.enable( gl.POLYGON_OFFSET_FILL );
} else {
if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
this.disable( gl.POLYGON_OFFSET_FILL );
gl.polygonOffset( factor, units );
}
currentPolygonOffsetFactor = factor;
currentPolygonOffsetUnits = units;
if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
}
gl.polygonOffset( factor, units );
} else {
currentPolygonOffsetFactor = factor;
currentPolygonOffsetUnits = units;
this.disable( gl.POLYGON_OFFSET_FILL );
}
......@@ -31206,6 +31225,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
currentStencilWrite = null;
currentFlipSided = null;
currentCullFace = null;
};
......
此差异已折叠。
......@@ -105,14 +105,13 @@
<div>Defines shadow map type (unfiltered, percentage close filtering, percentage close filtering with bilinear filtering in shader)</div>
<div>Options are THREE.BasicShadowMap, THREE.PCFShadowMap, THREE.PCFSoftShadowMap. Default is THREE.PCFShadowMap.</div>
<h3>[property:Boolean shadowMap.flipSidedFaces]</h3>
<h3>[property:Integer shadowMap.cullFace]</h3>
<div>Default is THREE.CullFaceFront. The faces that needed to be culled. Possible values: THREE.CullFaceFront and THREE.CullFaceBack</div>
<div>Whether to flip front and back sides of surfaces when rendering the shadow map. The default is true.</div>
<h3>[property:Boolean shadowMap.allowDoubleSided]</h3>
<div>Whether to allow double sided shadow rendering, off by default. When enabled, an appropriate shadow.bias must be set on the light source to keep surfaces from casting a shadow on themselves that will not render properly.</div>
<div>Whether to allow double sided shadow rendering, off by default. When enabled, an appropriate shadow.bias must be set on the light source to keep surfaces from casting a shadow on themselves that will not render properly. When disabled, double sided faces are treated like front-facing ones.</div>
<h3>[property:Integer maxMorphTargets]</h3>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../../" />
<script src="list.js"></script>
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<div class="desc">The Webglrenderer plugin class that allows shadowmaps to be rendered in the WebglRenderer. This plugin is automatically loaded in the Webglrenderer.</div>
<h2>Constructor</h2>
<h3>[name]()</h3>
<div>
Creates a new [name].
</div>
<h2>Methods</h2>
<h3>[method:null render]([page:Scene scene], [page:Camera camera])</h3>
<div>
scene -- The scene to render. <br />
camera -- The camera to render.
</div>
<div>
Prepares the shadowmaps to be rendered defined in the scene. This gets automatically called as pre render function to draw the lensflares.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</body>
</html>
......@@ -143,7 +143,6 @@ var list = {
"Renderers / WebGL / Plugins": [
[ "LensFlarePlugin", "api/renderers/webgl/plugins/LensFlarePlugin" ],
[ "ShadowMapPlugin", "api/renderers/webgl/plugins/ShadowMapPlugin" ],
[ "SpritePlugin", "api/renderers/webgl/plugins/SpritePlugin" ]
],
......
......@@ -1691,7 +1691,12 @@ THREE.WebGLRenderer = function ( parameters ) {
function setMaterial( material ) {
setMaterialFaces( material );
if ( material.side !== THREE.DoubleSide )
state.enable( _gl.CULL_FACE );
else
state.disable( _gl.CULL_FACE );
state.setFlipSided( material.side === THREE.BackSide );
if ( material.transparent === true ) {
......@@ -1711,13 +1716,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
function setMaterialFaces( material ) {
material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
state.setFlipSided( material.side === THREE.BackSide );
}
function setProgram( camera, fog, material, object ) {
_usedTextureUnits = 0;
......@@ -2584,39 +2582,8 @@ THREE.WebGLRenderer = function ( parameters ) {
this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
if ( cullFace === THREE.CullFaceNone ) {
state.disable( _gl.CULL_FACE );
} else {
if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
_gl.frontFace( _gl.CW );
} else {
_gl.frontFace( _gl.CCW );
}
if ( cullFace === THREE.CullFaceBack ) {
_gl.cullFace( _gl.BACK );
} else if ( cullFace === THREE.CullFaceFront ) {
_gl.cullFace( _gl.FRONT );
} else {
_gl.cullFace( _gl.FRONT_AND_BACK );
}
state.enable( _gl.CULL_FACE );
}
state.setCullFace( cullFace );
state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
};
......
......@@ -90,8 +90,8 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
this.needsUpdate = false;
this.type = THREE.PCFShadowMap;
this.cullFace = THREE.CullFaceFront;
this.flipSidedFaces = true;
this.allowDoubleSided = false;
this.render = function ( scene, camera ) {
......@@ -104,9 +104,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
// Set GL state for depth map.
_state.clearColor( 1, 1, 1, 1 );
_state.disable( _gl.BLEND );
_state.enable( _gl.CULL_FACE );
_gl.frontFace( _gl.CCW );
_gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
_state.setDepthTest( true );
_state.setScissorTest( false );
......@@ -286,14 +283,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
clearAlpha = _renderer.getClearAlpha();
_renderer.setClearColor( clearColor, clearAlpha );
_state.enable( _gl.BLEND );
if ( scope.cullFace === THREE.CullFaceFront ) {
_gl.cullFace( _gl.BACK );
}
scope.needsUpdate = false;
};
......@@ -367,9 +356,15 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
result.visible = material.visible;
result.wireframe = material.wireframe;
result.side = scope.allowDoubleSided ? material.side : THREE.FrontSide;
var side = material.side;
if ( ! scope.allowDoubleSided ) side &= 1;
if ( scope.flipSidedFaces && side < 2 ) side ^= 1;
result.side = side;
result.clipShadows = material.clipShadows;
result.clippingPlanes = material.clippingPlanes;
result.wireframeLinewidth = material.wireframeLinewidth;
result.linewidth = material.linewidth;
......@@ -414,4 +409,25 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
}
Object.defineProperty( this, 'cullFace', {
set: function( cullFace ) {
var flipSided = ( cullFace !== THREE.CullFaceBack );
console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. " +
" Set .shadowMap.flipSidedFaces to " + flipSided + "." );
this.flipSidedFaces = flipSided;
},
get: function() {
return this.flipSidedFaces ? THREE.CullFaceFront : THREE.CullFaceBack;
}
} );
};
......@@ -40,6 +40,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
var currentStencilZPass = null;
var currentFlipSided = null;
var currentCullFace = null;
var currentLineWidth = null;
......@@ -67,15 +68,14 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.clearStencil( 0 );
this.enable( gl.DEPTH_TEST );
gl.depthFunc( gl.LEQUAL );
this.setDepthFunc( THREE.LessEqualDepth );
gl.frontFace( gl.CCW );
gl.cullFace( gl.BACK );
this.setFlipSided( false );
this.setCullFace( THREE.CullFaceBack );
this.enable( gl.CULL_FACE );
this.enable( gl.BLEND );
gl.blendEquation( gl.FUNC_ADD );
gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
this.setBlending( THREE.NormalBlending );
};
......@@ -133,7 +133,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.disableUnusedAttributes = function () {
for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
......@@ -196,13 +196,15 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
if ( blending === THREE.NoBlending ) {
if ( blending !== THREE.NoBlending ) {
this.disable( gl.BLEND );
this.enable( gl.BLEND );
} else {
this.enable( gl.BLEND );
this.disable( gl.BLEND );
currentBlending = blending; // no blending, that is
return;
}
......@@ -495,6 +497,40 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
};
this.setCullFace = function ( cullFace ) {
if ( cullFace !== THREE.CullFaceNone ) {
this.enable( gl.CULL_FACE );
if ( cullFace !== currentCullFace ) {
if ( cullFace === THREE.CullFaceBack ) {
gl.cullFace( gl.BACK );
} else if ( cullFace === THREE.CullFaceFront ) {
gl.cullFace( gl.FRONT );
} else {
gl.cullFace( gl.FRONT_AND_BACK );
}
}
} else {
this.disable( gl.CULL_FACE );
}
currentCullFace = cullFace;
};
this.setLineWidth = function ( width ) {
if ( width !== currentLineWidth ) {
......@@ -513,18 +549,18 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
this.enable( gl.POLYGON_OFFSET_FILL );
} else {
if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
this.disable( gl.POLYGON_OFFSET_FILL );
gl.polygonOffset( factor, units );
}
currentPolygonOffsetFactor = factor;
currentPolygonOffsetUnits = units;
if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
}
gl.polygonOffset( factor, units );
} else {
currentPolygonOffsetFactor = factor;
currentPolygonOffsetUnits = units;
this.disable( gl.POLYGON_OFFSET_FILL );
}
......@@ -713,6 +749,7 @@ THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
currentStencilWrite = null;
currentFlipSided = null;
currentCullFace = null;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册