Skip to content

Commit

Permalink
1.4.3
Browse files Browse the repository at this point in the history
instalod duplication suffix fix.
instalod missing json discovery fix.
Cast shadows removed from eye occlusion, tearlines and scalps.
Raytrace disable for eye occlusion tearline and scalps moved to apply to prefab instances.
Pipeline specific shader packages included in package.
Code and meta guid prep for Single unified pipeline package.
  • Loading branch information
soupday committed Dec 20, 2022
1 parent 03923b7 commit b3741ed
Show file tree
Hide file tree
Showing 46 changed files with 521 additions and 85 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

### v 1.4.3
- Tries to untangle instalod duplication suffixes on accessories.
- inc. Script error fix that was blocking build materials when instalod meshes were not found in Json data.
- Cast shadows removed from Tearline, Eye occlusion and scalp meshes.
- Stand alone shader packages for the various pipelines included in /Packages/ folder.

### v 1.4.2
- OSX and Linux file path support.
- Tweaked character model importer settings for better normal import and blend shape normal generation. Should reduce mesh smoothing issues.
Expand Down
41 changes: 34 additions & 7 deletions Editor/CharacterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,52 @@ public QuickJSON GetMatJson(GameObject obj, string sourceName)
if (jsonMeshData != null)
{
jsonPath = objName + "/Materials/" + sourceName;
if (jsonMeshData.PathExists(jsonPath))
matJson = jsonMeshData.GetObjectAtPath(jsonPath);

if (matJson == null)
{
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
if (objName.iContains("_Extracted"))
{
objName = objName.Substring(0, objName.IndexOf("_Extracted", System.StringComparison.InvariantCultureIgnoreCase));

jsonPath = objName + "/Materials/" + sourceName;
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
}
}
else

if (matJson == null)
{
// there is a bug where a space in name causes the name to be truncated on export from CC3/4
if (objName.Contains(" "))
{
Util.LogWarn("Object name " + objName + " contains a space, this can cause the materials to setup incorrectly.");
string[] split = objName.Split(' ');
objName = split[0];
jsonPath = objName + "/Materials/" + sourceName;
Util.LogWarn("Object name " + objName + " contains a space, this can cause the materials to setup incorrectly...");
string[] split = objName.Split(' ');
jsonPath = split[0] + "/Materials/" + sourceName;
if (jsonMeshData.PathExists(jsonPath))
{
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
}
}
}

if (matJson == null)
{
// instalod will generate unique suffixes _0/_1/_2 on character objects where object names and container
// transforms have the same name, try to untangle the object name by speculatively removing this suffix.
// (seems to happen mostly on accessories)
if (objName[objName.Length - 2] == '_' && char.IsDigit(objName[objName.Length - 1]))
{
Util.LogWarn("Object name " + objName + " may by suffixed by InstaLod exporter. Attempting to untangle...");

string specName = objName.Substring(0, objName.Length - 2);
jsonPath = specName + "/Materials/" + sourceName;
if (jsonMeshData.PathExists(jsonPath))
{
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
}
}
}

}
if (matJson == null) Util.LogError("Unable to find json material data: " + jsonPath);

Expand Down
55 changes: 47 additions & 8 deletions Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public GameObject Import()
ProcessObjectTreeBakePass(fbx);

// create / apply materials and shaders with supplied or baked texures.
ProcessObjectTreeBuildPass(fbx);
ProcessObjectTreeBuildPass(fbx);

characterInfo.tempHairBake = false;

Expand Down Expand Up @@ -290,8 +290,8 @@ public GameObject Import()
AssetDatabase.Refresh();

// create prefab.
GameObject prefabAsset = RL.CreatePrefabFromFbx(characterInfo, fbx, out GameObject prefabInstance);
GameObject prefabAsset = RL.CreatePrefabFromFbx(characterInfo, fbx, out GameObject prefabInstance);

// setup 2 pass hair in the prefab.
if (characterInfo.DualMaterialHair)
{
Expand All @@ -313,6 +313,9 @@ public GameObject Import()
MeshUtil.FixSkinnedMeshBounds(prefabInstance);
}

// apply post setup to prefab instance
ProcessObjectTreePostPass(prefabInstance);

// save final prefab instance and remove from scene
RL.SaveAndRemovePrefabInstance(prefabAsset, prefabInstance);

Expand Down Expand Up @@ -373,8 +376,6 @@ private void ProcessObjectBuildPass(Renderer renderer)

Util.LogInfo(" Material name: " + sourceName + ", type:" + materialType.ToString());

FixRayTracing(obj, sharedMat, materialType);

// re-use or create the material.
Material mat = CreateRemapMaterial(materialType, sharedMat, sourceName);

Expand Down Expand Up @@ -499,7 +500,43 @@ private void ProcessObjectBakePass(Renderer renderer)
}
}
}
}
}

void ProcessObjectTreePostPass(GameObject obj)
{
Renderer[] renderers = obj.GetComponentsInChildren<Renderer>();

foreach (Renderer renderer in renderers)
{
ProcessObjectPostPass(renderer);
}
}

private void ProcessObjectPostPass(Renderer renderer)
{
GameObject obj = renderer.gameObject;

if (renderer)
{
Util.LogInfo("Post Processing sub-object: " + obj.name);

foreach (Material sharedMat in renderer.sharedMaterials)
{
// in case any of the materials have been renamed after a previous import, get the source name.
string sourceName = Util.GetSourceMaterialName(fbxPath, sharedMat);

// fetch the json parent for this material.
// the json data for the material contains custom shader names, parameters and texture paths.
QuickJSON matJson = characterInfo.GetMatJson(obj, sourceName);

// determine the material type, this dictates the shader and template material.
MaterialType materialType = GetMaterialType(obj, sharedMat, sourceName, matJson);

// Fix ray tracing and shadow casting
FixRayTracing(obj, sharedMat, materialType);
}
}
}

private MaterialType GetMaterialType(GameObject obj, Material mat, string sourceName, QuickJSON matJson)
{
Expand Down Expand Up @@ -679,12 +716,14 @@ private void FixRayTracing(GameObject obj, Material mat, MaterialType materialTy
materialType == MaterialType.Tearline)
{
Pipeline.DisableRayTracing(smr);
smr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
else if (materialType == MaterialType.Scalp)
{
if (smr.sharedMaterials.Length == 1)
{
Pipeline.DisableRayTracing(smr);
smr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
}
}
}
Expand Down Expand Up @@ -866,7 +905,7 @@ private void ConnectDefaultMaterial(GameObject obj, string sourceName, Material
string customShader = matJson?.GetStringValue("Custom Shader/Shader Name");
string jsonMaterialType = matJson?.GetStringValue("Material Type");

if (jsonMaterialType.iEquals("Tra"))
if (jsonMaterialType == "Tra")
{
if (RP == RenderPipeline.HDRP)
{
Expand Down Expand Up @@ -1159,7 +1198,7 @@ private void ConnectDefaultMaterial(GameObject obj, string sourceName, Material
mat.SetFloatIf("_GlossMapScale", smoothness - microRoughnessMod);
}
}
else if (jsonMaterialType.iEquals("Tra"))
else if (jsonMaterialType == "Tra")
{
float glossiness = 0.5f;
float specular = 1f;
Expand Down
4 changes: 3 additions & 1 deletion Editor/ImporterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,13 +1662,15 @@ public Styles()
fakeButtonContext.padding = new RectOffset(1, 1, 1, 1);
fakeButtonContext.stretchHeight = true;
fakeButtonContext.stretchWidth = true;

FixMeh();
}

public void FixMeh()
{
if (!dragTex)
{
dragTex = TextureColor(Color.white * 0.1f);
dragTex = TextureColor(new Color(0f,0f,0f,0.25f));
dragBarStyle.normal.background = dragTex;
}
if (!contextTex)
Expand Down
13 changes: 8 additions & 5 deletions Editor/MeshUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,20 +1130,23 @@ public static GameObject Extract2PassHairMeshes(CharacterInfo info, GameObject p

if (oldMat.shader.name.iContains(Pipeline.SHADER_HQ_HAIR))
{
float alphaClipValue = 0.666f;
if (Pipeline.is3D) alphaClipValue = 0.55f;

// set alpha clip and remap to values that work better
// with the two material system.
if (isFacialObject)
{
oldMat.SetFloatIf("_AlphaClip", 0.666f);
oldMat.SetFloatIf("_AlphaClip2", 0.666f);
{
oldMat.SetFloatIf("_AlphaClip", alphaClipValue);
oldMat.SetFloatIf("_AlphaClip2", alphaClipValue);
oldMat.SetFloatIf("_AlphaPower", 1.5f);
oldMat.SetFloatIf("_ShadowClip", 0.5f);
oldMat.SetFloatIf("_AlphaRemap", 1.0f);
}
else
{
oldMat.SetFloatIf("_AlphaClip", 0.666f);
oldMat.SetFloatIf("_AlphaClip2", 0.666f);
oldMat.SetFloatIf("_AlphaClip", alphaClipValue);
oldMat.SetFloatIf("_AlphaClip2", alphaClipValue);
oldMat.SetFloatIf("_AlphaPower", 0.7f);
oldMat.SetFloatIf("_ShadowClip", 0.5f);
oldMat.SetFloatIf("_AlphaRemap", 1.0f);
Expand Down
5 changes: 3 additions & 2 deletions Editor/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using UnityEngine;
using UnityEngine.Diagnostics;
using UnityEngine.Rendering;
using System.IO;
#if HDRP_10_5_0_OR_NEWER
using UnityEngine.Rendering.HighDefinition;
using UnityEditor.Rendering.HighDefinition;
Expand All @@ -34,13 +35,13 @@ public enum MaterialType
{
None, Skin, Head, Eye, Cornea, EyeOcclusion, Tearline, Hair, Scalp,
Eyelash, Teeth, Tongue, DefaultOpaque, DefaultAlpha, SSS
}
}

public enum MaterialQuality { None, Default, High, Baked }

public static class Pipeline
{
public const string VERSION = "1.4.2";
public const string VERSION = "1.4.3";

#if HDRP_10_5_0_OR_NEWER
// version
Expand Down
Loading

0 comments on commit b3741ed

Please sign in to comment.