Browse Source

Merge remote-tracking branch 'alteredq/dev' into dev

Mr.doob 13 years ago
parent
commit
fc8ac5814c

+ 2 - 2
doc/conf.py

@@ -48,9 +48,9 @@ copyright = u'2011, three.js Authors'
 # built documents.
 #
 # The short X.Y version.
-version = 'r46'
+version = 'r47'
 # The full version, including alpha/beta/rc tags.
-release = 'r46'
+release = 'r47'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.

+ 2 - 2
examples/webgl_interactive_draggablecubes.html

@@ -93,11 +93,11 @@
 				renderer.shadowMapEnabled = true;
 				renderer.shadowMapSoft = true;
 
-				renderer.shadowCameraNear = 3;
+				renderer.shadowCameraNear = 200;
 				renderer.shadowCameraFar = camera.far;
 				renderer.shadowCameraFov = 50;
 
-				renderer.shadowMapBias = 0.0039;
+				renderer.shadowMapBias = -0.00022;
 				renderer.shadowMapDarkness = 0.5;
 				renderer.shadowMapWidth = 1024;
 				renderer.shadowMapHeight = 1024;

+ 3 - 3
examples/webgl_materials_cubemap_dynamic.html

@@ -189,17 +189,17 @@
 
 				// SHADOW
 
-				renderer.shadowCameraNear = 2;
+				renderer.shadowCameraNear = 100;
 				renderer.shadowCameraFar = camera.far;
 				renderer.shadowCameraFov = 50;
 
-				renderer.shadowMapBias = 0.003885;
+				renderer.shadowMapBias = -0.00125;
 				renderer.shadowMapDarkness = 0.5;
 				renderer.shadowMapWidth = SHADOW_MAP_WIDTH;
 				renderer.shadowMapHeight = SHADOW_MAP_HEIGHT;
+				renderer.shadowMapCullFrontFaces = false;
 
 				renderer.shadowMapEnabled = true;
-				//renderer.shadowMapSoft = false;
 
 				// STATS
 

+ 4 - 1
examples/webgl_materials_normalmap.html

@@ -205,8 +205,11 @@
 
 				//
 
+				renderer.shadowCameraNear = 500;
 				renderer.shadowCameraFov = 70;
-				renderer.shadowMapBias = 0.0039;
+				renderer.shadowMapBias = 0.001;
+				renderer.shadowMapWidth = 1024;
+				renderer.shadowMapHeight = 1024;
 
 				renderer.shadowMapEnabled = true;
 				renderer.shadowMapSoft = true;

+ 2 - 1
examples/webgl_shading_physical.html

@@ -339,7 +339,8 @@
 				renderer.shadowMapAutoUpdate = false;
 				renderer.shadowMapEnabled = true;
 				renderer.shadowMapDarkness = 0.5 * sunIntensity;
-				renderer.shadowMapBias = 0.00390125;
+				renderer.shadowMapBias = 0.0;
+				renderer.shadowCameraNear = 50;
 
 				//
 

+ 2 - 2
examples/webgl_shadowmap.html

@@ -123,11 +123,11 @@
 				renderer.setClearColor( scene.fog.color, 1 );
 				renderer.autoClear = false;
 
-				renderer.shadowCameraNear = 3;
+				renderer.shadowCameraNear = 100;
 				renderer.shadowCameraFar = camera.far;
 				renderer.shadowCameraFov = 50;
 
-				renderer.shadowMapBias = 0.0039;
+				renderer.shadowMapBias = 0.0001;
 				renderer.shadowMapDarkness = 0.5;
 				renderer.shadowMapWidth = SHADOW_MAP_WIDTH;
 				renderer.shadowMapHeight = SHADOW_MAP_HEIGHT;

+ 22 - 25
src/extras/plugins/ShadowMapPlugin.js

@@ -4,14 +4,12 @@
 
 THREE.ShadowMapPlugin = function ( ) {
 
-	var _gl, _renderer,
-
-	_depthMaterial, _depthMaterialMorph,
-
+	var _gl,
+	_renderer,
 	_cameraLight,
+	_depthMaterial, _depthMaterialMorph,
 
 	_frustum = new THREE.Frustum(),
-
 	_projScreenMatrix = new THREE.Matrix4();
 
 	this.shadowMatrix = [];
@@ -61,6 +59,16 @@ THREE.ShadowMapPlugin = function ( ) {
 
 		}
 
+		// set GL state for depth map
+
+		_gl.clearColor( 1, 1, 1, 1 );
+		_gl.disable( _gl.BLEND );
+		if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.FRONT );
+
+		_renderer.setDepthTest( true );
+
+		// render depth map
+
 		for ( i = 0, il = lights.length; i < il; i ++ ) {
 
 			light = lights[ i ];
@@ -84,7 +92,6 @@ THREE.ShadowMapPlugin = function ( ) {
 
 				if ( _cameraLight.parent == null ) {
 
-					//console.warn( "Camera is not on the Scene. Adding it..." );
 					scene.add( _cameraLight );
 
 					if ( _renderer.autoUpdateScene ) scene.updateMatrixWorld();
@@ -115,20 +122,8 @@ THREE.ShadowMapPlugin = function ( ) {
 				_frustum.setFromMatrix( _projScreenMatrix );
 
 				_renderer.setRenderTarget( shadowMap );
-
-				// using arbitrary clear color in depth pass
-				// creates variance in shadows
-
-				_gl.clearColor( 1, 0, 1, 1 );
-				//_gl.clearColor( 0, 0, 0, 1 );
-
 				_renderer.clear();
 
-				var clearColor = _renderer.getClearColor(),
-					clearAlpha = _renderer.getClearAlpha();
-
-				_gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
-
 				// set matrices & frustum culling
 
 				renderList = scene.__webglObjects;
@@ -157,11 +152,6 @@ THREE.ShadowMapPlugin = function ( ) {
 
 				// render regular objects
 
-				_renderer.setDepthTest( true );
-				_renderer.setBlending( THREE.NormalBlending ); // maybe blending should be just disabled?
-
-				//_gl.cullFace( _gl.FRONT );
-
 				for ( j = 0, jl = renderList.length; j < jl; j ++ ) {
 
 					webglObject = renderList[ j ];
@@ -226,14 +216,21 @@ THREE.ShadowMapPlugin = function ( ) {
 
 				}
 
-				//_gl.cullFace( _gl.BACK );
-
 				shadowIndex ++;
 
 			}
 
 		}
 
+		// restore GL state
+
+		var clearColor = _renderer.getClearColor(),
+		clearAlpha = _renderer.getClearAlpha();
+
+		_gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
+		_gl.enable( _gl.BLEND );
+		if ( _renderer.shadowMapCullFrontFaces ) _gl.cullFace( _gl.BACK );
+
 	};
 
 };

+ 1 - 0
src/renderers/WebGLRenderer.js

@@ -62,6 +62,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	this.shadowMapEnabled = false;
 	this.shadowMapAutoUpdate = true;
 	this.shadowMapSoft = true;
+	this.shadowMapCullFrontFaces = true;
 
 	// morphs