From b477694298db31d1d6aebf87f83412b21c69c07c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 5 Feb 2025 16:21:03 +0900 Subject: [PATCH] MetallicRoughness --- .../VRM10Viewer/Assets/TinyPbr.shadergraph | 1090 ++++++++++++++++- .../VRM10Viewer/TinyPbrMaterialContext.cs | 47 +- .../TinyPbrMaterialDescriptorGenerator.cs | 23 +- 3 files changed, 1139 insertions(+), 21 deletions(-) diff --git a/Assets/VRM10_Samples/VRM10Viewer/Assets/TinyPbr.shadergraph b/Assets/VRM10_Samples/VRM10Viewer/Assets/TinyPbr.shadergraph index 4bfe92693..808e1111a 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Assets/TinyPbr.shadergraph +++ b/Assets/VRM10_Samples/VRM10Viewer/Assets/TinyPbr.shadergraph @@ -14,6 +14,15 @@ }, { "m_Id": "6b344f9254d2438b8ad07e5eef11db71" + }, + { + "m_Id": "c4ff105a2181464aaee7d5b6146a2c9b" + }, + { + "m_Id": "2859cb147a7742fca0dbb5256243d468" + }, + { + "m_Id": "fd4b1637b32c44d79eea652e4b5626b2" } ], "m_Keywords": [], @@ -77,6 +86,27 @@ }, { "m_Id": "19964d5b976e467eb1b4a7f544bf3fef" + }, + { + "m_Id": "1cb9d3109e954f59889461d6d563c74c" + }, + { + "m_Id": "bff080be2f534b5d82990c22e3cc631e" + }, + { + "m_Id": "91aa9548b6024d17b2b8a4be2770ad97" + }, + { + "m_Id": "177b02b8f3b64be1b2f2e7e0055128cb" + }, + { + "m_Id": "b08614dabfc6474ebee92e0b18d28d4b" + }, + { + "m_Id": "a60bd914ad7646698bb7f9c25f78f88d" + }, + { + "m_Id": "73efafc771664c7b8a4e4b9e58a6e868" } ], "m_GroupDatas": [], @@ -96,6 +126,34 @@ "m_SlotId": 0 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "177b02b8f3b64be1b2f2e7e0055128cb" + }, + "m_SlotId": 5 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "bff080be2f534b5d82990c22e3cc631e" + }, + "m_SlotId": 1 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "177b02b8f3b64be1b2f2e7e0055128cb" + }, + "m_SlotId": 6 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "1cb9d3109e954f59889461d6d563c74c" + }, + "m_SlotId": 1 + } + }, { "m_OutputSlot": { "m_Node": { @@ -110,6 +168,20 @@ "m_SlotId": 1 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "1cb9d3109e954f59889461d6d563c74c" + }, + "m_SlotId": 2 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0" + }, + "m_SlotId": 0 + } + }, { "m_OutputSlot": { "m_Node": { @@ -208,6 +280,20 @@ "m_SlotId": 3 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "73efafc771664c7b8a4e4b9e58a6e868" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "1cb9d3109e954f59889461d6d563c74c" + }, + "m_SlotId": 0 + } + }, { "m_OutputSlot": { "m_Node": { @@ -222,6 +308,48 @@ "m_SlotId": 0 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "91aa9548b6024d17b2b8a4be2770ad97" + }, + "m_SlotId": 2 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "53f1bc01113946bc946f0808f16df02b" + }, + "m_SlotId": 0 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "a60bd914ad7646698bb7f9c25f78f88d" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "bff080be2f534b5d82990c22e3cc631e" + }, + "m_SlotId": 0 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "b08614dabfc6474ebee92e0b18d28d4b" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "177b02b8f3b64be1b2f2e7e0055128cb" + }, + "m_SlotId": 1 + } + }, { "m_OutputSlot": { "m_Node": { @@ -235,6 +363,20 @@ }, "m_SlotId": 1 } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "bff080be2f534b5d82990c22e3cc631e" + }, + "m_SlotId": 2 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "91aa9548b6024d17b2b8a4be2770ad97" + }, + "m_SlotId": 1 + } } ], "m_VertexContext": { @@ -267,10 +409,10 @@ "m_Id": "58ee8fea72cc4a649f9a1198b12d621b" }, { - "m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0" + "m_Id": "53f1bc01113946bc946f0808f16df02b" }, { - "m_Id": "53f1bc01113946bc946f0808f16df02b" + "m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0" }, { "m_Id": "6f683c2eb23a4baf8dc028500640b75a" @@ -301,6 +443,21 @@ ] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "0066f90f9bd24aa69c3b20e8c87e10c6", + "m_Id": 5, + "m_DisplayName": "G", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "G", + "m_StageCapability": 2, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -343,6 +500,15 @@ }, { "m_Id": "6b344f9254d2438b8ad07e5eef11db71" + }, + { + "m_Id": "2859cb147a7742fca0dbb5256243d468" + }, + { + "m_Id": "fd4b1637b32c44d79eea652e4b5626b2" + }, + { + "m_Id": "c4ff105a2181464aaee7d5b6146a2c9b" } ] } @@ -383,6 +549,21 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "0ed4fbfbef64412cb58364eefca5123d", + "m_Id": 0, + "m_DisplayName": "Metallic", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -491,6 +672,66 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SampleTexture2DNode", + "m_ObjectId": "177b02b8f3b64be1b2f2e7e0055128cb", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Sample Texture 2D", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -633.9999389648438, + "y": 707.333251953125, + "width": 184.66668701171876, + "height": 254.66668701171876 + } + }, + "m_Slots": [ + { + "m_Id": "73dae5af12874f62a0ab55d8d0f86874" + }, + { + "m_Id": "68ec8f2063b9438c9d63bb33ab631b2d" + }, + { + "m_Id": "0066f90f9bd24aa69c3b20e8c87e10c6" + }, + { + "m_Id": "f270ed64ab2f4573bccddd9052f89b45" + }, + { + "m_Id": "f2cd25f551014ea49840fbd04e896d26" + }, + { + "m_Id": "ed7a1bf0296441bb937a9b1e6a9aa0c4" + }, + { + "m_Id": "580cf03335e3466680b45e02c4e8581a" + }, + { + "m_Id": "92d965669cb747908bb948442a355c47" + } + ], + "synonyms": [ + "tex2d" + ], + "m_Precision": 0, + "m_PreviewExpanded": false, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_TextureType": 0, + "m_NormalMapSpace": 1, + "m_EnableGlobalMipBias": true, + "m_MipSamplingMode": 0 +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.PropertyNode", @@ -566,6 +807,49 @@ "m_Space": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", + "m_ObjectId": "1cb9d3109e954f59889461d6d563c74c", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Multiply", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -324.6665954589844, + "y": 834.6666259765625, + "width": 209.33331298828126, + "height": 304.0001220703125 + } + }, + "m_Slots": [ + { + "m_Id": "5d77e11243834cf3a6f2e4fcf96ea6ff" + }, + { + "m_Id": "5b9961219b68470c9e8f957cef52af65" + }, + { + "m_Id": "3342995320024fdcb5e1e70917f28a44" + } + ], + "synonyms": [ + "multiplication", + "times", + "x" + ], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot", @@ -638,6 +922,58 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "26b0cc6a64b84c52993d605193516242", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "x": 1.0, + "y": 1.0, + "z": 1.0, + "w": 1.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "2859cb147a7742fca0dbb5256243d468", + "m_Guid": { + "m_GuidSerialized": "a6fd3729-c8ec-4297-8e95-c4d2117333eb" + }, + "m_Name": "Roughness", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "Roughness", + "m_DefaultReferenceName": "_Roughness", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 1.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", @@ -789,6 +1125,54 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "3342995320024fdcb5e1e70917f28a44", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 2, "m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalLitSubTarget", @@ -850,6 +1234,19 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot", + "m_ObjectId": "435d79c5527e4cd8935ce1a874f4ad05", + "m_Id": 0, + "m_DisplayName": "MetallicRoughnessMap", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_BareResource": false +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot", @@ -918,7 +1315,7 @@ "m_SerializableColors": [] }, "m_TextureType": 0, - "m_NormalMapSpace": 0, + "m_NormalMapSpace": 1, "m_EnableGlobalMipBias": true, "m_MipSamplingMode": 0 } @@ -945,6 +1342,54 @@ "m_Channel": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "4f7bef37b9a04a89a116a5756540a254", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -972,9 +1417,9 @@ "m_Expanded": true, "m_Position": { "serializedVersion": "2", - "x": 4.6667375564575199, - "y": 304.66668701171877, - "width": 200.00003051757813, + "x": 10.000014305114746, + "y": 317.3333435058594, + "width": 199.9999542236328, "height": 42.666656494140628 } }, @@ -994,6 +1439,28 @@ "m_SerializedDescriptor": "SurfaceDescription.Smoothness" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot", + "m_ObjectId": "580cf03335e3466680b45e02c4e8581a", + "m_Id": 2, + "m_DisplayName": "UV", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "UV", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [], + "m_Channel": 0 +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -1028,6 +1495,102 @@ "m_SerializedDescriptor": "SurfaceDescription.Occlusion" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "5b9961219b68470c9e8f957cef52af65", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "e00": 2.0, + "e01": 2.0, + "e02": 2.0, + "e03": 2.0, + "e10": 2.0, + "e11": 2.0, + "e12": 2.0, + "e13": 2.0, + "e20": 2.0, + "e21": 2.0, + "e22": 2.0, + "e23": 2.0, + "e30": 2.0, + "e31": 2.0, + "e32": 2.0, + "e33": 2.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "5d77e11243834cf3a6f2e4fcf96ea6ff", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -1174,6 +1737,21 @@ "m_MipSamplingMode": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "68ec8f2063b9438c9d63bb33ab631b2d", + "m_Id": 4, + "m_DisplayName": "R", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "R", + "m_StageCapability": 2, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot", @@ -1212,7 +1790,7 @@ "m_Guid": "" }, "isMainTexture": false, - "useTilingAndOffset": false, + "useTilingAndOffset": true, "m_Modifiable": true, "m_DefaultType": 0 } @@ -1266,6 +1844,67 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "73dae5af12874f62a0ab55d8d0f86874", + "m_Id": 0, + "m_DisplayName": "RGBA", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "RGBA", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "73efafc771664c7b8a4e4b9e58a6e868", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -813.333251953125, + "y": 816.6666259765625, + "width": 117.33331298828125, + "height": 36.00006103515625 + } + }, + "m_Slots": [ + { + "m_Id": "0ed4fbfbef64412cb58364eefca5123d" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "fd4b1637b32c44d79eea652e4b5626b2" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", @@ -1553,6 +2192,21 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "86409fdb77e447f19dcf968176770f7f", + "m_Id": 0, + "m_DisplayName": "Roughness", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -1568,6 +2222,54 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "86bb22958e0547bb9cc968a7ff4eb1b7", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "x": 1.0, + "y": 1.0, + "z": 1.0, + "w": 1.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "8730cfb2eee34a7aaa30bc67b7f03014", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -1603,6 +2305,63 @@ "m_DefaultType": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SubtractNode", + "m_ObjectId": "91aa9548b6024d17b2b8a4be2770ad97", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Subtract", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -178.66664123535157, + "y": 498.0000305175781, + "width": 127.33338928222656, + "height": 119.99990844726563 + } + }, + "m_Slots": [ + { + "m_Id": "26b0cc6a64b84c52993d605193516242" + }, + { + "m_Id": "86bb22958e0547bb9cc968a7ff4eb1b7" + }, + { + "m_Id": "8730cfb2eee34a7aaa30bc67b7f03014" + } + ], + "synonyms": [ + "subtraction", + "remove", + "minus", + "take away" + ], + "m_Precision": 0, + "m_PreviewExpanded": false, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SamplerStateMaterialSlot", + "m_ObjectId": "92d965669cb747908bb948442a355c47", + "m_Id": 3, + "m_DisplayName": "Sampler", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Sampler", + "m_StageCapability": 3, + "m_BareResource": false +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Internal.Texture2DShaderProperty", @@ -1633,6 +2392,90 @@ "m_DefaultType": 0 } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "9512c4f761ea4aaaa2db8e7ec9d7bf37", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "a60bd914ad7646698bb7f9c25f78f88d", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -829.9999389648438, + "y": 702.6666259765625, + "width": 134.0, + "height": 36.00006103515625 + } + }, + "m_Slots": [ + { + "m_Id": "86409fdb77e447f19dcf968176770f7f" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "2859cb147a7742fca0dbb5256243d468" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", @@ -1726,6 +2569,42 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "b08614dabfc6474ebee92e0b18d28d4b", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -901.9999389648438, + "y": 738.6666870117188, + "width": 206.0, + "height": 35.9998779296875 + } + }, + "m_Slots": [ + { + "m_Id": "435d79c5527e4cd8935ce1a874f4ad05" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "c4ff105a2181464aaee7d5b6146a2c9b" + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector3Node", @@ -1778,6 +2657,49 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", + "m_ObjectId": "bff080be2f534b5d82990c22e3cc631e", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Multiply", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -414.6666564941406, + "y": 530.6666259765625, + "width": 209.3333282470703, + "height": 304.0 + } + }, + "m_Slots": [ + { + "m_Id": "4f7bef37b9a04a89a116a5756540a254" + }, + { + "m_Id": "e96a61a3df77424ea29af5a57479b600" + }, + { + "m_Id": "9512c4f761ea4aaaa2db8e7ec9d7bf37" + } + ], + "synonyms": [ + "multiplication", + "times", + "x" + ], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.SamplerStateMaterialSlot", @@ -1806,6 +2728,36 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Internal.Texture2DShaderProperty", + "m_ObjectId": "c4ff105a2181464aaee7d5b6146a2c9b", + "m_Guid": { + "m_GuidSerialized": "77edee86-bd02-4114-a7f5-247e9ba9cf42" + }, + "m_Name": "MetallicRoughnessMap", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "MetallicRoughnessMap", + "m_DefaultReferenceName": "_MetallicRoughnessMap", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": { + "m_SerializedTexture": "", + "m_Guid": "" + }, + "isMainTexture": false, + "useTilingAndOffset": true, + "m_Modifiable": true, + "m_DefaultType": 0 +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -2024,6 +2976,72 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "e96a61a3df77424ea29af5a57479b600", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "e00": 2.0, + "e01": 2.0, + "e02": 2.0, + "e03": 2.0, + "e10": 2.0, + "e11": 2.0, + "e12": 2.0, + "e13": 2.0, + "e20": 2.0, + "e21": 2.0, + "e22": 2.0, + "e23": 2.0, + "e30": 2.0, + "e31": 2.0, + "e32": 2.0, + "e33": 2.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Texture2DInputMaterialSlot", + "m_ObjectId": "ed7a1bf0296441bb937a9b1e6a9aa0c4", + "m_Id": 1, + "m_DisplayName": "Texture", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Texture", + "m_StageCapability": 3, + "m_BareResource": false, + "m_Texture": { + "m_SerializedTexture": "", + "m_Guid": "" + }, + "m_DefaultType": 0 +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -2049,6 +3067,36 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "f270ed64ab2f4573bccddd9052f89b45", + "m_Id": 6, + "m_DisplayName": "B", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 2, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "f2cd25f551014ea49840fbd04e896d26", + "m_Id": 7, + "m_DisplayName": "A", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 2, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.BlockNode", @@ -2083,3 +3131,31 @@ "m_SerializedDescriptor": "VertexDescription.Position" } +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "fd4b1637b32c44d79eea652e4b5626b2", + "m_Guid": { + "m_GuidSerialized": "95cdef22-fc8b-49da-9fe2-98bab1d5658c" + }, + "m_Name": "Metallic", + "m_DefaultRefNameVersion": 1, + "m_RefNameGeneratedByDisplayName": "Metallic", + "m_DefaultReferenceName": "_Metallic", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_UseCustomSlotLabel": false, + "m_CustomSlotLabel": "", + "m_DismissedVersion": 0, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 1.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + diff --git a/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialContext.cs b/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialContext.cs index 2c4872e66..c9a8282f2 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialContext.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialContext.cs @@ -13,15 +13,22 @@ namespace UniVRM10.VRM10Viewer /// Texture2D = White /// When using shadergraph, require "Set as Main Texture" /// - private static readonly int BaseMap = Shader.PropertyToID("_BaseMap"); + private static readonly int BaseMapProp = Shader.PropertyToID("_BaseMap"); /// - /// float = 1 + /// float = 1.0 /// private static readonly int OcclusionStrengthProp = Shader.PropertyToID("_OcclusionStrength"); /// - /// Texture2D = White + /// Texture2D.Red = 1.0. /// - private static readonly int OcclusionMap = Shader.PropertyToID("_OcclusionMap"); + private static readonly int OcclusionMapProp = Shader.PropertyToID("_OcclusionMap"); + private static readonly int RoughnessProp = Shader.PropertyToID("_Roughness"); + private static readonly int MetallicProp = Shader.PropertyToID("_Metallic"); + /// + /// Texture2D.Green = 1.0. The roughness + /// Texture2D.Blue = 1.0. The metalness + /// + private static readonly int MetallicRoughnessMapProp = Shader.PropertyToID("_MetallicRoughnessMap"); public readonly Material Material; public TinyPbrMaterialContext(Material material) @@ -36,18 +43,18 @@ namespace UniVRM10.VRM10Viewer } public Texture BaseTexture { - get => Material.GetTexture(BaseMap); - set => Material.SetTexture(BaseMap, value); + get => Material.GetTexture(BaseMapProp); + set => Material.SetTexture(BaseMapProp, value); } public Vector2 BaseTextureOffset { - get => Material.GetTextureOffset(BaseMap); - set => Material.SetTextureOffset(BaseMap, value); + get => Material.GetTextureOffset(BaseMapProp); + set => Material.SetTextureOffset(BaseMapProp, value); } public Vector2 BaseTextureScale { - get => Material.GetTextureScale(BaseMap); - set => Material.SetTextureScale(BaseMap, value); + get => Material.GetTextureScale(BaseMapProp); + set => Material.SetTextureScale(BaseMapProp, value); } public float OcclusionStrength @@ -57,11 +64,27 @@ namespace UniVRM10.VRM10Viewer } public Texture OcclusionTexture { - get => Material.GetTexture(OcclusionMap); + get => Material.GetTexture(OcclusionMapProp); set { - Material.SetTexture(OcclusionMap, value); + Material.SetTexture(OcclusionMapProp, value); } } + + public float Roughness + { + get => Material.GetFloat(RoughnessProp); + set => Material.SetFloat(RoughnessProp, value); + } + public float Metallic + { + get => Material.GetFloat(MetallicProp); + set => Material.SetFloat(MetallicProp, value); + } + public Texture MetallicRoughnessMap + { + get => Material.GetTexture(MetallicRoughnessMapProp); + set => Material.SetTexture(MetallicRoughnessMapProp, value); + } } } \ No newline at end of file diff --git a/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialDescriptorGenerator.cs b/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialDescriptorGenerator.cs index 95b438467..7282b07af 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialDescriptorGenerator.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/TinyPbrMaterialDescriptorGenerator.cs @@ -70,7 +70,7 @@ namespace UniVRM10.VRM10Viewer // ImportSurfaceSettings(src, context); await ImportBaseColorAsync(data, src, context, getTextureAsync, awaitCaller); - // await ImportMetallicSmoothnessAsync(data, src, context, getTextureAsync, awaitCaller); + await ImportMetallicRoughnessAsync(data, src, context, getTextureAsync, awaitCaller); await ImportOcclusionAsync(data, src, context, getTextureAsync, awaitCaller); // await ImportNormalAsync(data, src, context, getTextureAsync, awaitCaller); // await ImportEmissionAsync(data, src, context, getTextureAsync, awaitCaller); @@ -96,11 +96,30 @@ namespace UniVRM10.VRM10Viewer } } } + + public static async Task ImportMetallicRoughnessAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller) + { + context.Metallic = src.pbrMetallicRoughness.metallicFactor; + context.Roughness = src.pbrMetallicRoughness.roughnessFactor; + + if (src is { pbrMetallicRoughness: { metallicRoughnessTexture: { index: >= 0 } } }) + { + var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.pbrMetallicRoughness.metallicRoughnessTexture); + if (GltfTextureImporter.TryCreateLinear(data, src.pbrMetallicRoughness.metallicRoughnessTexture.index, offset, scale, out var _, out var desc)) + { + context.MetallicRoughnessMap = await getTextureAsync(desc, awaitCaller); + context.Metallic = 1; + context.Roughness = 1; + } + } + } + public static async Task ImportOcclusionAsync(GltfData data, glTFMaterial src, TinyPbrMaterialContext context, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller) { if (src is { occlusionTexture: { index: >= 0 } }) { - if (GltfPbrTextureImporter.TryStandardTexture(data, src, out _, out var desc)) + var (offset, scale) = GltfTextureImporter.GetTextureOffsetAndScale(src.occlusionTexture); + if (GltfTextureImporter.TryCreateLinear(data, src.occlusionTexture.index, offset, scale, out var _, out var desc)) { context.OcclusionTexture = await getTextureAsync(desc, awaitCaller); context.OcclusionStrength = src.occlusionTexture.strength;