Hi all,
So I’ve created a custom shader using the Unity manual in order to apply it to a terrain to try and create some sort of tracks in the snow or footprints sort of effect. However, when I apply it to the terrain i get the following error:
![]()
I’m new to shaders, this is the first one I’ve messed around with. I have researched this and got the understanding that it’s something to do with normal maps but couldn’t find anything that made sense or worked.
Can anyone point me in the right direction or explain why the error is occurring in layman’s terms for me.
The shader code is:
Shader "Tracks" {
Properties {
_GroundColor ("Ground Color", color) = (1,1,1,1)
_GroundTex ("Ground Texture", 2D) = "white" {}
_TrackColor ("Displacement Color", color) = (1,1,1,0)
_TrackTex ("Displacement Texture", 2D) = "white" {}
_Splat ("Track Texture", 2D) = "black" {}
_Displacement ("Displacement", Range(0, 30)) = 0
_Tess ("Tessellation", Range(1,30)) = 4
_TessDist ("Tessolation Distance", Range(0, 1000)) = 0.0
_SpecColor ("Specular Color", color) = (0.5,0.5,0.5,0.5)
_SpecAmount ("Specular Amount", Range(0.1, 100)) = 0.2
_GlossAmount ("Reflective Amount", Range(0, 100)) = 0.1
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf BlinnPhong addshadow fullforwardshadows vertex:disp tessellate:tessDistance nolightmap
#pragma target 4.6
#include "Tessellation.cginc"
struct appdata {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
};
//Tesselation
float _Tess;
float _TessDist;
float4 tessDistance (appdata v0, appdata v1, appdata v2) {
float minDist = 0;
float maxDist = _TessDist;
return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, minDist, maxDist, _Tess);
}
//displacement
sampler2D _Splat;
float _Displacement;
void disp (inout appdata v)
{
float d = tex2Dlod(_Splat, float4(v.texcoord.xy,0,0)).r * _Displacement;
v.vertex.xyz -= v.normal * d;
v.vertex.xyz += v.normal * _Displacement;
}
//blendeding the two textures together based on height/displacement
fixed4 _GroundColor;
sampler2D _GroundTex;
fixed4 _TrackColor;
sampler2D _TrackTex;
struct Input {
float2 uv_GroundTex;
float2 uv_TrackTex;
float2 uv_Splat;
};
float _SpecAmount;
float _GlossAmount;
void surf (Input IN, inout SurfaceOutput o) {
half amount = tex2Dlod(_Splat, float4(IN.uv_Splat,0,0)).r;
fixed4 c = lerp(tex2D(_GroundTex, IN.uv_GroundTex) * _GroundColor, tex2D(_TrackTex, IN.uv_TrackTex) * _TrackColor, amount);
o.Albedo = c.rgb;
o.Specular = _SpecAmount;
o.Gloss = _GlossAmount;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}