Ver Fonte

dpoit, cleanup

Alexander Rose há 2 anos atrás
pai
commit
ed75a365d8

+ 10 - 2
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() {

+ 9 - 16
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();
         }
 

+ 0 - 2
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);