Skip to content

Commit

Permalink
Merge pull request #32 from soupday/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
soupday authored Dec 2, 2022
2 parents d533be6 + 37948f6 commit 9b78661
Show file tree
Hide file tree
Showing 16 changed files with 1,259 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Material:
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.25
- _Cutoff: 0.667
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 0.897
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 0.5
- _AlphaClip: 0.667
- _BumpScale: 1
- _Cutoff: 0.25
- _DetailNormalMapScale: 1
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

### v 1.4.1
- Traditional material glossiness fix.
- High poly (sub-division) hair mesh extraction fix.
- SSS Diffusion profile added.
- Remembers last used lighting preset on character preview change.
- Character icon list side bar can be dragged into a more compact list view.
- Character list sorted alphabetically.
- When HDRP Ray tracing is enabled:
- The material build function will turn off ray tracing on the Scalp (when separeated), Eye Occlusion and Tearline meshes as it causes darkening artifacts on the underlying skin and eye surfaces.
- (Typically the scalp is only separated from the hair materials when two-pass hair is enabled)
- Bake Hair function now only bakes the result of the 'Enable Color' properties into the diffuse maps of the hair materials. Press again to revert to original diffuse maps.
- Improved ActorCore and ActorBuild single material detection.

### v 1.4.0
- Import & Setup
- ActorBuild detection separated from ActorCore (ActorBuild can have more advanced materials)
Expand Down
167 changes: 164 additions & 3 deletions Editor/CharacterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;

namespace Reallusion.Import
{
Expand Down Expand Up @@ -51,7 +52,88 @@ public enum RigOverride { None = 0, Generic, Humanoid }
public RigOverride UnknownRigType { get; set; }
private bool bakeCustomShaders = true;
private bool bakeSeparatePrefab = true;
private bool useTessellation = false;
private bool useTessellation = false;
private GameObject prefabAsset;

public struct GUIDRemap
{
public string from;
public string to;

public GUIDRemap(string from, string to)
{
this.from = from;
this.to = to;
}

public GUIDRemap(Object from, Object to)
{
this.from = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(from));
this.to = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(to));
}
}

private List<GUIDRemap> guidRemaps;

public void AddGUIDRemap(Object from, Object to)
{
guidRemaps.Add(new GUIDRemap(from, to));
}

public Object GetGUIDRemapFrom(Object to)
{
string guidTo = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(to));

foreach (GUIDRemap gr in guidRemaps)
{
if (gr.to == guidTo)
{
string path = AssetDatabase.GUIDToAssetPath(gr.from);
if (!string.IsNullOrEmpty(path)) return AssetDatabase.LoadAssetAtPath<Object>(path);
else return null;
}
}

return null;
}

public Object GetGUIDRemapTo(Object from)
{
string guidFrom = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(from));

foreach (GUIDRemap gr in guidRemaps)
{
if (gr.from == guidFrom)
{
string path = AssetDatabase.GUIDToAssetPath(gr.to);
if (!string.IsNullOrEmpty(path)) return AssetDatabase.LoadAssetAtPath<Object>(path);
else return null;
}
}

return null;
}

public void RemoveGUIDRemap(Object from, Object to)
{
string guidTo = "";
string guidFrom = "";
if (to) guidTo = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(to));
if (from) guidFrom = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(from));
for (int i = 0; i < guidRemaps.Count; i++)
{
GUIDRemap gr = guidRemaps[i];
if (gr.from == guidFrom || gr.to == guidTo)
{
guidRemaps.RemoveAt(i--);
}
}
}

public void CleanGUIDRemaps()
{
RemoveGUIDRemap(null, null);
}

public ProcessingType BuildType { get { return logType; } set { logType = value; } }
public MaterialQuality BuildQuality
Expand Down Expand Up @@ -137,6 +219,7 @@ public CharacterInfo(string guid)
infoFilepath = Path.Combine(folder, name + "_ImportInfo.txt");
jsonFilepath = Path.Combine(folder, name + ".json");
if (path.iContains("_lod")) isLOD = true;
guidRemaps = new List<GUIDRemap>();

if (File.Exists(infoFilepath))
Read();
Expand All @@ -147,6 +230,7 @@ public CharacterInfo(string guid)
public void ApplySettings()
{
FixCharSettings();
CleanGUIDRemaps();

builtLogType = logType;
builtQualEyes = qualEyes;
Expand Down Expand Up @@ -184,7 +268,8 @@ public GameObject PrefabAsset
{
get
{
return Util.FindCharacterPrefabAsset(Fbx);
if (!prefabAsset) prefabAsset = Util.FindCharacterPrefabAsset(Fbx);
return prefabAsset;
}
}

Expand Down Expand Up @@ -251,6 +336,51 @@ public QuickJSON CharacterJsonData
}
}

public QuickJSON MeshJsonData
{
get
{
string jsonPath = name + "/Object/" + name + "/Meshes";
if (JsonData.PathExists(jsonPath))
return JsonData.GetObjectAtPath(jsonPath);
return null;
}
}

public QuickJSON GetMatJson(GameObject obj, string sourceName)
{
QuickJSON jsonMeshData = MeshJsonData;
QuickJSON matJson = null;
string objName = obj.name;
string jsonPath = "";
if (jsonMeshData != null)
{
jsonPath = objName + "/Materials/" + sourceName;
if (jsonMeshData.PathExists(jsonPath))
{
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
}
else
{
// 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;
if (jsonMeshData.PathExists(jsonPath))
{
matJson = jsonMeshData.GetObjectAtPath(jsonPath);
}
}
}
}
if (matJson == null) Util.LogError("Unable to find json material data: " + jsonPath);

return matJson;
}

public QuickJSON PhysicsJsonData
{
get
Expand Down Expand Up @@ -293,6 +423,25 @@ public BaseGeneration Generation
}
}

public bool HasColorEnabledHair()
{
if (PrefabAsset)
{
Renderer[] renderers = PrefabAsset.GetComponentsInChildren<Renderer>();
foreach (Renderer r in renderers)
{
foreach (Material m in r.sharedMaterials)
{
if (m.HasProperty("BOOLEAN_ENABLECOLOR"))
{
if (m.GetFloat("BOOLEAN_ENABLECOLOR") > 0f) return true;
}
}
}
}
return false;
}

public void CheckGeneration()
{
BaseGeneration oldGen = generation;
Expand Down Expand Up @@ -345,9 +494,10 @@ public bool CanHaveHighQualityMaterials
public void Read()
{
TextAsset infoAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(infoFilepath);

guidRemaps.Clear();
string[] lineEndings = new string[] { "\r\n", "\r", "\n" };
char[] propertySplit = new char[] { '=' };
char[] guidSplit = new char[] { '|' };
string[] lines = infoAsset.text.Split(lineEndings, System.StringSplitOptions.None);
string property = "";
string value = "";
Expand Down Expand Up @@ -412,6 +562,13 @@ public void Read()
case "rigOverride":
UnknownRigType = (RigOverride)System.Enum.Parse(typeof(RigOverride), value);
break;
case "GUIDRemap":
string[] guids = value.Split(guidSplit, System.StringSplitOptions.None);
if (guids.Length == 2)
{
guidRemaps.Add(new GUIDRemap(guids[0], guids[1]));
}
break;
}
}
ApplySettings();
Expand All @@ -434,6 +591,10 @@ public void Write()
writer.WriteLine("animationSetup=" + (animationSetup ? "true" : "false"));
writer.WriteLine("animationRetargeted=" + animationRetargeted.ToString());
writer.WriteLine("rigOverride=" + UnknownRigType.ToString());
foreach (GUIDRemap gr in guidRemaps)
{
writer.WriteLine("GUIDRemap=" + gr.from + "|" + gr.to);
}
writer.Close();
AssetDatabase.ImportAsset(infoFilepath);
}
Expand Down
24 changes: 24 additions & 0 deletions Editor/Compute/RLBakeShader.compute
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#pragma kernel RLCorneaThickness
#pragma kernel RLCorneaSubsurfaceMask
#pragma kernel RLHairColoredDiffuse
#pragma kernel RLHairColoredDiffuseOnly
#pragma kernel RLHairDiffuse
#pragma kernel RLHairMask
#pragma kernel RLHairMetallicGloss
Expand Down Expand Up @@ -1341,6 +1342,29 @@ void RLHairColoredDiffuse(uint3 id : SV_DispatchThreadID)
Result[id.xy] = color;
}

[numthreads(1, 1, 1)]
void RLHairColoredDiffuseOnly(uint3 id : SV_DispatchThreadID)
{
float2 uv = GetUV(id.xy);

float4 diffuse = SAMPLE(Diffuse, uv);
float4 rootMap = SAMPLE(Root, uv);
float4 idMap = SAMPLE(ID, uv);

float alpha = diffuse.a;

float4 color = RootEndBlend(diffuse, rootMap.g);
color = HighlightBlend(color, idMap.g, rootMap.g, highlightAColor, highlightADistribution,
highlightAStrength, highlightAOverlapEnd, highlightAOverlapInvert);
color = HighlightBlend(color, idMap.g, rootMap.g, highlightBColor, highlightBDistribution,
highlightBStrength, highlightBOverlapEnd, highlightBOverlapInvert);

color = LinearTosRGB(color);
color.a = alpha;

Result[id.xy] = color;
}

[numthreads(1, 1, 1)]
void RLHairDiffuse(uint3 id : SV_DispatchThreadID)
{
Expand Down
Loading

0 comments on commit 9b78661

Please sign in to comment.