Search Unity

Question Getting the Phong Tessellation Example of the Unity Docs to work

Discussion in 'Shaders' started by LeGoof, Jun 4, 2021.

  1. LeGoof

    LeGoof

    Joined:
    Jun 6, 2015
    Posts:
    8
    Hello,

    I am having trouble getting the Phong Tessellation Shader example from this Unity Docs article to work:
    https://docs.unity3d.com/2019.4/Documentation/Manual/SL-SurfaceShaderTessellation.html

    The tessellation works fine, new vertices and edges are being created (see attached screenshot). However, I would expect surface detail to increase (the cube becoming more round, eventually being shaped more and more like a sphere), like shown in the screenshot of the above mentioned doc article. This is not happening to me, changing the Phong Strength does not seem to have any effect at all.

    I used exactly the code of the article without any modifications. Unity versions do also match.

    What am I doing wrong?
    Screenshot 2021-06-04 at 12.27.35.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Nothing. What you're seeing is the expected result of using tessellation on a cube.

    Real time tessellation can smooth out low polygon, but still smooth geometry, but won't, and can't do anything to already hard edges. Phong tessellation is using the interpolated vertex normals to round the tessellated surface. But the interpolated normals for a cube are flat, there's nothing to "round".

    Understand that phong tessellation isn't spherifying anything, it has no effect on the mesh's original normals. If you want to turn a cube into a sphere, you can, and tessellation can help, but you need to write a shader that manually overrides the vertex normals to do so. For example if you modify the example Phong tessellation shader's
    dispNone
    function to look like this:
    Code (csharp):
    1. void dispNone (inout appdata v)
    2. {
    3.     float3 sphere = normalize(v.vertex.xyz);
    4.     float factor = _SinTime.z * 0.5 + 0.5;
    5.     v.normal = lerp(v.normal, sphere, factor);
    6.     v.vertex.xyz = lerp(v.vertex.xyz, sphere * 0.86, factor);
    7. }
    But then the phone tessellation isn't really doing any of the work as the
    vertex:
    function gets called after tessellation, and any tessellation method would produce roughly the same result here. And it's still probably not doing exactly what you're wanting, as it won't smooth out the corners until it's fully a sphere.
    upload_2021-6-4_10-11-57.png
     
  3. LeGoof

    LeGoof

    Joined:
    Jun 6, 2015
    Posts:
    8
    Thank you so much for your reply! It seems I had a wrong understanding of what it actually does.

    However, what is going on in the screenshot (https://docs.unity3d.com/2019.4/Documentation/uploads/Main/SurfaceShaderPhongTess.jpg) of the doc article then?

    You can definitely see rounded edges, so some kind of normal interpolation must have happened, right?

    I have tried to apply the same shader to low-poly deer model to smoothen it out, but as with the cube, it does not seem to have any effect on the surface detail whatsoever:

    deershadertest.png

    So what would be a scenario where the Phong Strength would actually have an effect?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    The example mesh's normals are smooth. So the phong tessellation is smooth.

    Your mesh's normals aren't smooth, so the tessellation isn't either.