Fog?
by Tom Spilman · in Torque Game Engine Advanced · 05/18/2005 (10:31 am) · 8 replies
My artist is looking to add fog within a room in an interior. What kinda fog options do i have with TSE out of the box that could handle that? Are there any more advanced techniques i could achive via shaders that would do a better job?
About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.
#2
Sounds like you need a new fog system and a modified fog procedural shader generator.
05/18/2005 (12:11 pm)
He wants fog just in one room but not elsewhere? It's not set up to do that kind of thing. You could use CustomMaterials for all the materials in that room and then code a special fog shader for them, but that's pretty special case.Sounds like you need a new fog system and a modified fog procedural shader generator.
#3
A volumetric fog object like in unreal would seem to be a good way to do this as it wouldn't require changes to all the materials in the room using a CustomMaterial as Brian suggests. It also sounds like a nice little project that doesn't effect other areas of the engine too much.
Must research it a bit. I remember alot of volumetric fog demos in the old DX SDKs and such. One of those should be easy to add as a mission object to TSE.
05/18/2005 (12:51 pm)
Yea the built in fog banks won't work for us and it does seem that there is not any other means of fogging a limited space.A volumetric fog object like in unreal would seem to be a good way to do this as it wouldn't require changes to all the materials in the room using a CustomMaterial as Brian suggests. It also sounds like a nice little project that doesn't effect other areas of the engine too much.
Must research it a bit. I remember alot of volumetric fog demos in the old DX SDKs and such. One of those should be easy to add as a mission object to TSE.
#4
In a 2nd pass over the scene, draw the volumetrig object with a shader that decreases the alpha value for the output color as the Z distance between the current fragment and the Z value already in the buffer decreases, based on a maximum distance value.
As example: you have a screen-aligned quad, with an alpha texture (a cloud texture, as example). You define a maximum distance of 50 units. You have an opaque screen-aligned quad positioned behind it by 25 units.
The "cloud" quad would be drawn at 50% alpha. If the opaque quad is brought closer to only 5 units from the cloud quad, the clouds would become 10% alpha. If both overlap, the clouds would become fully transparent. Since this is per-fragment, and uses the z-buffer to control the alpha, it pretty much does the same effect as fog (with a texture to boot). Of course there would be problems with semi-transparent objects, that wouldn't be correctly affected by fog since they don't write to the z-buffer.
I did a quick mock-up on Photoshop, using a Z-buffer as alpha channel, and the effect if quite interesting:
The scene:

With "fog" (a quad using the z-buffer values as alpha)

With fog modulating another alpha image:
11/09/2005 (7:26 am)
I have this idea for volumetric fog/sprites/lights, but not enough shader experience to implement it, but I think it should be straightforward.In a 2nd pass over the scene, draw the volumetrig object with a shader that decreases the alpha value for the output color as the Z distance between the current fragment and the Z value already in the buffer decreases, based on a maximum distance value.
As example: you have a screen-aligned quad, with an alpha texture (a cloud texture, as example). You define a maximum distance of 50 units. You have an opaque screen-aligned quad positioned behind it by 25 units.
The "cloud" quad would be drawn at 50% alpha. If the opaque quad is brought closer to only 5 units from the cloud quad, the clouds would become 10% alpha. If both overlap, the clouds would become fully transparent. Since this is per-fragment, and uses the z-buffer to control the alpha, it pretty much does the same effect as fog (with a texture to boot). Of course there would be problems with semi-transparent objects, that wouldn't be correctly affected by fog since they don't write to the z-buffer.
I did a quick mock-up on Photoshop, using a Z-buffer as alpha channel, and the effect if quite interesting:
The scene:

With "fog" (a quad using the z-buffer values as alpha)

With fog modulating another alpha image:
#5
11/09/2005 (12:53 pm)
In general, its traditional to simply use particles to do localized "fog." In the last splinter cell game there were some good examples in a Japanese bath house.
#6
Manoel's method (If I understand correctly) seems to appoximate the raycast by only considering the Z distance. Probably will work well in lots of common situations, but I imagine it'll look funny in bigger scenes when the raycasts aren't so in line with the Z axis.
Particle methods are a good half measure if you don't want to code in a 'real' volumetric fog solution.
11/09/2005 (1:20 pm)
Well, not traditional. It's 'traditional' to model volumetric fog with raycasting through the fog volume, and scaling the alpha blend to the length of the raycast. Sometimes you can speed this up with shaders or by using the stencil buffer.Manoel's method (If I understand correctly) seems to appoximate the raycast by only considering the Z distance. Probably will work well in lots of common situations, but I imagine it'll look funny in bigger scenes when the raycasts aren't so in line with the Z axis.
Particle methods are a good half measure if you don't want to code in a 'real' volumetric fog solution.
#7
Using the Z distance between the particle fragment and the existing buffer fragment to adjust the alpha, the particle will never "laser cut" other surfaces, since it'll fade out where the surfaces are close enough.
11/10/2005 (5:53 am)
Well, I've actually though of using "my" method to render particles. The problem with particles is that the illusion is completly destroyed the moment they intersect other geometry, making the quads themselves visible.Using the Z distance between the particle fragment and the existing buffer fragment to adjust the alpha, the particle will never "laser cut" other surfaces, since it'll fade out where the surfaces are close enough.
#8
07/24/2006 (3:37 pm)
Call of Duty 2 did some sort of displacement for smoke effects and such, resulting in a roundish curve at intersections. Would look a lot more natural than a flat billboard.
Associate Kyle Carter
A "Volumetric Fog Object" a al Unreal 1 would be cool tho I've no idea how one would implement it.