浏览代码

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 5 年之前
父节点
当前提交
5c72eaf5a3
共有 2 个文件被更改,包括 23 次插入0 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 22 0
      src/Materials/material.ts

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

@@ -116,6 +116,7 @@
 - Added `scene.environmentIntensity` to control the IBL strength overall in a scene ([Sebavan](https://github.com/sebavan/))
 - Added support of image processing for `WaterMaterial` ([julien-moreau](https://github.com/julien-moreau))
 - Added `pbrBRDFConfiguration.useSpecularGlossinessInputEnergyConservation` to allow Specular-Workflow energy conservation to be turned off ([ColorDigital-PS](https://github.com/ColorDigital-PS)).
+- Added `depthFunction` new property to `Material` base class ([Popov72](https://github.com/Popov72))
 
 ### ScreenshotTools
 

+ 22 - 0
src/Materials/material.ts

@@ -403,6 +403,12 @@ export class Material implements IAnimatable {
     public forceDepthWrite = false;
 
     /**
+     * Specifies the depth function that should be used. 0 means the default engine function
+     */
+    @serialize()
+    public depthFunction = 0;
+
+    /**
      * Specifies if there should be a separate pass for culling
      */
     @serialize()
@@ -541,6 +547,11 @@ export class Material implements IAnimatable {
     private _cachedDepthWriteState: boolean = false;
 
     /**
+     * Specifies if the depth function state should be cached
+     */
+    private _cachedDepthFunctionState: number = 0;
+
+    /**
      * Stores the uniform buffer
      */
     protected _uniformBuffer: UniformBuffer;
@@ -799,6 +810,12 @@ export class Material implements IAnimatable {
             this._cachedDepthWriteState = engine.getDepthWrite();
             engine.setDepthWrite(false);
         }
+
+        if (this.depthFunction !== 0) {
+            var engine = this._scene.getEngine();
+            this._cachedDepthFunctionState = engine.getDepthFunction() || 0;
+            engine.setDepthFunction(this.depthFunction);
+        }
     }
 
     /**
@@ -809,6 +826,11 @@ export class Material implements IAnimatable {
             this._onUnBindObservable.notifyObservers(this);
         }
 
+        if (this.depthFunction !== 0) {
+            var engine = this._scene.getEngine();
+            engine.setDepthFunction(this._cachedDepthFunctionState);
+        }
+
         if (this.disableDepthWrite) {
             var engine = this._scene.getEngine();
             engine.setDepthWrite(this._cachedDepthWriteState);