• Register

Started programming in 1984 on an Oric, when time progressed switched to MSX, Amiga and finally the Windows PC with T3D. Now trying to get my ideas into an epic fantasy game called the Master's Eye. You can visit me at www.richardsgamestudio.com

  • View media
  • View media
  • View media
  • View media
  • View media
  • View media
RSS My Blogs

Looking at some of the missions in my game The Master's Eye I felt that they were missing something related to the ambience of this missions. In one case it was a room where a furnace was spitting out smoke, but the room was clear and not filled with dust/smoke, in another one there is a graveyard which needed a more spooky ambience. The common factor here was that both missions needed a little bit of fog, but only in the assigned areas. The common fog in T3D doesn't let you assign an area whit fog, so I decided to create a Volumetric Fog object! Browsing the internet I stumbled upon a document describing how this could be achieved with multiple rendertargets and some shaders. The only little problem was: I didn't know much about multiple rendertargets and shaders, so the dreaded learning curve was very steep.

But now, after a few weeks (holiday not included), I have something that works!!

At first it was only capable of rendering a box-shaped volume hardcoded in the object, but now it is possible to render almost any shape as a fogvolume, you can even use an apple as a volume as you can see in the following image.
Volumetric Fog object for Torque3D
So how does it work?

It is a 3 step rendering using multiple rendertargets and 2 shaders. The first step is rendering the depth values of the backside of the shape to a rendertarget using some kind of a prepass shader. The next step is rendering the depth values of the front of the shape to another rendertarget using the same prepass shader. Finally, render the fog in the scene by subtracting the 2 rendertargets to get the thickness of the fog.

This works great if there is only fog. Unfortunately it could be that there are some objects in the fog. So to catch this it uses the prepass buffer to determine the depth value at the current screen position. If this value is within the front to back range than this pixel is in the fog and we will use this value to determine the thickness of the fog. If it is beyond the back depth then this pixel is completely fogged, if it is less than the front depth than it is not fogged.
Another case is when the camera is in the fog, but that was fairly easy to solve by taking the camera position and check if it was within bounds, if so than act accordingly.

A few other things appeared along the way. There was no good way to clip the volume to the surrounding environment, so I used the prepassbuffer again to clip the volume. Only the depth values of the front and back targets didn't seem to be compatible with the depths achieved from the prepassbuffer. I tried some kind of multiplier on the values and that did seem to work well until I tried it in another mission :( .
At last I figured out what the problem was :) . The visible distance has an effect on the depth values of the prepassbuffer (all has to be in the 0.0 to 1.0 range) so having a visible distance of 1000 gives a much lower precision than a visible distance of 250. So taking this value in account it solved the clipping problem.

There are still some issues with it, like handling concave shapes and overlapping volumes, but for now it is what I need.

I guess you are curious to see it work, so here is a vid of it.


So what's next?

There is some kind of modulation of the thickness of the fog using a texture, which can be animated, but it doesn't work that great, so it needs some more work on it. Also fixing the issue with overlapping volumes and being able to use concave shapes would be nice, but for now I focus on releasing the playable demo of The Master's Eye which is delayed over and over again, and starting a funding campaign.

Should I expose this object to the Community?

Mmmmmmmm, good question. First of all I don't know if there is much interest in it ;P. On the other hand, it took some time to create this and delayed the demo and campaign of my game (it is time to generate some income from this) and giving it all away for nothing is something of a bridge to far at the moment. If I decide to sell it, it would be a very reasonable price though. Another thought that crossed my mind about this is if people wanting the code make a donation of a self-determined amount of money at my website www.richardsgamestudio.com and choose Donations.

I hope you have enjoyed this blog and I thank you for reading it.

Richard

Start a group Groups
R.G.S. - Richards Game Studio

R.G.S. - Richards Game Studio

1 member Developer & Publisher

Richards Game Studio or in short R.G.S. is an independent game studio based in the Netherlands. The main target is making games for the PC with a low...

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account:

X

Latest posts from @richardsgame

RT @Yorkscatrescue: George Jr has had a reservation fall through for him twice now.😿 We are hoping for third time lucky! He adores cudd… T.co

Jul 6 2023

RT @CatsOfYore: RALEIGH, NC! Someone please go get Leo! He's blind and has FIV so a lot of people might pass him by due to misconce… T.co

Jun 25 2023

RT @mrfishtopher: KENT, WA! Petfinder.com T.co

Jun 23 2023

RT @LMuhs: If anyone is in the greater Kentucky area, this sweet man and his friends need adopted 💔 @mrfishtopher @JortsTheCat T.co

Jun 22 2023

RT @Rat_flavored: Some close friends need help with a hefty vet bill for a rare condition their cat just got diagnosed with. Belmont… T.co

May 30 2023

RT @mrfishtopher: bubba is one of the first cats ive ever posted and hes still looking for a home😭 T.co

May 28 2023

RT @SoftSide1: 📣 TWITTER! Ok, did we get your attention? Meet beautiful kitty Kayla! She’s 17 years old & up for adoption at… T.co

May 20 2023

RT @feederofcats: 🚨 SOMERS POINT, NJ 🚨 oh my god please let's find Honey a home! looks like she needs to be the only pet someone p… T.co

May 20 2023

RT @mjames323: Geo 🥺🥺🥺🥺 @mrfishtopher in Milwaukee!! T.co

May 17 2023