Transparent alphablend with zbuffer?

I have a really basic shader which basically draws a procedural shape instead of using a texture, on a single triangle, and uses the alpha to smooth between the interior and exterior of the shape. It works fine with alphablending on and zbuffer write off.

As soon as I switch on the zbuffer using ZTest LEqual, the z-clipping starts working but there is no blending happening - everything is drawn solid even the parts which have an alpha of 0. Is this normal? Could it be related to drawing everything at the same Z distance, ie is sorting/separation of distances required? Or am I missing something obvious?

Code?

“ZTest LEqual” and drawing everything at the same Z distance doesn’t make any sense to me, use “ZTest Always” in that case.

I’m just drawing a bunch of semi-transparent triangles. The question is why doesn’t it do alphablending when there is z testing active?

Hi

somewhere on the Wiki group I’ve found this shader:

Shader "Transparent/VertexLit with Z" {

Properties {
  	_Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

SubShader {
    Tags {"RenderType"="Transparent" "Queue"="Transparent"}
    // Render into depth buffer only
    Pass {
        ColorMask 0
    }
    // Render normally
    Pass {
        ZWrite Off
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask RGB
        Material {
            Diffuse [_Color]
            Ambient [_Color]
        }
        Lighting On
        SetTexture [_MainTex] {
            Combine texture * primary DOUBLE, texture * primary
        }
    }
}

}

Well, I’m just saying that I won’t look at this problem unless you provide me with some code. :slight_smile:

So, in that shader above, it does 2 passes, one to write to the z buffer, then one to apply the alphablending. I guess that would work but seems unfortunate to need 2 passes.

My question is about why, when you switch ztest on with ZTest LEqual, does the blending switch off?

Well… my background in creating shaders is basically null… so… I just found it and applied to my scene and it did want I wanted… :slight_smile: