소스 검색

Apply clipping planes in normal material

This fixes rendering of screen space effects depending on normals in the presence of a global clipping plane.
Olli Etuaho 6 년 전
부모
커밋
7ccc9b9a29

+ 20 - 1
examples/webgl_postprocessing_sao.html

@@ -41,6 +41,12 @@
 			var composer, renderPass, saoPass;
 			var group;
 
+			var params = {
+
+				clippingPlaneEnabled: false
+
+			};
+
 			init();
 			animate();
 
@@ -54,11 +60,13 @@
 				var devicePixelRatio = window.devicePixelRatio || 1;
 
 				renderer = new THREE.WebGLRenderer( { antialias: true } );
-				renderer.setClearColor( 0x000000 );
+				renderer.setClearColor( 0xffffff );
 				renderer.setPixelRatio( devicePixelRatio );
 				renderer.setSize( width, height );
 				document.body.appendChild( renderer.domElement );
 
+				var globalClipPlane = new THREE.Plane( new THREE.Vector3( 1, 0, -1 ), 0 );
+
 				camera = new THREE.PerspectiveCamera( 65, width / height, 3, 10 );
 				camera.position.z = 7;
 
@@ -141,6 +149,17 @@
 				gui.add( saoPass.params, 'saoBlurRadius', 0, 200 );
 				gui.add( saoPass.params, 'saoBlurStdDev', 0.5, 150 );
 				gui.add( saoPass.params, 'saoBlurDepthCutoff', 0.0, 0.1 );
+				gui.add( params, 'clippingPlaneEnabled' ).onChange( function() {
+					if ( params.clippingPlaneEnabled ) {
+
+						renderer.clippingPlanes = [ globalClipPlane ];
+
+					} else {
+
+						renderer.clippingPlanes = [];
+
+					}
+				} );
 
 				window.addEventListener( 'resize', onWindowResize, false );
 

+ 2 - 0
src/renderers/shaders/ShaderLib/normal_frag.glsl.js

@@ -27,9 +27,11 @@ uniform float opacity;
 #include <bumpmap_pars_fragment>
 #include <normalmap_pars_fragment>
 #include <logdepthbuf_pars_fragment>
+#include <clipping_planes_pars_fragment>
 
 void main() {
 
+	#include <clipping_planes_fragment>
 	#include <logdepthbuf_fragment>
 	#include <normal_fragment_begin>
 	#include <normal_fragment_maps>

+ 2 - 0
src/renderers/shaders/ShaderLib/normal_vert.glsl.js

@@ -25,6 +25,7 @@ export default /* glsl */`
 #include <morphtarget_pars_vertex>
 #include <skinning_pars_vertex>
 #include <logdepthbuf_pars_vertex>
+#include <clipping_planes_pars_vertex>
 
 void main() {
 
@@ -55,6 +56,7 @@ void main() {
 	#include <displacementmap_vertex>
 	#include <project_vertex>
 	#include <logdepthbuf_vertex>
+	#include <clipping_planes_vertex>
 
 #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )