diff --git a/src/mol-canvas3d/passes/dpoit.ts b/src/mol-canvas3d/passes/dpoit.ts index 4e2a8c09e855ee5e1ed6dead2ec6ba70550cc7a0..634d4ec658a4c532dc693ffcbdbeee3ef5682d7c 100644 --- a/src/mol-canvas3d/passes/dpoit.ts +++ b/src/mol-canvas3d/passes/dpoit.ts @@ -115,7 +115,11 @@ export class DpoitPass { state.blendEquation(blendMinMax!.MAX); 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() { @@ -138,7 +142,11 @@ export class DpoitPass { state.blendEquation(blendMinMax!.MAX); 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() { diff --git a/src/mol-canvas3d/passes/draw.ts b/src/mol-canvas3d/passes/draw.ts index 021c38858087dc17ee6d816d6e6ced12cf55da2b..a7b88cbbec59aaf79f4d07fa6874cdc0eb5aafa6 100644 --- a/src/mol-canvas3d/passes/draw.ts +++ b/src/mol-canvas3d/passes/draw.ts @@ -133,14 +133,13 @@ export class DrawPass { 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'); - this.colorTarget.bind(); + this.depthTextureOpaque.attachFramebuffer(this.colorTarget.framebuffer, 'depth'); renderer.clear(true); // render opaque primitives - this.depthTextureOpaque.attachFramebuffer(this.colorTarget.framebuffer, 'depth'); - this.colorTarget.bind(); - renderer.clearDepth(); - renderer.renderDpoitOpaque(scene.primitives, camera, null); + if (scene.hasOpaque) { + renderer.renderDpoitOpaque(scene.primitives, camera, null); + } if (PostprocessingPass.isEnabled(postprocessingProps)) { if (PostprocessingPass.isOutlineEnabled(postprocessingProps)) { @@ -156,32 +155,26 @@ export class DrawPass { // render transparent primitives 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'); + const dpoitTextures = this.dpoit.bind(); renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures); for (let i = 0; i < iterations; i++) { const dpoitTextures = this.dpoit.bindDualDepthPeeling(); renderer.renderDpoitTransparent(scene.primitives, camera, this.depthTextureOpaque, dpoitTextures); - if (PostprocessingPass.isEnabled(postprocessingProps)) { - this.postprocessing.target.bind(); - } else { - this.colorTarget.bind(); - } + target.bind(); this.dpoit.renderBlendBack(); } if (isTimingMode) this.webgl.timer.markEnd('DpoitPasses.render'); // evaluate dpoit - if (PostprocessingPass.isEnabled(postprocessingProps)) { - this.postprocessing.target.bind(); - } else { - this.colorTarget.bind(); - } + target.bind(); this.dpoit.render(); } diff --git a/src/mol-gl/shader/chunks/dpoit-write.glsl.ts b/src/mol-gl/shader/chunks/dpoit-write.glsl.ts index 289e4948767194363befe4edf94df93b28045ebc..23061cf8eed6ba42548cfd72c2f7f411c8a81777 100644 --- a/src/mol-gl/shader/chunks/dpoit-write.glsl.ts +++ b/src/mol-gl/shader/chunks/dpoit-write.glsl.ts @@ -41,7 +41,6 @@ export const dpoit_write = ` float furthestDepth = lastDepth.y; float alphaMultiplier = 1.0 - lastFrontColor.a; - if (fragmentDepth < nearestDepth || fragmentDepth > furthestDepth) { // Skip this depth since it's been peeled. return; @@ -56,7 +55,6 @@ export const dpoit_write = ` } // write to back and front color buffer - if (fragmentDepth == nearestDepth) { gl_FragColor.rgb += fragColor.rgb * fragColor.a * alphaMultiplier; gl_FragColor.a = 1.0 - alphaMultiplier * (1.0 - fragColor.a);