- Home /
Question by
aaronfjerstad · Nov 19, 2017 at 05:06 AM ·
alphashader programmingalphablend
Glitch in Shader with World-Relative Alpha
I attempted to make a shader whose transparency was based on world position. However, whenever alpha:blend or alpha:fade are enabled, I get weird glitching on the camera. Also, even when a pixel should be completely visible, some faces are partially see-through. I'm using a cube with the standard checker pattern, so that shouldn't be an issue
I show the effect of the shader and the glitches in this video:
https://www.youtube.com/watch?v=1lG0QYbHBMg
In addition, at some viewing angles in the viewport the cube is eclipsed by the plane behind it:
My shader code is:
Shader "Example/Something" {
Properties{
_MainTex("Texture", 2D) = "white" {}
}
SubShader{
Tags{ "RenderType" = "Opaque" }
Cull Off
CGPROGRAM
#pragma surface surf Lambert keepalpha alpha:fade
struct Input {
float2 uv_MainTex;
float3 worldPos;
};
sampler2D _MainTex;
void surf(Input IN, inout SurfaceOutput o) {
float4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rbg;
float a = IN.worldPos.x;
o.Alpha = saturate(a);
}
ENDCG
}
}
untitled.png
(202.6 kB)
Comment
Answer by Namey5 · Nov 24, 2017 at 06:20 AM
Change
Tags{ "RenderType" = "Opaque" }
To
Tags{ "RenderType" = "Transparent" "Queue"="Transparent" }