Search Unity

Question about implementing "sticky" decals

Discussion in 'General Graphics' started by xVergilx, Jul 16, 2018.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    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.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    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.
     
    xVergilx likes this.
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    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.
     
    Last edited: Jul 17, 2018
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296