Skip to content

Commit

Permalink
Turn on GroundReflector by default & some clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonnavis committed Feb 19, 2021
1 parent 98f9aaa commit 1142c1b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 4 additions & 2 deletions examples/jsm/objects/ReflectorForSSRPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var Reflector = function ( geometry, options ) {

//

scope.needsUpdate = false;

var reflectorPlane = new Plane();
var normal = new Vector3();
var reflectorWorldPosition = new Vector3();
Expand Down Expand Up @@ -91,8 +93,8 @@ var Reflector = function ( geometry, options ) {
this.material = material;

this.onBeforeRender = function ( renderer, scene, camera ) {
if (!window.needReflector) return;
window.needReflector=false
if ( !scope.needsUpdate ) return;
scope.needsUpdate = false;
// console.log('onBeforeRender')

reflectorWorldPosition.setFromMatrixPosition( scope.matrixWorld );
Expand Down
3 changes: 1 addition & 2 deletions examples/jsm/postprocessing/SSRPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var SSRPass = function({ scene, camera, width, height, selects, encoding, isPers
this.output = 0;

this.maxDistance = SSRShader.uniforms.maxDistance.value;
this.surfDist = SSRShader.uniforms.maxDistance.value;
this.surfDist = SSRShader.uniforms.surfDist.value;

this.encoding = encoding

Expand Down Expand Up @@ -349,7 +349,6 @@ SSRPass.prototype = Object.assign(Object.create(Pass.prototype), {
if (this.encoding) this.beautyRenderTarget.texture.encoding = this.encoding
renderer.setRenderTarget(this.beautyRenderTarget);
renderer.clear();
window.needReflector=true
renderer.render(this.scene, this.camera);

// render normals
Expand Down
30 changes: 15 additions & 15 deletions examples/webgl_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
enableSSR: true,
autoRotate: true,
isOtherMeshes: true,
isReflector: false,
isGroundReflector: true,
}
let composer
let ssrPass
Expand All @@ -46,8 +46,7 @@
let controls;
let camera, scene, renderer;
let otherMeshes = []
let reflector
let reflectorRenderTarget
let groundReflector
let selects=[]

const container = document.querySelector('#container');
Expand Down Expand Up @@ -135,18 +134,17 @@
}
{
const geometry = new THREE.PlaneBufferGeometry(8, 8);
reflector = new Reflector(geometry, {
groundReflector = new Reflector(geometry, {
clipBias: 0.003,
textureWidth: window.innerWidth,
textureHeight: window.innerHeight,
color: 0x888888,
useDepthTexture: true,
});
reflectorRenderTarget = reflector.getRenderTarget()
reflector.position.y = plane.position.y + .0001;
reflector.rotation.x = -Math.PI / 2
reflector.visible = params.isReflector
scene.add(reflector);
groundReflector.position.y = plane.position.y + .0001;
groundReflector.rotation.x = -Math.PI / 2
groundReflector.visible = params.isGroundReflector
scene.add(groundReflector);
}

// renderer
Expand Down Expand Up @@ -182,7 +180,7 @@
height: innerHeight,
encoding: THREE.sRGBEncoding,
isPerspectiveCamera: isPerspectiveCamera,
selects: params.isReflector ? selects : null,
selects: params.isGroundReflector ? selects : null,
// morphTargets: true,
});
// window.ssrPass = ssrPass
Expand All @@ -198,12 +196,12 @@
gui.add(ssrPass, 'isDistanceAttenuation');
ssrPass.maxDistance = .1
gui.add(ssrPass, 'maxDistance').min(0).max(1).step(.01);
gui.add(params, 'isReflector').onChange(() => {
if (params.isReflector) {
reflector.visible = true
gui.add(params, 'isGroundReflector').onChange(() => {
if (params.isGroundReflector) {
groundReflector.visible = true
ssrPass.selects = selects
} else {
reflector.visible = false
groundReflector.visible = false
ssrPass.selects = null
}
})
Expand Down Expand Up @@ -251,7 +249,7 @@

renderer.setSize(window.innerWidth, window.innerHeight);
composer.setSize(window.innerWidth, window.innerHeight);
reflectorRenderTarget.setSize(window.innerWidth, window.innerHeight);
groundReflector.getRenderTarget().setSize(window.innerWidth, window.innerHeight);

}

Expand Down Expand Up @@ -279,8 +277,10 @@
}

if (params.enableSSR) {
groundReflector.needsUpdate = true; // Just SSRPass's beautyRenderTarget (which rendered fisrt internally) need Reflector.
composer.render();
} else {
groundReflector.needsUpdate = true;
renderer.render(scene, camera)
}

Expand Down

0 comments on commit 1142c1b

Please sign in to comment.