Browse Source

Added MeshDepthMaterial to WebGLRenderer2.

Mr.doob 14 years ago
parent
commit
1d8fae82eb
2 changed files with 30 additions and 4 deletions
  1. 3 3
      src/renderers/Projector.js
  2. 27 1
      src/renderers/WebGLRenderer2.js

+ 3 - 3
src/renderers/Projector.js

@@ -34,11 +34,11 @@ THREE.Projector = function() {
 
 		objects = scene.objects;
 
-		for ( o = 0, ol = objects.length; o < ol; o++ ) {
+		for ( o = 0, ol = objects.length; o < ol; o ++ ) {
 
 			object = objects[ o ];
 
-			if ( object.visible === false || isInFrustum( object ) === false ) continue;
+			if ( !object.visible || !isInFrustum( object ) ) continue;
 
 			_object = _objectPool[ _objectCount ] = _objectPool[ _objectCount ] || new THREE.RenderableObject();
 
@@ -82,7 +82,7 @@ THREE.Projector = function() {
 
 			object = objects[ o ];
 
-			if ( object.visible === false ) continue;
+			if ( !object.visible ) continue;
 
 			object.autoUpdateMatrix && object.updateMatrix();
 

+ 27 - 1
src/renderers/WebGLRenderer2.js

@@ -157,8 +157,14 @@ THREE.WebGLRenderer2 = function () {
 
 						_gl.uniform1f( program.uniforms.mOpacity, material.opacity );
 
-					}
+					} else if ( material instanceof THREE.MeshDepthMaterial ) {
 
+						_gl.uniform1f( program.uniforms.m2Near, material.__2near );
+						_gl.uniform1f( program.uniforms.mFarPlusNear, material.__farPlusNear );
+						_gl.uniform1f( program.uniforms.mFarMinusNear, material.__farMinusNear );
+						_gl.uniform1f( program.uniforms.mOpacity, material.opacity );
+
+					}
 
 					_gl.uniform3f( program.uniforms.cameraPosition, camera.position.x, camera.position.y, camera.position.z );
 
@@ -500,6 +506,26 @@ THREE.WebGLRenderer2 = function () {
 				vs += '}';
 				fs += '}';
 
+			} else if ( material instanceof THREE.MeshDepthMaterial ) {
+
+				vs += 'void main() {\n';
+				fs += 'void main() {\n';
+
+				vs += 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n';
+
+				pfs += 'uniform float m2Near;\n';
+				pfs += 'uniform float mFarPlusNear;\n';
+				pfs += 'uniform float mFarMinusNear;\n';
+				pfs += 'uniform float mOpacity;\n';
+				fs += 'float w = 1.0 - ( m2Near / ( mFarPlusNear - gl_FragCoord.z * mFarMinusNear ) );\n';
+				fs += 'gl_FragColor = vec4( w, w, w, mOpacity );\n';
+
+				identifiers.push( 'm2Near', 'mFarPlusNear', 'mFarMinusNear', 'mOpacity' );
+
+				vs += '}';
+				fs += '}';
+
+
 
 			} else if ( material instanceof THREE.MeshShaderMaterial ) {