Merge pull request #2573 from ousttrue/fix/custom_material

_MainTex_ST の参照を修正
This commit is contained in:
ousttrue 2025-02-04 18:24:15 +09:00 committed by GitHub
commit 71e4a71d80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 1590 additions and 489 deletions

View File

@ -22,10 +22,6 @@ namespace UniVRM10
{
switch (bindType)
{
// case MaterialBindType.UvOffset:
// case MaterialBindType.UvScale:
// return UV_PROPERTY;
case MaterialColorType.color:
return COLOR_PROPERTY;

View File

@ -56,7 +56,9 @@ namespace UniVRM10
Material = material;
// uv default value
DefaultUVScaleOffset = material.GetVector(UV_PROPERTY);
var s = material.mainTextureScale;
var o = material.mainTextureOffset;
DefaultUVScaleOffset = new(s.x, s.y, o.x, o.y);
}
public Dictionary<UniGLTF.Extensions.VRMC_vrm.MaterialColorType, PropItem> PropMap = new Dictionary<UniGLTF.Extensions.VRMC_vrm.MaterialColorType, PropItem>();
@ -77,7 +79,6 @@ namespace UniVRM10
}
}
public static readonly string UV_PROPERTY = $"{MToon10Prop.BaseColorTexture.ToUnityShaderLabName()}_ST";
public static readonly string COLOR_PROPERTY = MToon10Prop.BaseColorFactor.ToUnityShaderLabName();
public static readonly string EMISSION_COLOR_PROPERTY = MToon10Prop.EmissiveFactor.ToUnityShaderLabName();
public static readonly string RIM_COLOR_PROPERTY = MToon10Prop.ParametricRimColorFactor.ToUnityShaderLabName();
@ -132,7 +133,8 @@ namespace UniVRM10
}
// clear UV
Material.SetVector(UV_PROPERTY, DefaultUVScaleOffset);
Material.mainTextureScale = new(DefaultUVScaleOffset.x, DefaultUVScaleOffset.y);
Material.mainTextureOffset = new(DefaultUVScaleOffset.z, DefaultUVScaleOffset.w);
}
/// <summary>
@ -142,9 +144,12 @@ namespace UniVRM10
/// <param name="weight"></param>
public void AddScaleOffset(Vector4 scaleOffset, float weight)
{
var value = Material.GetVector(UV_PROPERTY);
var s = Material.mainTextureScale;
var o = Material.mainTextureOffset;
var value = new Vector4(s.x, s.y, o.x, o.y);
value += (scaleOffset - DefaultUVScaleOffset) * weight;
Material.SetColor(UV_PROPERTY, value);
Material.mainTextureOffset = new(value.z, value.w);
Material.mainTextureScale = new(value.x, value.y);
}
}
}

View File

@ -9,6 +9,7 @@ namespace UniVRM10
(INormalizedPoseProvider, ITPoseProvider) ControlRig { get; }
IReadOnlyDictionary<ExpressionKey, Func<float>> ExpressionMap { get; }
public void ShowBoxMan(bool enable);
public void SetBoxManMaterial(Material material);
LookAtInput? LookAt { get; }
}
}

View File

@ -15,6 +15,11 @@ namespace UniVRM10
BoxMan.enabled = enable;
}
public void SetBoxManMaterial(Material material)
{
BoxMan.material = material;
}
public void Dispose()
{
if (Application.isPlaying)

View File

@ -65,5 +65,9 @@ namespace UniVRM10
public void ShowBoxMan(bool enable)
{
}
public void SetBoxManMaterial(Material material)
{
}
}
}

View File

@ -55,6 +55,10 @@ namespace UniVRM10.Cloth.Viewer
m_boxMan.enabled = enable;
}
public void SetBoxManMaterial(Material material)
{
}
public void Dispose()
{
GameObject.Destroy(m_context.Root);

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 64ea0443b7eb3f74a8a0d8a88f61558f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,975 @@
{
"m_SGVersion": 3,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "77181a4b19324ebdb175da71cf4f6186",
"m_Properties": [
{
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
],
"m_Keywords": [],
"m_Dropdowns": [],
"m_CategoryData": [
{
"m_Id": "0778abfa54c94f9abfd0482e1de4d602"
}
],
"m_Nodes": [
{
"m_Id": "f56f676a56e04566a12f41980b760358"
},
{
"m_Id": "307a94d3f1ca45a39f6170433e3c81c6"
},
{
"m_Id": "7b57df1b4e444208bd41b7b749f485d0"
},
{
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
{
"m_Id": "6f683c2eb23a4baf8dc028500640b75a"
},
{
"m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0"
},
{
"m_Id": "53f1bc01113946bc946f0808f16df02b"
},
{
"m_Id": "0f64718141f34878916463ec72c9d2d8"
},
{
"m_Id": "58ee8fea72cc4a649f9a1198b12d621b"
},
{
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
{
"m_Id": "305a571d629e4b258d80c3ad877cb596"
}
],
"m_GroupDatas": [],
"m_StickyNoteDatas": [],
"m_Edges": [
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "305a571d629e4b258d80c3ad877cb596"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
"m_SlotId": 1
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "6637a91f035a40e798e76f70bed17d7e"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
"m_SlotId": 0
}
}
],
"m_VertexContext": {
"m_Position": {
"x": 0.0,
"y": 0.0
},
"m_Blocks": [
{
"m_Id": "f56f676a56e04566a12f41980b760358"
},
{
"m_Id": "307a94d3f1ca45a39f6170433e3c81c6"
},
{
"m_Id": "7b57df1b4e444208bd41b7b749f485d0"
}
]
},
"m_FragmentContext": {
"m_Position": {
"x": 0.0,
"y": 200.0
},
"m_Blocks": [
{
"m_Id": "80fce1dbcef04945aa9b988609dbe324"
},
{
"m_Id": "6f683c2eb23a4baf8dc028500640b75a"
},
{
"m_Id": "6098dc7f36d84b83b8421cc0e56ed1a0"
},
{
"m_Id": "53f1bc01113946bc946f0808f16df02b"
},
{
"m_Id": "0f64718141f34878916463ec72c9d2d8"
},
{
"m_Id": "58ee8fea72cc4a649f9a1198b12d621b"
}
]
},
"m_PreviewData": {
"serializedMesh": {
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
"m_Guid": ""
},
"preventRotation": false
},
"m_Path": "Shader Graphs",
"m_GraphPrecision": 1,
"m_PreviewMode": 2,
"m_OutputNode": {
"m_Id": ""
},
"m_SubDatas": [],
"m_ActiveTargets": [
{
"m_Id": "15cb78699c8c4194ad103421699dbd17"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "02acc5a4d1de49f087b1a9268cf423ed",
"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.CategoryData",
"m_ObjectId": "0778abfa54c94f9abfd0482e1de4d602",
"m_Name": "",
"m_ChildObjectList": [
{
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "0f64718141f34878916463ec72c9d2d8",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Emission",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "a8a3476bbfe8465fbf208d8592d231a3"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Emission"
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalTarget",
"m_ObjectId": "15cb78699c8c4194ad103421699dbd17",
"m_Datas": [],
"m_ActiveSubTarget": {
"m_Id": "352f1953e12a45019330c49643812248"
},
"m_AllowMaterialOverride": false,
"m_SurfaceType": 0,
"m_ZTestMode": 4,
"m_ZWriteControl": 0,
"m_AlphaMode": 0,
"m_RenderFace": 2,
"m_AlphaClip": false,
"m_CastShadows": true,
"m_ReceiveShadows": true,
"m_SupportsLODCrossFade": false,
"m_CustomEditorGUI": "",
"m_SupportVFX": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "1773542df3cf4760b4bc7081934f54ca",
"m_Id": 0,
"m_DisplayName": "Smoothness",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Smoothness",
"m_StageCapability": 2,
"m_Value": 0.5,
"m_DefaultValue": 0.5,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "1b504994184f46fb86fd313496af2752",
"m_Id": 0,
"m_DisplayName": "Ambient Occlusion",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Occlusion",
"m_StageCapability": 2,
"m_Value": 1.0,
"m_DefaultValue": 1.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot",
"m_ObjectId": "1c1aa306b109406fae4e7ad7412fdb14",
"m_Id": 0,
"m_DisplayName": "Tangent",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Tangent",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "204b111e465b44809369f1d3e5a90370",
"m_Id": 0,
"m_DisplayName": "Normal (Tangent Space)",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "NormalTS",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 3
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.SamplerStateMaterialSlot",
"m_ObjectId": "2b57ee1b447443b39131b7d7ca5656c4",
"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.PropertyNode",
"m_ObjectId": "305a571d629e4b258d80c3ad877cb596",
"m_Group": {
"m_Id": ""
},
"m_Name": "Property",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -482.6666564941406,
"y": 233.3333282470703,
"width": 140.0,
"height": 35.99998474121094
}
},
"m_Slots": [
{
"m_Id": "46fb52b8b307424ab27250d54f2c27f9"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_Property": {
"m_Id": "92f5ab11614c4ec1b4d632f73041ba65"
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "307a94d3f1ca45a39f6170433e3c81c6",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Normal",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "e1de0ca351fd43ff866485e33328e300"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Normal"
}
{
"m_SGVersion": 2,
"m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalLitSubTarget",
"m_ObjectId": "352f1953e12a45019330c49643812248",
"m_WorkflowMode": 1,
"m_NormalDropOffSpace": 0,
"m_ClearCoat": false,
"m_BlendModePreserveSpecular": true
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "408c7be450e8421abf78f79621f38a90",
"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.Texture2DMaterialSlot",
"m_ObjectId": "46fb52b8b307424ab27250d54f2c27f9",
"m_Id": 0,
"m_DisplayName": "BaseMap",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_BareResource": false
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot",
"m_ObjectId": "4c1d0e69fdc7482b9e9587c61e9aee52",
"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",
"m_ObjectId": "53f1bc01113946bc946f0808f16df02b",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Smoothness",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1773542df3cf4760b4bc7081934f54ca"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Smoothness"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "58ee8fea72cc4a649f9a1198b12d621b",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Occlusion",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1b504994184f46fb86fd313496af2752"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Occlusion"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "6098dc7f36d84b83b8421cc0e56ed1a0",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Metallic",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "cd2a46a6fe0746ae965dc193ce0757eb"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Metallic"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PositionMaterialSlot",
"m_ObjectId": "619a91e5d75d4a629f14de895dbebb39",
"m_Id": 0,
"m_DisplayName": "Position",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Position",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.SampleTexture2DNode",
"m_ObjectId": "6637a91f035a40e798e76f70bed17d7e",
"m_Group": {
"m_Id": ""
},
"m_Name": "Sample Texture 2D",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -322.0,
"y": 200.0,
"width": 209.3333282470703,
"height": 438.6666259765625
}
},
"m_Slots": [
{
"m_Id": "02acc5a4d1de49f087b1a9268cf423ed"
},
{
"m_Id": "8057542115c941488ee696e0d023e9d8"
},
{
"m_Id": "c47fe1183b3b44d1ad66a998fde085f5"
},
{
"m_Id": "408c7be450e8421abf78f79621f38a90"
},
{
"m_Id": "70bb30a82355421ca010103090de0f4a"
},
{
"m_Id": "7aa32b9c5fc74c8088ac31ed5fc87f50"
},
{
"m_Id": "4c1d0e69fdc7482b9e9587c61e9aee52"
},
{
"m_Id": "2b57ee1b447443b39131b7d7ca5656c4"
}
],
"synonyms": [
"tex2d"
],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_TextureType": 0,
"m_NormalMapSpace": 0,
"m_EnableGlobalMipBias": true,
"m_MipSamplingMode": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "6f683c2eb23a4baf8dc028500640b75a",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.NormalTS",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "204b111e465b44809369f1d3e5a90370"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.NormalTS"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "70bb30a82355421ca010103090de0f4a",
"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.ColorRGBMaterialSlot",
"m_ObjectId": "7454a78d02bb4f79b6ff0f81f6b795a0",
"m_Id": 0,
"m_DisplayName": "Base Color",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "BaseColor",
"m_StageCapability": 2,
"m_Value": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 0,
"m_DefaultColor": {
"r": 0.5,
"g": 0.5,
"b": 0.5,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Texture2DInputMaterialSlot",
"m_ObjectId": "7aa32b9c5fc74c8088ac31ed5fc87f50",
"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.BlockNode",
"m_ObjectId": "7b57df1b4e444208bd41b7b749f485d0",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Tangent",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "1c1aa306b109406fae4e7ad7412fdb14"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Tangent"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "8057542115c941488ee696e0d023e9d8",
"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.BlockNode",
"m_ObjectId": "80fce1dbcef04945aa9b988609dbe324",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.BaseColor",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "7454a78d02bb4f79b6ff0f81f6b795a0"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.BaseColor"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Internal.Texture2DShaderProperty",
"m_ObjectId": "92f5ab11614c4ec1b4d632f73041ba65",
"m_Guid": {
"m_GuidSerialized": "df5eef53-f7a6-40ef-8fca-1fd91f86d83f"
},
"m_Name": "BaseMap",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "BaseMap",
"m_DefaultReferenceName": "_BaseMap",
"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": true,
"useTilingAndOffset": true,
"m_Modifiable": true,
"m_DefaultType": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "a8a3476bbfe8465fbf208d8592d231a3",
"m_Id": 0,
"m_DisplayName": "Emission",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Emission",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 1,
"m_DefaultColor": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "c47fe1183b3b44d1ad66a998fde085f5",
"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.Vector1MaterialSlot",
"m_ObjectId": "cd2a46a6fe0746ae965dc193ce0757eb",
"m_Id": 0,
"m_DisplayName": "Metallic",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Metallic",
"m_StageCapability": 2,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "e1de0ca351fd43ff866485e33328e300",
"m_Id": 0,
"m_DisplayName": "Normal",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Normal",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "f56f676a56e04566a12f41980b760358",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Position",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "619a91e5d75d4a629f14de895dbebb39"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Position"
}

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ac58f8c11a130e04ba883a82ae4b78e4
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

View File

@ -54,6 +54,11 @@ namespace UniVRM10.VRM10Viewer
m_boxMan.enabled = enable;
}
public void SetBoxManMaterial(Material material)
{
m_boxMan.material = material;
}
public void Dispose()
{
GameObject.Destroy(m_context.Root);

View File

@ -0,0 +1,33 @@
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
public class TinyPbrContext
{
private static readonly int BaseMap = Shader.PropertyToID("_BaseMap");
public readonly Material Material;
public Texture BaseTexture
{
get => Material.GetTexture(BaseMap);
set => Material.SetTexture(BaseMap, value);
}
public Vector2 BaseTextureOffset
{
get => Material.GetTextureOffset(BaseMap);
set => Material.SetTextureOffset(BaseMap, value);
}
public Vector2 BaseTextureScale
{
get => Material.GetTextureScale(BaseMap);
set => Material.SetTextureScale(BaseMap, value);
}
public TinyPbrContext(Material material)
{
Material = material;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8084ef1a84a110241ac5d3350832a9d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UniGLTF;
using UnityEngine;
namespace UniVRM10.VRM10Viewer
{
/// <summary>
/// GLTF の MaterialImporter
/// </summary>
public sealed class TinyPbrDescriptorGenerator : IMaterialDescriptorGenerator
{
public UrpGltfPbrMaterialImporter PbrMaterialImporter { get; } = new();
public UrpGltfDefaultMaterialImporter DefaultMaterialImporter { get; } = new();
public Material Material { get; set; }
public TinyPbrDescriptorGenerator(Material material)
{
Material = material;
}
public MaterialDescriptor Get(GltfData data, int i)
{
// TODO: VRM
// UNLIT
MaterialDescriptor param;
// if (BuiltInGltfUnlitMaterialImporter.TryCreateParam(data, i, out param)) return param;
if (TryCreateParam(data, i, out param)) return param;
// NOTE: Fallback to default material
if (Symbols.VRM_DEVELOP)
{
Debug.LogWarning($"material: {i} out of range. fallback");
}
return GetGltfDefault(GltfMaterialImportUtils.ImportMaterialName(i, null));
}
public MaterialDescriptor GetGltfDefault(string materialName = null) => DefaultMaterialImporter.CreateParam(materialName);
public bool TryCreateParam(GltfData data, int i, out MaterialDescriptor matDesc)
{
if (i < 0 || i >= data.GLTF.materials.Count)
{
matDesc = default;
return false;
}
var src = data.GLTF.materials[i];
matDesc = new MaterialDescriptor(
GltfMaterialImportUtils.ImportMaterialName(i, src),
Material.shader,
null,
new Dictionary<string, TextureDescriptor>(),
new Dictionary<string, float>(),
new Dictionary<string, Color>(),
new Dictionary<string, Vector4>(),
new List<Action<Material>>(),
new[] { (MaterialDescriptor.MaterialGenerateAsyncFunc)AsyncAction }
);
return true;
Task AsyncAction(Material x, GetTextureAsyncFunc y, IAwaitCaller z) => GenerateMaterialAsync(data, src, x, y, z);
}
public static async Task GenerateMaterialAsync(GltfData data, glTFMaterial src, Material dst, GetTextureAsyncFunc getTextureAsync, IAwaitCaller awaitCaller)
{
var context = new TinyPbrContext(dst);
if (src is { pbrMetallicRoughness: { baseColorTexture: { index: >= 0 } } })
{
if (GltfPbrTextureImporter.TryBaseColorTexture(data, src, out _, out var desc))
{
context.BaseTexture = await getTextureAsync(desc, awaitCaller);
context.BaseTextureOffset = desc.Offset;
context.BaseTextureScale = desc.Scale;
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e069c0db5336bc34f84bde3260c51d84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,14 @@ namespace UniVRM10.VRM10Viewer
[SerializeField]
Transform m_faceCamera = default;
[Header("Material")]
[SerializeField]
Material m_customMaterial = default;
[Header("UI")]
[SerializeField]
Toggle m_useCustomMaterial = default;
[SerializeField]
Button m_openModel = default;
@ -365,6 +372,7 @@ namespace UniVRM10.VRM10Viewer
{
var map = new ObjectMap(gameObject);
Root = map.Objects["Root"];
m_useCustomMaterial = map.Get<Toggle>("CustomMaterial");
m_openModel = map.Get<Button>("OpenModel");
m_openMotion = map.Get<Button>("OpenMotion");
m_pastePose = map.Get<Button>("PastePose");
@ -489,6 +497,10 @@ namespace UniVRM10.VRM10Viewer
if (m_motion != null)
{
Motion = BvhMotion.LoadBvhFromText(m_motion.text);
if (m_useCustomMaterial.isOn)
{
Motion.SetBoxManMaterial(Instantiate(m_customMaterial));
}
}
if (ArgumentChecker.TryGetFirstLoadable(out var cmd))
@ -780,21 +792,21 @@ namespace UniVRM10.VRM10Viewer
}
}
static IMaterialDescriptorGenerator GetMaterialDescriptorGenerator(bool useUrp)
IMaterialDescriptorGenerator GetMaterialDescriptorGenerator()
{
if (useUrp)
if (m_useCustomMaterial.isOn)
{
return new UrpGltfMaterialDescriptorGenerator();
return new TinyPbrDescriptorGenerator(m_customMaterial);
}
else
{
return new BuiltInGltfMaterialDescriptorGenerator();
return default;
}
}
IAwaitCaller GetIAwaitCaller()
{
if (m_useAsync)
if (m_useAsync.isOn)
{
#if UNITY_WEBGL
return new RuntimeOnlyNoThreadAwaitCaller();
@ -830,6 +842,7 @@ namespace UniVRM10.VRM10Viewer
canLoadVrm0X: true,
showMeshes: false,
awaitCaller: GetIAwaitCaller(),
materialGenerator: GetMaterialDescriptorGenerator(),
vrmMetaInformationCallback: m_texts.UpdateMeta,
ct: cancellationToken,
springboneRuntime: m_useSpringboneSingelton.isOn ? new Vrm10FastSpringboneRuntime() : new Vrm10FastSpringboneRuntimeStandalone());

View File

@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Rendering;
namespace UniVRM10.VRM10Viewer
{
@ -9,6 +10,11 @@ namespace UniVRM10.VRM10Viewer
{
[SerializeField] private PrimitiveType _primitiveType;
/// 'Always Inlucded Shaders` に `Universal Render Pipeline/Lit` を指定することが現実的でないため指定する。
/// 簡易なシェーダーで十分です。
/// ビルドするときに必要です。Editorでは無くても表示できるかもしれません。
[SerializeField] private Material _urpMaterialForGrayscale;
public PrimitiveType PrimitiveType
{
get => _primitiveType;
@ -22,6 +28,17 @@ namespace UniVRM10.VRM10Viewer
visual.transform.localPosition = Vector3.zero;
visual.transform.localRotation = Quaternion.identity;
visual.transform.localScale = Vector3.one;
// URP 判定
if (GraphicsSettings.renderPipelineAsset != null
// WebGL ビルドでは GraphicsSettings.renderPipelineAsset が常に null ?
|| Application.platform == RuntimePlatform.WebGLPlayer)
{
if (_urpMaterialForGrayscale != null)
{
visual.GetComponent<Renderer>().material = Instantiate(_urpMaterialForGrayscale);
}
}
}
void OnDrawGizmos()