Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Default tesselation with SV_VertexID Semantic

Discussion in 'Shaders' started by natesb, Jul 11, 2018.

  1. natesb

    natesb

    Joined:
    Aug 26, 2017
    Posts:
    25
    Hi,

    I was wondering if it is possible at all to use a standard surface shader/ Tesselation shader and use the SV_VertexID semantic at the same time?

    The reason I am doing this is that I am using a dummy mesh to inject procedural geometry into the Unity lighting pipeline. Now I would like to add a tesselation stage to add more detail to my instanced meshes.

    However it seems that since the vertex program is executed from the domain stage per

    https://forum.unity.com/threads/custom-domain-hull-shader-in-a-surface-shader.185238/
    and
    https://docs.unity3d.com/Manual/SL-SurfaceShaderTessellation.html

    So I am wondering if there is any way to modify a vertex BEFORE the tesselation stage, so that I could build my procedural geometry, then have that geometry be tesselated.

    Seems like it might be a limitation currently, but hoping someone might know a workaround?

    Thanks
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    5,093
    Uh ... that forum post ... that's not quite right.

    The vertex stage is wholly separate from the domain stage. They even occur at completely different ends of the pipeline. The reason for confusion is in a Surface Shader you can define a custom vertex function ... or rather a function that modifies the vertex data during the vertex stage. However when tessellation is enabled that custom "vertex" function gets called during the domain stage instead of the vertex stage allowing you to modify the post-tessellated geometry.

    To get the SV_VertexID, that has to happen in the vertex stage, and explicitly define it as an input into the main function. This is not possible with Surface Shaders as you cannot modify the main vertex function's input, even with out tessellation. The only option is to use a vertex fragment shader. The good news is you can still use a Surface Shader to generate the vertex fragment shader code to start from so you don't need to write it all from scratch ... the bad news is Surface Shaders generate really ugly code.
     
  3. natesb

    natesb

    Joined:
    Aug 26, 2017
    Posts:
    25
    That's not entirely true either... I'm able to use a custom appdata struct with SV_VertexID as inout to the vertex stage with a standard surface shader. It is just when I add the tesselation stage, it complains that it is not a valid input/output semantic for Hull/Domain, so I take this to mean that without tesselation, Unity wires it up correctly, however when the tesselation stage is added, it routes the inputs and outputs in a way that I don't fully understand...

    I don't think what I am trying to do is possible, just wanted to share that it IS possible to get SV_VertexID as an input to a vertex program with a standard shader, for posterity.
     
    bgolus likes this.