فهرست منبع

Fix glow transparency

sebavan 6 سال پیش
والد
کامیت
02a4666275
3فایلهای تغییر یافته به همراه23 افزوده شده و 3 حذف شده
  1. 13 3
      src/Layers/effectLayer.ts
  2. 8 0
      src/Layers/glowLayer.ts
  3. 2 0
      src/Shaders/glowMapGeneration.fragment.fx

+ 13 - 3
src/Layers/effectLayer.ts

@@ -358,6 +358,14 @@ import "../Shaders/glowMapGeneration.vertex";
         }
 
         /**
+         * Adds specific effects defines.
+         * @param defines The defines to add specifics to.
+         */
+        protected _addCustomEffectDefines(defines: string[]): void {
+            // Nothing to add by default.
+        }
+
+        /**
          * Checks for the readiness of the element composing the layer.
          * @param subMesh the mesh to check for
          * @param useInstances specify wether or not to use instances to render the mesh
@@ -375,7 +383,7 @@ import "../Shaders/glowMapGeneration.vertex";
                 return false;
             }
 
-            var defines = [];
+            var defines: string[] = [];
 
             var attribs = [VertexBuffer.PositionKind];
 
@@ -488,6 +496,8 @@ import "../Shaders/glowMapGeneration.vertex";
                 attribs.push("world3");
             }
 
+            this._addCustomEffectDefines(defines);
+
             // Get correct effect
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
@@ -594,7 +604,7 @@ import "../Shaders/glowMapGeneration.vertex";
          * @returns true if it can be rendered otherwise false
          */
         protected _canRenderMesh(mesh: AbstractMesh, material: Material): boolean {
-            return material.needAlphaBlendingForMesh(mesh);
+            return !material.needAlphaBlendingForMesh(mesh);
         }
 
         /**
@@ -624,7 +634,7 @@ import "../Shaders/glowMapGeneration.vertex";
             }
 
             // Do not block in blend mode.
-            if (this._canRenderMesh(mesh, material)) {
+            if (!this._canRenderMesh(mesh, material)) {
                 return;
             }
 

+ 8 - 0
src/Layers/glowLayer.ts

@@ -437,6 +437,14 @@ declare module "../abstractScene" {
         }
 
         /**
+         * Adds specific effects defines.
+         * @param defines The defines to add specifics to.
+         */
+        protected _addCustomEffectDefines(defines: string[]): void {
+            defines.push("#define GLOW");
+        }
+
+        /**
          * Add a mesh in the exclusion list to prevent it to impact or being impacted by the glow layer.
          * @param mesh The mesh to exclude from the glow layer
          */

+ 2 - 0
src/Shaders/glowMapGeneration.fragment.fx

@@ -54,6 +54,8 @@ vec4 finalColor = color;
     gl_FragColor = finalColor;
 #endif
 
+#ifdef GLOW
     gl_FragColor.rgb *= gl_FragColor.a;
     gl_FragColor.a = 1.0;
+#endif
 }