Improving the terrain texture blending
by Lukas Joergensen · in Torque 3D Professional · 07/20/2013 (12:10 pm) · 63 replies
Hey guys, I looked into this myself but it seems the terrain texture uses procedural shaders for blending textures and thats wayy too complex for me atm so I thought I would post it here and hope that someone have a better understanding of the procedural shader system and might be able to implement this.
I read this article on Gamasutra and found it very interesting.
It goes through a set of algorithms to go from this kind of blending which is the one it seems T3D has:

To this much more accurate and natural blending:

(All images is from the article linked above)
Using this algorithm that seems simple enough:
This seems like something that could improve the terrain detail of T3D alot, so whats your thoughts? Would this be possible to do? And it would be awesome if anyone had a good enough understanding of the shader system to actually implement this.
Lastly what do you think about having to have a depth map? obviously it would be best if that could be omitted if desired, using a default depthmap or just a grayscale image.
I read this article on Gamasutra and found it very interesting.
It goes through a set of algorithms to go from this kind of blending which is the one it seems T3D has:

To this much more accurate and natural blending:

(All images is from the article linked above)
Using this algorithm that seems simple enough:
float3 blend(float4 texture1, float a1, float4 texture2, float a2)
{
float depth = 0.2;
float ma = max(texture1.a + a1, texture2.a + a2) - depth;
float b1 = max(texture1.a + a1 - ma, 0);
float b2 = max(texture2.a + a2 - ma, 0);
return (texture1.rgb * b1 + texture2.rgb * b2) / (b1 + b2);
}Where a1 and a2 is the opacity of the respectively texture1 and texture2 and the alpha channel of texture1 and texture2 is a depth map.This seems like something that could improve the terrain detail of T3D alot, so whats your thoughts? Would this be possible to do? And it would be awesome if anyone had a good enough understanding of the shader system to actually implement this.
Lastly what do you think about having to have a depth map? obviously it would be best if that could be omitted if desired, using a default depthmap or just a grayscale image.
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
#22
The most direct way to change this would be to use the height map already used for parallax to modify the weight of pixels produced by parallax using materials. There would be a few assumptions about the height of materials without parallax. Not that parallax would need to actually be activated - just having the map and ticking a checkbox would be enough.
I can also see using the greyscale of the diffuse - not that it is correct, but I understand how to make it work. It could be pretty convenient to have, and for some textures it would probably work fine.
I don't know how to do something like this on the fly with normal maps. A height map could be computed and cached when the material loads I suppose. That's an extra step, but this would all work out the same - you'd just be pulling your comparison values from different places.
I'm going to look into this. No promises or estimates. I have a faint idea of where to look and what to change, and if I'm right it might not even have much of a performance hit.
07/25/2013 (2:16 pm)
I read this thread a few days ago, and it has been nagging me a little since then. I think I could come up with a way of doing this. If I recall correctly from previous terrain work, a pixel is computed for each terrain material that can influence that point, and all the pixels are just blended based on distance.The most direct way to change this would be to use the height map already used for parallax to modify the weight of pixels produced by parallax using materials. There would be a few assumptions about the height of materials without parallax. Not that parallax would need to actually be activated - just having the map and ticking a checkbox would be enough.
I can also see using the greyscale of the diffuse - not that it is correct, but I understand how to make it work. It could be pretty convenient to have, and for some textures it would probably work fine.
I don't know how to do something like this on the fly with normal maps. A height map could be computed and cached when the material loads I suppose. That's an extra step, but this would all work out the same - you'd just be pulling your comparison values from different places.
I'm going to look into this. No promises or estimates. I have a faint idea of where to look and what to change, and if I'm right it might not even have much of a performance hit.
#23
http://www.detailedterrain.com/index.php?page=guide
just ideas...
07/28/2013 (3:57 am)
Ok well, i know its from what i guess is now considered an ageing game, but i knew i saw this somewhere years ago and found the site again.http://www.detailedterrain.com/index.php?page=guide
just ideas...
#24
07/29/2013 (9:39 am)
Just great @Adam if you you're going to look at it! Any improvement is welcome. And personally, if you manage to get this working with a separate greyscale file or just the diffuse map, it will be already a great start :)
#25
07/29/2013 (9:40 am)
@Lukas, are you still with us?
#26
07/29/2013 (9:45 am)
Personally, I think this would be much more likely were we to implement opacity maps/masks into T3D. Is this possible? The reason I bring this up is because opacity maps would make possible several features that Torque is currently missing (in my opinion), such as improved materials handling with things like emission and glow. If this can be done, we might even be able to get some specularity on the terrain.
#27
Those pics on the site i posted above are from oblivion, thats using alpha opacity masks, which at some point was mentioned by tom for t3d's textures, i think he planned it for the detail alpha channel, which is still a spare channel as it stands, to add opacity maps to that alpha we would have to add another file into use for specularity maps unless the specularity goes into the detail's alpha and a separate greyscale image used for opacity maps? wouldnt be messing around with alphas then which does still seem to confuzzle some people
07/29/2013 (10:27 am)
the issue with specularity on terrain was the amount of passes already going through to render it, it was a case of parallax or specularity and tom went with parallax.Those pics on the site i posted above are from oblivion, thats using alpha opacity masks, which at some point was mentioned by tom for t3d's textures, i think he planned it for the detail alpha channel, which is still a spare channel as it stands, to add opacity maps to that alpha we would have to add another file into use for specularity maps unless the specularity goes into the detail's alpha and a separate greyscale image used for opacity maps? wouldnt be messing around with alphas then which does still seem to confuzzle some people
#28
07/29/2013 (10:31 am)
Yeah, I get that Andy, but I was hoping to finally get some think tanking going to address the inconsistencies between the way materials are handled by the terrain and objects. Hell, even the sky. It's 3:30am here though, so I'm probably not functioning as well as I should, mentally.
#29
07/29/2013 (10:37 am)
How is that grass texture going @Dan?
#30
Edit: 1.30 am over here
Edit the edit; it puts my edit in a separate post? What the... another anomaly!
07/29/2013 (10:38 am)
Edit: 1.30 am over here
Edit the edit; it puts my edit in a separate post? What the... another anomaly!
#31
Um.... I feel like this is a test. And I'm failing it. What grass texture mate?
btw Hendricks gin with cucumber is the best! ;)
07/29/2013 (10:56 am)
Quote:"How is that grass texture going @Dan?
Um.... I feel like this is a test. And I'm failing it. What grass texture mate?
btw Hendricks gin with cucumber is the best! ;)
#32
Tho here is just a thought, might be a bit of an offspin. Why not split the Normal map and the parallax map into 2 textures, calling the parallax map, "height map" or something like that. Then when the engine loads in the terrain textures, it takes the parallax map and merges it into the Normal map at run time to optimize the performance. Wouldn't that simplify things a lot from a user-perspective?
07/29/2013 (11:12 am)
Quote:@Lukas, are you still with us?Yes following the discussion post for post! Would wish I had more I could contribute with!
Tho here is just a thought, might be a bit of an offspin. Why not split the Normal map and the parallax map into 2 textures, calling the parallax map, "height map" or something like that. Then when the engine loads in the terrain textures, it takes the parallax map and merges it into the Normal map at run time to optimize the performance. Wouldn't that simplify things a lot from a user-perspective?
#33
07/29/2013 (11:45 am)
er, its more work (code) for the same result isnt it ? (and its a displacement map)
#34
But IMO it is much simpler to have it set up that way, when I first looked at terrains in T3D, the parallax maps was a mystery to me.
07/29/2013 (11:49 am)
@Andy Yeah from a coding-perspective it adds a little bit of complexity, but it makes it easier for the user, and makes it more obvious how to add a parallax map. It is the same result yes and it is more code.But IMO it is much simpler to have it set up that way, when I first looked at terrains in T3D, the parallax maps was a mystery to me.
#35
Currently were at:
Diffuse
Detail/Macro
Normal/Displacement
Separating things for the ideas in this thread would leave us with the following
Diffuse
Detail/Macro
Normal
Displacement
Opacity
Specularity
The reason some things are used in an alpha layer is because a single 8bit channel is needed yet creating a new file to be used for something like a displacement is creating 3 channels for the default file (3x the memory space of adding it to the alpha channel on an existing commonly used texture)
I think to get opacity and specularity in, it could be something set up like this
Diffuse
Detail / + new Opacity map in the alpha as its currently unused and can go into an alpha
Normal / Parallax-Displace Keep this, its the sensible option to me, displacement only needs an single channel, and keeps the height/shadow information together
Specular (new texture in use so more resources used, isnt a required texture, using a new texture for it instead of a alpha channel would allow coloured spec maps the same way shapes are handled, if this is possible. The alpha channel can be used to control the power of the specular)
leave the diffuse as is, just use the rgb channels, personally the way i feel about a diffuse is that it should be one large one for the map, not a tiled small one, we need to get people away from that impression due to the way it was handled in tge/tgea days...
07/29/2013 (12:01 pm)
Yeah thats true, and i understand where youre coming from, but we do have to be sensible and take into consideration the amount of passes were doing to render terrains aswell as the amount of textures were throwing about.Currently were at:
Diffuse
Detail/Macro
Normal/Displacement
Separating things for the ideas in this thread would leave us with the following
Diffuse
Detail/Macro
Normal
Displacement
Opacity
Specularity
The reason some things are used in an alpha layer is because a single 8bit channel is needed yet creating a new file to be used for something like a displacement is creating 3 channels for the default file (3x the memory space of adding it to the alpha channel on an existing commonly used texture)
I think to get opacity and specularity in, it could be something set up like this
Diffuse
Detail / + new Opacity map in the alpha as its currently unused and can go into an alpha
Normal / Parallax-Displace Keep this, its the sensible option to me, displacement only needs an single channel, and keeps the height/shadow information together
Specular (new texture in use so more resources used, isnt a required texture, using a new texture for it instead of a alpha channel would allow coloured spec maps the same way shapes are handled, if this is possible. The alpha channel can be used to control the power of the specular)
leave the diffuse as is, just use the rgb channels, personally the way i feel about a diffuse is that it should be one large one for the map, not a tiled small one, we need to get people away from that impression due to the way it was handled in tge/tgea days...
#36
Also the nice page that was linked also implements a render order via some form of layering that torque doesnt currently do that would also improve the visual slightly by giving something like cobbles priority over flat dirt for example.
07/29/2013 (12:43 pm)
Isnt this the kind of thing that konrads sahara addon does to objects?Also the nice page that was linked also implements a render order via some form of layering that torque doesnt currently do that would also improve the visual slightly by giving something like cobbles priority over flat dirt for example.
#37
07/29/2013 (12:56 pm)
Konrad did post the technicals somewhere about the material accumulation shader in the sahara pack, it uses the normals to see where the accumulation map would catch onto. That site i linked discusses the use of opacity maps for terrain materials, a similar effect to what lukas posted at the start
#38
And I can completely follow you on using a big diffuse map instead of a small tiled one. Doesn't most people do this anyways? Loading in the big diffuse map and setting it as the diffusemap on every channel?
07/29/2013 (12:59 pm)
@Andy well what I thought was doing something like:Texture NormalMap = ReadTextureFromFile(normalmapfile); Texture DisplacementMap = ReadTextureFromFile(displacementmapfile); NormalMap.Alpha = DisplacementMap; DisplacementMap.destroy();So while there is a slightly bigger overhead when initializing the textures, it doesn't hurt performance after it has been loaded.
And I can completely follow you on using a big diffuse map instead of a small tiled one. Doesn't most people do this anyways? Loading in the big diffuse map and setting it as the diffusemap on every channel?
#39
07/29/2013 (1:05 pm)
more people do it now than they used too, but its definiteley the way to go with terrain texturing
#40
All depending on the game, type of environment and method; I have chosen for the detail at close range only, after I ran into performance issues with in full fledged 2km2 levels. Now my diffuse maps are very small in size, reused and tiled, while the detail maps are at least 1024 and unique for every material. It took some time to get the feeling how the colors in the detail maps blend, but I'm satisfied with the result. No need for a macro texture in my case.
I also put a lot of effort in the normal maps. With the right workflow and tools you can have great results. Adding a parallax in a good designed normal map is often not a huge improvement.
---
I think we might want to leave the options open for the designer:
- Use the alpha in the normal map for parallax
- Use the displace map for parallax
- Use the alpha in the normal map for blending
- Use the displace map for blending
Or perhaps a wild idea is to have a dropDownMenu for blending with all possible options built;
- use diffuse map
- use macro map
- use detail map
- use diffuse alpha
- use macro alpha
- use normal alpha
- use displace map
All with all is to see it working with any method at all, a great start :)
07/29/2013 (8:06 pm)
Quote:Doesn't most people do this anyways? Loading in the big diffuse map and setting it as the diffusemap on every channel?
All depending on the game, type of environment and method; I have chosen for the detail at close range only, after I ran into performance issues with in full fledged 2km2 levels. Now my diffuse maps are very small in size, reused and tiled, while the detail maps are at least 1024 and unique for every material. It took some time to get the feeling how the colors in the detail maps blend, but I'm satisfied with the result. No need for a macro texture in my case.
I also put a lot of effort in the normal maps. With the right workflow and tools you can have great results. Adding a parallax in a good designed normal map is often not a huge improvement.
---
I think we might want to leave the options open for the designer:
- Use the alpha in the normal map for parallax
- Use the displace map for parallax
- Use the alpha in the normal map for blending
- Use the displace map for blending
Or perhaps a wild idea is to have a dropDownMenu for blending with all possible options built;
- use diffuse map
- use macro map
- use detail map
- use diffuse alpha
- use macro alpha
- use normal alpha
- use displace map
All with all is to see it working with any method at all, a great start :)
Torque Owner smally
TBD
First you don't create accurate height maps from diffuse color textures, especially if you have the normal map. Color information without the presence of lighting and shadow, have nothing to do with the height of a surface on it's material level. With parallax, or POM, The normal map is what is used to alter this and give the presence of depth. The defacto point to that is the normal map IS the only real choice there, if it's present as the result will look far more accurate. If you have both normal maps blending, you need to smooth these across the borders or you WILL end up with problems and artifacts between the two. Hence the issue.
I see absolutely no harm in having this there, or giving the option to use specular over a depth map. In the end that kind of flexibility just helps make the maps, worlds, art look that much more varied and that's what you really want to be able to accomplish.