Changes to the Terrain Class
First thing I had to do was figure out how to add tangents to the terrain Vertex Element, so I put a post on the XNA Creators Club (no laughing at my game tag, I have been trying to change it but to no avail..) and Shawn Hargreaves replied with the solution. I think I may have applied it too literally as there is another post on there pointing to an article on ziggyware describing how to generate tangents and it is quite a lump of code! Also, I have tested my stuff with the tangent elements removed...and it still seems to work, odd. But what the hell I am new to all this and I got the bump mapping working and that is all I am bothered about. Though, if you can point me in the direction for creating the tangent data correctly then please post a comment :)
So, the code changes. I added a tangent vector3 to the Vertex Element.
Once this was added I had to calcualte the tangent data per vertex. So in my BuildTerrain method of the class I added a line to the loop that calulates the vertex normal. (second loop in the method)
Now that was all set up I needed to get the normals passed to the class and store them. So I have added these fields and properties.
Now I altered the constructor to handle the new texture feed.
And added this loop to the LoadGraphicsContent method
Will all that set up I now altered the Render method to use the new textures
Now to the shaders, the first shader was Reimers origional terrain shader the only change I have really made is to add the bump/normal mapping. The second shader is mine, I have put a few more comments in mine so it should be a bit more readable.
Reimers Shader modified by me
Right here are a number of screen shots from different angles so you can see how the two shaders render, I have also put up my FPS counter so you can see the performance.
In each set I do my best to get the same camera position. Oh and I don't want you to think that Reimers shader is the worst of the two, my shader is quicker because it does the job in a much cruder way. I guess you have to go for speed or beuty, unless your machine is supper fast.
Riemers with Bump/Normal mapping Pic 1
My shader Pic 1
Riemers with Bump/Normal mapping Pic2
My shader Pic 2
Riemers with Bump/Normal mapping Pic 3
My shader Pic 3
Riemers with Bump/Normal mapping Pic 4
Terrain Up Close
Here are images of the terrain up close. I think you will agree using Remiers terrain render is better looking, well especialy now it has bump mapping :)
Riemers with Bump/Normal mapping Sand
My shader Sand
Riemers with Bump/Normal mapping Grass
My shader Grass
Riemers with Bump/Normal mapping Stone
My shader Stone
Riemers with Bump/Normal mapping Snow
My shader Snow
Textures and Normals
Here are the textures used in my examples, they are not the origional DDS files as this blog wont host them, all you have to do is go to Reimers turorial, and you can down load the textures there, all you have to do then is use PhotoShop and NVIDIAs Normal tool to generate the normal. If I have time I will put a zip up on my server and link to it from here.
Sand & Normal
Grass & Normal
Stone & Normal
Snow & Normal
By all means please, if you optomize these shaders ot even the terrain class I would love to know what you did. I am planning on doing terrain culling in the future and if I ever get time to get my head into it ROAM terrain.
PHEW! That has to be my biggest post!
Posted Mon, Oct 15 2007 8:14 PM by Charles Humphrey | Add post to favorites | Add blog to favorites
Filed under: Randomchaos 3D Engine, Terrain, Bump/Normal Mapping, XNA 1.0 [Edit Tags]