Question by
felixpk · Jun 08, 2016 at 11:25 AM ·
shaderalphafadevertex shadervertexcolor
Transparent Shader Ignores Background
Hello, im trying to make a SunGlow shader that is basically a vertex colored circle:
The rim of the circle should be alpha=0 and it is, but it ignores the quad (also vertex colored) in the background.
I'll post both shaders, I'm pretty sure it has something to do with the renderType and or ZWrite (?)
The SunGlow-Shader:
Shader "Custom/SunGlow" {
Properties{
_Glow("Glow", Color) = (0,1,0,1)
}
SubShader{
Tags{ "Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent" }
Blend SrcAlpha One
Lighting Off
ZWrite On
Fog{ Mode Off }
ZTest Always
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target es3.0
struct v2f {
fixed4 color : COLOR;
float4 pos : SV_POSITION;
};
fixed4 _Glow;
v2f vert(float4 vertex : POSITION, uint id : SV_VertexID){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, vertex);
if (id == 0){
o.color = _Glow;
}
else {
o.color = fixed4(_Glow.x, _Glow.y, _Glow.z,0);
}
return o;
}
fixed4 frag(v2f i) : COLOR{
return i.color;
}
ENDCG
}
}
}
And the BackgroundGradient-Shader:
Shader "Custom/SkyGradient" {
Properties
{
_SkyTop("Sky Top", Color) = (0,0,1,1)
_SkyMiddle("Sky Middle", Color) = (0,0,0,1)
_SkyBottom("Sky Bottom", Color) = (0,0,1,1)
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target es3.0
struct v2f {
fixed3 color : COLOR0;
float4 pos : SV_POSITION;
};
fixed4 _SkyTop;
fixed4 _SkyMiddle;
fixed4 _SkyBottom;
v2f vert(float4 vertex : POSITION, uint id : SV_VertexID){
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, vertex);
if (id < 2){
o.color = _SkyTop;
}
else if (id < 4) {
o.color = _SkyMiddle;
}
else if (id < 6) {
o.color = _SkyBottom;
}
return o;
}
fixed4 frag(v2f i) : SV_Target{
return fixed4(i.color, 1);
}
ENDCG
}
}
}
I really appreciate any help, thanks in advance!
Felix
shader-glow-problem.png
(165.2 kB)
Comment