Search Unity

How to add tessellation shader to unlit shader?

Discussion in 'Shaders' started by TheCelt, Sep 1, 2019.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    I have the following declarations in my unlit shader:

    Code (CSharp):
    1.             CGPROGRAM
    2.             #pragma vertex vert
    3.             #pragma fragment frag
    4.             #pragma tessellate:tessDistance
    5.             #pragma target 4.6
    6.             // make fog work
    7.             #pragma multi_compile_fog
    8.             #include "Tessellation.cginc"
    9.             #include "UnityCG.cginc"
    And then i have for my tessellation shader:


    Code (CSharp):
    1.             float4 tessDistance (appdata v0, appdata v1, appdata v2) {
    2.                 float minDist = 100.0;
    3.                 float maxDist = 200.0;
    4.                 return UnityDistanceBasedTess(v0.vertex, v1.vertex, v2.vertex, minDist, maxDist, _Tess);
    5.             }
    But it doesn't work for me. However if i use a standard shader it works fine. What am i missing in regards to my unlit shader to get it to work ? Thanks.
     
  2. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    992
    BUMP: Anyone know the solution to this?

    Is it possible to use "UnityDistanceBasedTess" in a Unlit shader?
     
  3. Wayward_Studios

    Wayward_Studios

    Joined:
    Dec 15, 2018
    Posts:
    23
    merpheus and zezba9000 like this.
  4. AlphaSilverback

    AlphaSilverback

    Joined:
    Aug 18, 2016
    Posts:
    10
    You can have a distance based tessellation in an unlit shader, but you need to build it yourself. If you look at the graphics pipeline for hlsl, you'll see the tessellation stage is controlled by a hull shader and a domain shader.


    It's not as bad as it sounds, because unity does the heavy lifting for you.
    If you really want to know step by step what to do, I'd recommend this tutorial by catlikecoding.

    It's a little difficult to follow, because she builds on top of her older tutorials, but you can download her projects and see how everything works.

    Here is a thread about a shader I made using both tessellation stage, geometry stage, and a shadow caster pass: LINK


    upload_2021-11-27_22-24-8.png