Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New terrain texture blending #712

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

lukaspj
Copy link
Contributor

@lukaspj lukaspj commented Jul 1, 2014

New terrain texture blending! As described here.

There is this thing called "blendDepth" that allows you to tweak how sharp the blending it is, to show you the effect of tweaking this depth I created the following album:
http://imgur.com/a/oae0O

First image is stock T3D blending, from there it is new blending with blendDepth 0.1,0.2 etc up to 0.9. Last image is blendDepth 0.99

You can set the "blendDepth" on the terrain material like this:

new TerrainMaterial()  
{  
   diffuseMap = "art/terrains/Example/sand";  
   diffuseSize = "500";  
   detailMap = "art/terrains/Example/sand_d";  
   detailSize = "2";  
   detailDistance = "50";  
   internalName = "sand2";  
   normalMap = "art/terrains/Example/sand_n";  
   blendDepth = 0.5;  // <---
};

You enable the new blending method by setting $terrain::lerpBlend = false; (defaults to true). This PR does not contain any UI changes so the new features have to be activated through script. (UI might come in a later PR!)

Note for the new blending to work properly, the textures HAVE to have a normal map with a heightmap in the alpha channel. If you don't use normal maps, then this texture blending method is not for you.

@LuisAntonRebollo
Copy link
Contributor

@LuisAntonRebollo LuisAntonRebollo commented Jul 1, 2014

WOOOO this look amazing 👍

Great work, We are very lucky to have you here :)

@crabmusket crabmusket added this to the 3.7 milestone Jul 1, 2014
@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Jul 1, 2014

Thanks @LuisAntonRebollo ! :)
Btw this contains a commit from #710 I don't know if it makes most sense to just merge this one or both of them..
Tell me if anything needs fixing! I'll be adding UI for the new options when this PR is accepted :)

@rextimmy
Copy link
Contributor

@rextimmy rextimmy commented Jul 1, 2014

Awesome stuff Lukas ;-)

@crabmusket crabmusket removed this from the 3.7 milestone Aug 21, 2014
@crabmusket crabmusket added this to the 3.6 milestone Aug 21, 2014
@lukaspj lukaspj mentioned this pull request Aug 22, 2014
@lukaspj lukaspj force-pushed the New-Terrain-Texture-Blending branch from 28ac021 to efaf311 Compare Aug 25, 2014
@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Aug 25, 2014

Now updated to use the latest fix for the blending, and tweaked the blending algorithm a little. Should be good to go now.

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Aug 25, 2014

Does this replace #710? I get a merge conflict when merging this after that.

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Aug 26, 2014

Hmm.. Sounds odd, seems like the commits has recieved new hashes for some reason.. I did a couple of resets, try re-merging the 3 textures blending fix.

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Aug 29, 2014

Right, rebasing will tend to screw things up a bit. I'll give it another go today. Any chance you could provide us with the texture/normal map you're using? The normal maps have to have depth in the alpha channel, right?

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Aug 29, 2014

@eightyeight unfortunately no, I got the textures from Andrew Mac for testing, and I can't really share them or use them outside of testing. I'll see if I can create some other textures for testing.

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Aug 29, 2014

@eightyeight you can use this zip file (Windows only) to generate some simply parallax maps.

You can use the "parallaxMask.bat" file to merge an existing heightmap with the parallax map or you can use "genParallaxMask.bat" to generate a parallax mask from a normal and a diffuse texture.
Just double click on either of them and follow instructions.

@lukaspj lukaspj force-pushed the New-Terrain-Texture-Blending branch from efaf311 to 6bd501d Compare Sep 10, 2014
@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Sep 10, 2014

Updated with fix for the bug described in #710 .

Now terrain basetexture is properly cleared and never transparent.
@lukaspj lukaspj force-pushed the New-Terrain-Texture-Blending branch from 6bd501d to ad1ada7 Compare Sep 10, 2014
Added an implementation of the terrain blending described in this article: http://www.gamasutra.com/blogs/AndreyMishkinis/20130716/196339/Advanced_Terrain_Texture_Splatting.php by Andrew Mishkinis.

Textures without a heightmap will blend linearly.
@lukaspj lukaspj force-pushed the New-Terrain-Texture-Blending branch from ad1ada7 to ce33589 Compare Sep 10, 2014
@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Sep 23, 2014

This has a small issue with currentAlpha and blendTotal essentially being the same thing, but only blendTotal is being outputtted while not being calculated properly when not lerpBlending.

Which I'll fix soon™

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Sep 25, 2014

I think we'll have to delay this and #714 ... #710 Should still be good though.

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Sep 25, 2014

Define good? ;P I'm happy to push this back to 3.7.

@crabmusket crabmusket removed this from the 3.6 milestone Sep 27, 2014
@crabmusket crabmusket added this to the 3.7 milestone Sep 27, 2014
@crabmusket crabmusket added this to the 3.7 milestone Sep 27, 2014
@crabmusket crabmusket removed this from the 3.6 milestone Sep 27, 2014
@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Sep 27, 2014

Pushed back due to time constraints.

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Sep 29, 2014

@eightyeight #710 isn't affected by the issues I found here in the last minute, it's just the new blending that is affected by it :)

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Sep 29, 2014

I meant this comment as a catch-all for the terrain blending issues - it was #710 that I was having problems with, and as it's prerequisite to these ones they've all had to be moved back a bit. I take it you fixed the 3-way blending issues I was having with the PR for basetex formats?

In any case, rest assured that these changes will be some of the first merged in in 3.7 :).

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Sep 29, 2014

Yup the blending issues should be fixed with that PR.
Thats fine, I'll see if I can fix this PR for that time as well.

@crabmusket crabmusket self-assigned this Nov 4, 2014
@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Nov 12, 2014

So much love went into this.. Sadly this is not possible to do, at least not under D3D9 afaik.
The limitation of not having access to the alpha value of the previous passes is too much, I have not been able to overcome this issue and this can as far as I can see, only be fixed in a way that still performs well by rendering at least 16 textures in each pass.

I do have a possible approximation.

Lower images are the approximation, upperleft is T3D's current blending and upper-right is the optimal blending. I can only achieve the optimal blending, between textures that render in the same pass.

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Nov 12, 2014

Oh :(. The results you had before were achieved with a more limited terrain situation? Also, to be honest, I don't think those lower images look all that bad.

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Nov 12, 2014

The results I had before were just a coincidence more or less. Somehow I managed to only blend the 3 textures together that were in the same pass, in bigger tests it would fail.

I fear that the approximated solution might have some cases that it doesn't handle properly.. Dunno man, unless someone have a bright idea I might call this dead :(

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Nov 13, 2014

Is this something that might become possible with the deferred shading branch, for example? Or would it take rewriting all the terrain shaders/shadergen?

@Azaezel
Copy link
Contributor

@Azaezel Azaezel commented Nov 13, 2014

10-1 having the capacity to write to a secondary render target during terrain layer accumulation would solve the problem. As would creating a one-off namedrendertarget similar to how the glowbuffer works. The latter line was explored though, and @lukaspj found the performance hit unacceptable.

Call it something to perhaps revisit once that is a stock feature if continued interest in that project is maintained.

@crabmusket
Copy link
Contributor

@crabmusket crabmusket commented Nov 13, 2014

Makes sense. @lukaspj I'll leave it in your hands if you want to close this PR and associated other ones. Would be a shame, but if we can't swing it then we can stop worrying about it and maybe revisit it later :).

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Nov 13, 2014

Hmm I'm currently thinking about trying to add a A8 texture, with the screen resolution, and make the pixelshader write and read that texture to preserve the Alpha and see the impact it has.

@rextimmy
Copy link
Contributor

@rextimmy rextimmy commented Nov 13, 2014

That A8 texture method may very well work. You can also tinker with the maximum number of combined materials. Currently it is hard coded at 3 (obviously each material has multiple textures). Modern GPU can handle a far higher number of samplers than when that code was written ;-)

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Nov 13, 2014

@rextimmy unfortunately dx9 has a hardcoded limit of 16, so thats as how as we can go anyways.
I'm thinking that this is the way to go if this should go anywhere:

Unless someone has a better idea :P

@rextimmy
Copy link
Contributor

@rextimmy rextimmy commented Nov 13, 2014

Oh yes your right, i'm stuck in OpenGL land where you will get double that :)

Let's say we have 3 passes. Pass one you write alpha to the new A8 texture, how are you going to sample and write to that texture in the second pass?

@lukaspj
Copy link
Contributor Author

@lukaspj lukaspj commented Nov 13, 2014

Well that was one of my issues, I wasn't sure whether that was possible or if I'd have to have two A8 textures and flip-flop between them.

@rextimmy
Copy link
Contributor

@rextimmy rextimmy commented Nov 13, 2014

Yeah you can't read and write to that texture at the same time :(. Give it a go with the two textures but it honestly sounds expensive :/

I think what i am going to do in DM to solve this is remove the macro texture (we don't use it) and increase that hard coded limit of 3 and get it as close to the maximum of 16. If it breaks the limit than spit out a warning and tell Nils to go easy and stop using so many textures in the one area lol

@crabmusket crabmusket removed their assignment Nov 27, 2014
@crabmusket crabmusket removed this from the 3.7 milestone Jan 28, 2015
@crabmusket crabmusket added this to the 3.8 milestone Jan 28, 2015
@crabmusket crabmusket added this to the 3.8 milestone Jan 28, 2015
@crabmusket crabmusket removed this from the 3.7 milestone Jan 28, 2015
@crabmusket crabmusket removed this from the 3.8 milestone Jun 24, 2015
@crabmusket crabmusket removed this from the 3.8 milestone Jun 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants