How to control normal map strength by a variable

Hi,
I have a shader that uses a (Damage) normal map, and I want to control this map’s strength with a float between 1 and 0, 0 = no strength and 1 = full strength (Just like the standard shader),

How can I do it?

This is the normal map lines :

_DamageMap ("Damagemap", 2D) = "bump" {}
_Damage ("Damage Value", Range(0.0,10.0)) = 0.0

sampler2D _DamageMap;
half _Damage;

void surf (Input IN, inout SurfaceOutput o)
{

fixed4 Dmg = tex2D(_DamageMap, IN.uv_MainTex);

o.Normal = UnpackNormal (Dmg);
}
1 Like

_DamageMap (“Damagemap”, 2D) = “bump” {}
_Damage (“Damage Value”, Range(0.0,10.0)) = 0.0

sampler2D _DamageMap;
half _Damage;

void surf (Input IN, inout SurfaceOutput o)
{
fixed4 Dmg = UnpackScaleNormal(tex2D(_DamageMap, IN.uv_MainTex),_Damage);
o.Normal =Dmg;
}

3 Likes

unfortunately, It didn’t work, but i have got the method from the UnityStandardUtils.cginc file itself form the UnpackScaleNormal function inside it :

fixed3 Dmg = UnpackNormal(tex2D(_DamageMap, IN.uv_MainTex));
           
Dmg.xy *= _Damage;
           
o.Normal = normalize(Dmg);

thanks for your reply.

3 Likes

Just lerp between your texture and (0.5, 0.5, 1):

float3 normal = lerp(float3(0.5, 0.5, 1), tex2D(_DamageMap, IN.uv_MainTex), _Damage);
o.Normal = UnpackNormal(normal);

15 Likes

6 years later, jbooth, thank you…

7 years later, @jbooth_1 , thanks!

8 years later, @jbooth_1 thank you.

9 years later, @jbooth_1 sheesh!

2023 here, cheers.

1 Like

2024

2025

Yea, 10 years later, thanks jbooth1