Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Where is the tessellation shader for default terrain? (URP)

Discussion in 'Shaders' started by ColePlusPlus, Dec 30, 2022.

  1. ColePlusPlus

    ColePlusPlus

    Joined:
    Feb 16, 2016
    Posts:
    7
    I am attempting to create a custom terrain shader based on the default "TerrainLit.shader" from URP.
    So far, I've managed to display the splat maps (imaged below) but what I really want to do is implement a geometry shader that spawns triangles on every vertex of the terrain, based on a splat map value. I haven't been able to get this to work however and I'm wondering if its because the tessellation stage is a complete mystery to me. How is Unity tessellating the terrain? I do not see anything like that in "TerrainLit.shader"

    Thank you.

    fge.PNG
     
  2. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    725
    The Unity default shader is not GPU tessellated. All the subdividing of triangles is based on a quad tree and done on the CPU (EDIT : CPU, not GPU).
     
    Last edited: Dec 31, 2022
  3. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    443
    is the quadtree algorithm really executed on the GPU? I always thought it was streamed CPU-side and pushed to the GPU to be drawn :D.
     
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    725
    Sorry, I meant CPU, yes you are correct.
     
    Kreshi likes this.
  5. ColePlusPlus

    ColePlusPlus

    Joined:
    Feb 16, 2016
    Posts:
    7
    Thanks for the information! I guess I wasn't expecting it to be a CPU task. Do you know how this might be affecting a geometry shader? I added a basic geometry that should spawn triangles on every vertex of the terrain but so far it has not worked.
     
  6. Kreshi

    Kreshi

    Joined:
    Jan 12, 2015
    Posts:
    443
    Have you tried to create a triangle for each vertex without the splatmap value to limit where the issue may come from?
    Have you tried your geometry shader on a simple mesh which is not a terrain to make sure it works?
     
  7. ColePlusPlus

    ColePlusPlus

    Joined:
    Feb 16, 2016
    Posts:
    7
    Yes, here's what I've tried so far:

    1.) Spawn a triangle on every vertex, regardless of splatmap value.
    2.) Spawn a single triangle at world position (0, 0, 0)
    3. Created an identical geometry shader to test on regular meshes (which worked)

    My geometry shader uses the same Varyings struct as input that the terrain vertex shader uses as output.