Skip to content

Commit 1483183

Browse files
committed
Rename surfDist to thickness and change behavior.
1 parent e980664 commit 1483183

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

examples/jsm/postprocessing/SSRPass.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var SSRPass = function ( { renderer, scene, camera, width, height, selects, enco
4141
this.output = 0;
4242

4343
this.maxDistance = SSRShader.uniforms.maxDistance.value;
44-
this.surfDist = SSRShader.uniforms.surfDist.value;
44+
this.thickness = SSRShader.uniforms.thickness.value;
4545

4646
this.encoding = encoding;
4747

@@ -153,7 +153,6 @@ var SSRPass = function ( { renderer, scene, camera, width, height, selects, enco
153153

154154
}
155155
} );
156-
this.thickTolerance = SSRShader.uniforms.thickTolerance.value;
157156

158157
// beauty render target with depth buffer
159158

@@ -234,7 +233,7 @@ var SSRPass = function ( { renderer, scene, camera, width, height, selects, enco
234233
this.ssrMaterial.uniforms[ 'tDepth' ].value = this.beautyRenderTarget.depthTexture;
235234
this.ssrMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
236235
this.ssrMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
237-
this.ssrMaterial.uniforms[ 'surfDist' ].value = this.surfDist;
236+
this.ssrMaterial.uniforms[ 'thickness' ].value = this.thickness;
238237
this.ssrMaterial.uniforms[ 'resolution' ].value.set( this.width, this.height );
239238
this.ssrMaterial.uniforms[ 'cameraProjectionMatrix' ].value.copy( this.camera.projectionMatrix );
240239
this.ssrMaterial.uniforms[ 'cameraInverseProjectionMatrix' ].value.copy( this.camera.projectionMatrixInverse );
@@ -393,8 +392,7 @@ SSRPass.prototype = Object.assign( Object.create( Pass.prototype ), {
393392

394393
this.ssrMaterial.uniforms[ 'opacity' ].value = this.opacity;
395394
this.ssrMaterial.uniforms[ 'maxDistance' ].value = this.maxDistance;
396-
this.ssrMaterial.uniforms[ 'surfDist' ].value = this.surfDist;
397-
this.ssrMaterial.uniforms[ 'thickTolerance' ].value = this.thickTolerance;
395+
this.ssrMaterial.uniforms[ 'thickness' ].value = this.thickness;
398396
this.renderPass( renderer, this.ssrMaterial, this.ssrRenderTarget );
399397

400398

examples/jsm/shaders/SSRShader.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ var SSRShader = {
3232
"opacity": { value: .5 },
3333
"maxDistance": { value: 180 },
3434
"cameraRange": { value: 0 },
35-
"surfDist": { value: .007 },
36-
"thickTolerance": { value: 0 },
35+
"thickness": { value: .007 },
3736

3837
},
3938

@@ -65,10 +64,9 @@ var SSRShader = {
6564
uniform float cameraNear;
6665
uniform float cameraFar;
6766
uniform float maxDistance;
68-
uniform float surfDist;
67+
uniform float thickness;
6968
uniform mat4 cameraProjectionMatrix;
7069
uniform mat4 cameraInverseProjectionMatrix;
71-
uniform float thickTolerance;
7270
#include <packing>
7371
float pointToLineDistance(vec3 x0, vec3 x1, vec3 x2) {
7472
//x0: point, x1: linePointA, x2: linePointB
@@ -180,28 +178,28 @@ var SSRShader = {
180178
// https://www.comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf
181179
float recipVPZ=1./viewPosition.z;
182180
float viewReflectRayZ=1./(recipVPZ+s*(1./d1viewPosition.z-recipVPZ));
183-
float sD=surfDist*cW;
181+
float tk=thickness*cW;
184182
#else
185183
float viewReflectRayZ=viewPosition.z+s*(d1viewPosition.z-viewPosition.z);
186-
float sD=surfDist;
184+
float tk=thickness;
187185
#endif
188-
if(viewReflectRayZ-sD>vZ) continue;
189186
190-
float op=opacity;
187+
if(viewReflectRayZ>vZ) continue;
191188
192189
bool hit;
193190
#ifdef INFINITE_THICK
194-
hit=(viewReflectRayZ+thickTolerance*clipW)<=vZ;
191+
hit=true;
195192
#else
196193
float away=pointToLineDistance(vP,viewPosition,d1viewPosition);
197-
hit=away<=sD;
194+
hit=away<=tk;
198195
#endif
199196
200197
if(hit){
201198
vec3 vN=getViewNormal( uv );
202199
if(dot(viewReflectDir,vN)>=0.) continue;
203200
float distance=pointPlaneDistance(vP,viewPosition,viewNormal);
204201
if(distance>maxDistance) break;
202+
float op=opacity;
205203
#ifdef DISTANCE_ATTENUATION
206204
float ratio=1.-(distance/maxDistance);
207205
float attenuation=ratio*ratio;
-3.15 KB
Loading

examples/webgl_postprocessing_ssr.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
const params = {
3535
enableSSR: true,
36-
autoRotate: true,
36+
autoRotate: false,
3737
otherMeshes: true,
3838
groundReflector: false,
3939
};
@@ -197,7 +197,10 @@
197197
}
198198

199199
} );
200-
ssrPass.infiniteThick = true
200+
// ssrPass.thickness = 0.0015;
201+
ssrPass.thickness = 0.03;
202+
gui.add( ssrPass, 'thickness' ).min( 0 ).max( .1 ).step( .0001 );
203+
ssrPass.infiniteThick = false
201204
gui.add( ssrPass, 'infiniteThick' );
202205
gui.add( params, 'autoRotate' ).onChange( () => {
203206

@@ -256,10 +259,8 @@
256259
groundReflector.opacity = ssrPass.opacity;
257260

258261
} );
259-
ssrPass.surfDist = 0.0015;
260-
folder.add( ssrPass, 'surfDist' ).min( 0 ).max( .005 ).step( .0001 );
261-
folder.add( ssrPass, 'thickTolerance' ).min( 0 ).max( .05 ).step( .0001 );
262262
folder.add( ssrPass, 'blur' );
263+
// folder.open()
263264
// gui.close()
264265

265266
}

0 commit comments

Comments
 (0)