Ooops
January 15, 2021, 05:43:20 PM

Author Topic: [bb] Swift Terrain System by sswift [ 1+ years ago ]  (Read 650 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Swift Terrain System by sswift [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Swift Terrain System
Author : sswift
Posted : 1+ years ago

Description : <a href="http://lightning.prohosting.com/~sswift/swift-terrain-system.zip" target="_blank">http://lightning.prohosting.com/~sswift/swift-terrain-system.zip[/url]

This is a demo of my terrain system, which you can license for use in your games.

The terrain system constructs it's terrains out of a series of tiles, each which is a discreet mesh which can have it's own texture.  For each tile, you can flip the texture so that you can dramatically reduce the number of textures you need.  You can also apply a lightmap seprately from the textures which is stretched over the entire terrain.

The system manages the level of detail at each tile replacing them with lower detail meshes as the tile receeds into the distance.  This allows very long view distances with high levels of detail, while maintaining a polygon count of between 10,000 to 50,000 polys per frame.  You can change parameters to decide where you want the detail to be, what kind of view distance you want, and you can even change the mesh detail on the fly in your game to a lower detail level instantly.

You should be aware that currently there can be cracking between tiles.  You can reduce the visiblity of this if you use a dark background for the lower half of the sky, or if you, like in my demo, move the distant tiles downward slightly.  Also, there will be visible popping of new tiles in the distance if the fog is not heavy enough to cover them up completely, or if you do not scale them vertically like I have also done in the demo.  This scaling and moving of tiles  which I do in the demo comes at the cost of potentially causing distant objects to appear to float above the terrain.  If your game has lots of flying enemies, this will not be a problem, and you can also use autofade to fade distant enemies out before they start to visiblity float above the ground which you should probably do anyway to avoid haivng too many enemies visible at once.  But the option is there to remove that scaling and motion if you need to.  Eventually I may come up with a way to seal the cracks between tiles, and if you buy a commercial license and need me to do that I'll certainly give it another shot, but it's not easy to do!

It is $10 for shareware/freeware use, and $100 for commercial use.  Both are licenses for an unlimited number of games.

To purchase it, simply go to www.paypal.com and send payment to sswift@....  If you have any questions you may email me at that address.  Upon receiving the confirmation email from paypal, I'll send you the source code right away!


Code :
Code: BlitzBasic
  1. Here is a sample of the start of the source code for the terrain system so you can see how much it's commented, and how many rendering options it has.
  2.  
  3.  
  4. ; -------------------------------------------------------------------------------------------------------------------
  5. ; Swift Terrain System:  Copyright 2002 - Shawn C. Swift
  6. ; -------------------------------------------------------------------------------------------------------------------
  7.  
  8. Const TERRAIN_TILES_X = 16                                                                              ; These values adjust the number of tiles across and down on the terrain.   If you try to create a terrain with too many tiles, Blitz will crash.  The number of tiles you can create depends on the max subdivision per tile.
  9. Const TERRAIN_TILES_Z = 16                                          ; If you want a larger terrain without adding more tiles, you can increase TERRAIN_TILE_SCALE_XZ#.  That will increase the size of the individual tiles.
  10.  
  11. Global TERRAIN_TILE_SCALE_XZ# = 64.0                                                    ; This is how wide/long each terrain tile is.  Increasing this value will stretch the textures out more, but give you a higher view distance.
  12.                                                                                                                                 ; The default settings for this is 128, and that combined with the other default settings gives you a view distance of 1 kilometer.
  13.  
  14. Global TERRAIN_TILE_SCALE_Y#  = 64.0                                                    ; This is the height scaling for the heightmaps.  The larger you make this value, the taller your mountains will be,
  15.                                                                                                                                 ; but because of the limitations of having only 256 shades of grey in an 8-bit image, you can only have 256 diffrent heights.
  16.                                                                                                                                 ; So the larger you make this value, the bigger the smallest change in height you can represent with a heightmap.
  17.  
  18. Const MAX_TERRAIN_SUBDIVISION   = 32                                                    ; This is the highest detail the terrain can be.  Must be a power of 2.
  19. Const MIN_TERRAIN_SUBDIVISION   = 2                                                             ; This is the lowest detail the terrain can be.  Also must be a power of 2.
  20. Const TERRAIN_DETAIL_LEVELS             = 5                                                             ; This is the number of detail levels the terrain has between MIN_TERRAIN_SUBDIVISION and MAX_TERRAIN_SUBDIVISION.  Between 2 and 32 for example, there are 5:  2, 4, 8, 16, and 32.  You MUST update this if you change MIN_TERRAIN_SUBDIVISION or MAX_TERRAIN_SUBDIVISION!
  21.  
  22. Const SKIP_SMOOTHING = True                                                                     ; Setting this to true will make heightmap calculation go faster, but the terrains will have more jagged edges.
  23.  
  24.  
  25. Global TERRAIN_NEAR_DETAIL_CLAMP = 0                                                    ; This is the highest detail level shown up close.  This variable allows you to you clamp the near detail without changing the highest detail which can be used in your game.
  26.                                                                                                                                 ; For example, if you use a max subdivision size of 32, and you want your game to run on slower PC's with a lower detail level, you can set this to 1 in your game at
  27.                                                                                                                                 ; any time, and the detail level shown up close would drop down to a subdivision of 16, and the game would run significantly faster.  
  28.  
  29.  
  30. Global TERRAIN_NEAR_DETAIL_DIST# = TERRAIN_TILE_SCALE_XZ#*4.0   ; This is the distance at which the second level of detail first kicks in.  It's a bit tricky to find a good value for this, but for most tile sizes,
  31.                                                                                                                                 ; TERRAIN_TILE_SCALE_XZ#*3.0 and TERRAIN_TILE_SCALE_XZ#*4.0 seem to work well.  Values smaller than these tend to show too much popping and reveal seams between the tiles.
  32.                                                                                                                                 ; Values larger than these tend to increase the polygon count far to much.  You should probably leave this at TERRAIN_TILE_SCALE_XZ#*4.0 if you use the other default terrain settings.
  33.  
  34. Global MAX_TILES_IN_VIEW = 8                                                                    ; This is roughly the maximum number of tiles which will be drawn into the distance from the camera.  This value is sort of like a far clipping plane, but more useful,
  35.                                                                                                                                 ; because more important than the distance which you can see, is the number of tiles which are in view.  You can change the scale of the terrain and not change the number
  36.                                                                                                                                 ; of tiles in view.  But if you change the number of levels of detail you can have, or increase the distance at which the first level of detail goes out to, you could
  37.                                                                                                                                 ; easily kill the framerate.  This gives you control over the number of tiles which are drawn, but you should probably never need to change this from it's default value,
  38.                                                                                                                                 ; unless you want a smaller view distance and a slightly higher speed.
  39.  
  40.  
  41. Global TERRAIN_SCALE# = Float(TERRAIN_TILES_X) * TERRAIN_TILE_SCALE_XZ#         ; This is the total width of the entire terrain.
  42.  
  43.  
  44. Type TerrainTile
  45.  
  46.         Field Current_Detail_Level
  47.  
  48.         Field TileHeightmap.Heightmap           ; The heightmap which this terrain tile uses.
  49.                                                                                 ; More than one tile may use the same heightmap.
  50.  
  51.         Field Mesh[TERRAIN_DETAIL_LEVELS]       ; This is a list of pointers to the entities which represent each detail level of this
  52.                                                                                 ; terrain tile.  The detail levels are 64, 32, 16, 8, 4, and 2.
  53.                                                                                
  54. End Type
  55.  
  56.  
  57. Type Heightmap
  58.  
  59.         ; If you adjust the number of detail levels, you must adjust this value.
  60.         ; You have to add one to each detail level, then square the value, and add all the detail levels together.
  61.         ; Ie, If you have three detail levels, 16, 8, and 4, then you would add (16+1)^2, (8+1)^2, and (4+1)^2.
  62.         Field Height#[33*33 + 17*17 + 9*9 + 5*5 + 3*3]
  63.                                
  64. End Type       
  65.  
  66.  
  67. ; These arrays hold the data for each tile of the terrain.
  68. Dim Terrain_Tile.TerrainTile(TERRAIN_TILES_X, TERRAIN_TILES_Z)
  69. Dim Terrain_Tile_Brush(TERRAIN_TILES_X, TERRAIN_TILES_Z)                        ; This is a list of which brushes go with which tiles.  These are not brush handles, they're indexes into the Brush_List() array.
  70. Dim Terrain_Tile_Rotate(TERRAIN_TILES_X, TERRAIN_TILES_Z)                       ; 0 = Normal  :  1 = 90 :  2 = 180  :  3 = 270
  71.  
  72.  
  73. ; This is the number of brushes which you are using on the terrain.
  74. ; You should set this to the exact number of brushes you have set up.
  75. Const TOTAL_TERRAIN_BRUSHES = 7
  76.  
  77.  
  78. ; This is a list of all the brushes used to paint the terrain.
  79. ; You should fill this array with handles to all the brushes you want to use after you create them.
  80. Dim Terrain_Brush_List(TOTAL_TERRAIN_BRUSHES)


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal