- Home /
Transparent shader with depth writes
Hi guys,
I spent the afternoon trying to find out how to make a shader that do a similar thing than this:
https://www.youtube.com/watch?v=CK5emREuwrQ#t=17
I added a second pass to the bumped specular, another surface shader with vertex shader (that scale the model up). So I have this model upscaled with alpha but it is semi-transparent and some surfaces overlay as the left figure in:
I tried to use an extra path to calculate the depth but nothing help I have always some overdrawing artifacts and I would like to have a uniform solid color or a gradient at best, like the right figure but impossible.
Any ideas how I could avoid two surfaces to overlap and display nicely like in oxide demo?
Thanks guys.
By the way,
Here is what I have with a second pass using a surface shader and the code.
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 300
Cull Back
CGPROGRA$$anonymous$$
#pragma surface surf BlinnPhong vertex:vert alpha
fixed4 _Color;
fixed4 _ShieldColor;
half _Scale;
half _Offset;
half _Shininess;
sampler2D _Bump$$anonymous$$ap;
sampler2D _$$anonymous$$ainTex;
struct Input
{
float2 uv_$$anonymous$$ainTex;
float2 uv_Bump$$anonymous$$ap;
};
void vert(inout appdata_full v)
{
v.vertex = mul(float4x4(
_Scale, 0, 0, 0,
0, _Scale, 0, 0,
0, 0, _Scale, 0,
0, 0, 0, 1 ), v.vertex);
}
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = _ShieldColor.rgb;
o.Emission = _ShieldColor.rgb * _ShieldColor.a;
o.Alpha = _ShieldColor.a;
}
ENDCG
Here is what I have with a second pass using a frag shader.
Pass
{
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
CGPROGRA$$anonymous$$
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 vertex : SV_POSITION;
};
half _Scale;
fixed4 _ShieldColor;
sampler2D _$$anonymous$$ainTex;
float4 _$$anonymous$$ainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
float4x4 matrix = float4x4(
_Scale, 0, 0, 0,
0, _Scale, 0, 0,
0, 0, _Scale, 0,
0, 0, 0, 1 );
o.vertex = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, mul(matrix, v.vertex));
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return _ShieldColor;
}
ENDCG
}
Answer by gpz22 · Jun 24, 2014 at 04:32 AM
Found a solution thanks to this thread:
http://answers.unity3d.com/questions/290333/transparent-solid-color-shader.html
And for the gradient like appearance:
http://answers.unity3d.com/questions/229829/shader-based-on-surface-distance-from-center-.html