瀏覽代碼

Fix tnagent issue with nme

David Catuhe 5 年之前
父節點
當前提交
73b46a272a

+ 4 - 0
inspector/src/components/actionTabs/tabs/propertyGrids/meshes/meshPropertyGridComponent.tsx

@@ -345,6 +345,10 @@ export class MeshPropertyGridComponent extends React.Component<IMeshPropertyGrid
                         <CheckBoxLineComponent label="Use vertex colors" target={mesh} propertyName="useVertexColors" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                     }
                     {
+                        mesh.isVerticesDataPresent(VertexBuffer.ColorKind) &&
+                        <CheckBoxLineComponent label="Has vertex alpha" target={mesh} propertyName="hasVertexAlpha" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
+                    }                    
+                    {
                         scene.fogMode !== Scene.FOGMODE_NONE &&
                         <CheckBoxLineComponent label="Apply fog" target={mesh} propertyName="applyFog" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                     }

+ 21 - 1
nodeEditor/src/blockTools.ts

@@ -411,7 +411,27 @@ export class BlockTools {
                 worldMatrixBlock.connectTo(transformBlock);
 
                 return transformBlock;
-            }                  
+            }     
+            case "WorldTangentBlock": {
+                let worldTangentBlock = nodeMaterial.getInputBlockByPredicate(b => b.isAttribute && b.name === "tangent");                
+                if (!worldTangentBlock) {
+                    worldTangentBlock = new InputBlock("tangent");
+                    worldTangentBlock.setAsAttribute("tangent");
+                }
+
+                let worldMatrixBlock = nodeMaterial.getInputBlockByPredicate(b => b.isSystemValue && b.systemValue === NodeMaterialSystemValues.World);  
+
+                if (!worldMatrixBlock) {
+                    worldMatrixBlock = new InputBlock("World");
+                    worldMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.World);
+                }
+
+                let transformBlock = new TransformBlock("World tangent");
+                worldTangentBlock.connectTo(transformBlock);
+                worldMatrixBlock.connectTo(transformBlock);
+
+                return transformBlock;
+            }              
         }
 
         return null;

+ 2 - 1
nodeEditor/src/components/nodeList/nodeListComponent.tsx

@@ -63,6 +63,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
         "TangentBlock": "A Vector3 representing the tangent of each vertex of the attached mesh",
         "UVBlock": "A Vector2 representing the UV coordinates of each vertex of the attached mesh",
         "WorldNormal": "A Vector4 representing the normal of each vertex of the attached mesh transformed into world space",
+        "WorldTangent": "A Vector4 representing the tangent of each vertex of the attached mesh transformed into world space",
         "PerturbNormalBlock": "Creates high-frequency detail normal vectors based on a normal map, the world position, and world normal",
         "NormalBlend": "Outputs the result of blending two normal maps together using a per-channel screen",
         "WorldPosition": "A Vector4 representing the position of each vertex of the attached mesh transformed into world space",
@@ -141,7 +142,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
             Math__Scientific: ["AbsBlock", "ArcCosBlock", "ArcSinBlock", "ArcTanBlock", "ArcTan2Block", "CosBlock", "DegreesToRadiansBlock", "ExpBlock", "Exp2Block", "FractBlock", "LogBlock", "PowBlock", "RadiansToDegreesBlock", "SawToothWaveBlock", "SinBlock", "SquareWaveBlock", "TanBlock", "TriangleWaveBlock"],
             Math__Vector: ["CrossBlock", "DerivativeBlock", "DistanceBlock", "DotBlock", "FresnelBlock", "LengthBlock", "ReflectBlock", "RefractBlock", "Rotate2dBlock", "TransformBlock", ],
             Matrices: ["Matrix", "WorldMatrixBlock", "WorldViewMatrixBlock", "WorldViewProjectionMatrixBlock", "ViewMatrixBlock", "ViewProjectionMatrixBlock", "ProjectionMatrixBlock"],
-            Mesh: ["InstancesBlock", "PositionBlock", "UVBlock", "ColorBlock", "NormalBlock", "PerturbNormalBlock", "NormalBlendBlock" , "TangentBlock", "MatrixIndicesBlock", "MatrixWeightsBlock", "WorldPositionBlock", "WorldNormalBlock", "FrontFacingBlock"], 
+            Mesh: ["InstancesBlock", "PositionBlock", "UVBlock", "ColorBlock", "NormalBlock", "PerturbNormalBlock", "NormalBlendBlock" , "TangentBlock", "MatrixIndicesBlock", "MatrixWeightsBlock", "WorldPositionBlock", "WorldNormalBlock", "WorldTangentBlock", "FrontFacingBlock"], 
             Noises: ["RandomNumberBlock", "SimplexPerlin3DBlock", "WorleyNoise3DBlock"],
             Output_Blocks: ["VertexOutputBlock", "FragmentOutputBlock", "DiscardBlock"],
             Range: ["ClampBlock", "RemapBlock", "NormalizeBlock"],

+ 25 - 5
src/Materials/Node/Blocks/Fragment/perturbNormalBlock.ts

@@ -35,6 +35,7 @@ export class PerturbNormalBlock extends NodeMaterialBlock {
         // Vertex
         this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector4, false);
         this.registerInput("worldNormal", NodeMaterialBlockConnectionPointTypes.Vector4, false);
+        this.registerInput("worldTangent", NodeMaterialBlockConnectionPointTypes.Vector4, true);
         this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false);
         this.registerInput("normalMapColor", NodeMaterialBlockConnectionPointTypes.Color3, false);
         this.registerInput("strength", NodeMaterialBlockConnectionPointTypes.Float, false);
@@ -64,26 +65,33 @@ export class PerturbNormalBlock extends NodeMaterialBlock {
     public get worldNormal(): NodeMaterialConnectionPoint {
         return this._inputs[1];
     }
+    
+    /**
+     * Gets the world tangent input component
+     */
+    public get worldTangent(): NodeMaterialConnectionPoint {
+        return this._inputs[2];
+    }
 
     /**
      * Gets the uv input component
      */
     public get uv(): NodeMaterialConnectionPoint {
-        return this._inputs[2];
+        return this._inputs[3];
     }
 
     /**
     * Gets the normal map color input component
     */
     public get normalMapColor(): NodeMaterialConnectionPoint {
-        return this._inputs[3];
+        return this._inputs[4];
     }
 
     /**
     * Gets the strength input component
     */
     public get strength(): NodeMaterialConnectionPoint {
-        return this._inputs[4];
+        return this._inputs[5];
     }
 
     /**
@@ -130,6 +138,7 @@ export class PerturbNormalBlock extends NodeMaterialBlock {
         let uv = this.uv;
         let worldPosition = this.worldPosition;
         let worldNormal = this.worldNormal;
+        let worldTangent = this.worldTangent;
 
         state.sharedData.blocksWithDefines.push(this);
         state.sharedData.bindableBlocks.push(this);
@@ -141,14 +150,25 @@ export class PerturbNormalBlock extends NodeMaterialBlock {
         let replaceForBumpInfos = this.strength.isConnectedToInputBlock && this.strength.connectInputBlock!.isConstant ? `${state._emitFloat(1.0 / this.strength.connectInputBlock!.value)}` : `1.0 / ${this.strength.associatedVariableName}`;
 
         state._emitExtension("derivatives", "#extension GL_OES_standard_derivatives : enable");
+
+        let tangentReplaceString = { search: /defined\(TANGENT\)/g, replace: worldTangent.isConnected ? "defined(TANGENT)" : "defined(IGNORE)" };
+
+        if (worldTangent.isConnected) {
+            state.compilationString += `vec3 tbnNormal = normalize(${worldNormal.associatedVariableName}.xyz);\r\n`;
+            state.compilationString += `vec3 tbnTangent = normalize(${worldTangent.associatedVariableName}.xyz);\r\n`;
+            state.compilationString += `vec3 tbnBitangent = cross(tbnNormal, tbnTangent);\r\n`;
+            state.compilationString += `mat3 vTBN = mat3(tbnTangent, tbnBitangent, tbnNormal);\r\n`;
+        }
+
         state._emitFunctionFromInclude("bumpFragmentFunctions", comments, {
             replaceStrings: [
                 { search: /vBumpInfos.y/g, replace: replaceForBumpInfos},
                 { search: /vTangentSpaceParams/g, replace: this._tangentSpaceParameterName},
                 { search: /vPositionW/g, replace: worldPosition.associatedVariableName + ".xyz"},
-                { search: /defined\(TANGENT\)/g, replace: "defined(IGNORE)" }
+                tangentReplaceString
             ]
         });
+
         state.compilationString += this._declareOutput(this.output, state) + " = vec4(0.);\r\n";
         state.compilationString += state._emitCodeFromInclude("bumpFragment", comments, {
             replaceStrings: [
@@ -158,7 +178,7 @@ export class PerturbNormalBlock extends NodeMaterialBlock {
                 { search: /vPositionW/g, replace: worldPosition.associatedVariableName + ".xyz"},
                 { search: /normalW=/g, replace: this.output.associatedVariableName + ".xyz = " },
                 { search: /normalW/g, replace: worldNormal.associatedVariableName + ".xyz" },
-                { search: /defined\(TANGENT\)/g, replace: "defined(IGNORE)" }
+                tangentReplaceString
             ]
         });
 

+ 1 - 1
src/Materials/Node/Blocks/transformBlock.ts

@@ -36,7 +36,7 @@ export class TransformBlock extends NodeMaterialBlock {
             if (other.ownerBlock.isInput) {
                 let otherAsInput = other.ownerBlock as InputBlock;
 
-                if (otherAsInput.name === "normal") {
+                if (otherAsInput.name === "normal" || otherAsInput.name === "tangent") {
                     this.complementW = 0;
                 }
             }