[MOD] Interesting Terrains [WIP]

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

[MOD] Interesting Terrains [WIP]

Post by monobelisk »

Image
Interesting Terrains

Current version: 0.4.1
Supported DFUnity version(s): 0.10.26 (older versions supporting 0.10.24 can be found under "Old Files")
Download and instructions: Nexus Mods page

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 steep 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, in order to make 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 on.

Image

Known issues
  • Locations in mountainous areas look unnatural - this is due to a limitation in the former version of the DFUnity code.
  • Locations close to the shore sometimes produces watery slopes with trees next to them - this is due to a limitation in DFUnity 0.10.24 and will be resolved for future versions (version 0.4.1 excluded, as it was a hotfix).
Purpose and motivation
For a long time I've been interested in the relationship between procedural generation and nature. While real-life topology appear 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 leafs 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 makes 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 individual 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:
  • Tedious Travel (be cautious when travelling 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:
  • Distant Terrain (we're working on it)
  • 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 tilemap generation happens as a post-processing job. In future versions of the mod, custom Terrain Texturers will be supported, and the tilemap generation will move there instead.

Changelog

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 travelling 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. I'm planning a future "Extended Developer Console" mod in which these commands (among others) will be added instead, but for now they live in Interesting Terrains. Don't save the 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.
  • tui: Toggles the in-game HUD and UI on and off, for screenshot purposes. When the UI is disabled, all menus and message boxes will malfunction until it's re-enabled.
  • tss: Toggles screenshot mode. Disabled by default. When enabled, pressing the "PrintScreen" key will save a screenshot in .png format to <MyPictures>/DaggerfallUnity.
  • 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 move speed increase for even faster (or slower) speeds.
Last edited by monobelisk on Sun Sep 27, 2020 9:46 am, edited 9 times in total.

User avatar
Nystul
Posts: 1470
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: 57
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: 2497
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: 310
Joined: Wed Jul 19, 2017 10:35 pm

Re: [MOD] Interesting Terrains [WIP]

Post by AlexanderSig »

Looks awesome, well done :)

monobelisk
Posts: 57
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: 57
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: 2497
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: 57
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: 512
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