Volumetric Fog V: The story continues (update & Fix)
by Richard Marrevee · 09/29/2014 (1:03 pm) · 27 comments
A few weeks ago I launched the Volumetric Fog pack for Torque3D and as this was a little side project of me, I thought that it all ended there. But some of you gave some feedback about the new Volumetric Fog object so I decided to extend this little project and see if I can uplift it to a higher standard.
So here it is, the first update of the Volumetric Fog Pack for T3D and it can be downloaded from here again.
What has changed?
A few things, not big but important imho.
First, there was an issue with overlapping or colliding Fog objects. The Fog effect vanished at the intersection. This is now fixed, also some kind of depth sorting of multiple Fog Objects is added as you can see in the following images.



Furthermore, I've added a new setting called FadeSize. This setting controls the fade out of the density and the modulation effects when getting further away from the object.
What hasn't changed?
Some people "complained" about the sharp edges of the Fog Object. I had some kind of solution for this issue, but I decided not to give it a go (at least not now) because it didn't look to well and it gave an immense drop of my FPS (15 to 25 FPS) when applied. I will try to find another way to solve this, but it might be difficult to get some good results. The main problem here is the way the Volumetric Fog is created/rendered, it is not a real volume. It is mainly a mesh like a TSStatic, the only difference is the rendering part. A TSStatic renders a texture (material to the outside of the mesh and that's it, but the Fog object renders in 3 stages: first the backside is rendered to rendertarget which after rendering holds all the depth values of the backside of the mesh. This step is repeated for the frontside which is rendered to another rendertarget. So now we have 2 rendertargets, one holding the depth values of the backside and one holding the depth values of the frontside of the mesh. Now if you substract these 2 values you have the depth inside the mesh which than can be used to determine the density of the fog. This goes well if there are no objects in the fog, so you must test the depth of the backside against the depth of the objects in the scene (by using the prepassbuffer) and use the depth of the prepassbuffer if this is smaller than the depth of the backside buffer. It is not difficult to see that you will get hard lines (is max depth) when the backside edge is alined with the front side edge and the connecting face is parallel to the view direction.
Now to solve the hard edges I've tried some kind of edge detecting when making the final renderstep, but as said, it didn't looked to well and was very costly. If you have any ideas just let me know.
At last I thank you all for the support and I hope you have some use for this thingy.
Here is a link to the theory behind this implementation of the Volumetric Fog.
Thanks
Richard
Edit:
Added the link to the theory.
Edit 2:
Bugs Fixed and files modified.
So here it is, the first update of the Volumetric Fog Pack for T3D and it can be downloaded from here again.
What has changed?
A few things, not big but important imho.
First, there was an issue with overlapping or colliding Fog objects. The Fog effect vanished at the intersection. This is now fixed, also some kind of depth sorting of multiple Fog Objects is added as you can see in the following images.



Furthermore, I've added a new setting called FadeSize. This setting controls the fade out of the density and the modulation effects when getting further away from the object.
What hasn't changed?
Some people "complained" about the sharp edges of the Fog Object. I had some kind of solution for this issue, but I decided not to give it a go (at least not now) because it didn't look to well and it gave an immense drop of my FPS (15 to 25 FPS) when applied. I will try to find another way to solve this, but it might be difficult to get some good results. The main problem here is the way the Volumetric Fog is created/rendered, it is not a real volume. It is mainly a mesh like a TSStatic, the only difference is the rendering part. A TSStatic renders a texture (material to the outside of the mesh and that's it, but the Fog object renders in 3 stages: first the backside is rendered to rendertarget which after rendering holds all the depth values of the backside of the mesh. This step is repeated for the frontside which is rendered to another rendertarget. So now we have 2 rendertargets, one holding the depth values of the backside and one holding the depth values of the frontside of the mesh. Now if you substract these 2 values you have the depth inside the mesh which than can be used to determine the density of the fog. This goes well if there are no objects in the fog, so you must test the depth of the backside against the depth of the objects in the scene (by using the prepassbuffer) and use the depth of the prepassbuffer if this is smaller than the depth of the backside buffer. It is not difficult to see that you will get hard lines (is max depth) when the backside edge is alined with the front side edge and the connecting face is parallel to the view direction.
Now to solve the hard edges I've tried some kind of edge detecting when making the final renderstep, but as said, it didn't looked to well and was very costly. If you have any ideas just let me know.
At last I thank you all for the support and I hope you have some use for this thingy.
Here is a link to the theory behind this implementation of the Volumetric Fog.
Thanks
Richard
Edit:
Added the link to the theory.
Edit 2:
Bugs Fixed and files modified.
About the author
Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now developing an epic fantasy game: The Master's Eye. Creator of the DoorClass pack and VolumetricFog pack @ richardsgamestudio.com
#22
and then
11/30/2014 (3:46 pm)
Also, the quick fix I found to resolve the issue was to changebool VolumetricFog::UpdateBuffers(U32 dl, bool force)
{
if (mVB.isNull() || mIsVBDirty || dl != mCurDetailLevel || force)
{
mVB.set(GFX, det_size[dl].num_verts, GFXBufferTypeDynamic);
mIsVBDirty = false;
}and then
void VolumetricFog::prepRenderImage(SceneRenderState *state)
{
if (!state->isDiffusePass() || !mShapeLoaded || mFogDensity <= 0.0f)
return;
UpdateBuffers(0, true);
PROFILE_SCOPE(VolumetricFog_prepRenderImage);
#23
11/30/2014 (3:48 pm)
I'll hold up the pull till you have this sorted. Just let me know when your good to go.
#24
Will
info AT hallowscreams DOT com
12/31/2014 (4:52 pm)
Is this ever going to be added to the next MIT release of Torque 3D? Is there any plans? Still can't get it installed on my end. Been trying off and on for the last month and I give up trying. I re installed June 2010 SDK and got it to compile without the fog object code but it won't compile with it at all. Anyways if anyone could help me get a working compile that would be awesome. Please let me know thanks guysWill
info AT hallowscreams DOT com
#26
I've gone over the install directions [difficult for old eyes to read] repeatedly and been trying to compile but I keep getting this error:
01/14/2015 (11:10 am)
Do I need updated files to get this to work in 3.6+?I've gone over the install directions [difficult for old eyes to read] repeatedly and been trying to compile but I keep getting this error:
Quote:1>..\..\..\..\..\Engine\source\windowManager\platformWindow.cpp(25): error C2065: 'smScreenResChangeSignal' : undeclared identifier
#27
01/14/2015 (2:20 pm)
hmmm well I merged 3.6.2 with Vince's project and Boom! - works. Seems I needed the updates to guiCanvas... 
Torque Owner Vince Gee
WinterLeaf Entertainment
You need to delete your mShapeInstance.