Skip to content

Commit

Permalink
chore: Material utils optimization (#579)
Browse files Browse the repository at this point in the history
* Use cached property indices

* Remove unused globalIlluminationFlags assignment

* Remove unnecessary _SpecTex_ST assignment
  • Loading branch information
LeeTwentyThree authored Dec 29, 2024
1 parent f811474 commit a1b4e2a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Nautilus/Utility/MaterialUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Nautilus.Utility;
public static partial class MaterialUtils
{
private static readonly int _emissionMap = Shader.PropertyToID("_EmissionMap");
private static readonly int _specInt = Shader.PropertyToID("_SpecInt");
private static readonly int _shininess = Shader.PropertyToID("_Shininess");
private static readonly int _fresnel = Shader.PropertyToID("_Fresnel");
private static readonly int _bumpMap = Shader.PropertyToID("_BumpMap");

internal static void Patch()
{
Expand Down Expand Up @@ -224,13 +228,12 @@ public static void ApplyUBERShader(Material material, float shininess, float spe
if (specularTexture != null)
{
material.SetTexture(ShaderPropertyID._SpecTex, specularTexture);
material.SetFloat("_SpecInt", specularIntensity);
material.SetFloat("_Shininess", shininess);
material.SetFloat(_specInt, specularIntensity);
material.SetFloat(_shininess, shininess);
material.EnableKeyword("_ZWRITE_ON");
material.EnableKeyword("MARMO_SPECMAP");
material.SetColor(ShaderPropertyID._SpecColor, new Color(1f, 1f, 1f, 1f));
material.SetFloat("_Fresnel", 0.24f);
material.SetVector("_SpecTex_ST", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
material.SetFloat(_fresnel, 0.24f);
}

// Apply emission if it was enabled in the standard shader
Expand All @@ -245,13 +248,12 @@ public static void ApplyUBERShader(Material material, float shininess, float spe
}

// Apply normal map if it was applied in the standard shader
if (material.GetTexture("_BumpMap"))
if (material.GetTexture(_bumpMap))
{
material.EnableKeyword("MARMO_NORMALMAP");
}

material.enableInstancing = true;
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.EmissiveIsBlack | MaterialGlobalIlluminationFlags.RealtimeEmissive;

switch (materialType)
{
Expand Down

0 comments on commit a1b4e2a

Please sign in to comment.