Browse Source

Re-merged logarithmic depth buffer code into new file structure

James Baicoianu 11 years ago
parent
commit
d542550851
2 changed files with 31 additions and 1 deletions
  1. 16 0
      src/renderers/WebGLRenderer.js
  2. 15 1
      src/renderers/webgl/WebGLProgram.js

+ 16 - 0
src/renderers/WebGLRenderer.js

@@ -24,6 +24,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	_antialias = parameters.antialias !== undefined ? parameters.antialias : false,
 	_premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
 	_preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
+	_logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
 
 	_clearColor = new THREE.Color( 0x000000 ),
 	_clearAlpha = 0;
@@ -184,6 +185,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 	var _glExtensionTextureFilterAnisotropic;
 	var _glExtensionCompressedTextureS3TC;
 	var _glExtensionElementIndexUint;
+	var _glExtensionFragDepth;
 	
 
 	initGL();
@@ -4100,6 +4102,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 			fogExp: fog instanceof THREE.FogExp2,
 
 			sizeAttenuation: material.sizeAttenuation,
+			logarithmicDepthBuffer: _logarithmicDepthBuffer,
 
 			skinning: material.skinning,
 			maxBones: maxBones,
@@ -4299,6 +4302,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			_gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
 
+			if ( _logarithmicDepthBuffer ) {
+
+				_gl.uniform1f(p_uniforms.logDepthBufFC, 2.0 / (Math.log(camera.far + 1.0) / Math.LN2));
+
+			}
+
+
 			if ( camera !== _currentCamera ) _currentCamera = camera;
 
 		}
@@ -6135,6 +6145,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 			}
 		}
 
+		if ( _logarithmicDepthBuffer ) {
+
+			_glExtensionFragDepth = _gl.getExtension( 'EXT_frag_depth' );
+
+		}
+
 	};
 
 	function setDefaultGLState () {

+ 15 - 1
src/renderers/webgl/WebGLProgram.js

@@ -146,6 +146,10 @@ THREE.WebGLProgram = ( function () {
 
 				parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
 
+				parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
+				//_this._glExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "",
+
+
 				"uniform mat4 modelMatrix;",
 				"uniform mat4 modelViewMatrix;",
 				"uniform mat4 projectionMatrix;",
@@ -242,6 +246,9 @@ THREE.WebGLProgram = ( function () {
 				parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
 				parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
 
+				parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
+				//_this._glExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "",
+
 				"uniform mat4 viewMatrix;",
 				"uniform vec3 cameraPosition;",
 				""
@@ -308,6 +315,13 @@ THREE.WebGLProgram = ( function () {
 
 		}
 
+		if ( parameters.logarithmicDepthBuffer ) {
+
+			identifiers.push('logDepthBufFC');
+
+		}
+
+
 		for ( var u in uniforms ) {
 
 			identifiers.push( u );
@@ -358,4 +372,4 @@ THREE.WebGLProgram = ( function () {
 
 	};
 
-} )();
+} )();