I trying my hand at creating a simple semi transparent “holograph” shader in Unity. I have the basic effect I am looking for working, but the transparency is causing me some grief. Depending on the viewpoint sometimes the render shows objects behind the transparent objects, sometimes no objects and its just the skybox you see through it, and sometimes its just a few objects and not others.
You can see a video of the problem here:
I am new to shaders, can you point me in the right direction?
Here is my shader code:
Shader “Custom/MyShader” {
Properties {
_RimColor (“Rim Color”, Color) = (1,1,1,1)
_MainColor (“Main Color”, Color) = (1,0,0,0)
}
SubShader {
Pass {
Tags { “Queue”=“Fade” “RenderType”=“Fade” }
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include “UnityCG.cginc”
uniform float4 _MainColor;
uniform float4 _RimColor;
struct vertexInput{
float4 vertex : POSITION;
float3 normal: NORMAL;
};
struct vertexOutput{
float4 pos : SV_POSITION;
float4 col: COLOR;
};
vertexOutput vert(vertexInput v){
vertexOutput o;
float3 normalDirection = normalize(mul(float4(v.normal, 0.0), _World2Object).xyz);
float3 viewDir = WorldSpaceViewDir(v.vertex);
half rim = 1.0 - dot(normalize(viewDir), v.normal) * 0.5;
o.col = rim * _RimColor + _MainColor;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag(vertexOutput i) : COLOR
{
return i.col;
}
ENDCG
}
}
FallBack “Diffuse”
}