소스 검색

Add light falloff setting

Popov72 5 년 전
부모
커밋
dde5f7cd03
1개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. 26 0
      src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

+ 26 - 0
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -102,6 +102,17 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Defines the  falloff type used in this material.
+     * It by default is Physical.
+     */
+    @editableInPropertyPage("Light falloff", PropertyTypeForEdition.List, "LIGHTING & COLORS", { "notifiers": { "update": true }, "options": [
+        { label: "Physical", value: PBRBaseMaterial.LIGHTFALLOFF_PHYSICAL },
+        { label: "GLTF", value: PBRBaseMaterial.LIGHTFALLOFF_GLTF },
+        { label: "Standard", value: PBRBaseMaterial.LIGHTFALLOFF_STANDARD },
+    ]})
+    public lightFalloff = 0;
+
+    /**
      * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.
      */
     @editableInPropertyPage("Alpha from albedo", PropertyTypeForEdition.Boolean, "TRANSPARENCY", { "notifiers": { "update": true }})
@@ -536,6 +547,18 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
         defines.setValue("ALBEDO", this.baseTexture.isConnected);
         defines.setValue("OPACITY", this.opacityTexture.isConnected);
 
+        // Lighting & colors
+        if (this.lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_STANDARD) {
+            defines.setValue("USEPHYSICALLIGHTFALLOFF", false);
+            defines.setValue("USEGLTFLIGHTFALLOFF", false);
+        } else if (this.lightFalloff === PBRBaseMaterial.LIGHTFALLOFF_GLTF) {
+            defines.setValue("USEPHYSICALLIGHTFALLOFF", false);
+            defines.setValue("USEGLTFLIGHTFALLOFF", true);
+        } else {
+            defines.setValue("USEPHYSICALLIGHTFALLOFF", true);
+            defines.setValue("USEGLTFLIGHTFALLOFF", false);
+        }
+
         // Transparency
         defines.setValue("ALPHABLEND", this.useAlphaBlending);
         defines.setValue("ALPHAFROMALBEDO", this.useAlphaFromAlbedoTexture);
@@ -993,6 +1016,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
     protected _dumpPropertiesCode() {
         let codeString: string = "";
 
+        codeString += `${this._codeVariableName}.lightFalloff = ${this.lightFalloff};\r\n`;
         codeString += `${this._codeVariableName}.useAlphaFromAlbedoTexture = ${this.useAlphaFromAlbedoTexture};\r\n`;
         codeString += `${this._codeVariableName}.useAlphaTest = ${this.useAlphaTest};\r\n`;
         codeString += `${this._codeVariableName}.alphaTestCutoff = ${this.alphaTestCutoff};\r\n`;
@@ -1019,6 +1043,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
             serializationObject.lightId = this.light.id;
         }
 
+        serializationObject.lightFalloff = this.lightFalloff;
         serializationObject.useAlphaFromAlbedoTexture = this.useAlphaFromAlbedoTexture;
         serializationObject.useAlphaTest = this.useAlphaTest;
         serializationObject.alphaTestCutoff = this.alphaTestCutoff;
@@ -1045,6 +1070,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
             this.light = scene.getLightByID(serializationObject.lightId);
         }
 
+        this.lightFalloff = serializationObject.lightFalloff ?? 0;
         this.useAlphaFromAlbedoTexture = serializationObject.useAlphaFromAlbedoTexture;
         this.useAlphaTest = serializationObject.useAlphaTest;
         this.alphaTestCutoff = serializationObject.alphaTestCutoff;