Skip to content

Commit

Permalink
add normalMapSacle to MRGTStandardShader (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoloMoto committed Jul 25, 2022
1 parent 7ee59b8 commit f36b152
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Expand Up @@ -100,7 +100,7 @@ protected static class Styles
public static readonly GUIContent enableChannelMap = new GUIContent("Channel Map", "Enable Channel Map, a Channel Packing Texture That Follows Unity's Standard Channel Setup");
public static readonly GUIContent channelMap = new GUIContent("Channel Map", "Metallic (Red), Occlusion (Green), Emission (Blue), Smoothness (Alpha)");
public static readonly GUIContent enableNormalMap = new GUIContent("Normal Map", "Enable Normal Map");
public static readonly GUIContent normalMap = new GUIContent("Normal Map");
public static readonly GUIContent normalMap = new GUIContent("Normal Map");
public static readonly GUIContent enableEmission = new GUIContent("Emission", "Enable Emission");
public static readonly GUIContent emissiveColor = new GUIContent("Color");
public static readonly GUIContent emissiveMap = new GUIContent("EmissionMap");
Expand Down Expand Up @@ -218,6 +218,7 @@ protected static class Styles
protected MaterialProperty channelMap;
protected MaterialProperty enableNormalMap;
protected MaterialProperty normalMap;
protected MaterialProperty normalMapScale;
protected MaterialProperty enableEmission;
protected MaterialProperty emissiveColor;
protected MaterialProperty emissiveMap;
Expand Down Expand Up @@ -332,6 +333,7 @@ protected override void FindProperties(MaterialProperty[] props)
channelMap = FindProperty("_ChannelMap", props);
enableNormalMap = FindProperty("_EnableNormalMap", props);
normalMap = FindProperty("_NormalMap", props);
normalMapScale = FindProperty("_NormalMapScale", props);
enableEmission = FindProperty("_EnableEmission", props);
emissiveMap = FindProperty("_EmissiveMap", props);
emissiveColor = FindProperty("_EmissiveColor", props);
Expand Down Expand Up @@ -457,6 +459,7 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad
float? specularHighlights = GetFloatProperty(material, "_SpecularHighlights");
float? normalMap = null;
Texture normalMapTexture = material.HasProperty("_BumpMap") ? material.GetTexture("_BumpMap") : null;
float? normalMapScale = GetFloatProperty(material, "_BumpScale");
float? emission = null;
Color? emissionColor = GetColorProperty(material, "_EmissionColor");
Texture emissionMapTexture = material.HasProperty("_EmissionMap") ? material.GetTexture("_EmissionMap") : null;
Expand Down Expand Up @@ -501,6 +504,8 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad
{
material.SetTexture("_NormalMap", normalMapTexture);
}

SetShaderFeatureActive(material, null, "_NormalMapScale", normalMapScale);

if (emissionMapTexture)
{
Expand Down Expand Up @@ -633,7 +638,7 @@ protected void MainMapOptions(MaterialEditor materialEditor, Material material)
if (PropertyEnabled(enableNormalMap))
{
EditorGUI.indentLevel += 2;
materialEditor.TexturePropertySingleLine(Styles.normalMap, normalMap);
materialEditor.TexturePropertySingleLine(Styles.normalMap, normalMap, normalMapScale);
EditorGUI.indentLevel -= 2;
}
}
Expand Down
Expand Up @@ -198,6 +198,7 @@ CBUFFER_START(UnityPerMaterial)
half _Metallic;
half _Smoothness;

half _NormalMapScale;
// #if defined(_ALPHA_CLIP)
half _Cutoff;

Expand Down
Expand Up @@ -568,13 +568,13 @@ half4 PixelStage(Varyings input, bool facing : SV_IsFrontFace) : SV_Target
#if defined(_NORMAL_MAP)
#if defined(_TRIPLANAR_MAPPING)
#if defined(_URP)
half3 tangentNormalX = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvX));
half3 tangentNormalY = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvY));
half3 tangentNormalZ = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvZ));
half3 tangentNormalX = UnpackNormalScale(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvX), _NormalMapScale);
half3 tangentNormalY = UnpackNormalScale(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvY), _NormalMapScale);
half3 tangentNormalZ = UnpackNormalScale(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, uvZ), _NormalMapScale);
#else
half3 tangentNormalX = UnpackNormal(tex2D(_NormalMap, uvX));
half3 tangentNormalY = UnpackNormal(tex2D(_NormalMap, uvY));
half3 tangentNormalZ = UnpackNormal(tex2D(_NormalMap, uvZ));
half3 tangentNormalX = UnpackScaleNormal(tex2D(_NormalMap, uvX), _NormalMapScale);
half3 tangentNormalY = UnpackScaleNormal(tex2D(_NormalMap, uvY), _NormalMapScale);
half3 tangentNormalZ = UnpackScaleNormal(tex2D(_NormalMap, uvZ), _NormalMapScale);
#endif
tangentNormalX.x *= axisSign.x;
tangentNormalY.x *= axisSign.y;
Expand All @@ -591,9 +591,9 @@ half4 PixelStage(Varyings input, bool facing : SV_IsFrontFace) : SV_Target
tangentNormalZ.xyz * triplanarBlend.z);
#else
#if defined(_URP)
half3 tangentNormal = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.uv));
half3 tangentNormal = UnpackNormalScale(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, input.uv), _NormalMapScale);
#else
half3 tangentNormal = UnpackNormal(tex2D(_NormalMap, input.uv));
half3 tangentNormal = UnpackScaleNormal(tex2D(_NormalMap, input.uv), _NormalMapScale);
#endif
worldNormal.x = dot(input.tangentX, tangentNormal);
worldNormal.y = dot(input.tangentY, tangentNormal);
Expand Down

0 comments on commit f36b152

Please sign in to comment.