Skip to content

Commit

Permalink
Merge pull request #95 from soupday/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
soupday authored Jul 29, 2024
2 parents f8f4d86 + beac073 commit 604abff
Show file tree
Hide file tree
Showing 17 changed files with 416 additions and 135 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
Changelog
=========

### 1.6.3
- Wrinkle manager update Blend shape indices button.
- Wrinkle system setup will look for wrinkle masks in Assets as well as packages. (If tools installed into assets and not with package manager)
- Wrinkle system added to URP shader graph shaders.
- Anisotropic highlights added to URP shader graph hair shaders.
- Mesh extraction checks for duplicate blend shape names.
- URP Amplify hair shaders support for Forward+ additional lights.
- URP Amplify shaders recompiled for ASE-1.9.6 (Fixes URP17 issues).
- Fix to colliders not being added with just hair physics.
- Fix to HDRP diffusion profiles not being added in HDRP17.

### 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).
- Fix to physics assignment when shared materials count does not match submesh count.

### 1.6.1
- Magica Cloth 2 support for hair physics.
Expand Down
27 changes: 19 additions & 8 deletions Editor/Compute/RLBakeShader.compute
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#pragma kernel RLChannelPackLinear
#pragma kernel RLChannelPackSymmetryLinear

#pragma multi_compile _ _MAC_OS

// Defines
//
#define SAMPLE(tex,coord) tex.SampleLevel (sampler##tex,coord, 0)
Expand Down Expand Up @@ -351,6 +353,8 @@ float4 LinearTosRGB(float4 In)
{
#ifdef UNITY_COLORSPACE_GAMMA
return In;
#elif _MAC_OS
return In;
#else
float3 sRGBLo = In.xyz * 12.92;
float3 sRGBHi = (pow(max(abs(In.xyz), 1.192092896e-07), float3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4)) * 1.055) - 0.055;
Expand Down Expand Up @@ -804,7 +808,8 @@ void RLHeadMask(uint3 id : SV_DispatchThreadID)

float metallic = mask.r;
float ao = INVERTED_SCALE(mask.g, aoStrength) * cavityAO;
float detailMask = mask.b * subsurfaceFlattenNormals;
//float detailMask = mask.b * subsurfaceFlattenNormals;
float detailMask = mask.b;
float smoothness = lerp(smoothnessMin, smoothnessMax, pow(mask.a, smoothnessPower));
smoothness = saturate((1.0 + smoothnessMod + microSmoothnessMod) * smoothness);
float4 packed = float4(metallic, ao, detailMask, smoothness);
Expand Down Expand Up @@ -864,7 +869,8 @@ void RLSkinMask(uint3 id : SV_DispatchThreadID)

float metallic = mask.r;
float ao = INVERTED_SCALE(mask.g, aoStrength);
float detailMask = mask.b * subsurfaceFlattenNormals;
//float detailMask = mask.b * subsurfaceFlattenNormals;
float detailMask = mask.b;
float smoothness = lerp(smoothnessMin, smoothnessMax, pow(mask.a, smoothnessPower));
smoothness = saturate((1.0 + smoothnessMod + microSmoothnessMod) * smoothness);
float4 packed = float4(metallic, ao, detailMask, smoothness);
Expand All @@ -887,7 +893,8 @@ void RLHeadMetallicGloss(uint3 id : SV_DispatchThreadID)

float metallic = mask.r;
float ao = INVERTED_SCALE(mask.g, aoStrength) * cavityAO;
float detailMask = mask.b * subsurfaceFlattenNormals;
//float detailMask = mask.b * subsurfaceFlattenNormals;
float detailMask = mask.b;
float smoothness = lerp(smoothnessMin, smoothnessMax, pow(mask.a, smoothnessPower));
smoothness = saturate((1.0 + smoothnessMod + microSmoothnessMod) * smoothness);
float4 packed = float4(metallic, metallic, metallic, smoothness);
Expand All @@ -909,7 +916,8 @@ void RLSkinMetallicGloss(uint3 id : SV_DispatchThreadID)

float metallic = mask.r;
float ao = INVERTED_SCALE(mask.g, aoStrength);
float detailMask = mask.b * subsurfaceFlattenNormals;
//float detailMask = mask.b * subsurfaceFlattenNormals;
float detailMask = mask.b;
float smoothness = lerp(smoothnessMin, smoothnessMax, pow(mask.a, smoothnessPower));
smoothness = saturate((1.0 + smoothnessMod + microSmoothnessMod) * smoothness);
float4 packed = float4(metallic, metallic, metallic, smoothness);
Expand Down Expand Up @@ -989,11 +997,13 @@ void RLHeadNormal(uint3 id : SV_DispatchThreadID)
float3 normalBlend = SAMPLE_NORMAL(NormalBlend, uv);
float microScatteringMultiplier = HeadScatterMask(uv) * subsurfaceScale;
float subsurface = SAMPLE(Subsurface, uv).y * microScatteringMultiplier;
float subsurfaceFlattenNormals = saturate(1.0 - (subsurface * subsurface * sssNormalSoften));
float subsurfaceFlattenNormals = saturate(1.0 - (subsurface * subsurface * sssNormalSoften));

float3 mn, bn, on;
NormalStrength_float3(normal, normalStrength * subsurfaceFlattenNormals, mn);
NormalStrength_float3(normalBlend, normalBlendStrength * subsurfaceFlattenNormals, bn);
//NormalStrength_float3(normal, normalStrength * subsurfaceFlattenNormals, mn);
//NormalStrength_float3(normalBlend, normalBlendStrength * subsurfaceFlattenNormals, bn);
NormalStrength_float3(normal, normalStrength, mn);
NormalStrength_float3(normalBlend, normalBlendStrength, bn);
NormalBlend_float3(mn, bn, on);

Result[id.xy] = PackNormal(on);
Expand All @@ -1011,7 +1021,8 @@ void RLSkinNormal(uint3 id : SV_DispatchThreadID)
float subsurfaceFlattenNormals = saturate(1.0 - (subsurface * subsurface * sssNormalSoften));

float3 ns;
NormalStrength_float3(normal, normalStrength * subsurfaceFlattenNormals, ns);
//NormalStrength_float3(normal, normalStrength * subsurfaceFlattenNormals, ns);
NormalStrength_float3(normal, normalStrength, ns);

Result[id.xy] = PackNormal(ns);
}
Expand Down
20 changes: 13 additions & 7 deletions Editor/ComputeBake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,11 @@ private Material BakeHairMaterial(Material mat, string sourceName,
firstPass = null;
secondPass = null;

bool useAmplify = characterInfo.BakeCustomShaders && mat.shader.name.iContains("/Amplify/");
bool useAmplify = characterInfo.BakeCustomShaders && mat.shader.name.iContains("/Amplify/");
bool useTessellation = characterInfo.BuiltFeatureTessellation;
bool useWrinkleMaps = characterInfo.BuiltFeatureWrinkleMaps;
bool useDigitalHuman = characterInfo.BakeCustomShaders && mat.shader.name.iEndsWith("_DH");
float diffuseAO = (useAmplify || (IS_URP && CUSTOM_SHADERS)) ? 0f : aoOccludeAll;

Texture2D bakedBaseMap = diffuse;
Texture2D bakedMaskMap = mask;
Expand All @@ -1577,7 +1578,7 @@ private Material BakeHairMaterial(Material mat, string sourceName,
if (enableColor)
{
bakedBaseMap = BakeHairDiffuseMap(diffuse, blend, id, root, mask,
diffuseStrength, alphaPower, alphaRemap, aoStrength, (useAmplify ? 0f : aoOccludeAll),
diffuseStrength, alphaPower, alphaRemap, aoStrength, diffuseAO,
rootColor, rootColorStrength, endColor, endColorStrength, globalStrength,
invertRootMap, baseColorStrength, highlightBlend,
highlightAColor, highlightADistribution, highlightAOverlapEnd,
Expand All @@ -1590,7 +1591,7 @@ private Material BakeHairMaterial(Material mat, string sourceName,
else
{
bakedBaseMap = BakeHairDiffuseMap(diffuse, blend, mask,
diffuseStrength, alphaPower, alphaRemap, aoStrength, (useAmplify ? 0f : aoOccludeAll),
diffuseStrength, alphaPower, alphaRemap, aoStrength, diffuseAO,
blendStrength, vertexBaseColor, vertexColorStrength,
sourceName + "_BaseMap");
}
Expand Down Expand Up @@ -1620,6 +1621,7 @@ private Material BakeHairMaterial(Material mat, string sourceName,
Action<Material> SetCustom = (bakeMat) =>
{
bakeMat.SetFloatIf("_AOOccludeAll", aoOccludeAll);
Debug.Log("AO Occlude All = " + aoOccludeAll);
bakeMat.SetTextureIf("_FlowMap", flow);
bakeMat.SetFloatIf("_FlowMapFlipGreen", flowMapFlipGreen);
bakeMat.SetFloatIf("_Translucency", translucency);
Expand Down Expand Up @@ -1913,7 +1915,8 @@ public Texture2D BakeChannelPackLinear(string folder,
alphaChannel = CheckBlank(alphaChannel);

int kernel = bakeShader.FindKernel("RLChannelPackLinear");
bakeTarget.Create(bakeShader, kernel);
bakeTarget.Create(bakeShader, kernel);

bakeShader.SetTexture(kernel, "RedChannel", redChannel);
bakeShader.SetTexture(kernel, "GreenChannel", greenChannel);
bakeShader.SetTexture(kernel, "BlueChannel", blueChannel);
Expand Down Expand Up @@ -1949,7 +1952,8 @@ public Texture2D BakeChannelPackSymmetryLinear(string folder,
alphaChannelR = CheckBlank(alphaChannelR);

int kernel = bakeShader.FindKernel("RLChannelPackSymmetryLinear");
bakeTarget.Create(bakeShader, kernel);
bakeTarget.Create(bakeShader, kernel);

bakeShader.SetTexture(kernel, "RedChannelL", redChannelL);
bakeShader.SetTexture(kernel, "GreenChannelL", greenChannelL);
bakeShader.SetTexture(kernel, "BlueChannelL", blueChannelL);
Expand Down Expand Up @@ -2192,7 +2196,8 @@ private Texture2D BakeHeadDiffuseMap(Texture2D diffuse, Texture2D blend, Texture
cavityAO = CheckMask(cavityAO);

int kernel = bakeShader.FindKernel("RLHeadDiffuse");
bakeTarget.Create(bakeShader, kernel);
bakeTarget.Create(bakeShader, kernel);

bakeShader.SetTexture(kernel, "Diffuse", diffuse);
bakeShader.SetTexture(kernel, "ColorBlend", blend);
bakeShader.SetTexture(kernel, "CavityAO", cavityAO);
Expand Down Expand Up @@ -2431,7 +2436,8 @@ private Texture2D BakeHeadSubsurfaceMap(Texture2D subsurface,
baseMap = CheckDiffuse(baseMap);

int kernel = bakeShader.FindKernel(kernelName);
bakeTarget.Create(bakeShader, kernel);
bakeTarget.Create(bakeShader, kernel);

bakeShader.SetTexture(kernel, "Subsurface", subsurface);
bakeShader.SetTexture(kernel, "NMUILMask", NMUIL);
bakeShader.SetTexture(kernel, "CFULCMask", CFULC);
Expand Down
22 changes: 17 additions & 5 deletions Editor/Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,8 +2040,9 @@ private void ConnectHQHairMaterial(GameObject obj, string sourceName, Material s
mat.SetFloatIf("_BlendStrength", Mathf.Clamp01(matJson.GetFloatValue("Textures/Blend/Strength") / 100f));
mat.SetColorIf("_VertexBaseColor", Util.LinearTosRGB(matJson.GetColorValue("Custom Shader/Variable/VertexGrayToColor")));
mat.SetFloatIf("_VertexColorStrength", 1f * matJson.GetFloatValue("Custom Shader/Variable/VertexColorStrength"));
mat.SetFloatIf("_BaseColorStrength", 1f * matJson.GetFloatValue("Custom Shader/Variable/BaseColorMapStrength"));
mat.SetFloatIf("_BaseColorStrength", 1f * matJson.GetFloatValue("Custom Shader/Variable/BaseColorMapStrength"));
mat.SetFloatIf("_DiffuseStrength", 1f * matJson.GetFloatValue("Custom Shader/Variable/Diffuse Strength"));

diffuseColor = Util.LinearTosRGB(matJson.GetColorValue("Diffuse Color"));
mat.SetColorIf("_DiffuseColor", diffuseColor);

Expand Down Expand Up @@ -2077,13 +2078,24 @@ private void ConnectHQHairMaterial(GameObject obj, string sourceName, Material s
mat.SetFloatIf("_RimTransmissionIntensity", 0.75f * specMapStrength * Mathf.Pow(rimTransmission, 0.5f));
mat.SetFloatIf("_FlowMapFlipGreen", 1f -
matJson.GetFloatValue("Custom Shader/Variable/TangentMapFlipGreen"));
mat.SetFloatIf("_SpecularShiftMin",
mat.SetFloatIf("_SpecularShiftMin",
matJson.GetFloatValue("Custom Shader/Variable/BlackColor Reflection Offset Z"));
mat.SetFloatIf("_SpecularShiftMax",
matJson.GetFloatValue("Custom Shader/Variable/WhiteColor Reflection Offset Z"));
}
else if (RP == RenderPipeline.URP && !USE_AMPLIFY_SHADER)
{
mat.SetFloatIf("_DiffuseStrength", 1.15f * matJson.GetFloatValue("Custom Shader/Variable/Diffuse Strength"));
mat.SetFloatIf("_SmoothnessMin", 0f);
mat.SetFloatIf("_SpecularMultiplier", Mathf.Lerp(0.1f, 0.5f, specMapStrength * specStrength));
mat.SetFloatIf("_FlowMapFlipGreen", 1f - matJson.GetFloatValue("Custom Shader/Variable/TangentMapFlipGreen"));
mat.SetFloatIf("_SpecularShiftMin",
matJson.GetFloatValue("Custom Shader/Variable/BlackColor Reflection Offset Z"));
mat.SetFloatIf("_SpecularShiftMax",
matJson.GetFloatValue("Custom Shader/Variable/WhiteColor Reflection Offset Z"));
matJson.GetFloatValue("Custom Shader/Variable/WhiteColor Reflection Offset Z"));
}
else
{
{
if (USE_AMPLIFY_SHADER)
{
SetFloatPowerRange(mat, "_SmoothnessMin", smoothnessStrength, 0f, smoothnessMax, smoothnessPowerMod);
Expand All @@ -2097,7 +2109,7 @@ private void ConnectHQHairMaterial(GameObject obj, string sourceName, Material s
matJson.GetFloatValue("Custom Shader/Variable/WhiteColor Reflection Offset Z"));
}
else
{
{
mat.SetFloatIf("_SmoothnessMin", Util.CombineSpecularToSmoothness(specMapStrength * specStrength, smoothnessStrength));
}
}
Expand Down
Loading

0 comments on commit 604abff

Please sign in to comment.