The shader works like I want it to in the “scene” view tab:
… but the skybox covers the transparent area in the game and “game” view tab:
I’m new-ish to shaders, so I’m probably missing something simple but I can’t figure it out.
Here’s the shader I’m using:
Shader ".Note" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Pass {
Tags { "Queue"="Geometry" }
LOD 200
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
struct v2f {
float4 pos : POSITION;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = v.vertex;
if (o.pos.z < 0)
o.pos.z += 0.25;
float fpz = 0.5;
if (-1 < o.pos.z o.pos.z < 1)
fpz = frac(abs(o.pos.z)) / 2.0;
if (v.normal.y < 0)
o.pos.y += fpz;
else
o.pos.y -= fpz;
if (v.normal.z < 0)
o.pos.z = -0.25;
else
o.pos.z = 0;
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
return o;
}
half4 frag(v2f i) : COLOR {
return _Color;
}
ENDCG
}
Pass {
Tags { "Queue"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
struct v2f {
float4 pos : POSITION;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = v.vertex;
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
return o;
}
half4 frag(v2f i) : COLOR {
half4 o;
o.xyz = _Color.rgb;
o.a = _Color.a;
return o;
}
ENDCG
}
}
Fallback "VertexLit"
}
I’ve tried various other tags and flags, and setting the camera to use a solid color works correctly in both the game and scene views, but the shader doesn’t work when the skybox is turned on. Does anybody know what I’m doing wrong?
Cheers,
~ andy.f
Jessy
December 29, 2010, 11:17pm
2
Queue is not a Pass Tag; it’s a Subshader Tag. I don’t know Cg, so can’t help you a lot, but you do need to get that fixed, and it could end up being helpful. You can’t put multiple passes in multiple queues. You need two different materials for that.
http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html
That makes sense. I’m not sure why it works in the scene view but not in game, but w/e.
Cheers,
~ af
Jessy
December 30, 2010, 6:32pm
4
No, if it seemed like it, it was a case of random drawing order working out in favor of what you wanted. You can see in the Inspector for a shader that you click in in the Project pane; a shader can only be in one queue, which is conveniently listed there. Unity 2.5 introduced that.
Take a look at the glass shader example at http://unity3d.com/support/documentation/Components/SL-Blend.html . Perhaps the first queue tag found in a pass is used if it’s not in the subshader tags? …or maybe it’s old documentation? Either way, it’s easy to get confused regarding what’s do-able or not in shader passes.
Cheers,
~ andy.f
Jessy:
No, if it seemed like it, it was a case of random drawing order working out in favor of what you wanted. You can see in the Inspector for a shader that you click in in the Project pane; a shader can only be in one queue, which is conveniently listed there. Unity 2.5 introduced that.
I was able to get the shader working in game by adding a surface shader after the last vert/frag pass …
Shader ".Note" {
Properties {
_Color ("Main Color", Color) = (1, 1, 1, 1)
_SpecularColor ("Specular Color", Color) = (1, 1, 1, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.01
}
SubShader {
Pass {
Tags { "Queue"="Geometry" }
LOD 200
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
struct v2f {
float4 pos : POSITION;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = v.vertex;
if (o.pos.z < 0)
o.pos.z += 0.25;
float fpz = 0.5;
if (-1 < o.pos.z o.pos.z < 1)
fpz = frac(abs(o.pos.z)) / 2.0;
if (v.normal.y < 0)
o.pos.y += fpz;
else
o.pos.y -= fpz;
if (v.normal.z < 0)
o.pos.z = -0.25;
else
o.pos.z = 0;
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
return o;
}
half4 frag(v2f i) : COLOR {
return _Color;
}
ENDCG
}
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 300
CGPROGRAM
#pragma surface surf BlinnPhong alpha
float4 _SpecularColor;
float _Shininess;
struct Input {
float4 color;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = _SpecularColor.rgb;
o.Gloss = _SpecularColor.a;
o.Alpha = _SpecularColor.a;
o.Specular = _Shininess;
}
ENDCG
}
Fallback "VertexLit"
}
Cheers,
~ andy.f
Jessy
December 30, 2010, 7:53pm
7
No idea why they did that. It doesn’t work; I’ll report a bug later.