[MOD] Interesting Terrains [WIP]

Show off your mod creations or just a work in progress.
Post Reply
monobelisk
Posts: 75
Joined: Tue Aug 25, 2020 10:43 am

[MOD] Interesting Terrains [WIP]

Post by monobelisk »

Image
Interesting Terrains

This mod has been discontinued but has been picked up by Freak2121 and transformed into Interesting Eroded Terrain.

Current version: 0.5.2
Supported DFUnity version: 0.10.27
Old Nexus page: Interesting Terrains
Nexus page: Interesting Eroded Terrain
Source code: Interesting Terrains on GitHub

Known issues
Until this mod reaches v. 1.0.0, issues are to be expected. As issues are found, either by myself or the community, they're listed in this section. Unless otherwise noted, the intention is that the issues are fixed in the next release.
  • Unintended terrain appearing around the player's ships
Description
A mod that aims to make the landscape of Daggerfall Unity more interesting by procedurally adding geological features such as mountains, cliffs, and dunes to the existing terrain heightmaps at appropriate places in the world.

Image

Currently, these landscape types are featured (though more may be added in the future):
  • Swiss Mountains (alpine-style fold mountains, for the densest mountain areas)
  • Jordan Mountains ("regular"-style mountains - varies between fold and fault types, and is repurposed for hills)
  • IQ Mountains (sparsely placed fold mountains for non-mountainous areas - invented by math genius Inigo Quilez)
  • Swiss Canyons (a modified variety of swiss mountains for canyons with cliffs)
  • Dunes
  • Bumpy Terrain (smooth bumps for non-mountainous areas)
  • Rocky terrain (sharp bumps for mountainous areas)
Mountains can be found in large quantities at places in the world that are naturally mountainous, such as the Wrothgarian Mountains and Dragontail Mountaints, but can also be found at rarer intervals and smaller quantities in the rest of the world. A noise mask is used to alternate between the two mountain types.

Hills are mainly found in woodland hills areas, such as the Ilessan Hills and the area between the Wrothgarian Mountains and Wayrest, but can, like mountains, be found to a lesser degree in the rest of the world. Except in the desert; in the desert areas, hills are replaced by dunes.

At places, the original terrain is preserved and used as its own "flatlands" landscape type. Furthermore, the original terrain is preserved at oceans and beaches.

This mod also textures the terrain differently, making cliffs and mountains have a rock texture and at the same time create more interesting grass-dirt variations than the vanilla game offers. There are no more random patches of rock on flat terrain, as they now have mountains and cliffs to serve their purpose.

Image

Purpose and motivation
For a long time, I've been interested in the relationship between procedural generation and nature. While real-life topology appears random and chaotic at a glance, it actually follows natural laws of self-similarity quite closely; if you zoom in on a coastline, for instance, you will find smaller versions of its shape repeating itself. This relationship exists everywhere in nature, from the shaping of continents and mountain ranges down to the segmentation of leaves and grass blades. Mathematical simulations of this phenomenon are referred to as "fractals", and are most famously illustrated in the Mandelbrot sequence.

For some time I've been experimenting with procedurally generating terrains in Unity using so-called fractional Brownian Motion, which is a fractaline noise generator algorithm that iteratively generates self-similar noise patterns while offering fine-grained control over the self-similarity aspect and, by using derivatives in the noise sampling process, makes it possible to simulate naturally occurring phenomena such as hydraulic erosion. The self-similarity and erosion make all the difference between odd looking tall hills and something that the human eyes instantly recognize as mountains.

I've loved Daggerfall since the first time I played it but always found the terrain to be highly uninteresting. Therefore I wanted to introduce this enhanced terrain generation algorithm to the game, but in a way that conforms to the original coastlines and various climate types in Daggerfall, to be both as compatible and lore-friendly as possible, while at the same time introducing enough different landscape types (and variations within each landscape type) to make the world look both natural and interestingly varied. Since the fBM algorithms are quite heavy, and several different fBM algorithms are used to compose the various landscape types, the GPU is used to perform the calculations; the GPU is an often under-utilized super computer that vastly outperforms the CPU when it comes to tasks like this.

Image

Compatibility
Known compatibilities:
  • Distant Terrain (disable Improved Terrain Sampler)
  • Tedious Travel (be cautious when traveling in mountainous areas, as you can still die from fall damage)
  • Airships (requires manual intervention when flying across mountainous areas)
  • Realtime Reflection (oddities do occur - will investigate)
  • D.R.E.A.M.
  • Realistic Grass
  • Realistic Wagon
  • New Cannon Locations
  • Windmills of Daggerfall
  • High Resolution Terrain Textures and Splat Terrain Texturing
Known incompatibilities:
  • Mountains and Hills (when both are loaded, one will completely overtake the other depending on load order)
  • New Locations/Location Loader, and mods depending on it (it currently doesn't support terrains with a max height that's different from vanilla terrains)
  • Basic Roads (Interesting Terrains currently doesn't smooth the roads, but plans are on the drawing board)
Other than those listed, this mod should be compatible with most mods. However, oddities and incompatibilities may occur with mods that in any way affects or relies on the vanilla terrain, or was designed specifically with the vanilla terrain in mind.

I have attempted to test Daggerfall Skyshards and Warm Ashes v4 on 0.10.25a, but couldn't get either to work even with Interesting Terrains disabled. If anyone has those two mods successfully enabled, I'd be very interested to know if they're compatible with Interesting Terrains.

Image

Technical details
This mod utilizes a custom Terrain Sampler, which dispatches the job to a compute shader on the main thread, rather than running an async CPU job.

The base tilemap generation has been overtaken by the terrain sampler, which now generates the tileData that the GenerateTileDataJob normally does - a clone of the default TerrainTexturer, in which the afforementioned job has been omitted, has been implemented. If you're the author of a mod that uses a custom TerrainTexturer, and would like to access the generated tileData, there's a mod message handler in place that will provide it as a byte array. Check out the InterestingTerrainTexturer class on GitHub for more info.

Changelog

Version 0.5.2
  • Fixed: Faulty location heights on Linux
Version 0.5.1
  • Fixed a bug where terrain blending for terrains close to each other glitches
  • Improved transition between terrain and locations
  • Improved rough heightmap generation (better accuracy in Distant Terrain)
  • Implemented initial Basic Roads support (still in extremely early stage - doesn't meet compatibility criteria)
Version 0.5.0
  • Updated for DFUnity 0.10.27
  • Fix: Location blending is now handled by the mod
  • Fix: Texturing around locations now performs properly
  • Compatibility: Now works with Distant Terrain
  • Misc: Removed 'tui' and 'tss' commands, as the game already has features to make them obsolete
Version 0.4.1
  • Fix: Removed bug that caused faulty terrain generation when using localization that doesn't use "." as decimal separator
Version 0.4.0
  • Major overhaul: Interesting Terrains is now implemented as a custom Terrain Sampler, making it an organic part of the game's terrain generation flow, rather than a post-processing job. This provides better compatibility with the game itself, and better compatibility with other mods in general.
  • Addition: Two new mountain types added, and hills are now a modified (smoothed) version of one of them.
  • Tweak: The landscape generator now properly follows the natural laws of mountain formation.
  • Fix: Removed Tedious Travel compatibility workarounds, as they caused issues. Fast traveling through mountains is now at your own risk!
Bonus features
A couple of console commands has been added, primarily for my own development-related benefits, but I've left them in the release version because why not. Don't save any important game after using any of these, as I cannot guarantee what would happen in the long run.
  • clearnoon: Forwards the time to midday, sets the weather to sunny, and kills all enemies.
  • speedy: Toggles "speedy" mode. When enabled, move speed and jump speed are greatly increased, and God Mode is enabled. Takes a number as an optional parameter, which multiplies the movement speed increase for even faster (or slower) speeds.
Last edited by monobelisk on Sun May 30, 2021 11:40 am, edited 15 times in total.

User avatar
Nystul
Posts: 1501
Joined: Mon Mar 23, 2015 8:31 am

Re: [MOD] Interesting Terrains [WIP]

Post by Nystul »

nice mod! trying it right now ;)

update: i get mountains so high that most locations are completely enclosed by sky height walls

monobelisk
Posts: 75
Joined: Tue Aug 25, 2020 10:43 am

Re: [MOD] Interesting Terrains [WIP]

Post by monobelisk »

Nystul wrote: Wed Aug 26, 2020 12:47 pm nice mod! trying it right now ;)

update: i get mountains so high that most locations are completely enclosed by sky height walls
Thanks :D

Yeah, the location fade distance most definitely needs tweaking! I have an upcoming version in the works in which it's greatly increased.

Btw, I really like your mods and would love to make this mod compatible with Distant Terrain. You wouldn't happen, by random chance, to have future plans of implementing something similar to the existing DaggerfallTerrain.OnPromoteTerrainData event handler for when the distant terrain object gets updated? (though, to be honest, I'm still new to the concept of asset bundles and have no idea if it's even possible for a script in a dfmod to access a script in another dfmod)
Edit: Never mind, it looks like I'll be able to implement a custom terrain sampler which, as I understand it, would make the mod more or less automatically compatible with Distant Terrain.
Last edited by monobelisk on Fri Aug 28, 2020 10:02 am, edited 1 time in total.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [MOD] Interesting Terrains [WIP]

Post by Hazelnut »

Hi, not tried it in game yet but I did take a look at the code.. nice work on the GPU delegation stuff.

I am curious about why you took the approach that you did where the terrain is generated and then your code re-generates it. is this why you didn't simply implement a Terrain Sampler? Does your code require that the heighmaps are generated first and then you use that as an input or something?
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
AlexanderSig
Posts: 324
Joined: Wed Jul 19, 2017 10:35 pm

Re: [MOD] Interesting Terrains [WIP]

Post by AlexanderSig »

Looks awesome, well done :)

monobelisk
Posts: 75
Joined: Tue Aug 25, 2020 10:43 am

Re: [MOD] Interesting Terrains [WIP]

Post by monobelisk »

Hazelnut wrote: Wed Aug 26, 2020 2:13 pm Hi, not tried it in game yet but I did take a look at the code.. nice work on the GPU delegation stuff.

I am curious about why you took the approach that you did where the terrain is generated and then your code re-generates it. is this why you didn't simply implement a Terrain Sampler? Does your code require that the heighmaps are generated first and then you use that as an input or something?
Thanks :D

The GPU offers considerably better multithreading than the CPU, and the noise generators I use are quite numerous and computation heavy. So I went straight for a GPU-accelerated solution. I did try to make a custom terrain sampler, but quickly discovered that it's not possible to dispatch compute shaders and read the data outside the main thread.

And correct, I need the original heightmap samples to, at the very least, preserve the ocean, coastlines and locations. I do have a crude heightmap texture, but it's "only" 4096x2048 pixels and the coastlines didn't line up precisely enough. At some point I'll probably give it another shot (despite the heightmap being lo-res compared to the size of the world, you can actually achieve a lot with bilinear interpolation and noise) and if successful, I'd replace the terrain sampler with one that just creates a flat terrain.

Maybe, some day, I may even try to move the shader code to the CPU, just to see if it actually performs as badly as I expect it would.

Also, I didn't realize that it's possible to extract the code from dfmod files, so please excuse my messy code :P My plan is to eventually clean it up and open source it.

monobelisk
Posts: 75
Joined: Tue Aug 25, 2020 10:43 am

Re: [MOD] Interesting Terrains [WIP]

Post by monobelisk »

AlexanderSig wrote: Wed Aug 26, 2020 9:33 pm Looks awesome, well done :)
Thank you! :D

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [MOD] Interesting Terrains [WIP]

Post by Hazelnut »

monobelisk wrote: Thu Aug 27, 2020 8:07 am The GPU offers considerably better multithreading than the CPU, and the noise generators I use are quite numerous and computation heavy. So I went straight for a GPU-accelerated solution. I did try to make a custom terrain sampler, but quickly discovered that it's not possible to dispatch compute shaders and read the data outside the main thread.
You can make a TerrainSampler implementation that doesn't use the Jobs system.. I ensured we had backwards compatibility. Look at the TerrainSampler and the abstract method GenerateSamples() in there. If you implement that, the default jobs schedule method calls it, then converts the output and returns a dummy job handle.

It's a shame you didn't come and discuss stuff with us here before now. :)
monobelisk wrote: Thu Aug 27, 2020 8:07 am And correct, I need the original heightmap samples to, at the very least, preserve the ocean, coastlines and locations. I do have a crude heightmap texture, but it's "only" 4096x2048 pixels and the coastlines didn't line up precisely enough. At some point I'll probably give it another shot (despite the heightmap being lo-res compared to the size of the world, you can actually achieve a lot with bilinear interpolation and noise) and if successful, I'd replace the terrain sampler with one that just creates a flat terrain.
Ah, maybe a another shot would allow it to be done as a TerrainSampler if you wanted to. Another thing is that I think you're overwriting the terrain texture tiles as well, is that right? That will mean it's not compatible with my upcoming roads mod unfortunately, as the roads / tracks are painted on the terrain during terrain texturing before your code runs. I suspect that given the quite steep terrain, that the roads might look silly anyway, like running up a 70deg incline or something. :D

Anyway I am very glad you dropped by the forums. More than happy to discuss tech stuff with people here, so hope you'll stick around - it's an impressive debut for sure. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

monobelisk
Posts: 75
Joined: Tue Aug 25, 2020 10:43 am

Re: [MOD] Interesting Terrains [WIP]

Post by monobelisk »

Hazelnut wrote: Thu Aug 27, 2020 9:25 am You can make a TerrainSampler implementation that doesn't use the Jobs system.. I ensured we had backwards compatibility. Look at the TerrainSampler and the abstract method GenerateSamples() in there. If you implement that, the default jobs schedule method calls it, then converts the output and returns a dummy job handle.

It's a shame you didn't come and discuss stuff with us here before now. :)
I suppose I'm not used to such a friendly and open community :)

But this is all great news! And I'm definitely interested in doing it the proper way. Though moving it to a custom sampler would require custom basemap sampling as well. I'm going through the existing terrain sampler to try and understand how it works. Am I correct to assume that the entire basemap is generated from a single 1000x500 px bitmap?
Hazelnut wrote: Thu Aug 27, 2020 9:25 am Another thing is that I think you're overwriting the terrain texture tiles as well, is that right? That will mean it's not compatible with my upcoming roads mod unfortunately, as the roads / tracks are painted on the terrain during terrain texturing before your code runs. I suspect that given the quite steep terrain, that the roads might look silly anyway, like running up a 70deg incline or something. :D
Yes, I am overwriting the terrain textures completely (in order to paint rock texture on steep mountaneous terrain), but it's funny you should mention it because I actually do have your upcoming mod in mind. If it's possible to obtain the road layout data, it could be sent to the compute shader and it would be possible to both smoothen areas with roads and retain the original road texture during tilemap sampling, much like how locations are currently handled. I assume your mod will be using a custom TerrainTexturer?
Hazelnut wrote: Thu Aug 27, 2020 9:25 am Anyway I am very glad you dropped by the forums. More than happy to discuss tech stuff with people here, so hope you'll stick around - it's an impressive debut for sure. :)
Thanks :D I'll definitely stick around - I should have started here, and not gone straight to Nexus. This definitely feels like an awesome community so far :)

By the way, you're all doing an amazing job with DFUnity - it's downright delightful to work with, especially compared to any other game I've tinkered with!

User avatar
MasonFace
Posts: 543
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: [MOD] Interesting Terrains [WIP]

Post by MasonFace »

May I suggest that you both keep TheLacus's Splat Terrain Texturing in mind with your implementations? It would be awesome to have the roads mod optionally output a spline curve as its path to smooth out the terrain topology, but also paint a path directly onto the splatmap so the road curves are less jagged and ugly.

I believe these three mods will form the holy terrain trinity!

The other thing that would greatly help the visuals is to adjust the UV scaling on distance terrain to reduce the tiling effect, but that would just be the icing on the top!

Great work to both of you guys so far. I'm really digging what you guys are putting out there!

Post Reply