Game Development Community

Fog Rendering

by William Todd Scott · in Torque Game Engine · 01/29/2006 (10:38 pm) · 7 replies

Hi all,

I have added a custom type of shape and am going through the process of making it render properly with fog.

From what I can tell, fog rendering is handled in different ways for different object types. It appears that interiors use fog coordinates, TS instances use a fog texture, and I haven't quite figured out what the terrain is doing.

Can someone let me know what method is best and perhaps explain to me why the different methods are used?

(or if I have completely missed what is going on!)

Thanks for the help.
Todd

#1
01/30/2006 (12:34 am)
You are correct, textured fogging is what TS instances use, while interiors use vertex-based fogging. Textured fogging is supported on pretty much any hardware, while vertex-based fogging requires certain hardware (although most hardware made within the last 8 years supports vertex-based fogging). Textured fogging is also quite a bit faster than vertex-based fogging, but a whole lot uglier.

Textured fogging basically creates a texture to be applied to your shape based on the shapes distance from your camera. Vertex fogging calculates a fog level (based on the distance from camera) for each vertice of an interior and then uses hardware to perform the actual fogging.

Anyway, to help you in getting your shape fogged... You first need to make sure you are inheriting from some type of class that gives you rendering capabilities. You will basically need the renderObject function to be able to tap into Torque's fogging. In the renderObject function, simply call 'state->getHazeAndFog(distance between camera and point, height difference between camera and point)' to determine how much fog a given point should get. 'state' in this case is a the SceneState object passed into the renderObject function.

An example of this would be:
Point3F cameraPosition = state->getCameraPosition();
// The render position of our shapebase object
Point3F shapePosition;
// Grab the render position of our shapebase object
getRenderTransform().getColumn(3, &shapePosition);
// A value to store the offset from our scene's camera to our shapebase
Point3F cameraOffset = shapePosition - cameraPosition;
// Grab the amount of fog at that distance from the camera
F32 fogAmount = state->getHazeAndFog(cameraOffset.len(), cameraOffset.z);

This would give you the fog amount at the position of the shape. You could then fog the entire shape this value (using the fogColor: state->getFogColor()). Torque's TS Instanced shapes are quite ugly since they are texture fogged uniformly (meaning they use the same fog value for the entire shape).

If you have access to vertice data, you can feed the 'getHazeAndFog' function the difference between your camera's position and your vertice positions and then use that to fog individual vertices. I won't get into this as it can get more complicated (although not really all that complex, if you're feeling adventurous) but you get the gist.

I hope this helped you a bit on your quest to get custom fogged shapes!

Cheers,

Stephane
#2
01/30/2006 (6:18 am)
Did anyone got to sucessfully use per-vertex hardware fog on TS instances? I tried to enable them, but the results were bizarre, with fog levels changing crazily with distance, and the fog values for some instances apparently bleeding onto another instances. I also tried per pixel fog, but the result was absolutely weird.

I have to use some large TS instances at times, and they don't get fogged correctly by the "single fog value for the entire model" system that TGE uses.
#3
01/30/2006 (6:38 am)
Stephane,

Thanks for the great description! Now I get what is going on and have a pretty good idea why.

I am going to implement vertex fogging and take a look at the performance hit. Looping through the vertices to assign fog coordinates every frame seems a bit painful, but it is working on the difs...

(Manoel, if I get this working I will post the code, that might help with implementing it for the dts shapes.)

Thanks again.
Todd
#4
02/15/2006 (8:12 pm)
Hey guys,

I have gotten vertex fogging into Torque... it wasn't all that complicated...

The performance hit is about 4 or 5 frames per second on an AMD 64 3000, GeForce 6600, 512 MB RAM.

It really makes a huge difference in visual quality though... We have some really massive shapes and they look like absolute ass without the vertex fogging.

@William: "if I get this working I will post the code, that might help with implementing it for the dts shapes." - What are you planning on implementing vertex fogging with, if not dts shapes?

Cheers,

Stephane

Edit: The frame-rate hit on a slower machine (I've tried it on a couple of pentium 3s with 600Mhz processors and GeForce 2 cards) is about the same (4 or 5 frames per second), but when you are already running at only 25fps, 4 or 5 frames can mean a world of difference...
#5
02/15/2006 (8:30 pm)
Hey Stephane,

I did get it working for my shapes. I am working on custom outdoor environment rendering and there are components that do not fit into the dts or dif type of shapes. I didn't post the code because I didn't feel like it could be pasted into the dts rendering code and I haven't had the the time to go through the dts code.

edit: But it would be great to see how you did it for dts shapes!

Thanks
Todd
#6
02/16/2006 (3:25 am)
Hi Stephane,

I'm also looking into how to get vertex fogging working for large dts shapes and would also really appreciate seeing how you did it.

If you get the chance to post your code I'd be eternally grateful!

Many Thanks

Simon
#7
02/18/2006 (3:44 am)
Hey guys,

Unfortunately, I'm pretty grossly busy at the moment, but I will try to post some stuff when I get a chance... I still have some outstanding water-block code that I promised to post a while back... so I probably have to get that out there first.

Cheers,

Stephane