Hello,
I’m working on a shader for a procedurally generated landscape, that comebines a basic surface shader with vertex colors with a secondary flat colored surface shader with a custom lighting model. Here is my shader code so far:
Shader "Custom/VertexColorLandscapeShader" {
Properties {
_Smoothness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
_Pov("Point of View", Vector) = (0,0,0,0)
_Color("Color Back", Color) = (0,1,0,1)
_CutOffDistance("Cut off at distance", Float) = 32
_FlattenDistance("Flatten at distance", Float) = 31
}
SubShader {
Tags { "RenderType"="Opaque" }
Cull Back
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
struct Input {
float3 worldPos;
float4 color : COLOR;
};
fixed4 _Color;
float4 _Pov;
float _CutOffDistance;
float _FlattenDistance;
void surf (Input IN, inout SurfaceOutputStandard o) {
o.Albedo = IN.color;
if(distance(float3(IN.worldPos.x, 0, IN.worldPos.z), float3(_Pov.x, 0, _Pov.z)) > _FlattenDistance-.5) discard;
}
ENDCG
Cull Back
CGPROGRAM
#pragma surface surf _Uniform
#pragma vertex vert
#pragma target 3.0
#include "UnityPBSLighting.cginc"
struct Input {
float3 worldPos;
};
fixed4 _Color;
float4 _Pov;
float _CutOffDistance;
float _FlattenDistance;
inline half4 Lighting_Uniform(SurfaceOutputStandard s, half3 viewDir, UnityGI gi) {
half4 c;
c.rgb = s.Albedo * (_LightColor0.rgb + UNITY_LIGHTMODEL_AMBIENT.rgb);
c.a = 1;
return c;
}
//New Standard Lighting model requires a GI function
inline void Lighting_Uniform_GI(
SurfaceOutputStandard s,
UnityGIInput data,
inout UnityGI gi)
{
gi = UnityGlobalIllumination (data, s.Occlusion, s.Smoothness, s.Normal);
}
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input,o);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex);
if(distance(float3(worldPos.x, 0, worldPos.z), float3(_Pov.x, 0, _Pov.z)) > _FlattenDistance) v.vertex.y = -0.5;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
o.Albedo = _Color;
if(distance(float3(IN.worldPos.x, 0, IN.worldPos.z), float3(_Pov.x, 0, _Pov.z)) < _FlattenDistance-.5) discard;
if(distance(float3(IN.worldPos.x, 0, IN.worldPos.z), float3(_Pov.x, 0, _Pov.z)) > _CutOffDistance+.5) discard;
if(IN.worldPos.y < -0.2) discard;
}
ENDCG
}
FallBack "Diffuse"
}
The problem is: it only works on the transparent render queue. when set to anything else (geometry or alpha test) the parts with the custom lighting are not drawn at all. There are no errors or warnings, they are just invisible (the solid grey parts in the first image):
set to geometry:
I’ve got no idea why this is happening, and I’d be happy about any hints in the right direction.
Thank you.



