XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

This Blog

Syndication

Twitters

RandomChaos

Simple Bumped Terrain and Water with Fog

http://www.youtube.com/v/z8C509TYnPA <p><a href="http://www.youtube.com/v/z8C509TYnPA">http://www.youtube.com/v/z8C509TYnPA</a></p>  

 

Well here is the same skybox, terrain and ocean objects, only this time I have added the fogging effect to the shader. Naturally the class' have had to be modified to pass the fog parameters and I have added a global static class that stores the fogging parameters that are to be applied to each object in the scene.

In the shaders, I have placed the fogging code into the second pass, in the case of the sky box this is not really needed as this shader uses very few instructions, but as for the terrain and ocean shaders they both touch the bounds of the PS instruction sets for the shader model I can use (SM2 64 instructions). You will also notice that the ocean that I have had to use COLOR channels for the return values from the vertex shader, this is because SM2 will only go as far as 7 texcoord channels (TEXTCOORD7), if you have the luxury of being able to use SM3 then you will be able to change these to TEXCOORD8. I also had to remove the old TEXCOORD7 so that I could use it for my WorldPos parameter, instead of this being passed, it is calculated in the pixel shader and so elevated the channel for this use.

Also in all the shaders I have decided to manage the render states in the passes, you may want to moth this to the code, but I guess it depends on how you intend to implement it. 

So the controls are the same as the last post, but you can now switch the fog on or off with F - fog on (default) or O  - fog off.

GenericXNAExampleTerrainWithFog.zip 

Comments

 

andrew said:

I found you from a forum post on riemer's site. I take it your terrain is an adaptation of his.

I was getting absolutely absurd fps problems with his code (averaging 30 fps), so I'm curious to see if i get the same problems with yours. well I'll check it out.

thanks much

October 30, 2007 4:55 AM
 

Nemo Krad said:

Yes the original is based on Riemer's work, and I too found it heavy of the FPS. I discovered this was down to the shader so in these Generic XNA samples I have put up I have written my own terrain shader.

It is cruder than Riemer's but give a boost to FPS, in this example though I have added a second pass for the fog and so this may pull it down again. I have not done this with Riemer's terrain shader.

Also remember I have added bump/normal mapping to this terrain also so that too will add to the FPS drain. If you look back through the posts you will find where I started to optimize the terrain shader, you will find Riemer's terrain shader (almost original), Riemer's terrain shader bumped as well as my derivative, both simple, bumped and fogged.

October 30, 2007 9:39 AM
 

andrew said:

out of curiosity, what frame rate are you getting with your version?

I added a simple FPS counter, and found that I was only getting around 15 fps when I expanded the window to full screen (1280*1024).

The weird thing is that my computer can handle Half Life 2 on full settings and Oblivion on medium. I know XNA doesn't perform as well as unmanaged code, but it should still run better than it does. I'm really puzzled by this,

heres the link to the FPS counter code if your interested

blogs.msdn.com/.../displaying-the-framerate.aspx

thanks,

Andrew

November 1, 2007 5:08 AM
 

Nemo Krad said:

I have an FPS counter like that, I am sure it is in one of my posts here.

I used FRAPS and found I am getting 25fps on my Laptop (windowed), you must keep in mind that this laptop is probably near the bottom end of specification for 3D and gaming in general.

Also, there is no culling of this terrain or any real LOD work done here, also  Half Life 2 and Oblivion are written by professional games developers that have had years of games writing experience, I get a bout 4 hours a week to play with this stuff :P

I have been working on a self culling terrain class and and this bumps the FPS up a great deal, once I have it down and it is in a presentable format I will post it here.

November 1, 2007 9:35 AM
 

andrew said:

cool. I'm very interested to see what you come up with.

thanks much

andrew

November 1, 2007 9:47 PM
 

JeBuS said:

Hey, these are great examples, but I was wondering something about the water.  The effect of the animated water makes it appear as though it is moving in one direction.  Is there some way to perhaps add a second pass using the normal map maybe inverted and going the opposite way?  I don't know much about HLSL, so forgive my ignorance is this is a simple matter.

December 29, 2007 6:51 AM
 

Nemo Krad said:

Yes I guess so, but I would think this would make the water look odd as you would want the flow to follow the wave...?

Are you asking me to do an example with a switchable direction of flow??

December 29, 2007 8:36 PM
 

JeBuS said:

Well, if it were a large body of water, like the open ocean, waves don't always just go in one direction.  The sea surface just kind of rises and falls, if you get my drift.  So having all of the waves going in one direction makes it look like it's either near a shore (where all of the water is going towards the shore), or it's some funky river in the ocean.

I hope I described that well. :-)

December 29, 2007 8:51 PM
 

Nemo Krad said:

Ah, I get what you are saying. Well the shader is by NVIDIA and I guess it was to be used for Ocean that is close to the shaw.

You could remove the flow, I have not looked at removing this yet, but will if you like, can't see it being that difficult.

December 30, 2007 7:29 PM
 

JeBuS said:

I'd appreciate it if you could.  It's not a huge deal, really, and it could wait until I have time to study HLSL, but who knows when that will be. :-)

December 31, 2007 7:15 PM
 

Nemo Krad said:

JeBuS,

OK, this is dead easy to sort out. In the shader set the bumpSpeed value to {0.0,0.0} and your flow is stopped.

Now if I was you I would add another field and property to the class so it can be altered at runtime and so giving you even more control over the shader. There are SOO many other params I have not touched in this shader, I love it, thank you NVIDIA.

I really should look at writing my own water one day...

Hope this helps :P

December 31, 2007 9:32 PM
 

JeBuS said:

I suppose stopping it altogether is an option, though I was hoping for something more along the lines of overlayed bump maps going in different directions.

Thanks for your help, though!

January 3, 2008 5:39 AM
 

Nemo Krad said:

OK, now I know what you are after I will take a look.

January 3, 2008 9:40 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About Nemo Krad

Have been a professional developer since 1995. My skill set ranges from C/C++, VB6,MSSQL, Java Script, VB Script, HTML/ASP, Java, C#, ASP.NET as well as others. I started 3D and games development when the first release of XNA came out in December 2006 and have become addicted to it.