Change the strength of a normal map in a Unity shader

I needed a function where i can change the “strength” of a normal. It seems to be not as easy as multiplying the normal vektor with a factor.

So i found the UnpackScaleNormal function from the Unity includes. You can use its exactly like UnpackNormal but with an extra argument for the strength of the normal.

So instead of for example:

UnpackNormal(tex2D(_NormalMap, IN.uv_NormalMap));

you do

UnpackScaleNormal(tex2D(_NormalMap, IN.uv_NormalMap), normalStrength);

In case you are wondering what the functions do exactly, here is the source code of both functions:

UnpackNormal

inline float3 UnpackNormal (fixed3 packedNormal)
{
    float3 normal;
    normal.xy = packedNormal.xy * 2 - 1;
    normal.z = sqrt(1 - dot(normal.xy, normal.xy));
    return normal;
}

UnpackScaleNormal

inline float3 UnpackScaleNormal (fixed3 packedNormal, float scale)
{
    float3 normal;
    normal.xy = packedNormal.xy * 2 - 1;
    normal.z = sqrt(1 - dot(normal.xy, normal.xy));
    normal *= scale;
    return Unity_NormalTransform(normal);
}

inline float3 Unity_NormalTransform (float3 normal)
{
    float3x3 worldToTangent = GetWorldToTangentMatrix();
    return mul(normal, worldToTangent);
}