Shadows don't work when using Vertex Alpha and Alpha Test

We’ve run into a case where we need to use Alpha Test to “cut” a model. Our model has a Vertex Alpha gradient, 0-1, from left to right. On the material, under opacity, we enable Vertex Color (which uses the Vertex Alpha channel), and then set a Alpha Test value. We noticed that realtime shadows don’t respect this value when using Vertex Alpha. When using textures instead of Vertex Alpha though, shadows do respect the Alpha Test value.

The following image is an example of a running application. The top row uses Alpha Test and a gradient texture. The bottom row uses Alpha Test and a Vertex Alpha gradient:

In the editor, shadows often freak out when using Vertex Alpha and Alpha test. Shadows flicker on and off depending on if you hover the mouse over the viewport or not, and the Alpha Test value that the light “sees” and uses for casting shadows depends on what object you have selected.

Also, using an Alpha Test value of 1 with Vertex Alpha seems to confuse the shader, creating an interference pattern. I’d expect a value of 1 would hide the entire object.

Here’s a test PlayCanvas project. Please take a look and see if this is something that can be fixed: PlayCanvas 3D HTML5 Game Engine

I’m having trouble reproducing the shadow flicker on my Macbook

@mvaligursky Any ideas here?

I’m pretty sure we don’t support some of the features, for example I don’t think our shadow shaders use vertex colors / alpha, and perhaps not even setting up the alpha test value - that would explain the flickering, as it would randomly used whatever alpha test value was set up last by whatever used it before.

I’d suggest to create a ticket here for us to investigate: Issues · playcanvas/engine · GitHub

1 Like

The flickering seems to happen when the texture-based Alpha Test boxes are hidden:

I’ve created an issue here:

2 Likes