Skip to content

Commit

Permalink
Add worldLightPosition option.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonnavis committed Jun 5, 2021
1 parent 619d4fe commit 334abca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
19 changes: 19 additions & 0 deletions examples/jsm/postprocessing/SSShadowPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ class SSRrPass extends Pass {
}
} );

this._worldLightPosition = SSRrShader.defines.WORLD_LIGHT_POSITION;
Object.defineProperty( this, 'worldLightPosition', {
get() {

return this._worldLightPosition;

},
set( val ) {

if ( this._worldLightPosition === val ) return;
this._worldLightPosition = val;
this.ssrrMaterial.defines.WORLD_LIGHT_POSITION = val;
this.ssrrMaterial.needsUpdate = true;

}
} );

// beauty render target with depth buffer

const depthTexture = new DepthTexture();
Expand Down Expand Up @@ -134,6 +151,7 @@ class SSRrPass extends Pass {
this.ssrrMaterial.uniforms[ 'resolution' ].value.set( this.width, this.height );
this.ssrrMaterial.uniforms[ 'cameraProjectionMatrix' ].value.copy( this.camera.projectionMatrix );
this.ssrrMaterial.uniforms[ 'cameraInverseProjectionMatrix' ].value.copy( this.camera.projectionMatrixInverse );
this.ssrrMaterial.uniforms[ 'cameraMatrixWorldInverse' ].value.copy( this.camera.matrixWorldInverse );

// normal material

Expand Down Expand Up @@ -231,6 +249,7 @@ class SSRrPass extends Pass {
this.ssrrMaterial.uniforms[ 'maxDistance' ].value = this.maxDistance;
this.ssrrMaterial.uniforms[ 'surfDist' ].value = this.surfDist;
this.ssrrMaterial.uniforms[ 'doubleSideCheckStartFrom' ].value = this.doubleSideCheckStartFrom;
this.ssrrMaterial.uniforms[ 'cameraMatrixWorldInverse' ].value.copy( this.camera.matrixWorldInverse );
this.renderPass( renderer, this.ssrrMaterial, this.ssrrRenderTarget );

// output result to screen
Expand Down
10 changes: 9 additions & 1 deletion examples/jsm/shaders/SSShadowShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const SSRrShader = {
MAX_STEP: 0,
PERSPECTIVE_CAMERA: true,
INFINITE_THICK: false,
WORLD_LIGHT_POSITION: false,
},

uniforms: {
Expand All @@ -23,6 +24,7 @@ const SSRrShader = {
'resolution': { value: new Vector2() },
'cameraProjectionMatrix': { value: new Matrix4() },
'cameraInverseProjectionMatrix': { value: new Matrix4() },
'cameraMatrixWorldInverse': { value: new Matrix4() },
'lightPosition': { value: new Vector3(1.7,1.7,0) },
'cameraRange': { value: 0 },
'maxDistance': { value: 180 },
Expand Down Expand Up @@ -60,6 +62,7 @@ const SSRrShader = {
uniform vec3 lightPosition;
uniform mat4 cameraProjectionMatrix;
uniform mat4 cameraInverseProjectionMatrix;
uniform mat4 cameraMatrixWorldInverse;
uniform float maxDistance;
uniform float surfDist;
uniform float doubleSideCheckStartFrom;
Expand Down Expand Up @@ -124,7 +127,12 @@ const SSRrShader = {
vec3 viewNormal=getViewNormal( vUv );
vec3 viewRefractDir=normalize(lightPosition-viewPosition);
#ifdef WORLD_LIGHT_POSITION
vec3 viewLightPosition=(cameraMatrixWorldInverse*vec4(lightPosition,1.)).xyz;
#else
vec3 viewLightPosition=lightPosition;
#endif
vec3 viewRefractDir=normalize(viewLightPosition-viewPosition);
vec3 d1viewPosition=viewPosition+viewRefractDir*maxDistance;
#ifdef PERSPECTIVE_CAMERA
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: false,
autoRotate: true,
};
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' ).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.lightPosition, 'x' ).name('lightX').min( -10 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'y' ).name('lightY').min( -10 ).max( 10 ).step( .0001 );
gui.add( ssrrPass.lightPosition, 'z' ).name('lightZ').min( -10 ).max( 10 ).step( .0001 );
gui.add( ssrrPass, 'worldLightPosition' );
gui.add( ssrrPass, 'doubleSideCheckStartFrom' ).min( 0 ).max( .1 ).step( .0001 );
gui.add( params, 'autoRotate' ).onChange( () => {

Expand Down

0 comments on commit 334abca

Please sign in to comment.