I am trying to create a shader that will speed up the process of texturing static objects with repeat textures. In this case I’m working on a skirting board.
So far I have a shader that uses world positions to apply a diffuse map but when trying to use this same method to apply the normal map, the normal map isn’t working off the tangent.
As you can see, the normal map maps to the face as should be correct. (This is not Unpacked at this stage and is applied to the Albedo)
When changing from Albedo to Normal, it does this
See below for my shader
Shader "Custom/World Normal" {
Properties
{
_Tint ("Color", 2D) = "white" {}
_MainTex ("Base (RGB)", 2D) = "white" {}
_Ramp ("Shading Ramp", 2D) = "white"{}
_Normal ("Normal", 2D) = "bump"{}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Ramp
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Ramp;
sampler2D _Tint;
sampler2D _Normal;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
};
half4 LightingRamp (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half NdotL = dot(s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half3 ramp = tex2D(_Ramp, float2(diff)).rgb;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (ramp * atten * 2);
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o) {
half4 x = tex2D (_MainTex, IN.worldPos.yz);
half4 y = tex2D (_MainTex, IN.worldPos.xz);
half4 z = tex2D (_MainTex, IN.worldPos.xy);
half4 c = tex2D (_Tint, IN.worldPos.xy);
c = lerp(c,x,abs(o.Normal.r));
c = lerp(c,y,abs(o.Normal.g));
c = lerp(c,z,abs(o.Normal.b));
half4 xn = tex2D(_Normal, IN.worldPos.zy);
half4 yn = tex2D(_Normal, IN.worldPos.zx);
half4 zn = tex2D(_Normal, IN.worldPos.xy);
half4 cn = lerp(xn, yn, abs(o.Normal.g));
cn = lerp(cn,zn,abs(o.Normal.b));
half3 bump = UnpackNormal(cn);
o.Normal = bump;
// o.Albedo = bump;
o.Albedo = c.rgb;
// o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

