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

Unity Terrain high performance Impact

Discussion in 'General Graphics' started by deraggi, Jan 6, 2017.

  1. deraggi

    deraggi

    Joined:
    Apr 29, 2016
    Posts:
    88
    Dear Unity Community,

    I'm using a Unity Terrain in our game. Granted I do not have much experience with it, however I did follow the guides I could find in order to set it up.

    This game is scoped as a PC VR experience.

    This is a simple scene with Low-Poly Objects, however on my mid-end PC I get between 60 and 90 FPS

    With_Terrain.png

    When I disable drawing of the terrain or the directional light, FPS are much higher and more consistent.
    Just to avoid confustion: The crops that appear in the screenshot below are from the skybox

    Without_Terrain.png

    The Terrain is not very large - here are my settings:

    Settings.png

    For me it's hard to understand how such a simple terrain can have such a huge performance impact when other games use terrains that are much larger.

    Any help is much appreciated!
     
  2. SirDevin

    SirDevin

    Joined:
    Oct 10, 2014
    Posts:
    30
    It's hard for me to see this either, the only possible performance impact I could think of is shadows being draw on the terrain. The shadow casters remain true for both scenes, but in the second scene there is no terrain to receive the shadows.
     
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    There are a few reasons I can think of:

    Unity Terrain uses a traditional splat mapping technique with a control texture to store the splat mapping data. Every four terrain textures you use it draws the entire terrain a second time. Every additional (real, not approximated) light doubles the number of passes required, since Unity uses multi-pass lighting.

    Each pass samples the control texture, then samples each terrain texture (4 per pass). So if you have diffuse + normals this is 9 texture samples per pass. If you have 8 textures and two lights, you draw the mesh 4 times and do 9 texture samples per pass. This adds up quick, especially in VR, and doesn't include things like the shadow pass (which is actually much cheaper since it doesn't need to sample textures).

    I don't believe only using one texture, for instance, removes those samples; it still samples all the textures even if you don't use them. I've also noticed that Unity Terrains just render slow compared to meshes, though I'm not entirely sure of all the reasons (since it's just a mesh at the end of the day)

    You can optimize this by writing your own shaders. For instance, my terrain texturing system on the asset store (which is not really focused on VR but rather high end visuals, though some people are actually using it for VR) allows you to pack normal, smoothness, and ambient occlusion into one texture, saving you the extra texture for the specular term while still giving you a full PBR surface.

    You could do things like calculate a known number of lights in a shader, preventing the need for multiple lighting passes if you need multiple lights. Or if your lighting is static, do a MatCap style shader and remove most of the lighting calculations all together. The terrain system we use at work (runs on super low end mobile) packs the luminance for four terrain textures in a single RGBA texture, then packs the chroma values for color into the vertices and recombines them in the shader (luminance resolution is very important, chroma not so much). This gives a four texture splat mapping style shader with 1 sample per pixel, plus 1 sample for a noise texture, which is unbelievably cheap. There's a lot of options if you write shaders, basically..
     
    DevIsDave likes this.
  4. DevIsDave

    DevIsDave

    Joined:
    Aug 8, 2017
    Posts:
    19
    I know this is an old post, but I'm wondering if this texture count includes normal maps. So if I have 4 textures in my terrain, and each one has a normal map also, does that count as 8 textures and thus 2 draws for the terrain?

    Thanks.
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    no, it's per set of textures.
     
    DevIsDave likes this.
  6. DevIsDave

    DevIsDave

    Joined:
    Aug 8, 2017
    Posts:
    19
    Perfect, thanks!