Skip to content

Commit 8734d84

Browse files
committed
Update ShockWaveDemo.js
1 parent ebd5f50 commit 8734d84

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

demo/src/demos/ShockWaveDemo.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,24 @@ export class ShockWaveDemo extends PostProcessingDemo {
105105
ndc.x = (event.clientX / window.innerWidth) * 2.0 - 1.0;
106106
ndc.y = -(event.clientY / window.innerHeight) * 2.0 + 1.0;
107107

108-
ndc.z = await this.depthPickingPass.readDepth(ndc);
108+
const renderer = this.composer.getRenderer();
109+
let depth = await this.depthPickingPass.readDepth(ndc);
110+
111+
if(renderer.capabilities.reversedDepthBuffer) {
112+
113+
depth = 1.0 - depth;
114+
115+
} else if(renderer.capabilities.logarithmicDepthBuffer) {
116+
117+
const camera = this.camera;
118+
const d = Math.pow(2.0, depth * Math.log2(camera.far + 1.0)) - 1.0;
119+
const a = camera.far / (camera.far - camera.near);
120+
const b = camera.far * camera.near / (camera.near - camera.far);
121+
depth = a + b / d;
122+
123+
}
124+
125+
ndc.z = depth;
109126
ndc.z = ndc.z * 2.0 - 1.0;
110127

111128
// Convert from NDC to world position.

0 commit comments

Comments
 (0)