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
#42
07/30/2013 (6:00 am)
Don't forget specular ;)
#43
I'm poking at terrain/terrFeatureHLSL.cpp seeing if I can get something working using parallax as a mask, even if it isn't actually being rendered. I'm just going for a proof of concept to see how much improvement it brings. Using the alpha of the detail textures is an interesting idea, but I just wanted to quickly mess with something I already know is there.
I think different terrain materials need different maps, and it should be left up to designers to be able to pick and choose. Snow would really benefit from a specular, as would wet sand along a beach. That being said, just activating everything is probably a bad idea. Having a diffuse/detail/macro/normal/parallax/specular is one thing, but having two or three materials being blended where they border each other? I think the terrain materials dialog might need a warning built into it. Or perhaps a terrain quality slider users can adjust.
I finally let myself play Skyrim (I have a self imposed $20 limit on Steam) and I was struck at how poor the terrain system was. The terrain they actually built was beautiful though, and they really get a lot of mileage out of models blended into the terrain. That's a different topic I suppose. Anyways, I'm poking at this. I'm finishing moving, have a contract to finish, and am sick, so nothing soon probably.
07/30/2013 (11:18 am)
Criminy, there's some interest in this.I'm poking at terrain/terrFeatureHLSL.cpp seeing if I can get something working using parallax as a mask, even if it isn't actually being rendered. I'm just going for a proof of concept to see how much improvement it brings. Using the alpha of the detail textures is an interesting idea, but I just wanted to quickly mess with something I already know is there.
I think different terrain materials need different maps, and it should be left up to designers to be able to pick and choose. Snow would really benefit from a specular, as would wet sand along a beach. That being said, just activating everything is probably a bad idea. Having a diffuse/detail/macro/normal/parallax/specular is one thing, but having two or three materials being blended where they border each other? I think the terrain materials dialog might need a warning built into it. Or perhaps a terrain quality slider users can adjust.
I finally let myself play Skyrim (I have a self imposed $20 limit on Steam) and I was struck at how poor the terrain system was. The terrain they actually built was beautiful though, and they really get a lot of mileage out of models blended into the terrain. That's a different topic I suppose. Anyways, I'm poking at this. I'm finishing moving, have a contract to finish, and am sick, so nothing soon probably.
#44
But if you want larger transition zones where two textures blend into each other, alpha mask maps could be useful.
This is default Torque blending two similar pattern textures, they blend very seamless to me:
Just noticed even without parallax there is not much difference.
So I wonder what you want to improve there. You would need to increase the blending zone also to really take use of alpha mask maps, but I think this could give quite some nice effects if you could blend more textures into each other and also have larger transition areas.
In default Torque (my picture) it seams to be 1 meter of blending zone.
07/30/2013 (12:15 pm)
In my opinion parallax textures already blend pretty good in many cases, only for very different patterns like grass to pavement you will see a blurry transition zone, but this does not happen very often. With using the heightmap out of the normal, this maybe could be improved a little, but not so much I think.But if you want larger transition zones where two textures blend into each other, alpha mask maps could be useful.
This is default Torque blending two similar pattern textures, they blend very seamless to me:
Just noticed even without parallax there is not much difference.So I wonder what you want to improve there. You would need to increase the blending zone also to really take use of alpha mask maps, but I think this could give quite some nice effects if you could blend more textures into each other and also have larger transition areas.
In default Torque (my picture) it seams to be 1 meter of blending zone.
#45
In that image, I don't see much of a problem. I don't imagine masking would be used everywhere all the time, but in certain spots for certain textures it would help. Cobblestone roads next to grass are an obvious example. Large rocks near a sandy beach.
I don't want to force a new workflow or rendering slow-down on anyone. It will be completely optional on a per-material basis, just a simple check box for now. If I understand how this stuff works correctly, it should just be another texture look up and multiply, which isn't much if you look at the procedural terrain shaders.
Also, your blend area of 1 meter I think is tied to your terrain square size. Larger square sizes blend over more area. Changing the blending distance is beyond my understanding right now, but since I find myself using large square sizes and making models for terrain details, having better blending for the most ugly transitions makes a lot of sense.
07/30/2013 (1:07 pm)
Duion,In that image, I don't see much of a problem. I don't imagine masking would be used everywhere all the time, but in certain spots for certain textures it would help. Cobblestone roads next to grass are an obvious example. Large rocks near a sandy beach.
I don't want to force a new workflow or rendering slow-down on anyone. It will be completely optional on a per-material basis, just a simple check box for now. If I understand how this stuff works correctly, it should just be another texture look up and multiply, which isn't much if you look at the procedural terrain shaders.
Also, your blend area of 1 meter I think is tied to your terrain square size. Larger square sizes blend over more area. Changing the blending distance is beyond my understanding right now, but since I find myself using large square sizes and making models for terrain details, having better blending for the most ugly transitions makes a lot of sense.
#46
But alpha masks could become useful on larger square size terrain, since the terrain is always squares you can see that in the game the bigger the square size gets. A spot of a different texture inside another would be clearly identifiable as a square. Even the default 1 unit is hard at the limit of looking like squares.
07/30/2013 (1:38 pm)
This is actually rock next to sand ;) but I think you mean flat sand, also I posted an example on page 1 of one of the worst cases, cobblestone pavement vs grass, it looks like the grass decides to go over the stones, the other way around it would be better, but there is no control over it.But alpha masks could become useful on larger square size terrain, since the terrain is always squares you can see that in the game the bigger the square size gets. A spot of a different texture inside another would be clearly identifiable as a square. Even the default 1 unit is hard at the limit of looking like squares.
#47
So what I'd very much like to try is using black & white brush masks. I know some engines do that very thing, and I know zBrush does, but I wouldn't expect it to be that simple with Torque. I'd think this is all systemic. Tweak one thing here and you get errors over here.
Man, I should get coffee before I do this....
07/30/2013 (3:30 pm)
Did you guys ever try setting the terrain square size to 0.25? It'll give you the appearance of properly blended textures, but it really is all about the brush. What I think we need, and this may circumvent a lot of hassle (not to mention spamming the materials list), is to have masks for the brush. At present we have a linear falloff, and that is what causes this terrible blending. Well, that and the terrain square size. Take a round brush with linear falloff and paint onto a square and you're always going to have issues. In the case of square size, those squares (on my maps I use a 2048px diffuse on a 2048px heightmap at 1:1) are actually pixels. Nothing we can do about that, is there?So what I'd very much like to try is using black & white brush masks. I know some engines do that very thing, and I know zBrush does, but I wouldn't expect it to be that simple with Torque. I'd think this is all systemic. Tweak one thing here and you get errors over here.
Man, I should get coffee before I do this....
#48
Without a LOD-system it would turn up your polycount 16 times for the same space.
Such a terrain does not feel right, maybe 0.5 would be ok for smaller terrains/scenes.
07/30/2013 (4:11 pm)
0.25 will turn your map 0.25 of the size but increase polycount about 50% to 100%, depending on your position.Without a LOD-system it would turn up your polycount 16 times for the same space.
Such a terrain does not feel right, maybe 0.5 would be ok for smaller terrains/scenes.
#49

No parallax used
Textures with similar tones will of course blend much better linear then when in strong contrast with each other. Adding parallax for a better blending (@Duion) only works if the light is right, just like normal maps*. In areas where there's only shadow it will not work very well (too bad SSAO is not good enough for that yet).
*Edit: of course parallax still works better then normal when the light isn't right.
---
@Adam; I know how that feels. I wish you good luck and a speedy recovery!
07/30/2013 (10:26 pm)
I agree that decreasing the square size can be too costly. Wanting to have more polys in the props, I'm using a square size of 2. I'm adding larger detail sizes in normal maps underneath the small ones to cover that up a bit:
No parallax used
Textures with similar tones will of course blend much better linear then when in strong contrast with each other. Adding parallax for a better blending (@Duion) only works if the light is right, just like normal maps*. In areas where there's only shadow it will not work very well (too bad SSAO is not good enough for that yet).
*Edit: of course parallax still works better then normal when the light isn't right.
---
Quote:I'm finishing moving, have a contract to finish, and am sick, so nothing soon probably.
@Adam; I know how that feels. I wish you good luck and a speedy recovery!
#50
To me it sounds like you create a normal detail map, make a normal out of it, then you create another normal map but with bigger pattern and blend it together with the original normal map.
07/31/2013 (1:49 am)
A bigger detail map underneath in the normal map? Sounds confusing.To me it sounds like you create a normal detail map, make a normal out of it, then you create another normal map but with bigger pattern and blend it together with the original normal map.
#51
07/31/2013 (2:35 am)
Quote:A bigger detail map underneath in the normal map? Sounds confusing.@Duion; I didn't wrote that, or mean for you to understand it like that. I just put in one normal map!
#52
07/31/2013 (4:35 am)
Now I am confused, you probably need to explain it now ;) I meant blend in the normal map in an image program and then save it down as one.
#53
My main point was and is that we should see about adding alpha masks to our brush. However, even were we to get that working, it would still be subjected to the problem of blending across squares.
Sorry for the miscommunication there.
07/31/2013 (7:52 pm)
I wasn't suggesting that a square size of 0.25 was a good idea, just brought it up to demonstrate that having the extra detail somewhat obfuscates the issue of texture blending across terrain squares. My main point was and is that we should see about adding alpha masks to our brush. However, even were we to get that working, it would still be subjected to the problem of blending across squares.
Sorry for the miscommunication there.
#54
08/01/2013 (3:13 pm)
Terrain textures mapping to whole squares is the most obvious proble and is what is causing me and my project the most headaches visually, without the replicators functioning correctly this is a borderline showstopper issue in my book that i have no way of fixing myself.
#55
08/01/2013 (3:45 pm)
You can try blending the base texture, that one that is generated and called yourlevel_basetex.dds try open it and blur it, so the main colors of the textures will overlap a little bit, but only works after you have done your terrain, because the file gets overwritten if you change something.
#56
However, were Torque able to map textures using an alpha mask, we need only change the brush to use masks.
08/02/2013 (1:39 am)
See, taking the _basetex.dds and manipulating it isn't a bad idea as such, but this is circular logic. I've done this, and it works, but why not just use a sindle diffuse texture that does this? Because it's a diffuse texture, and by its very nature doesn't do shit with detail. Having said that, the _basetex.dds file is itself comosed of all the different terrain material layers on that terrain, and Torque must have some way of knowing the x,y coordinates of each detail texture so that it can composite that _basetex.dds file. What we need is to expose that method to the editor, so that we have a visual method of defining where the details go. However, we're still going to be limited by the number of pixels in the masks that we'd be using. No way to circumvent the fact that a pixel is square. However, were Torque able to map textures using an alpha mask, we need only change the brush to use masks.
#57

So, I have spent a lot of time learning the shader system to a point where I could implement it myself... I don't need your help anymore!

I'll return shortly with before and after images!
I ended up just using the alpha channel of the detail texture, it was the simplest solution for now.
Edit: Btw I know rock on sand is a bad example, but wth I just needed to use stock resources :P
06/25/2014 (10:10 am)
So, I have spent a lot of time learning the shader system to a point where I could implement it myself... I don't need your help anymore!

I'll return shortly with before and after images!
I ended up just using the alpha channel of the detail texture, it was the simplest solution for now.
Edit: Btw I know rock on sand is a bad example, but wth I just needed to use stock resources :P
#59
06/25/2014 (12:24 pm)
Lukas could you explain what you did..That's pretty cool stuff!!
#60

... I'm still working on it, trying to get it working with more than 2 textures. Then I'll probably upload it, it still needs a lot of improvement.
It was pretty easy to get it working with 2 textures actually, I just wrote it into the shader :P
06/25/2014 (12:55 pm)
... I'm still working on it, trying to get it working with more than 2 textures. Then I'll probably upload it, it still needs a lot of improvement.
It was pretty easy to get it working with 2 textures actually, I just wrote it into the shader :P





Duion