Mods / Algernon's Terrain Sampler Lib
- Tags:
- Author:
- Algernon
- Side:
- Both
- Created:
- Mar 25th at 11:15 AM
- Last modified:
- Apr 27th at 9:19 AM
- Downloads:
- 5970
- Follow Unfollow 225
-
Latest release (for Vintage Story 1.22.0, potentially outdated):
algernonsterrainsampler_1.2.1.zip 1-click install
A simple tool for efficiently getting the generated terrain's height anywhere in the world.
Even if the chunk hasn't been created or even loaded yet, this still works. You could sample 2 billion blocks away as long as it's within the world boundary.
Use /terrainsampler columnheight ingame to test it out.
To get this function working in your mod, reflect this mod's assembly, then reflect sampleHeight as shown here:
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
Type modType = assembly.GetType("AlgernonsTerrainSampler.TerrainSamplerMod");
if (modType == null)
continue;
PropertyInfo instanceProperty = modType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static);
MethodInfo getHeightMethod = modType.GetMethod("GetBlockColumnHeight", BindingFlags.Public | BindingFlags.Instance, null, [typeof(int), typeof(int)], null);
if (instanceProperty == null || getHeightMethod == null)
break;
object instance = instanceProperty.GetValue(null);
int sampleHeight(int blockX, int blockZ) => (int)getHeightMethod.Invoke(instance, [blockX, blockZ]);
Then give the height sampler delegate (sampleHeight) to your code that uses terrain height samples.
The terrain generation usually changes every major update, so don't use this on a different major version than the one it's made for.
This tool was made to help Farseer and the other two LOD mods in development, but you could use it for a lot of different things.
Originally, this came from the Watersheds mod. Terrain sampling is the core foundation of what enabled me to create terrain-respecting streams.
Here are some mod ideas you could make from terrain sampling:
- Terrain erosion effects
- Rain shadows
- Realistic wind flows
- Very long roads that respect the terrain, maybe between story structures
- Very long pathfinding routes, maybe for animal herds or trader routes
- Rivers and streams
- Realistic pond, lake, and spring placement
- Realistic snow depths (unsheltered areas have less snow, sheltered has more snow)
- Realistic fog areas (in sheltered areas)
- Groundwater and aquifers (a basic groundwater system is in Watersheds)
- Strategic/believable placement of ruins/structures/villages
| Mod Version | Mod Identifier | For Game version | Downloads | Released | Changelog | Download | 1-click mod install* |
|---|---|---|---|---|---|---|---|
| 1.2.1 | algernonsterrainsampler | 5357 | Apr 27th at 9:19 AM | algernonsterrainsampler_1.2.1.zip | 1-click install | ||
|
Fix an intermittent case where this isn't compatible with watersheds | |||||||
| 1.2.0 | algernonsterrainsampler | 539 | Apr 15th at 8:01 PM | algernonsterrainsampler_1.2.0.zip | 1-click install | ||
|
update to 1.22 rc8 | |||||||
| 1.0.1 | algernonsterrainsampler | 74 | Mar 26th at 12:05 PM | Empty | algernonsterrainsampler_1.0.1.zip | 1-click install | |
| 1.0.0 | algernonsterrainsampler | 0 | Mar 26th at 11:18 AM | Release Retracted | |||
Retraction Reason:One last change Changelog: | |||||||
Now open source at https://github.com/Algernon733/AlgernonsTerrainSampler
What's the time complexity of this tool? Playing around with it, it seems to drastically slow when sampling outside of nearby chunks, but it could also be my implementation.
Every sample should take around 1-2ms each on average
Theres no time/space scaling, but it has to generate the region maps before sampling within that region. So the first sample on a fresh region is slower
Also im open sourcing it today so you'll be able to check it out
Seeing the source has helped, thank you! I wonder if it would be worth implementing a method that just samples straight from the terrain noise, without evaluating each region alongside upheaval and ocean noise. That would allow for rapidly generating visualisations of generated worlds across large resolutions. As it is, the region map generation is a pretty big bottleneck (though a necessary one with the current implementation).
Upheaval and ocean noise both have very large impacts on the terrain shape, unless you have 0% upheaval and no oceans, same with the other maps, except maybe the geo map.
There's definitely room to optimise the region map generation for the sampler if you want to add your own GetBlockColumnHeight method variant to it.
You could put stopwatch profiling around each region map's generation to find the bottleneck, then edit the slow region map's scale to be lower resolution, hot reload it in, then check how much the terrain deviates or at all with a cheaper lower res. Or you could try get into the algebra and optimise the actual region noise.
Algernon
I have added support for this to Fast Map v5 experimental to pregenerate map tiles.
It's pretty insane. Very nice lib you've put together here.
https://mods.vintagestory.at/show/mod/48907
holy shit
This will completely change the game
Actually mindblowing to see after playing hundreds of hours playing with the normal map
Is this mod drop in compatible with farseer to see improvements? Or do I need to alter some files to make it work?
Just enable this mod and it'l make Farseer faster and more stable
Oh man, I am so glad you pointed this out to me on the other post :) Thanks a ton!
How did I not find this mod before now?
I'm using Farseer and was struggling with random 1 second lockups when exploring.
After installing this, it's just butter smooth! 😄
Thank you so much!
Yeah it tripped me out the first time I loaded in the game after I hooked farseer into this, multiplied by the fact it just worked first try
This is amazing for inspecting different landform generator mods with farseer and see how the terrain will look like on a large scale.
Here is a world with these mods: 512 World Height Landforms 128 Sea Level Fork + Continental World.
Settings are: Landocver 30%, Landcover scale 200%, Upheaval 0%, Landform scale 300%, 512 height world with sea level at 128, 1st screenshot taken on y=1000, farseer distance on 16384. 2nd is at y=130.
Crazy to say I never thought about testing worldgen like that
Definitely using Farseer to get my Continental World.settings right for our next playthrough
Sparkplug04 JerreyRough Mr_Cookie13
Should be fixed with the newest updates on watersheds and my terrain sampler
Algernon Thanks for the update! Good to see it's working now, though now that I know it is baked into Watersheds, I guess it is redundant when used together.
Thanks for the awesome mod! I love the performance increase in Farseer
There's an error in Watersheds in the client-main when both are enabled. The world still loads but idk if this will stop watersheds from working?
Appreciate the log, i'll figure this out
CG23Sailor Sparkplug04 Mr_Cookie13 Haven't looked at this lib in awhile. There's been some updates to watersheds since then, so now its getting used I'll try make sure they're working together again today
Edit: works for me with watersheds 6.0.5
Sparkplug04 just tested it with Watersheds it's incompatible.
Adding to that question from Sailor, this isn't incompatible with Watersheds, right? Or would it be redundant?
The wording has me confused.
I just came here after seeing the update to farseer.
You say here that this originally comes from your watershed mod, which I have.
I came here to get this for farseer, but do I need to if I have Watershed?
You still need the terrain sampler even if you have watersheds
I don't know why, but Rider prompts that `"TerrainSamplerMod.Instance" is only supported on "Windows" version 7.0 and above.`
However, since this feature can only be used on the server side, it cannot replace `BlockAccessor.GetRainMapHeightAt` when adding path points on the minimap, as the latter is purely client-side.
Unlucky. Yeah the client only knows about already loaded worldgen, the server deals with unloaded/ungenerated worldgen
You could still query the server to do the calculation for you though
Wait, is `AlgernonsTerrainSampler.TerrainSamplerMod.Instance.GetBlockColumnHeight` only available on Windows and the server side?
Don't know why this would be windows-only, its all normal .NET code, no extra libraries used
Worldgen is serverside so this worldgen sampling has to be on the server. If you want clients to get the samples, you have to have the clients ask the server to do the sampling
Can this replace `BlockAccessor.GetRainMapHeightAt`? When adding waypoints on the minimap, the original game uses `BlockAccessor.GetRainMapHeightAt` to obtain the y-coordinate at the mouse position, but it fails to correctly retrieve the y-coordinate for unloaded or already unloaded chunks.
Pretty sure things like trees and bushes impact the rain height map, so you can't check a single coordinate in isolation to get it perfect
As a fallback for unloaded/ungenerated chunks, the next best thing you could do is first use this sampler to get the terrain height, then clamp to min sealevel. You won't get the accurate rainmap height where theres ponds bushes and trees, but it will still follow the sea/ocean and terrain.
SiiMeR Could even get colours if you sample the climate map as well
You could actually make a mapgenerator preview from this that shows the general world shape if you combine it with the sea height