BloodRayne@Posted: Tue Dec 07, 2004 11:58 am :
It can be a pain in the ass to set up real looking fog for a level of Doom 3. Sure, we have the fog lights but they never seem to look good enough and have lots of glitches. While working on a swamp-like level for the Hexen conversion I've devised a good way for setting up fog which acts the way you expect it would act. This tutorials is not for beginners, it's an advanced method. Unfortunately I don't have much time to answer any questions that may popup but maybe other posters can chip in for me here. This is for singleplayer only!

The way fog works:
Real fog has a visibility which is defined in an amount of meters(or miles) away from the pov. This means that if you stand on point A and you have 50 meters visibility then walk to point B you would still have 50 meters visibility. The foglights in the Doom3 engine don't have this property. They are stationary and that's where the problems begin.

Doom3
In the Doom 3 engine you have two types of fogs, the first is a foglight and the second on is a blendlight. For this method we will be using the blendlight type because this one is easier to setup and control.

Skies
One problem with fog is that skies are allways rendered straight over everything. This means that the sky will not look 'fogged'. This means that you will have to make a new skyshader (for outdoors) that will have the same color as the fog blends to. You'll see what I mean later.

On to the method
The material:
For this we first make a light which has the following shader, make *sure* that this shader has an alpha channel. I won't explain alpha channels here but there are tutorials on this board about that.
Image

Place this texture as a .tga file into your textures directory, we will make a reference to this texture from the material file below. I've named the texture fog_tex.tga. Imagine now that the players pov is where the black dot is. Inside the black dot the player can see as far as the black dot reaches. The white is what gets fogged out, you can give the fog different colors by editing this texture and giving the white part a different color. This way you can make fog in any color. I've chosen for a yellowish white in this instance. Now make a new material file called 'myfogs.mtr' inside the materials directory and copy and paste in this code:

Code:
fogs/real_fog
{
   noShadows
   blendLight
   {
      blend add
      map      textures/fog_tex.tga
      zeroclamp   // make sure it doesn't bleed over the edges
   }
}


You can edit the material to add animations or other shader tricks, you can even add overlapping layers but this will complicate things. You can also use this method to make rain or snow but I won't go into that now.

Here's how to add a layer, in this instance I added a black&white clouds texture. The fog now looks like it's slowly creaping upwards.
Code:
fogs/swamp_glare
{
   noShadows
   blendLight
   //lightFalloffImage   textures/fog_tex.tga
   
   {
      blend add
      map      textures/fog_tex1.tga
      zeroclamp   // make sure it doesn't bleed over the edges
      //colored      // take rgba from entity shaderparms
   }
   {
      blend filter
      map       textures/clouds.tga
      scroll       time * 0.02, 0
   }
}


The script:
You will have to add a script to your map to make this method work, see rich's tutorial on mapscripts to see how to set up a script. Inside this script we spawn a light and bind this light to the player.

Code:
// sets up the fog for this level

void setup_objects()
{
      entity foglight;
   $foglight = sys.spawn( "light" );
      $foglight.setShader( "fogs/swamp_glare" );
     $foglight.setRadius( 15850 );
     
   $foglight.bindPosition( $player1 );
   $foglight.setOrigin( '0 0 0' );
}

// function that executes when script is loaded

void main ()
{
   setup_objects ();
   sys.print( "Fog created!\n" );
}


Now, this is a pretty straightforward script. But there is one line that you will have to take note of:
$foglight.setRadius( 15850 );

The radius for the light will *HAVE* to encompass the entire level at any point of the level (or the farthest that the player can see at any time in the level). So if the player is at the very edge of the level it will still have to encompass the entire map. If it does not encompass the entire map then glitches will arise and anomlies in the fog will pop up. In this instance I have a very high number: 15850 this is because my map is an outdoor map and it's pretty huge. You can adjust this number to make the fog go farther or closerby as long as it keeps encompassing the map.
And that's all there is to it. The fog will behave very much like fog behaves in games such as Unreal that utilize fog.

Some screenshots:

Light fog:
Image

Heavy fog:
Image

Image

Image

EDIT:
Changes bind() to bindPosition() command in the script.



BloodRayne@Posted: Tue Dec 07, 2004 12:31 pm :
I thought I started this in the level_editing section but that damned hack sent me back and forth to that other forum so it ended up here. :x:evil::x

Can anybody move this to the appropriate forum?

Thanks.

[EDIT]done didley do diddly sorted >kat<



kat@Posted: Tue Dec 07, 2004 2:09 pm :
You are seriously working your ass of for this project..!!

Is that lamp casting light/shadows like that cubemap demo der_ton did a while back, you know where the corner supports are, are they casting shadows?



BloodRayne@Posted: Tue Dec 07, 2004 2:13 pm :
Yup, those cast shadows. But I am trying to make lights cast as little shadows as possible without losing effect.



m!chi:be@Posted: Tue Dec 07, 2004 8:37 pm :
very cool stuff.
i had my hands on the same stuff some time ago for our mod with a different aproach to the problem and failed.
will insert the new fog tomorrow into the maps.



Darkspiral@Posted: Wed Dec 08, 2004 12:53 am :
Hrm... I can't seem to get this to work. I have it so that the fog_tex appears in the lights section in edit, but its completely black and when I run the game everything is pitch black and I can't even see my own hand in front of my face. I think the problem is that when I go to save the texture as a .tga, it wont let me check the box that says, "alpha channels". I did make the layer into an alpha channel, so I have no idea why the hell it won't let me save it as one... Anyone know a workaround to this? I use PS 7.0 btw.



rich_is_bored@Posted: Wed Dec 08, 2004 1:14 am :
Goto adobe.com and download the updated TGA export plugin. The one that comes with PS 7.0 cannot export targas with alpha channels.



Darkspiral@Posted: Wed Dec 08, 2004 2:41 am :
Thanks for the info Rich... I downloaded the plugin and I remade the textures and got rid of the old ones, but I'm still getting pitch black... I can't figure this out. Am I supposed to make a diffusemap as well as the alpha? There's a texture spot for the light in the lights section, but it doesn't show me a picture of what the fog should look like, so I'm assuming I should make another texture with _ed at the end of it.. I don't know... :? I hate to be annoying but this is bugging me.



rich_is_bored@Posted: Wed Dec 08, 2004 3:56 pm :
Are you saving the targa as 32 bit?

Each channel should be 8 bits. A targa without an alpha channel would be 24 bit (r,g,b). A targa with an alpha channel would be 32 bit (r,g,b,a).



Darkspiral@Posted: Wed Dec 08, 2004 9:36 pm :
Yeah I'm saving it as 32 bit, I made sure to do that. I saved both the scrolling clouds texture and the initial fog both as 32 bit.



BloodRayne@Posted: Wed Dec 08, 2004 9:55 pm :
You should break up the problem. First get the fog to work (don't use the added cloud material) and then when that works use the cloud material.

I won't be having much time but maybe you can put the stuff you have online in a zip so we can download it and see what the problem is.



irishlostboy1980@Posted: Wed Jun 21, 2006 11:12 am :
i have the fog working, just like you have said here, i have the scrolling cloud effect working fine. i even have matching skybox, which looks just fine.
one problem though. i get verticle stripes on any walls etc. i think its the cloud texture. it seems to project the "cloudy" look vertically, but not horizontally. so what you get is the edge of the scrolling texture meeting the walls, leaving a streaked effect.

is there any way to fix this problem? or is it a side effect that must be lived with when it comes to applieng textures to lights?



BloodRayne@Posted: Wed Jun 21, 2006 1:37 pm :
irishlostboy1980 wrote:
i have the fog working, just like you have said here, i have the scrolling cloud effect working fine. i even have matching skybox, which looks just fine.
one problem though. i get verticle stripes on any walls etc. i think its the cloud texture. it seems to project the "cloudy" look vertically, but not horizontally. so what you get is the edge of the scrolling texture meeting the walls, leaving a streaked effect.

is there any way to fix this problem? or is it a side effect that must be lived with when it comes to applieng textures to lights?

Woahh.. necro alert! (joke) :P

Why don't you try rotating the texture 90 degrees? You can even do that simply in the shader definition.



irishlostboy1980@Posted: Fri Jun 23, 2006 12:30 pm :
necro alert??? :shock:

call me slow, but i dont get it? oh well.
i will give rotating the texture a go. is there no way to project the texture out in multiple directions?
thanks for the help :)



voldemort@Posted: Fri Jun 23, 2006 1:32 pm :
if your having problems with the rotation if I recal its in decimal not 360 value so .5 would equal 90 degreee turn***edit**oops poor math it equalas 180 degrees***

Going off memory since IM at work may be wrong but that does seem to click in my head etiher that or that clicking sound is something broken up there again



BloodRayne@Posted: Sat Jun 24, 2006 6:36 am :
irishlostboy1980 wrote:
necro alert??? :shock:

call me slow, but i dont get it? oh well.

It's a forum term, ressurecting or replying to an old thread is often referred to as 'necroing', from the word 'necrophelia'. :wink:



irishlostboy1980@Posted: Sun Jun 25, 2006 2:03 pm :
[quote="BloodRayne"][quote="irishlostboy1980"]necro alert??? :shock:

ah. i get it now. guess you can tell i dont get to spend much time online.