Terrain Shader with Splatmap
- MasonFace
- Posts: 543
- Joined: Tue Nov 27, 2018 7:28 pm
- Location: Tennessee, USA
- Contact:
Terrain Shader with Splatmap
In working with upscaled graphics, I've noticed that it is very difficult, if not impossible, to get the terrain textures to align seamlessly when they are stitched together in the context of the tilemap. I had been thinking on how to overcome this issue and haven't been able to come up with any other alternative but to try to use a custom terrain shader with a splatmap.
I'm terrible with shader code, but I've recently purchased amplify shader editor and have been having fun with it and thought it would be neat to take a stab at creating a new terrain shader that could generate a splatmap from the DFTFU generated tilemap, as detailed here.
So far, I've gotten a shader that, if provided with a RGBA splatmap, can draw up to 5 albedo/normals over the terrain with heightmap blending between them. In the case of the temperate tile set (archive 302), I have the dirt texture as a base, then the (R) channel of the splatmap is for Roads, the (G) channel is for Grass, (B) is for water, and (A) is for rock.
My plan (which I have only just barely started looking at) is to try to intercept the tilemap index values and map them to a custom tileset atlas that that will build a splatmap to indicate where and how much of each texture to draw onto the terrain.
My opinion is that a splatmap based terrain shader would work much better for mods, particularly mods where upscaling the terrain graphics is needed (such as DREAM and PVE), and where custom road paths (or rivers!) may be drawn (Roads of Daggerfall).
On the other hand, it may not look as good when using just the vanilla graphics.
I don't have much to show at this point, but I wanted to get some general feedback from the community before I spent any more time on it. Does this sound like a worthwhile endeavor?
As an aside, another feature I'd like to include is a detail texture that reduces texture tiling repetition when viewed at a far distance.
Aside #2: Using a splatmap was alluded to in this post from InterKarma back in 2015 (see benefit number 9 in his list).
I'm terrible with shader code, but I've recently purchased amplify shader editor and have been having fun with it and thought it would be neat to take a stab at creating a new terrain shader that could generate a splatmap from the DFTFU generated tilemap, as detailed here.
So far, I've gotten a shader that, if provided with a RGBA splatmap, can draw up to 5 albedo/normals over the terrain with heightmap blending between them. In the case of the temperate tile set (archive 302), I have the dirt texture as a base, then the (R) channel of the splatmap is for Roads, the (G) channel is for Grass, (B) is for water, and (A) is for rock.
My plan (which I have only just barely started looking at) is to try to intercept the tilemap index values and map them to a custom tileset atlas that that will build a splatmap to indicate where and how much of each texture to draw onto the terrain.
My opinion is that a splatmap based terrain shader would work much better for mods, particularly mods where upscaling the terrain graphics is needed (such as DREAM and PVE), and where custom road paths (or rivers!) may be drawn (Roads of Daggerfall).
On the other hand, it may not look as good when using just the vanilla graphics.
I don't have much to show at this point, but I wanted to get some general feedback from the community before I spent any more time on it. Does this sound like a worthwhile endeavor?
As an aside, another feature I'd like to include is a detail texture that reduces texture tiling repetition when viewed at a far distance.
Aside #2: Using a splatmap was alluded to in this post from InterKarma back in 2015 (see benefit number 9 in his list).
Last edited by MasonFace on Wed Sep 25, 2019 4:22 pm, edited 2 times in total.
- King of Worms
- Posts: 4752
- Joined: Mon Oct 17, 2016 11:18 pm
- Location: Scourg Barrow (CZ)
- Contact:
Re: Terrain Shader with Splatmap
Any improvement to current terrain tiling/shader would be welcomed!
DREAM Nexus https://www.nexusmods.com/users/73250038?tab=user+files
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
- MasonFace
- Posts: 543
- Joined: Tue Nov 27, 2018 7:28 pm
- Location: Tennessee, USA
- Contact:
Re: Terrain Shader with Splatmap
Just a quick picture now that I'm home to show what I'm talking about.
I'm only using 5 textures from archive 302 (record 0, 1, 2, 3, and 46) and a splat map and by using height maps for these textures I can transition between them semi-naturally. Look closely how the sand blends into the cracks of the stone road and the grass grows over the road bricks.
Another picture, this one showing the splat map used.
I'm only using 5 textures from archive 302 (record 0, 1, 2, 3, and 46) and a splat map and by using height maps for these textures I can transition between them semi-naturally. Look closely how the sand blends into the cracks of the stone road and the grass grows over the road bricks.
Another picture, this one showing the splat map used.
- jayhova
- Posts: 924
- Joined: Wed Jul 19, 2017 7:54 pm
- Contact:
Re: Terrain Shader with Splatmap
do you have a picture without the splatmap to give an idea of how radical the change is? It looks great.
Remember always 'What would Julian Do?'.
- King of Worms
- Posts: 4752
- Joined: Mon Oct 17, 2016 11:18 pm
- Location: Scourg Barrow (CZ)
- Contact:
Re: Terrain Shader with Splatmap
Wow, this is amazing.
EDIT: Im not sure this is falls in the area you working at atm, but would it be possible to include standard normal mapping to the terrain?
As it is now, that feature is unusable... you can apply normal maps, but it looks downright hideous, you cant controll the strength of normalmaps, its not mipmapped etc.
EDIT: Im not sure this is falls in the area you working at atm, but would it be possible to include standard normal mapping to the terrain?
As it is now, that feature is unusable... you can apply normal maps, but it looks downright hideous, you cant controll the strength of normalmaps, its not mipmapped etc.
DREAM Nexus https://www.nexusmods.com/users/73250038?tab=user+files
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
- MasonFace
- Posts: 543
- Joined: Tue Nov 27, 2018 7:28 pm
- Location: Tennessee, USA
- Contact:
Re: Terrain Shader with Splatmap
I'll import a Terrain chunk from DFU and try to manually create a splatmap to compare the two, although I think it may be more trouble than it's worth. I may just try to recreate a few edge cases to demonstrate the main differences.
This splatmap terrain shader supports normal mapping and it is working, but I don't have any sliders to control the strength of the normal maps.King of Worms wrote: ↑Tue Sep 24, 2019 8:38 am Wow, this is amazing.
EDIT: Im not sure this is falls in the area you working at atm, but would it be possible to include standard normal mapping to the terrain?
As it is now, that feature is unusable... you can apply normal maps, but it looks downright hideous, you cant control the strength of normal maps, its not mipmapped etc.
I did, however, make the water have animated normal UVs so it looks like water ripples which is kind of neat.
- King of Worms
- Posts: 4752
- Joined: Mon Oct 17, 2016 11:18 pm
- Location: Scourg Barrow (CZ)
- Contact:
Re: Terrain Shader with Splatmap
Animated water? Yes! No worries about the normals
Yea I guess the comparison can ppl make when its ready, now its just another thing to distract you, IMO.
"Just run the original game and see for yourself" maybe?
Yea I guess the comparison can ppl make when its ready, now its just another thing to distract you, IMO.
"Just run the original game and see for yourself" maybe?
DREAM Nexus https://www.nexusmods.com/users/73250038?tab=user+files
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
DREAM Forums viewtopic.php?f=27&t=1168
DISCORD: king_of_worms_cz
- MasonFace
- Posts: 543
- Joined: Tue Nov 27, 2018 7:28 pm
- Location: Tennessee, USA
- Contact:
Re: Terrain Shader with Splatmap
It won't be any trouble to make a comparison, but only after I've tackled the programming side of it. I'll need to read in InterKarma's tilemap data and generate a splatmap from that. Otherwise, I'd have to try to create a splatmap by hand to get a reasonably accurate apples-to-apples comparison which would probably be time consuming with little payback. If I do a comparison at the moment, it would just show a few edge cases of how the textures look blended together. So yeah, I mostly agree; I'll probably do more development before I tackle any demonstrative comparisons.Yea I guess the comparison can ppl make when its ready, now its just another thing to distract you, IMO.
"Just run the original game and see for yourself" maybe?
One thing that stands out at the moment about the splatmap approach is that the textures appear to repeat a lot. From reading InterKarma's post about his tilemap shader, it looks like classic DF would rotate and mirror the textured tiles to create more variations from the same textures. InterKarma baked these translations into a texture atlas (called a tileset) and builds one big texture from them stitched together, mapped by the tilemap which indicates which texture gets painted onto which location.
The most straightforward method to reduce repetition when using a splatmap would be to use a much larger texture that has variations baked into it. The downfall to this approach is that, especially with upscaled textures, there will be a big increase in texture size and the texture will still repeat predictably, just less often.
Here's an open question to anyone with shader experience: I'm wondering if there is a way to change the UV sampling direction each time the texture would repeat. So basically, every time the texture has been sampled it either swaps the U and V sampling coordinates to rotate it, or does 1 minus U or V to mirror it. Is this possible without branching the shader code and making it terribly slow?
- pango
- Posts: 3358
- Joined: Wed Jul 18, 2018 6:14 pm
- Location: France
- Contact:
Re: Terrain Shader with Splatmap
Actually now it's done using matrices, to avoid branching: https://github.com/Interkarma/daggerfal ... shader#L92MasonFace wrote: ↑Wed Sep 25, 2019 4:17 pm Here's an open question to anyone with shader experience: I'm wondering if there is a way to change the UV sampling direction each time the texture would repeat. So basically, every time the texture has been sampled it either swaps the U and V sampling coordinates to rotate it, or does 1 minus U or V to mirror it. Is this possible without branching the shader code and making it terribly slow?
But it's not done to get "more variety", instead tiles are rotated or mirrored so they match their neighboor tiles; If you just change how they're rotated or mirrored the floor will look broken.
Depending on each tile symmetries you could sometimes use alternate transformations and still match neighboor tiles, but not in general.
Mastodon: @pango@fosstodon.org
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart
When a measure becomes a target, it ceases to be a good measure.
-- Charles Goodhart
- MasonFace
- Posts: 543
- Joined: Tue Nov 27, 2018 7:28 pm
- Location: Tennessee, USA
- Contact:
Re: Terrain Shader with Splatmap
Thanks for the insight, Pango.
You're right. I'd have to make sure that each of the splat textures' edges perfectly seam with the other 3 edges, and doing that would show a very obvious pattern which doesn't really help prevent repetition... I guess I'll just go the route of using a larger texture to reduce repetition.
You're right. I'd have to make sure that each of the splat textures' edges perfectly seam with the other 3 edges, and doing that would show a very obvious pattern which doesn't really help prevent repetition... I guess I'll just go the route of using a larger texture to reduce repetition.