Decal depth/draw order

Hi again folks,

I’m trying to make a decal projection system akin to this one:

It basically works by cutting out a portion of an existing mesh to make a decal geometry that conforms to the shape it’s being projected onto. I’m making good headway with mesh generation, but I’m having trouble with the material.

Seeing as the resulting mesh will be placed directly on top of the existing one, it will of course result in flickering and z-fighting. How can I mitigate this? I need to make sure it’s being rendered on-top.

I’ve toyed with StandardMaterial.depthBias which seems to work nicely, but not when I disable StandardMaterial.depthWrite, which I believe is the correct thing to do for transparent decals?

Is there some clever combination or draw-back that I’m oblivious to? :thinking:

@mvaligursky ? :bowing_man:

Hold up, this combination seems to do the trick:

const decalMaterial = new pc.StandardMaterial();
decalMaterial.diffuse = pc.Color.RED;
decalMaterial.depthWrite = false;
decalMaterial.blend = true;
decalMaterial.depthBias = -1;
decalMaterial.slopeDepthBias = -1;

Think this could work? :smile:

1 Like

Have you seen this example? Is it not applicable to your use case?

There is also this example by @kungfooman which is based on your reference blog post I believe:
Some additional details here: Implement generic decal geometry placement over meshes · Issue #4053 · playcanvas/engine · GitHub

1 Like

Thanks for the links, LeXXik :+1:

I think the first method could prove useful for animated meshes such as characters.

For now I’m only aiming for static meshes. The original intent is to use it for dynamic bullet hole decals.