Normal on mega terrains
by Kory Imaginism · in Torque Game Engine Advanced · 04/26/2008 (2:17 pm) · 11 replies
Do you think it possible to change the sources code of a mega terrain and have it read materials.cs so you can add normal map on the mega terrain?
thanks
thanks
#2
04/26/2008 (5:15 pm)
Awesome. Does your implementation take multiple normal maps into account? Like, can each base layer have its own normal map or does it just use one normal map?
#3
04/26/2008 (10:26 pm)
That looks pretty darn cool. =)
#4
04/28/2008 (5:45 am)
Would you mind sharing how you managed to get it working?
#5
Quite fun!
04/28/2008 (8:34 am)
It looks sweet in close-up, but seems to accentuate the tile-ness of the terrain in the distance, at least with the textures used.Quite fun!
#6
04/28/2008 (9:16 am)
Click on picture 4 and read the Comment if you want to know how it done.
#7
04/28/2008 (3:54 pm)
In all seriousness, such technology is available without many changes. I'm working on an implementation of dynamic lighting and normal mapped terrains which should be ready soon.
#8
04/28/2008 (6:11 pm)
Thank you sorry about the joke, i was just trying to get someone with programming skill to check it out.
#9
Normal maps are related to the diffuse texture they are rendered with, so the source for the normal map needs to be blended along side the diffuse, or it needs to be a unique source along side a unique diffuse source. So either way it looks like you are going to have a clipmap for the normal map. Normal maps need to be high-fidelity or it doesn't really do much good. The clipmap already uploads a lot of texture data per frame, depending on how fast you are moving etc in your game (you can get this information via nvPerfHud or GPU PerfStudio), so adding a second clipmap would really eat up some texture space.
Another thing to consider is what space the normal maps will be in. Chances are they will be in tangent space, especially if they are blended, so you will need to construct an object-to-tangent space matrix in the vertex shader, in the same way that ShaderGen does now, and pass it to the pixel shader. It probably makes the most sense to only do the bump mapping on the highest clipmap level render. Otherwise you are just burning fillrate on effects that are too far away to see anyway.
It would be really interesting to figure out if you could pack both diffuse information and normal into a single clipmap. A tangent-space normal can be stored with only 2 components, x and y, because Z is always positive, and the normal is normalized so you can reconstruct z.
Not sure if any of that helps, or just throws people off course. I think the easiest way to do this, though (ie requiring least # of code changes) is to try packing everything into one clipmap entry (maybe try a 64-bit format to start with).
04/29/2008 (9:56 am)
I thought about doing this in Legions but ran out of time. Here is a bit of a brain dump for people who want to get this working:Normal maps are related to the diffuse texture they are rendered with, so the source for the normal map needs to be blended along side the diffuse, or it needs to be a unique source along side a unique diffuse source. So either way it looks like you are going to have a clipmap for the normal map. Normal maps need to be high-fidelity or it doesn't really do much good. The clipmap already uploads a lot of texture data per frame, depending on how fast you are moving etc in your game (you can get this information via nvPerfHud or GPU PerfStudio), so adding a second clipmap would really eat up some texture space.
Another thing to consider is what space the normal maps will be in. Chances are they will be in tangent space, especially if they are blended, so you will need to construct an object-to-tangent space matrix in the vertex shader, in the same way that ShaderGen does now, and pass it to the pixel shader. It probably makes the most sense to only do the bump mapping on the highest clipmap level render. Otherwise you are just burning fillrate on effects that are too far away to see anyway.
It would be really interesting to figure out if you could pack both diffuse information and normal into a single clipmap. A tangent-space normal can be stored with only 2 components, x and y, because Z is always positive, and the normal is normalized so you can reconstruct z.
|V| = sqrt( x*x + y*y + z*z ) |V| = 1 for normalized vectors 1 = sqrt( x*x + y*y + z*z ) sqrt(1) = x*x + y*y + z*z sqrt(1) - z*z = x*x + y*y -z*z = x*x + y+y - 1 z*z = -x*x - y*y + 1 z*z = 1 - x*x -y*y z = +/-sqrt( 1 - x*x -y*y )This is the 'trick' behind using DXT1/5 to compress normal maps. It works perfectly in tangent space because z is always positive. So my thoughts are that you could load a pair (diffuse and normal) into a single R8G8B8A8 texture. Storing the normal in 16 bits is no problem, storing the diffuse texture in 16 bits could be a problem. Once that problem is solved (and I suspect there are numerous solutions) then you should be pretty golden. The blending of normal maps should yield some interesting artifacts, and work-arounds.
Not sure if any of that helps, or just throws people off course. I think the easiest way to do this, though (ie requiring least # of code changes) is to try packing everything into one clipmap entry (maybe try a 64-bit format to start with).
#10
The next step would be sampling the opacity/blend map and setting this as a per-base texture effect. For example, you could have a bump map specifically being applied to stones, but another being specifically applied to grass.

05/01/2008 (4:06 pm)
Hmm. Interesting. Due to the challenges involved with clipmapped normal mapping and the fact that it's a subtle effect reserved for close-up details, I decided to implement normal mapping on a detail texture basis. Currently, the effect is being done using the detail shader code combined with normal-map specific elements. A parallax map is sampled using the red channel, though once I figure out how to load up ddses, it will use the alpha channel.The next step would be sampling the opacity/blend map and setting this as a per-base texture effect. For example, you could have a bump map specifically being applied to stones, but another being specifically applied to grass.

#11
A better implementation of this with normal mapping would be great. Vanguard does this on their terrain and it is by far the best looking terrain I've ever seen in a video game. Another trick they use is that they use a different detail texture up close and another one at a distance which gives the mountains a very nice ridge like look, and far off terrain looks bumpy and grassy. Because they use a high amount of grass or groundcover its very hard to actually tell that its using different details from far and near. When I was coding my detail textures though I put a lot of time in trying to figure out what they were doing and duplicating it. My implementation fell well short of where I wanted it to be unfortunately.
05/02/2008 (1:36 am)
I took a stab at doing multiple detail textures with clipmaps a while back. I was able to get it working, but I had some bad issues with popping at different clipmap levels, and as a result of that I had to limit the detail texture distance to be really close (like 50 meters) so that it wasn't noticeable, and the tradeoff there was that it hurt the overall effect. Basically for testing I used a single texture with 4 8 bit values each being an 8 bit detail texture. For testing I just numbered them 1, 2, 3 and 4 and then used an opacity map (which was a load in option) and sampled the location from the opacity map and then used a different detail shader for each of the layers, one which used the red channel, one green, one blue, one alpha. The problem though was that as you moved an area which would have been using the red channel originally would pop and hange to the blue channel as you moved through it, and the popping was really noticeable and ugly. I think part of this had to do with clipmapping and part had to do with the way I was sampling the opacity map. With a very small distance the popping was stil there but it wasn't very evident, you really couldn't tell if you had some foliage or clutter in the area, and that was basically the concession I had to live with. A better implementation of this with normal mapping would be great. Vanguard does this on their terrain and it is by far the best looking terrain I've ever seen in a video game. Another trick they use is that they use a different detail texture up close and another one at a distance which gives the mountains a very nice ridge like look, and far off terrain looks bumpy and grassy. Because they use a high amount of grass or groundcover its very hard to actually tell that its using different details from far and near. When I was coding my detail textures though I put a lot of time in trying to figure out what they were doing and duplicating it. My implementation fell well short of where I wanted it to be unfortunately.
Torque Owner Kory Imaginism
innovative imaginations
4