diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b01414..cb44a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +### 1.6.2 +- URP Amplify shader fix for when there is no main light. +- Work around to intermittent CC4 specular export issue when exporting with 'Bake diffuse maps from skin color' option (which is enabled by default now). + ### 1.6.1 - Magica Cloth 2 support for hair physics. - Magica Cloth and collider navigation tools added. diff --git a/Editor/Importer.cs b/Editor/Importer.cs index 68a4c06..8da5523 100644 --- a/Editor/Importer.cs +++ b/Editor/Importer.cs @@ -1464,7 +1464,7 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson) if (matJson.PathExists("Textures/Normal/Strength")) mat.SetFloat("_NormalScale", matJson.GetFloatValue("Textures/Normal/Strength") / 100f); } - } + } private void ConnectHQSkinMaterial(GameObject obj, string sourceName, Material sharedMat, Material mat, MaterialType materialType, QuickJSON matJson) @@ -1594,14 +1594,42 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson) if (matJson != null) { + float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular"); + bool specularBakeZero = false; + + // work around CC4 Head specular export bug, when exporting with bake skin option + if (specular == 0.0f && materialType == MaterialType.Head) + { + float skinSpecular = 0.0f; + QuickJSON materialsJson = jsonData.FindParentOf(matJson); + if (materialsJson != null) + { + QuickJSON skinJson = null; + if (materialsJson.PathExists("Std_Skin_Body")) + skinJson = materialsJson.GetObjectAtPath("Std_Skin_Body"); + else if (materialsJson.PathExists("Std_Skin_Arm")) + skinJson = materialsJson.GetObjectAtPath("Std_Skin_Arm"); + else if (materialsJson.PathExists("Std_Skin_Leg")) + skinJson = materialsJson.GetObjectAtPath("Std_Skin_Leg"); + if (skinJson != null) + skinSpecular = skinJson.GetFloatValue("Custom Shader/Variable/_Specular"); + } + + if (skinSpecular != 0.0f) + { + Util.LogWarn("Specular export bug in skin material, setting head specular to: " + skinSpecular); + specular = skinSpecular; + specularBakeZero = true; + } + } + mat.SetFloatIf("_AOStrength", Mathf.Clamp01(matJson.GetFloatValue("Textures/AO/Strength") / 100f)); if (matJson.PathExists("Textures/Glow/Texture Path")) mat.SetColorIf("_EmissiveColor", Color.white * (matJson.GetFloatValue("Textures/Glow/Strength") / 100f)); if (matJson.PathExists("Textures/Normal/Strength")) mat.SetFloatIf("_NormalStrength", matJson.GetFloatValue("Textures/Normal/Strength") / 100f); mat.SetFloatIf("_MicroNormalTiling", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Tiling")); - mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength")); - float specular = matJson.GetFloatValue("Custom Shader/Variable/_Specular"); + mat.SetFloatIf("_MicroNormalStrength", matJson.GetFloatValue("Custom Shader/Variable/MicroNormal Strength")); float smoothnessMax = Util.CombineSpecularToSmoothness(specular, ValueByPipeline(1f, 0.9f, 1f)); mat.SetFloatIf("_SmoothnessMax", smoothnessMax); //float secondarySmoothness = 0.85f * smoothnessMax; @@ -1617,7 +1645,10 @@ private void PrepBlenderTextures(string sourceName, QuickJSON matJson) if (materialType == MaterialType.Head) { - mat.SetFloatIf("_ColorBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength")); + // specular bake bug bakes color blend into diffuse + float colorBlenderStrength = matJson.GetFloatValue("Custom Shader/Variable/BaseColor Blend2 Strength"); + if (specularBakeZero) colorBlenderStrength = 0.0f; + mat.SetFloatIf("_ColorBlendStrength", colorBlenderStrength); mat.SetFloatIf("_NormalBlendStrength", matJson.GetFloatValue("Custom Shader/Variable/NormalMap Blend Strength")); mat.SetFloatIf("_MouthCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Inner Mouth Ao")); mat.SetFloatIf("_NostrilCavityAO", matJson.GetFloatValue("Custom Shader/Variable/Nostril Ao")); diff --git a/Editor/Physics.cs b/Editor/Physics.cs index ae4e81d..a547232 100644 --- a/Editor/Physics.cs +++ b/Editor/Physics.cs @@ -953,87 +953,89 @@ private void AddUnityClothInstance() } - private void DoCloth(GameObject clothTarget, string meshName) - { - SkinnedMeshRenderer renderer = clothTarget.GetComponent(); - if (!renderer) return; - Mesh mesh = renderer.sharedMesh; - if (!mesh) return; - - List settingsList = new List(); - - bool hasPhysics = false; - - for (int i = 0; i < mesh.subMeshCount; i++)// - { - Material mat = renderer.sharedMaterials[i]; - - if (!mat) continue; - string sourceName = mat.name; - if (sourceName.iContains("_2nd_Pass")) continue; - if (sourceName.iContains("_1st_Pass")) - { - sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass")); - } - - foreach (SoftPhysicsData data in softPhysics) - { - if (data.materialName == sourceName && - data.meshName == meshName && - CanAddPhysics(data)) - { - WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings(); - - settings.name = sourceName; - settings.activate = data.activate; - settings.gravity = data.gravity; - settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false; - settings.softRigidCollision = data.softRigidCollision; - settings.softRigidMargin = data.softRigidMargin; - - if (data.isHair) - { - // hair meshes degenerate quickly if less than full stiffness - // (too dense, too many verts?) - settings.bending = 0f; - settings.stretch = 0f; - } - else - { - settings.bending = data.bending; - settings.stretch = data.stretch; - } - - settings.solverFrequency = data.solverFrequency; - settings.stiffnessFrequency = data.stiffnessFrequency; - settings.mass = data.mass; - settings.friction = data.friction; - settings.damping = data.damping; - settings.selfMargin = data.selfMargin; - settings.maxDistance = 20f; - settings.maxPenetration = 10f; - settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD; - - Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true); - if (!weightMap) weightMap = Texture2D.blackTexture; - settings.weightMap = weightMap; - - settingsList.Add(settings); - hasPhysics = true; - } - } - } - - if (hasPhysics) - { - WeightMapper mapper = clothTarget.GetComponent(); - if (!mapper) mapper = clothTarget.AddComponent(); - - mapper.settings = settingsList.ToArray(); - mapper.characterGUID = characterGUID; - mapper.ApplyWeightMap(); - } - } + private void DoCloth(GameObject clothTarget, string meshName) + { + SkinnedMeshRenderer renderer = clothTarget.GetComponent(); + if (!renderer) return; + Mesh mesh = renderer.sharedMesh; + if (!mesh) return; + + List settingsList = new List(); + + bool hasPhysics = false; + + for (int i = 0; i < mesh.subMeshCount; i++) + { + if (i >= renderer.sharedMaterials.Length) break; + + Material mat = renderer.sharedMaterials[i]; + + if (!mat) continue; + string sourceName = mat.name; + if (sourceName.iContains("_2nd_Pass")) continue; + if (sourceName.iContains("_1st_Pass")) + { + sourceName = sourceName.Remove(sourceName.IndexOf("_1st_Pass")); + } + + foreach (SoftPhysicsData data in softPhysics) + { + if (data.materialName == sourceName && + data.meshName == meshName && + CanAddPhysics(data)) + { + WeightMapper.PhysicsSettings settings = new WeightMapper.PhysicsSettings(); + + settings.name = sourceName; + settings.activate = data.activate; + settings.gravity = data.gravity; + settings.selfCollision = Importer.USE_SELF_COLLISION ? data.selfCollision : false; + settings.softRigidCollision = data.softRigidCollision; + settings.softRigidMargin = data.softRigidMargin; + + if (data.isHair) + { + // hair meshes degenerate quickly if less than full stiffness + // (too dense, too many verts?) + settings.bending = 0f; + settings.stretch = 0f; + } + else + { + settings.bending = data.bending; + settings.stretch = data.stretch; + } + + settings.solverFrequency = data.solverFrequency; + settings.stiffnessFrequency = data.stiffnessFrequency; + settings.mass = data.mass; + settings.friction = data.friction; + settings.damping = data.damping; + settings.selfMargin = data.selfMargin; + settings.maxDistance = 20f; + settings.maxPenetration = 10f; + settings.colliderThreshold = PHYSICS_WEIGHT_MAP_DETECT_COLLIDER_THRESHOLD; + + Texture2D weightMap = GetTextureFrom(data.weightMapPath, data.materialName, "WeightMap", out string texName, true); + if (!weightMap) weightMap = Texture2D.blackTexture; + settings.weightMap = weightMap; + + settingsList.Add(settings); + hasPhysics = true; + } + } + } + + if (hasPhysics) + { + WeightMapper mapper = clothTarget.GetComponent(); + if (!mapper) mapper = clothTarget.AddComponent(); + + mapper.settings = settingsList.ToArray(); + mapper.characterGUID = characterGUID; + mapper.ApplyWeightMap(); + } + } private void AddMagicaMeshCloth() { @@ -1111,6 +1113,8 @@ private bool CanAddMagicaCloth(GameObject clothTarget, string meshName) // adds for (int i = 0; i < mesh.subMeshCount; i++) { + if (i >= renderer.sharedMaterials.Length) break; + Material mat = renderer.sharedMaterials[i]; if (!mat) continue; diff --git a/Editor/Pipeline.cs b/Editor/Pipeline.cs index d0dd69e..f6b263a 100644 --- a/Editor/Pipeline.cs +++ b/Editor/Pipeline.cs @@ -40,7 +40,7 @@ public enum MaterialQuality { None, Default, High, Baked } public static class Pipeline { - public const string VERSION = "1.6.1"; + public const string VERSION = "1.6.2"; #if HDRP_10_5_0_OR_NEWER // version diff --git a/README.md b/README.md index aca3f17..e7daf7b 100644 --- a/README.md +++ b/README.md @@ -17,25 +17,25 @@ Links [HDRP Version](https://github.com/soupday/cc_unity_tools_HDRP) Note: There are two verions of the HDRP package -- [**CC Unity Tools HDRP10**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.1.HDRP10) for Unity 2020.3+ -- [**CC Unity Tools HDRP12**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.1.HDRP12) for Unity 2021.2+ +- [**CC Unity Tools HDRP10**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.2.HDRP10) for Unity 2020.3+ +- [**CC Unity Tools HDRP12**](https://github.com/soupday/cc_unity_tools_HDRP/releases/tag/1.6.2.HDRP12) for Unity 2021.2+ The main repository contains the HDRP10 version. See the releases page for the HDRP12 version. [URP Version](https://github.com/soupday/cc_unity_tools_URP) Note: There are four verions of the URP package -- [**CC Unity Tools URP10**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP10) for Unity 2020.3+ -- [**CC Unity Tools URP12**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP12) for Unity 2021.2+ -- [**CC Unity Tools URP14**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP14) for Unity 2022.3+ -- [**CC Unity Tools URP15**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.1.URP15) for Unity 2023.1+ +- [**CC Unity Tools URP10**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP10) for Unity 2020.3+ +- [**CC Unity Tools URP12**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP12) for Unity 2021.2+ +- [**CC Unity Tools URP14**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP14) for Unity 2022.3+ +- [**CC Unity Tools URP15**](https://github.com/soupday/cc_unity_tools_URP/releases/tag/1.6.2.URP15) for Unity 2023.1+ The main repository contains the URP10 version. See the releases page for the URP12/14/15 version. [3D/Built-in Version](https://github.com/soupday/cc_unity_tools_3D) The built-in pipeline version is for Unity 2019.4 and upwards. -- [**CC Unity Tools 3D**](https://github.com/soupday/cc_unity_tools_3D/releases/tag/1.6.1) for Unity 2019.4+ +- [**CC Unity Tools 3D**](https://github.com/soupday/cc_unity_tools_3D/releases/tag/1.6.2) for Unity 2019.4+ How it works ============ diff --git a/package.json b/package.json index aa7a373..5958b01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.soupday.cc3_unity_tools", - "version": "1.6.1", + "version": "1.6.2", "displayName": "CC/iC Unity Tools HDRP", "description": "Unity importer for Character Creator 3 & 4 and iClone 7 and 8.", "unity": "2020.3",