Skip to content

Commit 619d4fe

Browse files
committed
DoubleSide check.
1 parent 4883818 commit 619d4fe

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

examples/jsm/postprocessing/SSShadowPass.js

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SSRrPass extends Pass {
4343
this.lightPosition = SSRrShader.uniforms.lightPosition.value;
4444
this.maxDistance = SSRrShader.uniforms.maxDistance.value;
4545
this.surfDist = SSRrShader.uniforms.surfDist.value;
46+
this.doubleSideCheckStartFrom = SSRrShader.uniforms.doubleSideCheckStartFrom.value;
4647

4748
this.encoding = encoding;
4849

@@ -229,6 +230,7 @@ class SSRrPass extends Pass {
229230
this.ssrrMaterial.uniforms[ 'lightPosition' ].value = this.lightPosition;
230231
this.ssrrMaterial.uniforms[ 'maxDistance' ].value = this.maxDistance;
231232
this.ssrrMaterial.uniforms[ 'surfDist' ].value = this.surfDist;
233+
this.ssrrMaterial.uniforms[ 'doubleSideCheckStartFrom' ].value = this.doubleSideCheckStartFrom;
232234
this.renderPass( renderer, this.ssrrMaterial, this.ssrrRenderTarget );
233235

234236
// output result to screen

examples/jsm/shaders/SSShadowShader.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const SSRrShader = {
2727
'cameraRange': { value: 0 },
2828
'maxDistance': { value: 180 },
2929
'surfDist': { value: .007 },
30+
'doubleSideCheckStartFrom': { value: .01 },
3031

3132
},
3233

@@ -61,6 +62,7 @@ const SSRrShader = {
6162
uniform mat4 cameraInverseProjectionMatrix;
6263
uniform float maxDistance;
6364
uniform float surfDist;
65+
uniform float doubleSideCheckStartFrom;
6466
#include <packing>
6567
float pointToLineDistance(vec3 x0, vec3 x1, vec3 x2) {
6668
//x0: point, x1: linePointA, x2: linePointB
@@ -173,7 +175,12 @@ const SSRrShader = {
173175
gl_FragColor=texture2D(tDiffuse,vUv);
174176
if(hit){
175177
vec3 vN=getViewNormal( uv );
176-
if(dot(viewRefractDir,vN)>=0.) continue;
178+
179+
// if(dot(viewRefractDir,vN)>=0.) continue;
180+
181+
if((length(viewPosition-vP)<doubleSideCheckStartFrom)&&(dot(viewRefractDir,vN)>=0.)) continue;
182+
// May not need "doubleSideCheckStartFrom", use "surfDist" or change starting "i" of "for(float i=1.;i<float(MAX_STEP);i++){" instead.
183+
177184
gl_FragColor.rgb*=.5;
178185
return;
179186
}
Loading

examples/webgl_postprocessing_ssshadow.html

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

3434
const params = {
3535
enableSSRr: true,
36-
autoRotate: true,
36+
autoRotate: false,
3737
};
3838
let composer;
3939
let ssrrPass;
@@ -179,9 +179,10 @@
179179

180180
gui = new GUI();
181181
gui.add( params, 'enableSSRr' ).name( 'Enable SSRr' );
182-
gui.add( ssrrPass.lightPosition, 'x' ).min( 0 ).max( 10 ).step( .0001 );
183-
gui.add( ssrrPass.lightPosition, 'y' ).min( 0 ).max( 10 ).step( .0001 );
184-
gui.add( ssrrPass.lightPosition, 'z' ).min( 0 ).max( 10 ).step( .0001 );
182+
gui.add( ssrrPass.lightPosition, 'x' ).name('lightX').min( 0 ).max( 10 ).step( .0001 );
183+
gui.add( ssrrPass.lightPosition, 'y' ).name('lightY').min( 0 ).max( 10 ).step( .0001 );
184+
gui.add( ssrrPass.lightPosition, 'z' ).name('lightZ').min( 0 ).max( 10 ).step( .0001 );
185+
gui.add( ssrrPass, 'doubleSideCheckStartFrom' ).min( 0 ).max( .1 ).step( .0001 );
185186
gui.add( params, 'autoRotate' ).onChange( () => {
186187

187188
controls.enabled = ! params.autoRotate;

0 commit comments

Comments
 (0)