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

Custom domain/hull shader in a surface shader

Discussion in 'Shaders' started by jesta, Jun 6, 2013.

  1. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    293
    Is it possible to define custom domain/hull shaders for surface shaders, the same way we can define custom vertex shaders?

    Thanks!
     
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    When using default tessellation, the vertex function will be called from the domain shader, instead of from the vertex shader. This is also why that function doesn't quite accept as many arguments as the normal vertex function.

    Other than that, I think you'll have to switch to classic shaders to take control over the the hull and domain shader while still having the vertex function called from the vertex shader. (#pragma vertex [name], #pragma hull [name], #pragma domain [name], etc)
     
  3. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    293
    So, with the default tessellation, the vertex function is actually the domain shader (takes place after the tessellator)? If yes, that's good news because I only need to modify the tessellated vertices (my actual vertex shader would be pass-through).
     
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Yep, pretty much.

    To be more precise, the vertex function isn't the domain shader, it's just called from the domain shader. You can use #pragma debug to have the processed but uncompiled code show up in the compiled shader, to see exactly where it is called.

    After your custom function is called, it does all the work it would usually do in the vertex shader.
     
  5. jesta

    jesta

    Joined:
    Jun 19, 2010
    Posts:
    293
    That explains all the confusion I had with vertex function parameters when using the default tessellation. Thanks a lot RC!