Jelajahi Sumber

custom defines for pbr roughness and microsurface

lockphase 6 tahun lalu
induk
melakukan
64e5536394

+ 18 - 2
materialsLibrary/src/custom/pbrCustomMaterial.ts

@@ -18,6 +18,10 @@ export class ShaderAlebdoParts {
     public Fragment_Custom_Albedo: string;
     // lights
     public Fragment_Before_Lights: string;
+	// roughness
+    public Fragment_Custom_MetallicRoughness: string;
+	// microsurface
+    public Fragment_Custom_MicroSurface: string;
     // fog
     public Fragment_Before_Fog: string;
     // alpha
@@ -135,6 +139,8 @@ export class PBRCustomMaterial extends PBRMaterial {
             .replace('#define CUSTOM_FRAGMENT_UPDATE_ALBEDO', (this.CustomParts.Fragment_Custom_Albedo ? this.CustomParts.Fragment_Custom_Albedo : ""))
             .replace('#define CUSTOM_FRAGMENT_UPDATE_ALPHA', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
             .replace('#define CUSTOM_FRAGMENT_BEFORE_LIGHTS', (this.CustomParts.Fragment_Before_Lights ? this.CustomParts.Fragment_Before_Lights : ""))
+			.replace('#define CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS', (this.CustomParts.Fragment_Custom_MetallicRoughness ? this.CustomParts.Fragment_Custom_MetallicRoughness : ""))
+			.replace('#define CUSTOM_FRAGMENT_UPDATE_MICROSURFACE', (this.CustomParts.Fragment_Custom_MicroSurface ? this.CustomParts.Fragment_Custom_MicroSurface : ""))
             .replace('#define CUSTOM_FRAGMENT_BEFORE_FOG', (this.CustomParts.Fragment_Before_Fog ? this.CustomParts.Fragment_Before_Fog : ""))
             .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
 
@@ -203,8 +209,18 @@ export class PBRCustomMaterial extends PBRMaterial {
         this.CustomParts.Fragment_Before_Lights = shaderPart;
         return this;
     }
-
-    public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {
+	
+	public Fragment_Custom_MetallicRoughness(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Custom_MetallicRoughness = shaderPart;
+        return this;
+    }
+	
+	public Fragment_Custom_MicroSurface(shaderPart: string): PBRCustomMaterial {
+        this.CustomParts.Fragment_Custom_MicroSurface = shaderPart;
+        return this;
+    }
+    
+	public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {
         this.CustomParts.Fragment_Before_Fog = shaderPart;
         return this;
     }

+ 8 - 3
src/Shaders/pbr.fragment.fx

@@ -191,7 +191,9 @@ void main(void) {
             metallicRoughness.g *= microSurfaceTexel.r;
         #endif
 
-        // Compute microsurface form roughness.
+		#define CUSTOM_FRAGMENT_UPDATE_METALLICROUGHNESS
+		
+        // Compute microsurface from roughness.
         microSurface = 1.0 - metallicRoughness.g;
 
         // Diffuse is used as the base of the reflectivity.
@@ -239,11 +241,14 @@ void main(void) {
                     vec4 microSurfaceTexel = texture2D(microSurfaceSampler, vMicroSurfaceSamplerUV + uvOffset) * vMicroSurfaceSamplerInfos.y;
                     microSurface *= microSurfaceTexel.r;
                 #endif
+				
+				#define CUSTOM_FRAGMENT_UPDATE_MICROSURFACE
+				
             #endif
         #endif
     #endif
-
-    // Adapt microSurface.
+	
+	// Adapt microSurface.
     microSurface = saturate(microSurface);
     // Compute roughness.
     float roughness = 1. - microSurface;