Question about implementing "sticky" decals

I’ve implemented basic deferred “quad” decals, via CommandBuffer rendering.
But now I can’t figure out how to apply them on top of the surface in a way so that they envelop it, instead of penetrating through. Like sticking decals to the terrain, or on uneven surface.

Is there any decent information about implementing decals that repeat form of an object?
Projectors seems to be one way to do it, but it seems they’re really bad in terms of performance.

I would really appreciate if someone would point me in a right direction on how it’s supposed to be done with Unity.

Projectors re-render the object’s mesh with a projection matrix used to compute the decal UVs. An optimization to this is to cull all triangles from the mesh that are outside of the projector’s frustum, and optionally culling “back” faces, so that the rendered mesh is mostly limited to the region wanted. Unreal used to do this, during the Unreal Engine 2.0 days, but Unity never has. Mainly because it’s often more expensive to cull the triangles on the CPU and reupload the mesh than just rendering the entire thing. For mostly static decals it’s still a useful technique, though does require you handle the projector entirely manually. I believe some assets on the store do something like this.

For deferred decals (if by deferred you mean the deferred rendering path) generally you’re rendering a box or simple shape and applying a projection matrix against the depth buffer. This means the geometry you’re rendering only needs to be a box rather than the original mesh’s geometry, but there are new problems to do with mip mapping.

1 Like

That’s where I’m stuck right now, I’m rendering box to the GBuffer0, 1, 2, and CameraTarget, but it just same as any other mesh.
It doesn’t have an overlay effect, and simply penetrates other geometry.

Seems like I do need either screen space depth overlay shader, or a projection shader.
Graphics are tough to pick up from ground zero. I should really dig into those. Thanks.

1 Like

After looking briefly over the project, I think it’s what I’ve been looking for. It even works in 2018.2 :hushed:
I’m really impressed. Decal system a bit outdated and uses old API, but shaders are invaluable.
I think I’ll be able to figure out the rest now. Thanks again :slight_smile: