@@ -13,7 +13,8 @@ import {
1313 WebGLRenderTarget ,
1414 DepthTexture ,
1515 UnsignedShortType ,
16- NearestFilter
16+ NearestFilter ,
17+ Plane
1718} from '../../../build/three.module.js' ;
1819
1920var ReflectorForSSRPass = function ( geometry , options ) {
@@ -29,6 +30,7 @@ var ReflectorForSSRPass = function ( geometry, options ) {
2930 var color = ( options . color !== undefined ) ? new Color ( options . color ) : new Color ( 0x7F7F7F ) ;
3031 var textureWidth = options . textureWidth || 512 ;
3132 var textureHeight = options . textureHeight || 512 ;
33+ var clipBias = options . clipBias || 0 ;
3234 var shader = options . shader || ReflectorForSSRPass . ReflectorShader ;
3335 var useDepthTexture = options . useDepthTexture === true ;
3436 var yAxis = new Vector3 ( 0 , 1 , 0 ) ;
@@ -135,6 +137,9 @@ var ReflectorForSSRPass = function ( geometry, options ) {
135137
136138 this . material = material ;
137139
140+ const globalPlane = new Plane ( new Vector3 ( 0 , 1 , 0 ) , clipBias ) ;
141+ const globalPlanes = [ globalPlane ] ;
142+
138143 this . doRender = function ( renderer , scene , camera ) {
139144
140145 material . uniforms [ 'maxDistance' ] . value = scope . maxDistance ;
@@ -201,33 +206,6 @@ var ReflectorForSSRPass = function ( geometry, options ) {
201206 textureMatrix . multiply ( virtualCamera . matrixWorldInverse ) ;
202207 textureMatrix . multiply ( scope . matrixWorld ) ;
203208
204- /* Note: For the sake of accurate tDepth, temporarily turned off this Oblique Near-Plane Clipping feature. https://github.com/mrdoob/three.js/pull/21403
205-
206- // Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
207- // Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
208- reflectorPlane.setFromNormalAndCoplanarPoint( normal, reflectorWorldPosition );
209- reflectorPlane.applyMatrix4( virtualCamera.matrixWorldInverse );
210-
211- clipPlane.set( reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant );
212-
213- var projectionMatrix = virtualCamera.projectionMatrix;
214-
215- q.x = ( Math.sign( clipPlane.x ) + projectionMatrix.elements[ 8 ] ) / projectionMatrix.elements[ 0 ];
216- q.y = ( Math.sign( clipPlane.y ) + projectionMatrix.elements[ 9 ] ) / projectionMatrix.elements[ 5 ];
217- q.z = - 1.0;
218- q.w = ( 1.0 + projectionMatrix.elements[ 10 ] ) / projectionMatrix.elements[ 14 ];
219-
220- // Calculate the scaled plane vector
221- clipPlane.multiplyScalar( 2.0 / clipPlane.dot( q ) );
222-
223- // Replacing the third row of the projection matrix
224- projectionMatrix.elements[ 2 ] = clipPlane.x;
225- projectionMatrix.elements[ 6 ] = clipPlane.y;
226- projectionMatrix.elements[ 10 ] = clipPlane.z + 1.0 - clipBias;
227- projectionMatrix.elements[ 14 ] = clipPlane.w;
228-
229- */
230-
231209 // Render
232210
233211 renderTarget . texture . encoding = renderer . outputEncoding ;
@@ -238,9 +216,11 @@ var ReflectorForSSRPass = function ( geometry, options ) {
238216
239217 var currentXrEnabled = renderer . xr . enabled ;
240218 var currentShadowAutoUpdate = renderer . shadowMap . autoUpdate ;
219+ var currentClippingPlanes = renderer . clippingPlanes ;
241220
242221 renderer . xr . enabled = false ; // Avoid camera modification
243222 renderer . shadowMap . autoUpdate = false ; // Avoid re-computing shadows
223+ renderer . clippingPlanes = globalPlanes ;
244224
245225 renderer . setRenderTarget ( renderTarget ) ;
246226
@@ -251,6 +231,7 @@ var ReflectorForSSRPass = function ( geometry, options ) {
251231
252232 renderer . xr . enabled = currentXrEnabled ;
253233 renderer . shadowMap . autoUpdate = currentShadowAutoUpdate ;
234+ renderer . clippingPlanes = currentClippingPlanes ;
254235
255236 renderer . setRenderTarget ( currentRenderTarget ) ;
256237
0 commit comments