[Solved] Mesh decals clipping near camera

**Alright guys, I’m an idiot, I was getting the world position of each individual vertex, rather than the pixel, when the centre of the vertex was outside of the fov, then it would clip the whole vertex. I feel like a real idiot now! **

For others, just make sure you don’t try to do visibility calculations in the vertex shader unless you have a high density mesh or you are using mesh decals for something in the distance.

*Hello all, i made this post a few days ago but since it was lacking in detail/information I thought I’d try again.

[Original Post]

I heard about a technique called Mesh Decals recently, where you can project decals using mesh geometry, it seems like a very useful technique, given that you can paint these decals using a foliage painter, easily place them using splines, and they can be instanced (although I’m a little uncertain about the benefits of this when regarding decals.

The effect is perfect when viewed from certain angles, as shown here:

https://i.gyazo.com/thumb/1000/a3bf9a81b1b30405a24e783e27882611-jpg.jpg

As you can see, you can create a nice gradual falloff, and there are no planes floating about the landscape and no mesh protruding in an ugly fashion. I have not tried using normal decals yet, but these seem like they would not be as intuitive to place using splines, although I am not against using that approach if the limitations of mesh decals appear unsolvable.

These limitations appear in the form of the quads of the decal mesh clipping along the bottom border of the screen:

https://i.gyazo.com/18f57501a919ffe18c334399f5518652.gif

Unfortunately this issue is exacerbated when you are in a gameplay perspective, as the bottom border of the screen is where the ground usually is! I also see this weird stretching.

https://i.gyazo.com/2a998ae565c07c74200856c63bd750ec.gif

Have i bumped into some limitations of the mesh decals feature, or is there something that I am missing in the way that I have set this up?

Here is a screen of my material setup:

*

I’m still struggling to find a solution to this, it does not happen to normal decals, and it seems to be individual quads that are clipping, so the density of the mesh has a direct effect on the clipping. A high resolution mesh has less visible (but still apparent clipping)

Also, the clipping only happens along the bottom border of the screen, weirdly. it’s not distance based as I first assumed. It happens regardless of how close you are. So perhaps it is something to do with the view frustum occlusion?

Alright guys, I solved this. The solution is at the top of the first post, I feel like a moron now.

looks interesting, but your material isn’t really visible :stuck_out_tongue:

You can check if the vertex is at or behind near clipping plane. If so, move it, so it is in front of clipping plane using WPO , leaving rest of your material calculations use unmodified WPO positions.
Hacky and dirty, but reliable.

actually I was trying to check if the OP’s material was using WorldSpace-mapped UVs for the spline. I’ve been trying on and off to re-project the original spline UV’s similar to WorldPositionBehindTranslucency so that I can keep the directionality of the decal UVs (i.e. to have the texture ‘follow’ the spline) but the answer eludes me

The answer was to initial topic question.
OP is not doing what you are asking about.

You can project the UVs, You can encode all the data, needed to retrieve that, per vertex, during spline mesh creation. But it is prone to same limitations as before. If your render mesh is a flat splinemesh, at high angles/ lower camera height, you will inevitably run into a case, where UVs will be shifted beyond boundaries of the mesh or your camera would simply be below the mesh. In that case, you need a volume and task becomes exactly the same, as silhouette parallax occlusion mapping. You would need to split the mesh into prisms, with all the consequences of not being affordable real-time.

That is why when speaking about spline decals, the only acceptable solution up to date is to generate rendermesh, that would be fitting tightly enough to the landscape.

Thank you for the replies

Good thing I love dirty hacks

I don’t think it is a clipping plane issue unless there is something that I have misunderstood about mesh decals. The clipping occurred along the bottom of the screen, no matter the viewing distance. This could come in handy though, thanks.

​​I am using worldspace-mapped Uvs, although re-projecting Uv’s sounds like it could be useful for certain things like road markings, I haven’t tried that yet, I was just planning to overlay more meshes/decals for those.

Here is the material currently.

I use terrain height data to map the spline somewhat correctly, but it is not always perfect, so I use vertex painting to weight the alignment to the terrain, and since the mesh is offset from the ground by default, this allows me to trade off close alignment for a better projection sometimes, although it’s not perfect.

I do have another problem, which is that the “recieves decals” flag doesn’t appear to affect mesh decalas annoyingly.

I think I’m halfway there, I’m making my spline conform to the landscape by using wpo and a heightmap. It’s not perfect, but it’s giving me acceptable results. I’m not sure how to go about encoding the data/retrieving it to project the uv’s, does that involve manipulating the world position (maybe rotating it) based off of the orientation of the decal in the world?