Procházet zdrojové kódy

Merge branch 'master' into gltf-spec-sheen-clearcoat

Popov72 před 4 roky
rodič
revize
2d2ae66e9f

+ 5 - 0
gui/src/2D/controls/selector.ts

@@ -325,6 +325,11 @@ export class SelectionPanel extends Rectangle {
         return "SelectionPanel";
     }
 
+    /** Gets the (stack) panel of the SelectionPanel  */
+    public get panel(): StackPanel {
+        return this._panel;
+    }
+
     /** Gets or sets the headerColor */
     public get headerColor(): string {
         return this._headerColor;

+ 1 - 0
inspector/src/components/actionTabs/tabs/propertyGrids/materials/pbrMaterialPropertyGridComponent.tsx

@@ -176,6 +176,7 @@ export class PBRMaterialPropertyGridComponent extends React.Component<IPBRMateri
                             <SliderLineComponent label="Intensity" target={material.clearCoat} propertyName="intensity" minimum={0} maximum={1} step={0.01} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                             <SliderLineComponent label="Roughness" target={material.clearCoat} propertyName="roughness" minimum={0} maximum={1} step={0.01} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                             <SliderLineComponent label="IOR" target={material.clearCoat} propertyName="indexOfRefraction" minimum={1.0} maximum={3} step={0.01} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
+                            <CheckBoxLineComponent label="Remap F0" target={material.clearCoat} propertyName="remapF0OnInterfaceChange" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                             <TextureLinkLineComponent label="Clear coat" texture={material.clearCoat.texture} onTextureCreated={(texture) => material.clearCoat.texture = texture} onTextureRemoved={() => material.clearCoat.texture = null} material={material} onSelectionChangedObservable={this.props.onSelectionChangedObservable} onDebugSelectionChangeObservable={this._onDebugSelectionChangeObservable} />
                             <TextureLinkLineComponent label="Roughness" texture={material.clearCoat.textureRoughness} onTextureCreated={(texture) => material.clearCoat.textureRoughness = texture} onTextureRemoved={() => material.clearCoat.textureRoughness = null} material={material} onSelectionChangedObservable={this.props.onSelectionChangedObservable} onDebugSelectionChangeObservable={this._onDebugSelectionChangeObservable} />
                             <TextureLinkLineComponent label="Bump" texture={material.clearCoat.bumpTexture} onTextureCreated={(texture) => material.clearCoat.bumpTexture = texture} onTextureRemoved={() => material.clearCoat.bumpTexture = null} material={material} onSelectionChangedObservable={this.props.onSelectionChangedObservable} onDebugSelectionChangeObservable={this._onDebugSelectionChangeObservable} />

+ 1 - 0
loaders/src/glTF/2.0/Extensions/KHR_materials_clearcoat.ts

@@ -62,6 +62,7 @@ export class KHR_materials_clearcoat implements IGLTFLoaderExtension {
 
         babylonMaterial.clearCoat.isEnabled = true;
         babylonMaterial.clearCoat.useRoughnessFromMainTexture = false;
+        babylonMaterial.clearCoat.remapF0OnInterfaceChange = false;
 
         if (properties.clearcoatFactor != undefined) {
             babylonMaterial.clearCoat.intensity = properties.clearcoatFactor;

+ 3 - 0
src/Debug/ISkeletonViewer.ts

@@ -43,6 +43,9 @@ export interface ISkeletonViewerDisplayOptions{
    /** Ratio for the Sphere Size */
    sphereFactor? : number;
 
+   /** Whether a spur should attach its far end to the child bone position */
+   spurFollowsChild? : boolean;
+
    /** Whether to show local axes or not  */
    showLocalAxes? : boolean;
 

+ 23 - 13
src/Debug/skeletonViewer.ts

@@ -389,6 +389,7 @@ export class SkeletonViewer {
         options.displayOptions.sphereBaseSize = options.displayOptions.sphereBaseSize ?? 0.15;
         options.displayOptions.sphereScaleUnit = options.displayOptions.sphereScaleUnit ?? 2;
         options.displayOptions.sphereFactor = options.displayOptions.sphereFactor ?? 0.865;
+        options.displayOptions.spurFollowsChild = options.displayOptions.spurFollowsChild ?? false;
         options.displayOptions.showLocalAxes = options.displayOptions.showLocalAxes ?? false;
         options.displayOptions.localAxesSize = options.displayOptions.localAxesSize ?? 0.075;
         options.computeBonesUsingShaders = options.computeBonesUsingShaders ?? true;
@@ -666,19 +667,27 @@ export class SkeletonViewer {
                         updatable: false
                     },  scene);
 
-                    spur.convertToFlatShadedMesh();
-
                     let numVertices = spur.getTotalVertices();
                     let mwk: number[] = [], mik: number[] = [];
 
                     for (let i = 0; i < numVertices; i++) {
                         mwk.push(1, 0, 0, 0);
-                        mik.push(bone.getIndex(), 0, 0, 0);
+
+                        // Select verts at end of spur (ie vert 10 to 14) and bind to child
+                        // bone if spurFollowsChild is enabled.
+                        if (displayOptions.spurFollowsChild && i > 9) {
+                            mik.push(bc.getIndex(), 0, 0, 0);
+                        }
+                        else {
+                            mik.push(bone.getIndex(), 0, 0, 0);
+                        }
                     }
+
                     spur.position = anchorPoint.clone();
 
                     spur.setVerticesData(VertexBuffer.MatricesWeightsKind, mwk, false);
                     spur.setVerticesData(VertexBuffer.MatricesIndicesKind, mik, false);
+                    spur.convertToFlatShadedMesh();
 
                     spurs.push(spur);
                 });
@@ -865,16 +874,17 @@ export class SkeletonViewer {
     }
 
     /** Sets a display option of the skeleton viewer
-	 *
-     * | Option          | Type    | Default | Description |
-     * | --------------- | ------- | ------- | ----------- |
-     * | midStep         | float   | 0.235   | A percentage between a bone and its child that determines the widest part of a spur. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
-     * | midStepFactor   | float   | 0.15    | Mid step width expressed as a factor of the length. A value of 0.5 makes the spur width half of the spur length. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
-     * | sphereBaseSize  | float   | 2       | Sphere base size. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
-     * | sphereScaleUnit | float   | 0.865   | Sphere scale factor used to scale spheres in relation to the longest bone. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
-     * | showLocalAxes   | boolean | false   | Displays local axes on all bones. |
-	 * | localAxesSize   | float   | 0.075   | Determines the length of each local axis. |
-	 *
+     *
+     * | Option           | Type    | Default | Description |
+     * | ---------------- | ------- | ------- | ----------- |
+     * | midStep          | float   | 0.235   | A percentage between a bone and its child that determines the widest part of a spur. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
+     * | midStepFactor    | float   | 0.15    | Mid step width expressed as a factor of the length. A value of 0.5 makes the spur width half of the spur length. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
+     * | sphereBaseSize   | float   | 2       | Sphere base size. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
+     * | sphereScaleUnit  | float   | 0.865   | Sphere scale factor used to scale spheres in relation to the longest bone. Only used when `displayMode` is set to `DISPLAY_SPHERE_AND_SPURS`. |
+     * | spurFollowsChild | boolean | false   | Whether a spur should attach its far end to the child bone. |
+     * | showLocalAxes    | boolean | false   | Displays local axes on all bones. |
+     * | localAxesSize    | float   | 0.075   | Determines the length of each local axis. |
+     *
      * @param option String of the option name
      * @param value The numerical option value
      */

+ 3 - 3
src/Materials/Node/Blocks/PBR/ambientOcclusionBlock.ts

@@ -29,8 +29,8 @@ export class AmbientOcclusionBlock extends NodeMaterialBlock {
         this.registerInput("intensity", NodeMaterialBlockConnectionPointTypes.Float, true, NodeMaterialBlockTargets.Fragment);
         this.registerInput("directLightIntensity", NodeMaterialBlockConnectionPointTypes.Float, true, NodeMaterialBlockTargets.Fragment);
 
-        this.registerOutput("ambientOcclusion", NodeMaterialBlockConnectionPointTypes.Object, NodeMaterialBlockTargets.Fragment,
-            new NodeMaterialConnectionPointCustomObject("ambientOcclusion", this, NodeMaterialConnectionPointDirection.Output, AmbientOcclusionBlock, "AOBlock", "ambientOcc"));
+        this.registerOutput("ambientOcc", NodeMaterialBlockConnectionPointTypes.Object, NodeMaterialBlockTargets.Fragment,
+            new NodeMaterialConnectionPointCustomObject("ambientOcc", this, NodeMaterialConnectionPointDirection.Output, AmbientOcclusionBlock, "AOBlock", "ambientOcc"));
     }
 
     /**
@@ -79,7 +79,7 @@ export class AmbientOcclusionBlock extends NodeMaterialBlock {
     /**
      * Gets the ambient occlusion object output component
      */
-    public get ambientOcclusion(): NodeMaterialConnectionPoint {
+    public get ambientOcc(): NodeMaterialConnectionPoint {
         return this._outputs[0];
     }
 

+ 2 - 2
src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts

@@ -437,7 +437,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
     /**
      * Gets the ambient occlusion object parameters
      */
-    public get ambientOcclusion(): NodeMaterialConnectionPoint {
+    public get ambientOcc(): NodeMaterialConnectionPoint {
         return this._inputs[8];
     }
 
@@ -917,7 +917,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
         state.compilationString += state._emitCodeFromInclude("depthPrePass", comments);
 
         // _____________________________ AO  _______________________________
-        const aoBlock = this.ambientOcclusion.connectedPoint?.ownerBlock as Nullable<AmbientOcclusionBlock>;
+        const aoBlock = this.ambientOcc.connectedPoint?.ownerBlock as Nullable<AmbientOcclusionBlock>;
 
         state.compilationString += AmbientOcclusionBlock.GetCode(aoBlock);
 

+ 1 - 0
src/Materials/PBR/pbrBaseMaterial.ts

@@ -228,6 +228,7 @@ export class PBRMaterialDefines extends MaterialDefines
     public CLEARCOAT_TEXTURE_ROUGHNESS_IDENTICAL = false;
     public CLEARCOAT_BUMP = false;
     public CLEARCOAT_BUMPDIRECTUV = 0;
+    public CLEARCOAT_REMAPP_F0 = true;
     public CLEARCOAT_TINT = false;
     public CLEARCOAT_TINT_TEXTURE = false;
     public CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 541 - 531
src/Materials/PBR/pbrClearCoatConfiguration.ts


+ 35 - 6
src/Misc/khronosTextureContainer2.ts

@@ -7,7 +7,6 @@ declare var KTX2DECODER: any;
 
 /**
  * Class for loading KTX2 files
- * @hidden
  */
 export class KhronosTextureContainer2 {
     private static _WorkerPoolPromise?: Promise<WorkerPool>;
@@ -15,9 +14,24 @@ export class KhronosTextureContainer2 {
     private static _Ktx2Decoder: any; // used when no worker pool is used
 
     /**
-     * URL to use when loading the KTX2 decoder module
+     * URLs to use when loading the KTX2 decoder module as well as its dependencies
+     * If a url is null, the default url is used (pointing to https://preview.babylonjs.com)
+     * Note that jsDecoderModule can't be null and that the other dependencies will only be loaded if necessary
+     * Urls you can change:
+     *     URLConfig.jsDecoderModule
+     *     URLConfig.wasmUASTCToASTC
+     *     URLConfig.wasmUASTCToBC7
+     *     URLConfig.jsMSCTranscoder
+     *     URLConfig.wasmMSCTranscoder
+     * You can see their default values in this PG: https://playground.babylonjs.com/#EIJH8L#9
      */
-    public static JSModuleURL = "https://preview.babylonjs.com/babylon.ktx2Decoder.js";
+    public static URLConfig = {
+        jsDecoderModule: "https://preview.babylonjs.com/babylon.ktx2Decoder.js",
+        wasmUASTCToASTC: null,
+        wasmUASTCToBC7: null,
+        jsMSCTranscoder: null,
+        wasmMSCTranscoder: null
+    };
 
     /**
      * Default number of workers used to handle data decoding
@@ -66,7 +80,7 @@ export class KhronosTextureContainer2 {
 
                         worker.postMessage({
                             action: "init",
-                            jsPath: KhronosTextureContainer2.JSModuleURL
+                            urls: KhronosTextureContainer2.URLConfig
                         });
                     });
                 }
@@ -83,6 +97,7 @@ export class KhronosTextureContainer2 {
 
     /**
      * Constructor
+     * @param engine The engine to use
      * @param numWorkers The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.
      */
     public constructor(engine: ThinEngine, numWorkers = KhronosTextureContainer2.DefaultNumWorkers) {
@@ -93,6 +108,7 @@ export class KhronosTextureContainer2 {
         }
     }
 
+    /** @hidden */
     public uploadAsync(data: ArrayBufferView, internalTexture: InternalTexture): Promise<void> {
         const caps = this._engine.getCaps();
 
@@ -237,13 +253,26 @@ declare function postMessage(message: any, transfer?: any[]): void;
 
 declare var KTX2DECODER: any;
 
-export function workerFunc(): void {
+function workerFunc(): void {
     let ktx2Decoder: any;
 
     onmessage = (event) => {
         switch (event.data.action) {
             case "init":
-                importScripts(event.data.jsPath);
+                const urls = event.data.urls;
+                importScripts(urls.jsDecoderModule);
+                if (urls.wasmUASTCToASTC !== null) {
+                    KTX2DECODER.LiteTranscoder_UASTC_ASTC.WasmModuleURL = urls.wasmUASTCToASTC;
+                }
+                if (urls.wasmUASTCToBC7 !== null) {
+                    KTX2DECODER.LiteTranscoder_UASTC_BC7.WasmModuleURL = urls.wasmUASTCToBC7;
+                }
+                if (urls.jsMSCTranscoder !== null) {
+                    KTX2DECODER.MSCTranscoder.JSModuleURL = urls.jsMSCTranscoder;
+                }
+                if (urls.wasmMSCTranscoder !== null) {
+                    KTX2DECODER.MSCTranscoder.WasmModuleURL = urls.wasmMSCTranscoder;
+                }
                 ktx2Decoder = new KTX2DECODER.KTX2Decoder();
                 postMessage({ action: "init" });
                 break;

+ 5 - 1
src/Shaders/ShadersInclude/pbrBlockClearcoat.fx

@@ -142,7 +142,11 @@ struct clearcoatOutParams
         // clearCoatRoughness = mix(0.089, 0.6, clearCoatRoughness);
 
         // Remap F0 to account for the change of interface within the material.
-        vec3 specularEnvironmentR0Updated = getR0RemappedForClearCoat(specularEnvironmentR0);
+        #ifdef CLEARCOAT_REMAPP_F0
+            vec3 specularEnvironmentR0Updated = getR0RemappedForClearCoat(specularEnvironmentR0);
+        #else
+            vec3 specularEnvironmentR0Updated = specularEnvironmentR0;
+        #endif
         outParams.specularEnvironmentR0 = mix(specularEnvironmentR0, specularEnvironmentR0Updated, clearCoatIntensity);
 
         // Needs to use the geometric normal before bump for this.

+ 1 - 1
tests/validation/config.json

@@ -79,7 +79,7 @@
         },    
         {
             "title": "Node material PBR 1",
-            "playgroundId": "#D8AK3Z#7",
+            "playgroundId": "#D8AK3Z#15",
             "referenceImage": "node-material-pbr-1.png"
         },    
         {