Game Development Community

dev|Pro Game Development Curriculum

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.

games.marrevee.com/images/VF1a.png

games.marrevee.com/images/VF1b.png

games.marrevee.com/images/VF1c.png

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

Page «Previous 1 2
#1
09/29/2014 (1:34 pm)
Cool stuff, Richard!

Just a thought about the hard edges ... would it be possible to have like ... zones or something going deeper inside the object, each with their own level of density? Sort of like faking density changes ... so outer (light fog), inner (foggier), central (foggiest) ... just a thought anyhow.
#2
09/29/2014 (2:58 pm)
Looking very pretty! Thanks for going the extra distance and putting in the effort to improve and maintain this!
#3
09/29/2014 (7:08 pm)
Looks great, but there appears to be a couple bugs still.

Use Rock1 as the model for the fog and there will be spots where you can see through the fog where the angles change.
#4
09/29/2014 (11:30 pm)
@Steve:
Yes, that would be possible, I've tried it but it also had some issues at the corners. You can also have fog in fog with different densities.

@Daniel:
Thanks, I hope you like it.

@Vince:
It is not a bug but Rock1 is a concave shape, which do not render right, due to limitations of the rendertargets/hardware/gfx. It is possible to implement a sort of correct rendering of concave shapes, but it will become costly (it will add a few drawcalls and consume a lot of memory because there are at least 2 more rendertargets necessary), but then you will have issues with objects in the fog, which might or might not be solved.
#5
09/30/2014 (8:36 pm)
Also,

One other bug, if you don't texture the fog it will crash saying $modspeed is not assigned.

To fix, change the code in VolumetricFog.cpp

if (mIsTextured && mStrength > 0.0f)
	{
		GFX->setTexture(3, mTexture);
		mShaderConsts->setSafe(mIsTexturedSC, 1.0f);
		
	}
	else
		mShaderConsts->setSafe(mIsTexturedSC, 0.0f);
	mShaderConsts->setSafe(mModStrengthSC, mStrength);
	mShaderConsts->setSafe(mModSpeedSC, mSpeed);
	mShaderConsts->setSafe(mViewPointSC, mViewPoint);
	mShaderConsts->setSafe(mTexScaleSC, mTexScale * mFOV);
	mShaderConsts->setSafe(mTexTilesSC, mTexTiles);
#6
10/01/2014 (1:36 am)
@Vince:
Normally this should happen only when running a debug build of the engine, but you're right.

Also found another bug which only occurs whit a debug build, here is the fix:

In VolumetricFog.cpp at line 769 change:
ri->defaultKey = dist;

into this:
if (dist<1.0)
		ri->defaultKey = 1;
	else
		ri->defaultKey = U32(dist);

Or you can download the updated file.
#7
10/01/2014 (4:38 am)
Cool Stuff, Richard! Really like that fog. Made a twister with a fog model, looking not too bad :)
#8
10/01/2014 (8:25 am)
@D Fasel:
If you can please post a picture of it. I'm curious on what other people do with it.
#9
10/01/2014 (6:09 pm)

that was just a fast test, I'm sure it could look much better.
#10
10/02/2014 (7:06 am)
@D Fasel:
It's looking good already. Thanks.
#11
10/10/2014 (2:15 pm)
Question's come up of integrating this into head. Interested?
#12
10/13/2014 (12:56 pm)
@Azaezel:
Sure I'm interested, but right now I'm busy with a Door class for T3D.
#13
10/13/2014 (1:37 pm)
Richard,

Great work. I would also add into the 'wish it could do this' category...Adapt the sun/light color within the fog 'object'. This is coming from a purely artist standpoint since... hey.... the light affects everything.

Overall, GREAT work and even with errors here and there.... IMPRESSIVE as all hell. I like it an now include it in all of my 'project' builds.

Ron
#14
10/14/2014 (11:07 am)
@Ron:
Nice to see you're still roaming these lands. Glad you like it. The lighting adaptation is on my todo list, but first I want to launch the playable demo of my game The Master's Eye, which will be after I've finished the new Door class for T3D (which is almost finished).
#15
11/13/2014 (7:04 am)
The fog disappear in t3d 3.6.2 after i switch to the editor or change the screen resolution. The fog come back after restart the mission.
Did i some thing wrong, or is this a bug?
#16
11/13/2014 (1:09 pm)
@D Fasel:
You didn't something wrong here, it isn't a bug also, it is however known and I am working on a way to catch the resize of the Torque screen. The problem is caused by the rendertargets which are created at game startup. If you change the resolution after that, they don't resize too and causing the issues you see. As said I am working on the resize part.
#17
11/13/2014 (7:29 pm)
Cool idea I want to get around to: link fog zones to triggers that enable screen-space glow and sun rays. For bonus points, link all of that to a dynamic value that increases/decreases the shader strengths when the fog thickness changes. Bonus bonus points for creating fog volumes dynamically in areas with lots of gunfire :D.

I think at least enabling screenspace glow in smoky rooms would be nice, and give a bit more atmosphere to taverns, etc.
#18
11/15/2014 (1:39 pm)
@Daniel:
I'll see what I can do.
#19
11/30/2014 (2:19 pm)
@Richard,

I don't mind doing the pull for you if you don't have time. I also have a work around for the bug on screen resolution changing. If you can just give the MIT Committee permission to incorporate this into the head I'll take care of the details.

Vince
#20
11/30/2014 (2:40 pm)
@Vince:
Permission granted!, but... I am almost finished with a big update, which includes fixing the resolution change, but also adding a few things like screenspace glow and influencing lightrays when in the fog. If you have some patience you'll get something more complete, it should be ready before the end of the week (all work is done except the installation guide and the manual).
Page «Previous 1 2