Hey,
So I’m working on a procedural terrain and Standard Shader simply doesn’t work for me. Instead I have created my own shader (evaluated from standard surface shader) that doesn’t require UV and It works great with textures, however, when I try to add normal maps (more accurately I add “o.Normal = stuff”) everything breaks (e.g. object becomes perfect black) so how do I add normal map support?
Here is shader in the albedo state:
Shader "Custom/Terrain" {
Properties {
_TopTexture ("Top Texture", 2D) = "white" {}
_TopNormal ("Top NormalMap", 2D) = "bump" {}
_TopTexScale ("Top Texture Scale", float) = 0
_Glossiness ("Smoothness", Range(0,1)) = 0.0
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input {
float3 worldPos;
float3 worldNormal; INTERNAL_DATA
};
half _Glossiness;
half _Metallic;
float _TopTexScale;
sampler2D _TopTexture;
sampler2D _TopNormal;
void surf (Input IN, inout SurfaceOutputStandard o) {
float3 scaledWorldPos = IN.worldPos / _TopTexScale;
float3 blendAxes = abs(IN.worldNormal);
blendAxes /= blendAxes.x + blendAxes.y + blendAxes.z;
float3 xProjection = tex2D(_TopTexture, scaledWorldPos.yz) * blendAxes.x;
float3 yProjection = tex2D(_TopTexture, scaledWorldPos.xz) * blendAxes.y;
float3 zProjection = tex2D(_TopTexture, scaledWorldPos.xy) * blendAxes.z;
o.Albedo = xProjection + yProjection + zProjection;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
}
ENDCG
}
FallBack "Diffuse"
}