Decal depth/draw order

Hi again folks,

I’m trying to make a decal projection system akin to this one:
http://blog.wolfire.com/2009/06/how-to-project-decals/

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;
decalMaterial.update();

Think this could work? :smile:

1 Like

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

https://playcanvas.github.io/#/graphics/paint-mesh

There is also this example by @kungfooman which is based on your reference blog post I believe:

https://playcanvas.com/project/907728/overview/decals
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.