Skip to content

Commit

Permalink
DoubleSide check.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonnavis committed Jun 5, 2021
1 parent 4883818 commit 619d4fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/jsm/postprocessing/SSShadowPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SSRrPass extends Pass {
this.lightPosition = SSRrShader.uniforms.lightPosition.value;
this.maxDistance = SSRrShader.uniforms.maxDistance.value;
this.surfDist = SSRrShader.uniforms.surfDist.value;
this.doubleSideCheckStartFrom = SSRrShader.uniforms.doubleSideCheckStartFrom.value;

this.encoding = encoding;

Expand Down Expand Up @@ -229,6 +230,7 @@ class SSRrPass extends Pass {
this.ssrrMaterial.uniforms[ 'lightPosition' ].value = this.lightPosition;
this.ssrrMaterial.uniforms[ 'maxDistance' ].value = this.maxDistance;
this.ssrrMaterial.uniforms[ 'surfDist' ].value = this.surfDist;
this.ssrrMaterial.uniforms[ 'doubleSideCheckStartFrom' ].value = this.doubleSideCheckStartFrom;
this.renderPass( renderer, this.ssrrMaterial, this.ssrrRenderTarget );

// output result to screen
Expand Down
9 changes: 8 additions & 1 deletion examples/jsm/shaders/SSShadowShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const SSRrShader = {
'cameraRange': { value: 0 },
'maxDistance': { value: 180 },
'surfDist': { value: .007 },
'doubleSideCheckStartFrom': { value: .01 },

},

Expand Down Expand Up @@ -61,6 +62,7 @@ const SSRrShader = {
uniform mat4 cameraInverseProjectionMatrix;
uniform float maxDistance;
uniform float surfDist;
uniform float doubleSideCheckStartFrom;
#include <packing>
float pointToLineDistance(vec3 x0, vec3 x1, vec3 x2) {
//x0: point, x1: linePointA, x2: linePointB
Expand Down Expand Up @@ -173,7 +175,12 @@ const SSRrShader = {
gl_FragColor=texture2D(tDiffuse,vUv);
if(hit){
vec3 vN=getViewNormal( uv );
if(dot(viewRefractDir,vN)>=0.) continue;
// if(dot(viewRefractDir,vN)>=0.) continue;
if((length(viewPosition-vP)<doubleSideCheckStartFrom)&&(dot(viewRefractDir,vN)>=0.)) continue;
// May not need "doubleSideCheckStartFrom", use "surfDist" or change starting "i" of "for(float i=1.;i<float(MAX_STEP);i++){" instead.
gl_FragColor.rgb*=.5;
return;
}
Expand Down
Binary file modified examples/screenshots/webgl_postprocessing_ssshadow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions examples/webgl_postprocessing_ssshadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

const params = {
enableSSRr: true,
autoRotate: true,
autoRotate: false,
};
let composer;
let ssrrPass;
Expand Down Expand Up @@ -179,9 +179,10 @@

gui = new GUI();
gui.add( params, 'enableSSRr' ).name( 'Enable SSRr' );
gui.add( ssrrPass.lightPosition, 'x' ).min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'y' ).min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'z' ).min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'x' ).name('lightX').min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'y' ).name('lightY').min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'z' ).name('lightZ').min( 0 ).max( 10 ).step( .0001 );
gui.add( ssrrPass, 'doubleSideCheckStartFrom' ).min( 0 ).max( .1 ).step( .0001 );
gui.add( params, 'autoRotate' ).onChange( () => {

controls.enabled = ! params.autoRotate;
Expand Down

0 comments on commit 619d4fe

Please sign in to comment.