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

Terrain behave like a Array or a List?

Discussion in 'Getting Started' started by tawdry, Aug 22, 2015.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hey
    So question is if I have a terrain of 1000x1000 and 600 height or a terrain of 1000x1000 and 2000 height. And both are just flat with no geometry. Will they take up the same storage area or will the later be more expensive?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not relevant; that's just an arbitrary measurement. Terrains use 16-bit heightmaps for the data.

    --Eric
     
  3. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    How does unity store terrain data does unused height get stored or ignored unless filled I am not sure what your reply means?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    He means they consume a fixed amount of ram regardless of terrain size, and this ram is the 16 bit heightmap.

    Basically YES it will consume ram if you edited it or not.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's no such thing as unused height; every pixel in the heightmap has a height, by definition. Whether it's 0 (the minimum), 65,535 (the maximum), or anything in between, it uses 16 bits. The heightmap values aren't related to the physical size of the terrain.

    --Eric
     
    jhocking likes this.
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    So just to be clear a terrain of 1000x1000x600 height would use 1000x1000x600x (heightmap resolution) x16 bits ram? Does the detail resolution also factor into this calculation?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, the heightmap isn't related to the terrain size; they're entirely separate things. Like if you put a texture on a plane, the resolution of the texture has nothing to do with the size of the plane. Likewise the detail resolution is also completely separate. All of this is in the terrain settings.

    --Eric
     
  8. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Ok so the detail resolution isn't an issue. but how is the height of your terrain not related to its memory size?if a terrain is 1000x1000x 1 height it uses less memory than 1000x1000x 10000 height surely?
    Ok to simplify for this simpleton what is the calculation needed to determine the footprint of a terrain?
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Because pushing a vertex along Y makes no difference to memory consumption. You're just going around in circles learning nothing. I would suggest googling what a height map is, and how it works.

    The memory doesn't come from the mesh of the terrain. The mesh of the terrain is an expression, an interpretation of the heightmap texture, where the true storage is.

    Moved thread to getting started.
     
  10. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Maybe you should read some fundamentals on data types in C and how that information is stored in memory. With that knowledge your initial question should answer itself (with the information that has already been given in this thread) and it will be useful for understanding many memory related things in the future.
     
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I think you guys are being a little harsh. @tawdry is just making an incorrect assumption: he's assuming it's some sort of binary voxel map, dividing space into little cubes along X, Y, and Z. Such an approach would be (somewhat) reasonable if Unity terrains supported caves, holes, bridges, etc.

    But, of course, they don't. Space is divided into little squares in X and Z, but it is not divided in Y; instead what you have is a big look-up table that tells you the terrain height (Y) for any position in the XZ grid. This Y value is conceptually a fraction between 0 (as low as possible) and 1 (as high as possible). That's why it doesn't make any difference what you set the "as high as possible" value to. Whether it's 1 unit high or 1000 units high is just a matter of scaling.

    So, to simplify it: multiply the terrain rows (X divisions) by columns (Z divisions) by 2 bytes. That's the memory footprint of your terrain.
     
    Ryiah and Martin_H like this.
  12. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,965
    It may help to explain how a terrain stores its data in memory. Terrains stored their data in heightmaps which are basically two-dimension grids of integers. Each integer in the grid represents the height of that position in the grid.

    Heightmaps are often stored as actual images and they appear similar to the following grayscale image. If you want to calculate the size of the heightmap, you will need the terrain's heightmap size. Simply click the Terrain, then click the Terrain Settings (right most button), and under "Resolution" is "Heightmap Resolution".

    Heightmaps are always square-shaped, so you simply square the value of the heightmap and then multiply by two to get the number of bytes the heightmap is using. So a value of 513 would result in a heightmap using 526,338 bytes (this is prior to any compression, just in case the engine does it).

     
    JoeStrout likes this.
  13. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hmm i think i finally got this . The height of the terrain is inconsequential as y will use the same amount of ram regardless of height as it will always have a value even if that value is 0. .So terrain is like an array to answer my own question. Facepalm.
    Thx @joe for the "u guys are been a little harsh" comment :D.
     
    Martin_H, Ryiah and JoeStrout like this.
  14. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Sorry, I was just trying to help. Didn't mean to sound harsh.

    And now I'm wondering if and where the generated quads from the terrain are saved. And aren't there optimization steps that the terrain engine does automatically, like having the areas near the camera higher resolution than the areas far away? Wouldn't it make sense if those results would be cached in RAM instead of recalculating them at every frame?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Nowhere, aside from temporarily using RAM.

    Yes.

    They're not recalculated every frame, only when needed.

    --Eric
     
    Martin_H likes this.
  16. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    @Eric5h5: Thanks a lot for the explanation. I might have misread the question. "Storage" hints at the install size while I was thinking RAM is the concern here.