soupday / cc_unity_tools_HDRP

Package for importing and auto setup of Character Creator (3 & 4) and iClone (7 & 8) character exports for Unity HDRP Pipeline.
GNU General Public License v3.0
131 stars 37 forks source link

Dark skin color sometimes appear white #32

Closed kandohar closed 2 years ago

kandohar commented 2 years ago

Hi, I'm using this package to import Avatars in Unity HDRP and I experienced some problems with dark skinned avatars. They sometimes appears white, Cf picture below, 1,2, and 5 are bad whereas 3 and 4 look good. darkSkin

And I experience a weird visual artefact with the hair of 5, they look like this: weirdHair The GameObjects are named "Undercut_fade", "Undercut_fade 1" and "Undercut_fade0" and all the materials use the "HDRP/Lit" shader.

Otherwise the result is very convincing, nice job! Don't hesitate if you need more information.

soupday commented 2 years ago

Are they using the new skin colouring options in CC4? You'll need to bake the skin colouring when exporting from CC4 (It think it's the very last option in the export window). Until I can figure out what those colour controls actually do and update the Unity shaders.

soupday commented 2 years ago

The hair: Is it using the digital human hair shader in CC? Looks like it's not detecting that it should be transparent. You can try switching the materials in Unity to transparent,

But basic alpha blending really doesn't work very well in Unity, so your best option might be to set the shader type to digital human hair in CC, then it will use the Unity hair shader and should look a lot better though it may need some tweaking.

kandohar commented 2 years ago

For the skin color, no we use CC3 but I'm not the one who created and exported the avatars. But yes, the texture is white in Unity so I guess the Bake option was not used. I will check that.

soupday commented 2 years ago

Ok, this was my fault. There was a diffuse colour modifier missing from the skin shaders. I've updated the packages, it should fix your problem.

kandohar commented 2 years ago

Ok thanks! I re-imported them all and they now look like that: darkSkin_solved That's definitely better but they appear a bit darker than the reference. The color in the json is perhaps not that perfect.

kandohar commented 2 years ago

About the man's hair, when re-importing him, I got these 2 errors: Unable to find json material data: Undercut_fade 1/Materials/Scalp_Pbr UnityEngine.Debug:LogError (object) Reallusion.Import.Importer:ProcessObjectBuildPass (UnityEngine.GameObject) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:305) Reallusion.Import.Importer:ProcessObjectTreeBuildPass (UnityEngine.GameObject) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:273) Reallusion.Import.Importer:Import () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:227) Reallusion.Import.ImporterWindow:ImportCharacter (Reallusion.Import.CharacterInfo) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:850) Reallusion.Import.ImporterWindow:BuildCharacter () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:987) Reallusion.Import.ImporterWindow:OnGUI () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:346) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) and Unable to find json material data: Undercut_fade 1/Materials/Hair_Pbr UnityEngine.Debug:LogError (object) Reallusion.Import.Importer:ProcessObjectBuildPass (UnityEngine.GameObject) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:305) Reallusion.Import.Importer:ProcessObjectTreeBuildPass (UnityEngine.GameObject) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:273) Reallusion.Import.Importer:Import () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/Importer.cs:227) Reallusion.Import.ImporterWindow:ImportCharacter (Reallusion.Import.CharacterInfo) (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:850) Reallusion.Import.ImporterWindow:BuildCharacter () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:987) Reallusion.Import.ImporterWindow:OnGUI () (at Library/PackageCache/com.soupday.cc3_unity_tools@1219467552/Editor/ImporterWindow.cs:346) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

I can't check right now about the settings in CC, but I will do ASAP.

soupday commented 2 years ago

Diffuse colour modifier probably needs a colour space correction. (Some of the parameters are in linear space, some in RGB, but it's hit and miss which is which...)

Can you attach the .json data file for the character that causes those errors. I've never seen a case where it can't find specific materials (it's usually all or nothing). I suspect it's something to do with the space in the name, (they're usually all replaced with underscores).

kandohar commented 2 years ago

Ok thanks, I see.

Here is the file (renamed to .txt because .json are not allowed): Adult_Male21.txt

soupday commented 2 years ago

This might be a long shot, but try this json data. I think you've found a bug in character creator. It's truncating the object name at the space and putting the material definition in the wrong section. This is a corrected Json.

Adult_Male21.txt

kandohar commented 2 years ago

Yes, totally fixed, no error, no weird hair.

kandohar commented 2 years ago

Should I report a bug somewhere?

kandohar commented 2 years ago

oh, and one last thing, on some avatars, there are some visual artefacts on hairs, like flat surfaces. Here are 2 examples: hair

Do you know where these came from? and if it's fixable?

soupday commented 2 years ago

That's Unity making a mess of the recalculated normals.

I added a function to smooth out the normals just for this: select the mesh object and use menu - Reallusion > Mesh Tools > Auto smooth Normals. It usually does a better job of it.

It applies the smoothed mesh to the prefab. It might be best to do this in the preview scene.

soupday commented 2 years ago

I'll try and figure out what's causing the bug at the character creator side of things and report it to devs directly.

kandohar commented 2 years ago

Works like a charm! (only did it on the bun) image

Thank you for your time!

kandohar commented 2 years ago

Hi again, I tried to fix the skin color problem and you were right, it's a Color Space problem for the Diffuse Color. I added some code just before here : https://github.com/soupday/cc3_unity_tools_HDRP/commit/121946755298ba378eb2a490e0c360abb31815b4#diff-c89a8555fe4a5b6481ae8332f3774e0542d8132f964dc7969c4e8e901fd11993R1008

Color diffuseColor = matJson.GetColorValue("Diffuse Color");
Color convertedDiffuse = new Color();
convertedDiffuse.r = Mathf.LinearToGammaSpace(diffuseColor.r);
convertedDiffuse.g = Mathf.LinearToGammaSpace(diffuseColor.g);
convertedDiffuse.b = Mathf.LinearToGammaSpace(diffuseColor.b);
convertedDiffuse.a = diffuseColor.a;
mat.SetColorIf("_DiffuseColor", convertedDiffuse);

And the result is very good: colorSpaceCorrection

I'm not sure if this correction is always mandatory but can you maybe add an option to allow it?

kandohar commented 2 years ago

@soupday any feedback about my request?

soupday commented 2 years ago

Changes live now. The colour space correction is pretty much mandatory, no need to make it optional. It was the same for the eyes and the hair colour parameters.

Speaking of the hair I've added a colour modifier for the hair too, and even remembered to put it in the right colour space.

kandohar commented 2 years ago

And that's perfect! The hair look more accurate now thanks! Thanks again for your works!