- Home /
Surface Shader not working when using Vertex Lit render settings?
Hi, Firstly yes I am new to the world of shaders, I have just about got my head around writing surface shaders but for some reason non of my shaders are rendering when the camera is set to vertex lit?
I have had a read around and think i now need to move onto fixed function shaders which seems a totally different shader language?
Is it true that surface shaders just wont work on vertex lit or is it down to the lighting set up and therefore can be configured to work in both set ups?
Thanks for any advice given I'm looking to learn and progress!
Here is the shader im working with:
Shader "Custom/UV2AlphaMask" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_AlphaMask ("Alpha Mask (A)", 2D) = "white" {}
_AlphaAmt ("Alpha Amount", Range(0,1)) = 0.5
}
SubShader {
Tags { "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
sampler2D _MainTex, _AlphaMask;
fixed _AlphaAmt;
struct Input {
float2 uv_MainTex, uv2_AlphaMask;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
half4 mask = tex2D (_AlphaMask, IN.uv2_AlphaMask);
o.Albedo = c.rgb;
o.Alpha = mask.a * _AlphaAmt;
}
ENDCG
}
FallBack "Diffuse"
}
update
As an example I found this shader as part of the unity default terrain shaders, is anyone able/willing to explain a little about how come this seems to be a mix of both surface shader and fragment shader? and possibly a nudge in the right direction for further investigation?
Thanks,
Shader "Hidden/TerrainEngine/Details/Vertexlit" {
Properties {
_MainTex ("Main Texture", 2D) = "white" { }
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
fixed4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
Tags { "LightMode" = "Vertex" }
ColorMaterial AmbientAndDiffuse
Lighting On
SetTexture [_MainTex] {
combine texture * primary DOUBLE, texture * primary
}
}
Pass {
Tags { "LightMode" = "VertexLMRGBM" }
ColorMaterial AmbientAndDiffuse
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] { combine texture * previous QUAD, texture }
}
}
Fallback "VertexLit"
}
Answer by Earlybird · Jun 25, 2014 at 10:54 PM
After some research I have discovered that the above is in fact two shaders contained inside one, rather a separate fallback if the first subshader is unable to render it will move to the next and try to render that. So in short the second shader contains its own fallback.
Surface shader wont render under vertex lit rendering due to them being per pixel shaders rather than just vertex lit shaders.
For vertex lit render path you should look into Fixed Function shaders.
Answer by Ackerka · Aug 09, 2017 at 01:17 PM
I also had a problem of missing transparency in case of using legacy vertex lit rendering path. The surface was opaque instead of semi-transparent. Your posted hint led me to the solution which was to use the Legacy Shaders/Transparent/VertexLit shader for the semi-transparent game object instead of the Standard shader.