I am using unity.
I used Triplanar to make the top of the cube as snow terrain and the rest of the sides as cliff terrain.
Here I have to insert a normal map.
However, if the normal map is applied, the image of the cliff face is covered with the image of the snow terrain.
The phenomenon is shown in the following image.
Properties
{
[NoScaleOffset]_MainTex ("TopTex", 2D) = "white" {}
_MainTexUV("tileU, tileV, offsetU, offsetV", vector) = (1, 1, 0, 0)
[NoScaleOffset]_MainTex2("sideTex", 2D) = "white" {}
_MainTex2UV("tileU, tileV, offsetU, offsetV", vector) = (1, 1, 0, 0)
_Bumpmap ("NormalMap", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _MainTex2;
sampler2D _Bumpmap;
float4 _MainTexUV;
float4 _MainTex2UV;
struct Input
{
float2 uv_Bumpmap;
float3 worldPos;
float3 worldNormal;
INTERNAL_DATA
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
float2 topUV = float2(IN.worldPos.x, IN.worldPos.z);
float2 frontUV = float2(IN.worldPos.x, IN.worldPos.y);
float2 sideUV = float2(IN.worldPos.z, IN.worldPos.y);
o.Normal = UnpackNormal(tex2D(_Bumpmap, IN.uv_Bumpmap));
float4 topTex = tex2D(_MainTex, topUV * _MainTexUV.xy + _MainTexUV.zw);
float4 frontTex = tex2D (_MainTex2, frontUV * _MainTex2UV.xy + _MainTex2UV.zw);
float4 sideTex = tex2D (_MainTex2, sideUV * _MainTex2UV.xy + _MainTex2UV.zw);
o.Albedo = lerp(topTex, frontTex, abs(IN.worldNormal.z));
o.Albedo = lerp(o.Albedo, sideTex, abs(IN.worldNormal.x));
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
Why does this happen?
Also, how do I apply the normal map to only one side?
According to the documentation, you need to use WorldNormalVector(IN, o.Normal)
instead of IN.worldNormal
if you modify o.Normal
;
And, to apply the normal to only one side, you can simply use a neutral normal (.5,.5,1) for the other sides and use the same lerp trick you do with the albedo:
Properties
{
[NoScaleOffset] _MainTex("TopTex", 2D) = "white" {}
_MainTexUV("tileU, tileV, offsetU, offsetV", vector) = (1, 1, 0, 0)
[NoScaleOffset]_MainTex2("sideTex", 2D) = "white" {}
_MainTex2UV("tileU, tileV, offsetU, offsetV", vector) = (1, 1, 0, 0)
_Bumpmap("NormalMap", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
sampler2D _MainTex;
sampler2D _MainTex2;
sampler2D _Bumpmap;
float4 _MainTexUV;
float4 _MainTex2UV;
struct Input
{
float2 uv_Bumpmap;
float3 worldPos;
float3 worldNormal;
INTERNAL_DATA
};
void surf(Input IN, inout SurfaceOutputStandard o)
{
float2 topUV = float2(IN.worldPos.x, IN.worldPos.z);
float2 frontUV = float2(IN.worldPos.x, IN.worldPos.y);
float2 sideUV = float2(IN.worldPos.z, IN.worldPos.y);
float3 worldNormal = WorldNormalVector(IN, o.Normal);
float3 topNormal = float3(.5, .5, 1);
float3 frontNormal = float3(.5, .5, 1);
float3 sideNormal = UnpackNormal(tex2D(_Bumpmap, IN.uv_Bumpmap));
o.Normal = lerp(topNormal, frontNormal, abs(worldNormal.z));
o.Normal = lerp(o.Normal, sideNormal, abs(worldNormal.x));
float4 topTex = tex2D(_MainTex, topUV * _MainTexUV.xy + _MainTexUV.zw);
float4 frontTex = tex2D(_MainTex2, frontUV * _MainTex2UV.xy + _MainTex2UV.zw);
float4 sideTex = tex2D(_MainTex2, sideUV * _MainTex2UV.xy + _MainTex2UV.zw);
o.Albedo = lerp(topTex, frontTex, abs(worldNormal.z));
o.Albedo = lerp(o.Albedo, sideTex, abs(worldNormal.x));
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"