瀏覽代碼

Implement the unlit code path

Popov72 5 年之前
父節點
當前提交
79a8a695f6
共有 1 個文件被更改,包括 65 次插入59 次删除
  1. 65 59
      src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

+ 65 - 59
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -670,79 +670,85 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
 
         state.compilationString += AmbientOcclusionBlock.getCode(aoBlock);
 
-        // _____________________________ Reflectivity _______________________________
-        const aoIntensity = aoBlock?.intensity.isConnected ? aoBlock.intensity.associatedVariableName : "1.";
-
-        state.compilationString += (this.reflectivityParams.connectedPoint?.ownerBlock as Nullable<ReflectivityBlock>)?.getCode(aoIntensity) ?? "";
-
-        // _____________________________ Geometry info _________________________________
-        state.compilationString += state._emitCodeFromInclude("pbrBlockGeometryInfo", comments, {
-            replaceStrings: [
-                { search: /REFLECTIONMAP_SKYBOX/g, replace: reflectionBlock?._defineSkyboxName ?? "REFLECTIONMAP_SKYBOX" },
-                { search: /REFLECTIONMAP_3D/g, replace: reflectionBlock?._define3DName ?? "REFLECTIONMAP_3D" },
-            ]
-        });
+        if (this.unlit) {
+            state.compilationString += `vec3 diffuseBase = vec3(1., 1., 1.);\r\n`;
+        } else {
+            // _____________________________ Reflectivity _______________________________
+            const aoIntensity = aoBlock?.intensity.isConnected ? aoBlock.intensity.associatedVariableName : "1.";
 
-        // _____________________________ Anisotropy _______________________________________
-        const anisotropyBlock = this.anisotropyParams.isConnected ? this.anisotropyParams.connectedPoint?.ownerBlock as AnisotropyBlock : null;
+            state.compilationString += (this.reflectivity.connectedPoint?.ownerBlock as Nullable<ReflectivityBlock>)?.getCode(aoIntensity) ?? "";
 
-        if (anisotropyBlock) {
-            anisotropyBlock.worldPositionConnectionPoint = this.worldPosition;
-            anisotropyBlock.worldNormalConnectionPoint = this.worldNormal;
+            // _____________________________ Geometry info _________________________________
+            state.compilationString += state._emitCodeFromInclude("pbrBlockGeometryInfo", comments, {
+                replaceStrings: [
+                    { search: /REFLECTIONMAP_SKYBOX/g, replace: reflectionBlock?._defineSkyboxName ?? "REFLECTIONMAP_SKYBOX" },
+                    { search: /REFLECTIONMAP_3D/g, replace: reflectionBlock?._define3DName ?? "REFLECTIONMAP_3D" },
+                ]
+            });
 
-            state.compilationString += anisotropyBlock.getCode(state, !this.perturbedNormal.isConnected);
-        }
+            // _____________________________ Anisotropy _______________________________________
+            const anisotropyBlock = this.anisotropy.isConnected ? this.anisotropy.connectedPoint?.ownerBlock as AnisotropyBlock : null;
 
-        // _____________________________ Reflection _______________________________________
-        if (reflectionBlock && reflectionBlock.hasTexture) {
-            state.compilationString += reflectionBlock.getCode(state, anisotropyBlock ? "anisotropicOut.anisotropicNormal" : "normalW", "environmentRadiance", "irradianceVector", "environmentIrradiance");
-        }
+            if (anisotropyBlock) {
+                anisotropyBlock.worldPositionConnectionPoint = this.worldPosition;
+                anisotropyBlock.worldNormalConnectionPoint = this.worldNormal;
 
-        // ___________________ Compute Reflectance aka R0 F0 info _________________________
-        state.compilationString += state._emitCodeFromInclude("pbrBlockReflectance0", comments);
-
-        // ________________________________ Sheen ______________________________
+                state.compilationString += anisotropyBlock.getCode(state, !this.perturbedNormal.isConnected);
+            }
 
-        // _____________________________ Clear Coat ____________________________
-        state.compilationString += `clearcoatOutParams clearcoatOut;
-            #ifdef CLEARCOAT
-            #else
-                clearcoatOut.specularEnvironmentR0 = specularEnvironmentR0;
-            #endif\r\n`;
+            // _____________________________ Reflection _______________________________________
+            if (reflectionBlock && reflectionBlock.hasTexture) {
+                state.compilationString += reflectionBlock.getCode(state, anisotropyBlock ? "anisotropicOut.anisotropicNormal" : "normalW", "environmentRadiance", "irradianceVector", "environmentIrradiance");
+            }
 
-        // _________________________ Specular Environment Reflectance __________________________
-        state.compilationString += state._emitCodeFromInclude("pbrBlockReflectance", comments, {
-            replaceStrings: [
-                { search: /REFLECTIONMAP_SKYBOX/g, replace: reflectionBlock?._defineSkyboxName ?? "REFLECTIONMAP_SKYBOX" },
-                { search: /REFLECTIONMAP_3D/g, replace: reflectionBlock?._define3DName ?? "REFLECTIONMAP_3D" },
-            ]
-        });
+            // ___________________ Compute Reflectance aka R0 F0 info _________________________
+            state.compilationString += state._emitCodeFromInclude("pbrBlockReflectance0", comments);
 
-        // ___________________________________ SubSurface ______________________________________
-        state.compilationString += `subSurfaceOutParams subSurfaceOut;
-            #ifdef SUBSURFACE
-            #else
-                subSurfaceOut.specularEnvironmentReflectance = specularEnvironmentReflectance;
-            #endif\r\n`;
+            // ________________________________ Sheen ______________________________
 
-        // _____________________________ Direct Lighting Info __________________________________
-        state.compilationString += state._emitCodeFromInclude("pbrBlockDirectLighting", comments);
+            // _____________________________ Clear Coat ____________________________
+            state.compilationString += `clearcoatOutParams clearcoatOut;
+                #ifdef CLEARCOAT
+                #else
+                    clearcoatOut.specularEnvironmentR0 = specularEnvironmentR0;
+                #endif\r\n`;
 
-        /*if (this.light) {
-            state.compilationString += state._emitCodeFromInclude("lightFragment", comments, {
+            // _________________________ Specular Environment Reflectance __________________________
+            state.compilationString += state._emitCodeFromInclude("pbrBlockReflectance", comments, {
                 replaceStrings: [
-                    { search: /{X}/g, replace: this._lightId.toString() }
+                    { search: /REFLECTIONMAP_SKYBOX/g, replace: reflectionBlock?._defineSkyboxName ?? "REFLECTIONMAP_SKYBOX" },
+                    { search: /REFLECTIONMAP_3D/g, replace: reflectionBlock?._define3DName ?? "REFLECTIONMAP_3D" },
                 ]
             });
-        } else {
-            state.compilationString += state._emitCodeFromInclude("lightFragment", comments, {
-                repeatKey: "maxSimultaneousLights"
-            });
-        }*/
-
-        // _____________________________ Compute Final Lit and Unlit Components ________________________
-        state.compilationString += state._emitCodeFromInclude("pbrBlockFinalLitComponents", comments);
 
+            // ___________________________________ SubSurface ______________________________________
+            state.compilationString += `subSurfaceOutParams subSurfaceOut;
+                #ifdef SUBSURFACE
+                #else
+                    subSurfaceOut.specularEnvironmentReflectance = specularEnvironmentReflectance;
+                #endif\r\n`;
+
+            // _____________________________ Direct Lighting Info __________________________________
+            state.compilationString += state._emitCodeFromInclude("pbrBlockDirectLighting", comments);
+
+            /*if (this.light) {
+                state.compilationString += state._emitCodeFromInclude("lightFragment", comments, {
+                    replaceStrings: [
+                        { search: /{X}/g, replace: this._lightId.toString() }
+                    ]
+                });
+            } else {
+                state.compilationString += state._emitCodeFromInclude("lightFragment", comments, {
+                    repeatKey: "maxSimultaneousLights"
+                });
+            }*/
+
+            // _____________________________ Compute Final Lit Components ________________________
+            state.compilationString += state._emitCodeFromInclude("pbrBlockFinalLitComponents", comments);
+
+        } // UNLIT
+
+        // _____________________________ Compute Final Unlit Components ________________________
         const aoColor = this.ambientColor.isConnected ? this.ambientColor.associatedVariableName : "vec3(0., 0., 0.)";
 
         let aoDirectLightIntensity = aoBlock?.directLightIntensity.isConnected ? aoBlock.directLightIntensity.associatedVariableName : PBRBaseMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS.toString();