Search Issue Tracker

Duplicate

Votes

2

Found in

2018.4

2019.1

2019.3

2020.1

2020.1.0a13

Issue ID

1198997

Regression

No

Tessellation/surface shaders are throwing graphical artifacts when Terrain instancing is enabled

Terrain

-

How to reproduce:
1. Open attached project "case_1198997-REPRO.zip"
2. Open Terrain scene
3. Select Terrain Game object
4. Open Inspector window
5. Open Terrain Component settings
6. Tick Draw Instanced

Expected result: Terrain is visible
Actual result: Terrains isn't rendered

Reproducible with: 2018.4.17f1, 2019.3.2f1, 2020.1.0a23
Not tested with: 2017.4.37f1 (no instancing)

  1. Resolution Note (2020.2.X):

    I'm going to close this one as a duplicate (since the attached scenes demonstrates a problem caused by missing pragmas which is misleading). I've reopened https://fogbugz.unity3d.com/f/cases/1111579/ and will track the real problem through the other bug

    It looks like the MicroSplat tessellation shader is missing the instancing option pragmas defined. Using the same instancing options from the Example_Base shader seems to fix the Example_Tessellation_Base shader:

    #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd

Comments (3)

  1. jeanphilippe_unity297

    Aug 28, 2020 13:01

    Hi Jason, I wonder if there's two entangled issues here. The scenario I looked at yesterday definitely seemed to have missing pragmas in the generated shader:

    (emailed you the link of what I'm seeing since I can't seem to share google drive links here)

    Am I debugging the wrong thing? What am I missing here?

  2. JasonBooth

    Aug 27, 2020 14:46

    So I think I have some more info on this issue:

    - The fix in this answer is most definitely incorrect. The shader has the pragmas.
    - I originally filed a bug on this not working when instancing shipped. At the time, it threw an error about not having the instance ID in one of the shader stages. This bug was resolved as fixed in a future version of Unity, so I waited a few months for that to be released and retested. However, when I could repro in that version, the terrain was still transparent, but the bug was closed anyway since the error was no longer thrown.

    When tessellation is enabled, the shader uses a different vertex function - which does not contain the terrain instancing code. However, when adding that code (or calling the regular vertex function), it still does not work correctly- the quad close to the camera works correctly, but the others do not draw.

    Note that the surface shader only uses a single 'vertex' function, which is called after the vertex has been tessellated. In reality, there are two functions in the resulting shader - one in which the regular vertex is transformed, and one in which the tessellated vertex is displaced. But the current surface shader system only lets you write the second one. So doing everything here would be wasteful and slow- but let's put that aside for now.

    A simple way to repro this:

    Change the #pragma from:

    #pragma surface surf Standard vertex:disp tessellate:TessDistance fullforwardshadows addshadow

    to

    #pragma surface surf Standard vertex:vert tessellate:TessDistance fullforwardshadows addshadow

    This will call the original vertex function which does the terrain instancing code. Note that with instancing on, you still have disappearing quads, but if you zoom very close to one it will correctly display. Note that this pathway simply tessellates the mesh and does not do the actual displacement - if you want that, you have to add:

    #if _TESSDISTANCE
    i.vertex.xyz += OffsetVertex(i.vertex, i.normal, i.tangent, i.texcoord);
    #endif

    to the bottom of the vert function.

  3. JasonBooth

    Aug 27, 2020 13:52

    This is easily verifiable as incorrect. If you open the shader file, you will see the pragma's are added to both the tessellation and base shaders:

    #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.