|
@@ -385,6 +385,16 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
|
|
|
return defines;
|
|
|
}
|
|
|
|
|
|
+ private static readonly ORTHO_DEPTH_PROJECTION = [
|
|
|
+ 1, 0, 0,
|
|
|
+ 0, 1, 0,
|
|
|
+ 0, 0, 1];
|
|
|
+
|
|
|
+ private static readonly PERSPECTIVE_DEPTH_PROJECTION = [
|
|
|
+ 0, 0, 0,
|
|
|
+ 0, 0, 0,
|
|
|
+ 1, 1, 1];
|
|
|
+
|
|
|
private _createSSAOPostProcess(ratio: number): void {
|
|
|
this._sampleSphere = this._generateHemisphere();
|
|
|
|
|
@@ -401,7 +411,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
|
|
|
[
|
|
|
"sampleSphere", "samplesFactor", "randTextureTiles", "totalStrength", "radius",
|
|
|
"base", "range", "projection", "near", "far", "texelSize",
|
|
|
- "xViewport", "yViewport", "maxZ", "minZAspect"
|
|
|
+ "xViewport", "yViewport", "maxZ", "minZAspect", "depthProjection"
|
|
|
],
|
|
|
samplers,
|
|
|
ratio, null, Texture.BILINEAR_SAMPLINGMODE,
|
|
@@ -424,8 +434,21 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
|
|
|
effect.setFloat("base", this.base);
|
|
|
effect.setFloat("near", this._scene.activeCamera.minZ);
|
|
|
effect.setFloat("far", this._scene.activeCamera.maxZ);
|
|
|
- effect.setFloat("xViewport", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));
|
|
|
- effect.setFloat("yViewport", Math.tan(this._scene.activeCamera.fov / 2));
|
|
|
+ if (this._scene.activeCamera.mode === Camera.PERSPECTIVE_CAMERA) {
|
|
|
+ effect.setMatrix3x3("depthProjection", SSAO2RenderingPipeline.PERSPECTIVE_DEPTH_PROJECTION);
|
|
|
+ effect.setFloat("xViewport", Math.tan(this._scene.activeCamera.fov / 2) * this._scene.getEngine().getAspectRatio(this._scene.activeCamera, true));
|
|
|
+ effect.setFloat("yViewport", Math.tan(this._scene.activeCamera.fov / 2));
|
|
|
+ } else {
|
|
|
+ const halfWidth = this._scene.getEngine().getRenderWidth() / 2.0;
|
|
|
+ const halfHeight = this._scene.getEngine().getRenderHeight() / 2.0;
|
|
|
+ const orthoLeft = this._scene.activeCamera.orthoLeft ?? -halfWidth;
|
|
|
+ const orthoRight = this._scene.activeCamera.orthoRight ?? halfWidth;
|
|
|
+ const orthoBottom = this._scene.activeCamera.orthoBottom ?? -halfHeight;
|
|
|
+ const orthoTop = this._scene.activeCamera.orthoTop ?? halfHeight;
|
|
|
+ effect.setMatrix3x3("depthProjection", SSAO2RenderingPipeline.ORTHO_DEPTH_PROJECTION);
|
|
|
+ effect.setFloat("xViewport", (orthoRight - orthoLeft) * 0.5);
|
|
|
+ effect.setFloat("yViewport", (orthoTop - orthoBottom) * 0.5);
|
|
|
+ }
|
|
|
effect.setMatrix("projection", this._scene.getProjectionMatrix());
|
|
|
|
|
|
if (this._forceGeometryBuffer) {
|