Kaynağa Gözat

Add SpriteManager.disableDepthWrite property

Popov72 5 yıl önce
ebeveyn
işleme
4835a3f088

+ 1 - 0
dist/preview release/what's new.md

@@ -180,6 +180,7 @@
 - MultiPickSprite and multiPickSpriteWithRay added to sprites ([JohnK](https://github.com/BabylonJSGuide))
 - SpritePackedManager support for JSON Objects that where not stringified, of with the frames parameter accepting Objects and Arrays ([Pryme8](https://github.com/Pryme8))
 - Added `SpriteMap` for creation of grid-based dynamically animated sprite atlas rendering (Beta) ([Pryme8](https://github.com/Pryme8))
+- Add `SpriteManager.disableDepthWrite` property ([Popov72](https://github.com/Popov72))
 
 ### WebXR / WebVR
 

+ 13 - 5
src/Sprites/spriteManager.ts

@@ -151,6 +151,12 @@ export class SpriteManager implements ISpriteManager {
         this._blendMode = blendMode;
     }
 
+    /** Disables writing to the depth buffer when rendering the sprites.
+     *  It can be handy to disable depth writing when using textures without alpha channel
+     *  and setting some specific blend modes.
+    */
+    public disableDepthWrite: boolean = false;
+
     /**
      * Creates a new sprite manager
      * @param name defines the manager's name
@@ -576,11 +582,13 @@ export class SpriteManager implements ISpriteManager {
 
         // Draw order
         engine.setDepthFunctionToLessOrEqual();
-        effect.setBool("alphaTest", true);
-        engine.setColorWrite(false);
-        engine.drawElementsType(Material.TriangleFillMode, 0, (offset / 4) * 6);
-        engine.setColorWrite(true);
-        effect.setBool("alphaTest", false);
+        if (!this.disableDepthWrite) {
+            effect.setBool("alphaTest", true);
+            engine.setColorWrite(false);
+            engine.drawElementsType(Material.TriangleFillMode, 0, (offset / 4) * 6);
+            engine.setColorWrite(true);
+            effect.setBool("alphaTest", false);
+        }
 
         engine.setAlphaMode(this._blendMode);
         engine.drawElementsType(Material.TriangleFillMode, 0, (offset / 4) * 6);