Search Unity

Clone terrain to mesh with aligned vertices?

Discussion in 'Editor & General Support' started by GoldFireStudios, Nov 12, 2020.

  1. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    We are building a deformable snow system with the following approach:

    * Clone the terrain into chunked mesh tiles using `terrainData.GetInterpolatedHeights`.
    * Slightly raise the cloned mesh tiles above the terrain and apply the deformable snow shader to it to create the snow layer.

    This works great; however, because the actual vertices of the terrain aren't accessible (or are we overlooking something here?), the vertices don't always line up and cause areas where the mesh and terrain intersect (see below screenshot). Is there a way to get the cloned terrain to match exactly or should we maybe be taking a different approach altogether?

     
  2. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    Bump. Any ideas?
     
  3. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    398
    Not an expert in this area by any means but doesn't the terrain system potentially dynamically change the number of vertices based on e.g. pixel error etc?

    I have not tried it but the trax microsplat solution might be a quick approach you can use here if you are willing to try a third party asset.
     
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    The terrain is not a simple mesh, it's made of chunks which have different levels of detail depending on the distance to the camera, based on the pixel error setting.

    Instead of a mesh, you could try adding another pass to your terrain material to draw the snow.
     
  5. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    I hadn't come across the MicroSplat solution, it looks pretty neat. Although, we've already built a fully functioning custom solution that works great other than this terrain clipping issue. We actually initially set it up to deform a duplicated terrain tile, which didn't have this clipping issue, but it was incredibly slow, which is why we switched it to mesh tiles.

    We also really need the snow to have actual depth over the terrain for the effect we are trying to create (for example, so objects, trees, etc are actually rooted to the ground with snow covering them at the base rather than the actual ground deforming).