I am working on a multiple pass surface shader based on the Unity builtin VertexLit shader...
Basically, what I am trying to do is let the shader do its thing in its own passes, and then add a second pass to layer some extra color on top of what color was originally there.
I've gotten that far, however the problem is, my surface shader pass is ignoring transparency -- returning an alpha of zero should cause colors from the the original VertexLit shader to bleed through, right? Apparently not!
I am very new to any form of advanced shaders, and clearly there is something here I don't understand. Does anyone care to give a bit of clarity to a noob? Thankyou!
Here is the code for the aforementioned shader: -- I've noted the part of the code that stores my "secondary pass"
Shader "VertexLit Toon" {
Properties {
_RimPower ("Rim Power", Float) = 2.5
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emissive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_MainTex ("Base (RGB)", 2D) = "white" {}
}
// 2/3 texture stage GPUs
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
// Non-lightmapped
Pass {
Tags { "LightMode" = "Vertex" }
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
// Lightmapped, encoded as dLDR
Pass {
Tags { "LightMode" = "VertexLM" }
BindChannels {
Bind "Vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
constantColor [_Color]
combine texture * constant
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE, texture * primary
}
}
// Lightmapped, encoded as RGBM
Pass {
Tags { "LightMode" = "VertexLMRGBM" }
BindChannels {
Bind "Vertex", vertex
Bind "normal", normal
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord1", texcoord1 // unused
Bind "texcoord", texcoord2 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [unity_Lightmap] {
constantColor [_Color]
combine previous * constant
}
SetTexture [_MainTex] {
combine texture * previous QUAD, texture * primary
}
}
// Pass to render object as a shadow caster
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
Fog {Mode Off}
ZWrite On ZTest Less Cull Off
Offset 1, 1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
v2f vert( appdata_base v )
{
v2f o;
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag( v2f i ) : COLOR
{
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
// Pass to render object as a shadow collector
Pass
{
Name "ShadowCollector"
Tags { "LightMode" = "ShadowCollector" }
Fog {Mode Off}
ZWrite On ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcollector
#define SHADOW_COLLECTOR_PASS
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
V2F_SHADOW_COLLECTOR;
};
v2f vert (appdata v)
{
v2f o;
TRANSFER_SHADOW_COLLECTOR(o)
return o;
}
half4 frag (v2f i) : COLOR
{
SHADOW_COLLECTOR_FRAGMENT(i)
}
ENDCG
}
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//########## BEGIN SECONDARY SURFACE SHADER PASS ############
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
CGPROGRAM
#pragma surface surf Lambert
struct Input
{
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = 0;
o.Alpha = 0;
}
ENDCG
}
// 1 texture stage GPUs
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
// Non-lightmapped
Pass {
Tags { "LightMode" = "Vertex" }
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Lighting On
SeparateSpecular On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
// Lightmapped, encoded as dLDR
Pass {
Tags { "LightMode" = "VertexLM" }
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
constantColor [_Color]
combine texture * constant
}
}
Pass {
Tags { "LightMode" = "VertexLM" }
ZWrite Off
Blend DstColor Zero
SetTexture [_MainTex] {
combine texture
}
}
}
}
↧