ソースを参照

Merge pull request #6200 from lockphase/master

Custom roughness and microsurface defines for PBRCustomMaterial
David Catuhe 6 年 前
コミット
cee2fd4c88

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

@@ -136,6 +136,7 @@
 - Added LoadScriptAsync tools helper function [MackeyK24](https://github.com/mackeyk24))
 - Added LoadScriptAsync tools helper function [MackeyK24](https://github.com/mackeyk24))
 - Added customShaderNameResolve to PBRMaterialBase to allow subclasses to specify custom shader information [MackeyK24](https://github.com/mackeyk24))
 - Added customShaderNameResolve to PBRMaterialBase to allow subclasses to specify custom shader information [MackeyK24](https://github.com/mackeyk24))
 - Added PBRCustomMaterial to material library to allow easy subclassing of PBR materials [MackeyK24](https://github.com/mackeyk24))
 - Added PBRCustomMaterial to material library to allow easy subclassing of PBR materials [MackeyK24](https://github.com/mackeyk24))
+- Added custom defines for roughness and microsurface in PBRCustomMaterial [Lockphase](https://github.com/lockphase)) 
 - Added `auto-exposure` support in `StandardRenderingPipeline` when `HDR` is enabled ([julien-moreau](https://github.com/julien-moreau))
 - Added `auto-exposure` support in `StandardRenderingPipeline` when `HDR` is enabled ([julien-moreau](https://github.com/julien-moreau))
 - Add `EquiRectangularCubeTexture` class to enable the usage of browser-canvas supported images as `CubeTexture`'s ([Dennis Dervisis](https://github.com/ddervisis))
 - Add `EquiRectangularCubeTexture` class to enable the usage of browser-canvas supported images as `CubeTexture`'s ([Dennis Dervisis](https://github.com/ddervisis))
 - Add `EquiRectangularCubeTextureAssetTask` to be able to load `EquiRectangularCubeTextures`s via Asset Manager ([Dennis Dervisis](https://github.com/ddervisis))
 - Add `EquiRectangularCubeTextureAssetTask` to be able to load `EquiRectangularCubeTextures`s via Asset Manager ([Dennis Dervisis](https://github.com/ddervisis))

+ 16 - 0
materialsLibrary/src/custom/pbrCustomMaterial.ts

@@ -18,6 +18,10 @@ export class ShaderAlebdoParts {
     public Fragment_Custom_Albedo: string;
     public Fragment_Custom_Albedo: string;
     // lights
     // lights
     public Fragment_Before_Lights: string;
     public Fragment_Before_Lights: string;
+    // roughness
+    public Fragment_Custom_MetallicRoughness: string;
+    // microsurface
+    public Fragment_Custom_MicroSurface: string;
     // fog
     // fog
     public Fragment_Before_Fog: string;
     public Fragment_Before_Fog: string;
     // alpha
     // 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_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_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_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_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 : ""));
             .replace('#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
 
 
@@ -204,6 +210,16 @@ export class PBRCustomMaterial extends PBRMaterial {
         return this;
         return this;
     }
     }
 
 
+    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 {
     public Fragment_Before_Fog(shaderPart: string): PBRCustomMaterial {
         this.CustomParts.Fragment_Before_Fog = shaderPart;
         this.CustomParts.Fragment_Before_Fog = shaderPart;
         return this;
         return this;

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

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