Shbli
1
Hi,
I have a basic click pointer for my game, basically what I need is that part of that pointer get blocked by another 3D object, it should render that part on top of it with 50% transparent.
For example, this screenshot:
[32715-2014-09-21+12_47_30-unity±+defaultscene.unity±+the+royal+quest+unity+3d±+iphone,+ipod+touch+and+i.jpg|32715]
50% of the blue pointer is covered by the stairs, what I want is to show that 50% part as 50% transparent to complete it.
I have no issues getting a paid shader from the assets store, not sure how to search for a shader like that. As I have no experience writing shaders.
What the shader need to do is something really basic
1- Draw the clicked pointer as it would usually normal with 50% opacity
2- Draw it second time without a Z Test (or with) so that it’s always on top, but that second time it will be drawn with 50% opacity of it’s original opacity
so, when the two appear on top of each other, I have a higher opacity pointer, when one disappear or part of it, I have a 50% opacity pointer!
Thanks!
Try this:
Shader "Custom/Overdraw" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
// Include functions common to both passes
CGINCLUDE
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
};
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
ENDCG
// Pass for fully visible parts of the object
Pass {
ZTest LEqual
CGPROGRAM
fixed4 frag (v2f i) : COLOR
{
fixed4 col = tex2D(_MainTex, i.texcoord);
return col;
}
ENDCG
}
//Pass for obscured parts of the object
Pass {
ZTest Greater
CGPROGRAM
fixed4 frag (v2f i) : COLOR
{
fixed4 col = tex2D(_MainTex, i.texcoord);
col.a *= 0.5;
return col;
}
ENDCG
}
}
}
