- Home /
Strange alpha result
I'm having a strange result with a shader that uses blending:
The sphere at center should be invisible (I need it to write on the Z-buffer, see shader at the end). I can't understand why the pixel that are intersected by the sphere and the left wall are grey. The wall and the floor have the same shader (default/diffuse) This is most probably due to alpha, as you can see in here (Editor camera set to alpha)
This is the shader applied to the sphere:
Shader "Subtractive"
{
SubShader
{
Pass
{
// use a pixel blend that takes from the buffer before
Blend SrcAlpha OneMinusSrcAlpha
// pixel blending only works with lighting
Lighting On
// make sure the depth gets written in
ZWrite On
// set the material color to invisible
Material
{
Diffuse (0,0,0,0)
}
}
}
It could be that you have z-write on and the objects behind fail the z-test, so their fragments are discarded.
Try moving the shader to a higher render queue so that objects behind are rendered first: http://docs.unity3d.com/Documentation/Components/SL-SubshaderTags.html
You are indeed right, now the shaders works fine, thank for your answer.
However I don't understand why it works. The wall and the floor have the same shader (so the same render queue). Why do they behave differently?. Second: I thought that the object to be drawn were z-tested first, and that the rendering queue was applied at the end. Is this right? In this graph, where is the rendering queue applied? http://docs.unity3d.com/Documentation/Images/manual/SL-CullAndDepth-0.jpg
Ordering is done in the CPU first to group objects by queues and then by distance to the camera using the bounding box, for objects in the same queues. Then when rendered z-test is done the GPU/shader.
In your example, the wall and floor are in the same rendering queue, so they are sorted by distance. The wall is behind the circle farther away from the camera and the floor in front of the circle closer to the camera.
Your answer
![](https://koobas.hobune.stream/wayback/20220613102909im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Transparency with correct culling 2 Answers
Blending and Decaying Alphas 0 Answers
Is it possible to change blend mode in shader at runtime? 1 Answer
Z-priming alpha-per-vertex 0 Answers
Remove white edges on texture help 2 Answers