Browse Source

fix MeshDepthMaterial, addresses issue #8550 (#8558)

* fix MeshDepthMaterial.

* use a single float instead of a vec3 for optimization purposes.

* use ThreeJS conventions for varyings.
Ben Houston (Clara.io) 9 years ago
parent
commit
0a60f11565

+ 3 - 11
src/renderers/shaders/ShaderLib/depth_frag.glsl

@@ -2,6 +2,8 @@ uniform float mNear;
 uniform float mFar;
 uniform float opacity;
 
+varying float vViewZDepth;
+
 #include <common>
 #include <packing>
 #include <logdepthbuf_pars_fragment>
@@ -12,17 +14,7 @@ void main() {
 	#include <clipping_planes_fragment>
 	#include <logdepthbuf_fragment>
 
-	#ifdef USE_LOGDEPTHBUF_EXT
-
-		float depth = gl_FragDepthEXT / gl_FragCoord.w;
-
-	#else
-
-		float depth = gl_FragCoord.z / gl_FragCoord.w;
-
-	#endif
-
-	float color = 1.0 - smoothstep( mNear, mFar, depth );
+	float color = 1.0 - smoothstep( mNear, mFar, vViewZDepth );
 	gl_FragColor = vec4( vec3( color ), opacity );
 
 }

+ 4 - 0
src/renderers/shaders/ShaderLib/depth_vert.glsl

@@ -3,6 +3,8 @@
 #include <logdepthbuf_pars_vertex>
 #include <clipping_planes_pars_vertex>
 
+varying float vViewZDepth;
+
 void main() {
 
 	#include <begin_vertex>
@@ -11,4 +13,6 @@ void main() {
 	#include <logdepthbuf_vertex>
 	#include <clipping_planes_vertex>
 
+	vViewZDepth = - mvPosition.z;
+
 }