Added half res depth buffer switching for dynamic AO

This commit is contained in:
Alex
2022-10-27 13:12:08 +03:00
parent 3653083ece
commit 639ae9cd2a
4 changed files with 41 additions and 10 deletions
+3 -3
View File
@@ -35,10 +35,10 @@ export default class Sandbox {
accumulationFrames: 16,
dynamicAoEnabled: true,
dynamicAoParams: {
intensity: 1.25,
intensity: 1.5,
scale: 0,
kernelRadius: 5,
bias: 0.15,
kernelRadius: 10,
bias: 0.2,
normalsType: 2,
blurEnabled: true,
blurRadius: 2,
@@ -21,9 +21,16 @@ export enum DepthType {
LINEAR_DEPTH
}
export enum DepthSize {
FULL,
HALF
}
export class DepthPass extends Pass implements SpecklePass {
private renderTarget: WebGLRenderTarget
private renderTargetHalf: WebGLRenderTarget
private depthMaterial: SpeckleDepthMaterial = null
private depthBufferSize: DepthSize = DepthSize.FULL
private scene: Scene
private camera: Camera
@@ -40,6 +47,10 @@ export class DepthPass extends Pass implements SpecklePass {
return this.renderTarget.texture
}
get outputTextureHalf(): Texture {
return this.renderTargetHalf.texture
}
public set depthType(value: DepthType) {
if (value === DepthType.LINEAR_DEPTH)
this.depthMaterial.defines['LINEAR_DEPTH'] = ' '
@@ -47,6 +58,10 @@ export class DepthPass extends Pass implements SpecklePass {
this.depthMaterial.needsUpdate = true
}
public set depthSize(value: DepthSize) {
this.depthBufferSize = value
}
constructor() {
super()
@@ -54,12 +69,19 @@ export class DepthPass extends Pass implements SpecklePass {
minFilter: NearestFilter,
magFilter: NearestFilter
})
this.renderTargetHalf = new WebGLRenderTarget(256, 256, {
minFilter: NearestFilter,
magFilter: NearestFilter
})
/** On Chromium, on MacOS the 16 bit depth render buffer appears broken.
* We're not really using a stencil buffer at all, we're just forcing
* three.js to use a 24 bit depth render buffer
*/
this.renderTarget.depthBuffer = true
this.renderTarget.stencilBuffer = true
this.renderTargetHalf.depthBuffer = true
this.renderTargetHalf.stencilBuffer = true
this.depthMaterial = new SpeckleDepthMaterial(
{
@@ -96,7 +118,7 @@ export class DepthPass extends Pass implements SpecklePass {
const originalClearAlpha = renderer.getClearAlpha()
const originalAutoClear = renderer.autoClear
renderer.setRenderTarget(this.renderTarget)
renderer.setRenderTarget(this.depthBufferSize === DepthSize.FULL ? this.renderTarget: this.renderTargetHalf)
renderer.autoClear = false
renderer.setClearColor(0x000000)
@@ -122,5 +144,6 @@ export class DepthPass extends Pass implements SpecklePass {
public setSize(width: number, height: number) {
this.renderTarget.setSize(width, height)
this.renderTargetHalf.setSize(width * 0.5, height * 0.5)
}
}
@@ -48,13 +48,13 @@ export interface DynamicAOPassParams {
}
export const DefaultDynamicAOPassParams = {
intensity: 1.25,
intensity: 1.5,
scale: 0,
kernelRadius: 5,
bias: 0.15,
kernelRadius: 10,
bias: 0.2,
normalsType: NormalsType.ACCURATE,
blurEnabled: true,
blurRadius: 4,
blurRadius: 2,
blurStdDev: 4,
blurDepthCutoff: 0.0007
}
@@ -7,7 +7,7 @@ import Batcher from '../batching/Batcher'
import SpeckleRenderer from '../SpeckleRenderer'
import { ApplySAOPass } from './ApplyAOPass'
import { CopyOutputPass } from './CopyOutputPass'
import { DepthPass, DepthType } from './DepthPass'
import { DepthPass, DepthSize, DepthType } from './DepthPass'
import { NormalsPass } from './NormalsPass'
import {
DefaultDynamicAOPassParams,
@@ -97,6 +97,7 @@ export class Pipeline {
switch (outputType) {
case PipelineOutputType.FINAL:
pipeline = this.getDefaultPipeline()
this.depthPass.depthSize = DepthSize.FULL
this.applySaoPass.setTexture('tDiffuse', this.staticAoPass.outputTexture)
this.applySaoPass.setTexture('tDiffuseInterp', this.dynamicAoPass.outputTexture)
this.needsProgressive = true
@@ -105,6 +106,7 @@ export class Pipeline {
case PipelineOutputType.DEPTH_RGBA:
pipeline.push(this.depthPass)
pipeline.push(this.copyOutputPass)
this.depthPass.depthSize = DepthSize.FULL
this.copyOutputPass.setTexture('tDiffuse', this.depthPass.outputTexture)
this.copyOutputPass.setOutputType(PipelineOutputType.DEPTH_RGBA)
this.needsProgressive = false
@@ -113,6 +115,7 @@ export class Pipeline {
case PipelineOutputType.DEPTH:
pipeline.push(this.depthPass)
pipeline.push(this.copyOutputPass)
this.depthPass.depthSize = DepthSize.FULL
this.copyOutputPass.setTexture('tDiffuse', this.depthPass.outputTexture)
this.copyOutputPass.setOutputType(PipelineOutputType.DEPTH)
this.needsProgressive = false
@@ -137,6 +140,7 @@ export class Pipeline {
pipeline.push(this.copyOutputPass)
this.dynamicAoPass.enabled = true
this.depthPass.depthType = DepthType.PERSPECTIVE_DEPTH
this.depthPass.depthSize = DepthSize.HALF
this.dynamicAoPass.setOutputType(DynamicAOOutputType.RECONSTRUCTED_NORMALS)
this.copyOutputPass.setTexture('tDiffuse', this.dynamicAoPass.outputTexture)
this.copyOutputPass.setOutputType(PipelineOutputType.GEOMETRY_NORMALS)
@@ -171,6 +175,7 @@ export class Pipeline {
: false
this.dynamicAoPass.enabled = true
this.depthPass.depthType = DepthType.PERSPECTIVE_DEPTH
this.depthPass.depthSize = DepthSize.HALF
this.copyOutputPass.setTexture('tDiffuse', this.dynamicAoPass.outputTexture)
this.copyOutputPass.setOutputType(PipelineOutputType.COLOR)
this.dynamicAoPass.setOutputType(DynamicAOOutputType.AO_BLURRED)
@@ -184,6 +189,7 @@ export class Pipeline {
pipeline.push(this.staticAoPass)
pipeline.push(this.copyOutputPass)
this.depthPass.depthType = DepthType.LINEAR_DEPTH
this.depthPass.depthSize = DepthSize.FULL
this.copyOutputPass.setTexture('tDiffuse', this.staticAoPass.outputTexture)
this.copyOutputPass.setOutputType(PipelineOutputType.COLOR)
this.needsProgressive = true
@@ -257,7 +263,7 @@ export class Pipeline {
)
this.applySaoPass.renderToScreen = true
this.dynamicAoPass.setTexture('tDepth', this.depthPass.outputTexture)
this.dynamicAoPass.setTexture('tDepth', this.depthPass.outputTextureHalf)
this.dynamicAoPass.setTexture('tNormal', this.normalsPass.outputTexture)
this.applySaoPass.setTexture('tDiffuse', this.dynamicAoPass.outputTexture)
this.applySaoPass.setTexture('tDiffuseInterp', this.dynamicAoPass.outputTexture)
@@ -344,6 +350,7 @@ export class Pipeline {
this.accumulationFrame = 0
this.depthPass.enabled = true
this.depthPass.depthType = DepthType.LINEAR_DEPTH
this.depthPass.depthSize = DepthSize.FULL
this.normalsPass.enabled = false
this.dynamicAoPass.enabled = false
this.renderPass.enabled = true
@@ -361,6 +368,7 @@ export class Pipeline {
this.accumulationFrame = 0
this.renderType = RenderType.NORMAL
this.depthPass.depthType = DepthType.PERSPECTIVE_DEPTH
this.depthPass.depthSize = DepthSize.HALF
this.staticAoPass.enabled = false
this.applySaoPass.enabled = true
this.dynamicAoPass.enabled = true