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"
}
I don't really understand what you are trying to achieve with your shader... Normally for normal mapping you should have a normal map UV in your Input structure and then you simply do something like
– AtGfxo.Normal = text2D(_TopNormal, input.normalUV);Maybe you can have a look [here][1] and start with the provided example of normal mapping shader and try to make the effect you want. Step by step you could isolate the problem that renders your object completely black. Hope it helps ;) [1]: https://docs.unity3d.com/420/Documentation/Components/SL-SurfaceShaderExamples.htmlYou are correct, oversight on my end. I will adjust my answer to account for this when I have a moment
– Deathdefy