- Home /
Semitransparent shader not visible in front of objects
Hey Guys,
im looking to get a Forcefield like effect with a Semitransparent Rim Shader. The shader in and of itself already looks aproximately how i want it to, i just have a problem where the Forcefield isnt visible when there is an Object behind it. It only correctly shows on the Object it encompasses and on the skybox.
Here are some screens:
And here the Shader im using right now:
Shader "Custom/Shield" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Cube ("Cubemap", CUBE) = "" {}
_ReflColor ("Relection Color", Color) = (0.26,0.19,0.16,0.0)
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
_AlphPower ("Alpha Rim Power", Range(0.0,8.0)) = 3.0
_AlphaMin ("Alpha Minimum", Range(0.0,1.0)) = 0.5
}
SubShader {
Tags { "RenderType" = "Transparent" }
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input {
float2 uv_MainTex;
float3 worldRefl;
float3 viewDir;
INTERNAL_DATA
};
sampler2D _MainTex;
samplerCUBE _Cube;
float4 _RimColor;
float4 _ReflColor;
float _RimPower;
float _AlphPower;
float _AlphaMin;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow (rim, _RimPower) + texCUBE(_Cube, WorldReflectionVector (IN, o.Normal)).rgb*_ReflColor*2 ;
o.Alpha = (pow (rim, _AlphPower)*(1-_AlphaMin))+_AlphaMin ;
}
ENDCG
}
Fallback "Diffuse"
}
any help would be greatly appreciated!
Edit:
after playing around with it some more im now even more confused. The following pictures are of 3 cubes with the same standard shader. Depending on the Distance some Cubes work and others dont. There isnt a specific Range where they work or dont work either. The shield just flickers in and out of existance every step i take.
I maybe say this too often, but a lot of the time this is the Unity 5 render queue bug. If you switch the material to another shader and then back it should fix that (if it is the problem), and you can check by selecting the material in debug mode.
https://docs.unity3d.com/$$anonymous$$anual/InspectorOptions.html
Answer by Ragingpixels · Jul 06, 2016 at 09:03 PM
Alright Guys i figured it out. There was nothing wrong with my Shader but it wasnt shown correctly due to the following Bug in Unity:
All i needed to do was to change the shader in my material to a different one and back to update the renderqueue used.
Please consider voting for this Bug, as it can cost hours of time figuring it out if you dont know the bug exists