Real world terrain in roblox! (triangle terrain)

Real Terrain

I'm probably never gonna finish my game so heres my resource, For basically FREE!!!

Jiuzhaigou national part, Changhaizi lake, China (PRC) lod=8 Render (NOT FOR REAL GAME)

WARNING: WILL INCREASE GAME LOAD TIME, LAG AND FILESIZE SIGNIFICANTLY


Features

  • Load height data from real earth!
  • Up to around 30 mb of data possible before crashing studio on pasting (On run time though, it should be able to run smoothly still) or 100km by 100km map
  • LOD implemented, increase performance by using differend levels of details
  • Automatically determine material and color based on height and slope.
  • Very high render distance possible, up to 100,000 stud (34.2km)
  • Runs well (30 fps++) even on tablet or phone (17.1km render distance)
  • Test it here China Mountain Driving Simulator - Roblox

Gallary

Images Comparing


This is a full resolution render with no lod, all chunks are rendered at 8 resolution , where as in real game there would be lods, thus faster rendering at the cost of quality (lod levels can be adjusted in the script)

full resolution render with no lod,8 res chunk rendering in Jiuzhaigou national park, China (33.139812,103.869786)


Requirements

Download these if you don't have them
  • Powershell (Windows)
  • QGIS
  • Somewhat powerful PC (Only for setup, A bad phone can still run the game)

Downloading Elevation Data from STRM 30

REMEMBER TO CITE THE SOURCE IN YOUR GAME PROPERLY

Post Processing and Importing to roblox

  • Open the downloaded file and unzip it, you’ll find output… something . TIF file, extract it somewhere easily reacable by command ( For me F: Drive)

  • Press properties and note the resolution (VERY IMPORTATANT) (For me its width 915 by 1831 px)

  • Open QGIS and drag and drop the unzipped TIF file into the main white area

  • Now on the top bar, click Raster > Conversion > Translate

  • Now it should look like this, Open advance parameters > Output datatype and set to int 16


  • Set the output somewhere easy by clicking … and save to file as a .bil file

THE FILE SIZE SHOULD BE BELOW 15,000 KB FOR GOOD PERFORMANCE
  • Now that we have got data.bil, open Powershell and type in
[Convert]::ToBase64String([IO.File]::ReadAllBytes("F:\data.bil")) | Set-Content "F:\base64_output.txt"

Change the path as appropiate. then enter and wait for it to finish

  • Open the file in notepad, and turn it into a module script by adding
local bob = [[

at the start and

]]
return bob

at the end and remember to not leave any space between the [[ and the data output, or else it might break

  • Go ahead and copy the entire thing and paste into a module script in roblox studio, wait for it to finish then quickly close the script window, AND DONOT OPEN IT AGAIN, ITLL TAKE VERY LONG TO LOAD AND CLOSE , then move the module script to replicated storage

Implementing

  • Download Splines.rbxm (34.2 KB) and place it in replicatedfirst (this is implemented for my game, If theres any undefinded things, or error, reply here or just delete them)

  • Download base64.lua (2.4 KB) and place in replicated storage

  • Open chunks module and you’ll see this

local module = {}

--[[
	STEP 1: CONFIGURE YOUR TERRAIN DATA
]]
local chunkVerticalBounds = {}
local DATA_CONFIG = {
	-- Dimensions of your raster image from QGIS (in pixels)
	Width = 2502, 
	Height = 3233,

	-- The real-world coordinates of your data from met.txt
	MinLon = 103.47061157226562,
	MaxLon = 104.16549682617188,
	MinLat = 32.575242677692542,
	MaxLat = 33.47333455036764,

	-- The latitude and longitude you wa33.041825,103.932972nt at the center of your map (0, 0, 0) in Roblox
	CenterLatLon = Vector2.new(33.0434771,103.9313511),--Vector2.new(32.8036653,103.6428384), -- {Lat, Lon}
	-- Real-world resolution of the data in meters/pixel (SRTM GL1 is ~30m)
	METERS_PER_PIXEL = 30 
}

Change the width and heigh to the width and heigh of the image that you’ve remembered, the MinLon to Xmin MinLat to Ymin and so on that you’ve saved. Change the CenterLatLon to the coordinate at the center of your map (Can Be anywhere in the range)

--[[ DATA LOADING AND INITIALIZATION ]]
--------------------------------------------------------------------------------
local tdata = require(script.Parent.TerrainData)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ReplicatedStorage")
local Base64 = require(ReplicatedStorage.base64)
local encodedData = require( ServerStorage:WaitForChild("Jiuzhai2"))
local elevationDataString = Base64.decode(encodedData)
local stitchesFolder = workspace:FindFirstChild("TerrainStitches") or Instance.new("Folder", workspace)
stitchesFolder.Name = "TerrainStitches"

Change the “Jiuzhai2” to the actual name of your module script
Then its officially finished!! Now press play and the game will freeze roughly 5 times and then the terrail will start loading, remember to reduce fog to 0.15, and look above your head, The terrain is realscale, so for high area, it might even appear at 15k stud above spawn!!


Bugs

  • It should work, there are still some unresolved bug like LOD not deleting, chunk not updating, most of these minor bugs, If you happen to see any bugs in my code, feel free to inquire and post so that I can improve the resource
  • Terrain stitchs : they will sometime appear dark, This is due to roblox’s not allowing custom normal which would fix it, as heigh between different lod mismatch in steep area
  • Lag : Decrease render distance and change LOD function in the Spline.lua main script, as the current render distance of 55 chunks (56,320 studs) may be overkill for your usecase

Limitations

  • Chunk render distance is currently should be maxed out at 55, or 17.1 km, Roblox cap render distance at 100,000 stud, Or 100 ish chunks or 34 ish km
  • You can change the LOD inside the script, though the max resolution of the data is 30 meters, so increasing max lod beyond 2^4 or 16 is pretty pointless, unless you add some noise
  • Loading inside game will take long, less than a minute but enough to be a problem IF you insta load the terrain, as it might error as some modules might not finished loading when called, so PLEASE LOAD WHEN PLAYER PRESS PLAY, NOT ON JOIN
  • No water, lakes, or foliage support yet

Attribution

  • Attribute my name in the description of your game (If you use the spline.rbxm, otherwise no credit needed)
  • Attribute the data from opentopo properly too!
23 Likes

QGIS has Linux support, tutorial for Linux soon, or maybe describe what’s happening?

Okay, so what that powershell command job is to turn our binary height data into base64 text, that can be inputted into roblox, without linebreaks, so the equivalent in linux would be

base64 -w 0 /path/to/data.bil > /path/to/base64_output.txt