Skip to content
Snippets Groups Projects
Commit ed75a365 authored by Alexander Rose's avatar Alexander Rose
Browse files

dpoit, cleanup

parent f5ff13ff
No related branches found
No related tags found
No related merge requests found
...@@ -115,7 +115,11 @@ export class DpoitPass { ...@@ -115,7 +115,11 @@ export class DpoitPass {
state.blendEquation(blendMinMax!.MAX); state.blendEquation(blendMinMax!.MAX);
state.depthMask(false); state.depthMask(false);
return { depth: this.depthTextures[1], frontColor: this.colorFrontTextures[1], backColor: this.colorBackTextures[1] }; return {
depth: this.depthTextures[1],
frontColor: this.colorFrontTextures[1],
backColor: this.colorBackTextures[1]
};
} }
bindDualDepthPeeling() { bindDualDepthPeeling() {
...@@ -138,7 +142,11 @@ export class DpoitPass { ...@@ -138,7 +142,11 @@ export class DpoitPass {
state.blendEquation(blendMinMax!.MAX); state.blendEquation(blendMinMax!.MAX);
state.depthMask(false); state.depthMask(false);
return { depth: this.depthTextures[this.readId], frontColor: this.colorFrontTextures[this.readId], backColor: this.colorBackTextures[this.readId] }; return {
depth: this.depthTextures[this.readId],
frontColor: this.colorFrontTextures[this.readId],
backColor: this.colorBackTextures[this.readId]
};
} }
renderBlendBack() { renderBlendBack() {
......
...@@ -133,14 +133,13 @@ export class DrawPass { ...@@ -133,14 +133,13 @@ export class DrawPass {
private _renderDpoit(renderer: Renderer, camera: ICamera, scene: Scene, iterations: number, transparentBackground: boolean, postprocessingProps: PostprocessingProps) { private _renderDpoit(renderer: Renderer, camera: ICamera, scene: Scene, iterations: number, transparentBackground: boolean, postprocessingProps: PostprocessingProps) {
if (!this.dpoit?.supported) throw new Error('expected dpoit to be supported'); if (!this.dpoit?.supported) throw new Error('expected dpoit to be supported');
this.colorTarget.bind(); this.depthTextureOpaque.attachFramebuffer(this.colorTarget.framebuffer, 'depth');
renderer.clear(true); renderer.clear(true);
// render opaque primitives // render opaque primitives
this.depthTextureOpaque.attachFramebuffer(this.colorTarget.framebuffer, 'depth'); if (scene.hasOpaque) {
this.colorTarget.bind();
renderer.clearDepth();
renderer.renderDpoitOpaque(scene.primitives, camera, null); renderer.renderDpoitOpaque(scene.primitives, camera, null);
}
if (PostprocessingPass.isEnabled(postprocessingProps)) { if (PostprocessingPass.isEnabled(postprocessingProps)) {
if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) { if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) {
...@@ -156,32 +155,26 @@ export class DrawPass { ...@@ -156,32 +155,26 @@ export class DrawPass {
// render transparent primitives // render transparent primitives
if (scene.opacityAverage < 1) { if (scene.opacityAverage < 1) {
const dpoitTextures = this.dpoit.bind(); const target = PostprocessingPass.isEnabled(postprocessingProps)
? this.postprocessing.target : this.colorTarget;
if (isTimingMode) this.webgl.timer.mark('DpoitPasses.render'); if (isTimingMode) this.webgl.timer.mark('DpoitPasses.render');
const dpoitTextures = this.dpoit.bind();
renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures); renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures);
for (let i = 0; i < iterations; i++) { for (let i = 0; i < iterations; i++) {
const dpoitTextures = this.dpoit.bindDualDepthPeeling(); const dpoitTextures = this.dpoit.bindDualDepthPeeling();
renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures); renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures);
if (PostprocessingPass.isEnabled(postprocessingProps)) { target.bind();
this.postprocessing.target.bind();
} else {
this.colorTarget.bind();
}
this.dpoit.renderBlendBack(); this.dpoit.renderBlendBack();
} }
if (isTimingMode) this.webgl.timer.markEnd('DpoitPasses.render'); if (isTimingMode) this.webgl.timer.markEnd('DpoitPasses.render');
// evaluate dpoit // evaluate dpoit
if (PostprocessingPass.isEnabled(postprocessingProps)) { target.bind();
this.postprocessing.target.bind();
} else {
this.colorTarget.bind();
}
this.dpoit.render(); this.dpoit.render();
} }
......
...@@ -41,7 +41,6 @@ export const dpoit_write = ` ...@@ -41,7 +41,6 @@ export const dpoit_write = `
float furthestDepth = lastDepth.y; float furthestDepth = lastDepth.y;
float alphaMultiplier = 1.0 - lastFrontColor.a; float alphaMultiplier = 1.0 - lastFrontColor.a;
if (fragmentDepth < nearestDepth || fragmentDepth > furthestDepth) { if (fragmentDepth < nearestDepth || fragmentDepth > furthestDepth) {
// Skip this depth since it's been peeled. // Skip this depth since it's been peeled.
return; return;
...@@ -56,7 +55,6 @@ export const dpoit_write = ` ...@@ -56,7 +55,6 @@ export const dpoit_write = `
} }
// write to back and front color buffer // write to back and front color buffer
if (fragmentDepth == nearestDepth) { if (fragmentDepth == nearestDepth) {
gl_FragColor.rgb += fragColor.rgb * fragColor.a * alphaMultiplier; gl_FragColor.rgb += fragColor.rgb * fragColor.a * alphaMultiplier;
gl_FragColor.a = 1.0 - alphaMultiplier * (1.0 - fragColor.a); gl_FragColor.a = 1.0 - alphaMultiplier * (1.0 - fragColor.a);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment