Cubic fog

Blitz3D Forums/Blitz3D Programming/Cubic fog

Neochrome(Posted 2004) [#1]
Has any one here got a better way of making cubing fog, mine is clumbsy and slow, it has some intelegence, but the result is still slow.

Has anyone got any ideas?


Eole(Posted 2004) [#2]
Go to www.gamedev.net ... ou www.flipcode.com


aCiD2(Posted 2004) [#3]
um... whats cubic fog :) is that where the fog rises from the ground? or is that volumetric fog?


Neochrome(Posted 2004) [#4]
Sorry, yeah, Volumetric, Sorry i wrote this forum at 3am in the morning, half my brains where dribbling out my ears..


sswift(Posted 2004) [#5]
Volumetric fog is easy.

Make a polygon volume for yuor fog. For example, a sphere.

Cast a ray from the camera through each vertex touching a front facing tri. Determine where that ray hits the back of the volume.

The distance between the vertex and the point the ray exits the fog is the thickness of the fog.

Use an exponential formula to then choose the value to set that vertex's alpha to.

For example,
Alpha# = (Distance#/FogFar#)^2

Where FogFar# is the thickness of the fog where alpha reaches 1, and below which where it falls off exponentially.

In other words, if FogFar# is 2.0 and the fog is 1.0 thick, if the equation were linear alpha would be 0.5, but it's exponential so alpha will be much less than 0.5.

Exponential is how real fog works. But you might want linear fog if you don't want your fog volumes to be too big.

You can also change the eponentiality of the equation by reducing the exponent. For example, instead of ^2, you can ^1.5. That will give you a more linear curve.

There's functions in the code archives which will tell you if a ray or line segment instersects a polygon.

Btw you need to update this whenever the camera moves. So you won't want your fog volume to have too many vertices.

Another less accurate way you can make a fog volume is by using spherical environment maps. Just make a map that goes from black in the middle to white at the edges. Apply this to your fog shape on one surface. Then on a second surface, apply the inverse of this map, and set the surface to add. The color of the second surface will be the color of the fog. The spherical environment map acts as an alpha channel.

Neither of these methods take into account objects within the fog though. If you want an object within fog to appear fogged the right amount, if that object is an animated object in Blitz you may be out of luck, unless Blitz's linepicks work properly with animated objects. Cause you can't do your own linepicks on animated objects. There's no way to know where the vertcies are as they change during animation.

Then again, it might still be possible. It is possile to generate a pseudo zbuffer like map by using regular fog on an entity so that parts of it farther from the camera are darker. If you can generate that then you might be able to use it as an alpha map to control how much fog the entity recieves on each part. Of course, it would be a linear change, but that would probably not be too noticeable.

Of course, it occurs to me that you might be able to get away with simply finding how deep inside the fog volume the entity is realtive to the camera, and then just use a single fog value for it to kinda fake it. But that would mean if the entity sticks it head up out of the fog it would not be fogged. You'd change the amount of fog on the entity by giving it a second surface with alpha blending.

Well, that's enought o get you started. I guess it's not such an easy effect after all when you don't have access to all the data. :-)


CyberHeater(Posted 2004) [#6]
That was a great tute on the subject sswift. You should write a book on blitz with explainations like that. I for one would buy it.


sswift(Posted 2004) [#7]
I thought about writing a book on Blitz, but as far as I know book writers don't make a whole hell of a lot and a book on Blitz isn't likely to sell to many copies, and besides, it's a hell of a lot of work to write a book! :-) I can't just throw a bunch of anecdotes like this together and call it a book! :-)


Neochrome(Posted 2004) [#8]
any code? i cant seem to make mine work :(

i think iv got writers block!


SabataRH(Posted 2004) [#9]
JFK wrote a vol fog routine, its in the codelibs, damn nice one too.

PS: or was that GFK.. hell I don't .., I think i'll change my handle to YFK


Neochrome(Posted 2004) [#10]
wheres the link?


Isaac P(Posted 2004) [#11]
code archives.. its the grass system by JFK, also includes some volumetric fog


Red Ocktober(Posted 2004) [#12]
@ sswift:

EASY... you call that scientific geek speech you made above easy!!!

will someone explain to me, in plain english, exactly what the f##k he just said :)


actually, that was pretty good... the only thing missing is a few pictures and diagrams... for the slow of mind, like me.

i'm copying it now before you get the idea to put it in your book and start charging for it :)

this'll come in handy... THANKS...

--Mike


Jeroen(Posted 2004) [#13]
Sswift explodes an array of thoughts :D


JAW(Posted 2004) [#14]
sswift: Well a book would probably be too much work, but how about a nice simple website with tutorials, equations, and reference material? You posted a big list of helpful equation stuff you've collected once. I've got it saved in a txt file. Type that up nice and organize it, throw a few tuts together from stuff you've already written, and there you go :) I have yet to find a really good site with useful general programming/game programming reference material. I thought of putting one up myself a few times..


sswift(Posted 2004) [#15]
"Type that up nice and organize it, throw a few tuts together from stuff you've already written, and there you go :)"

Yeah but nobody pays for access to websites. :-) And it's not like there aren't OTHER websites where you can get said information for free.

If I wrote a book on Blitz, it'd be more like "How to write a first person shooter in Blitz 3D." or "How to write a racing game in Blitz 3d". It'd include all the basic physics and graphics stuff you need to know to make such a game. But not volumetric fog. :-)


Red Ocktober(Posted 2004) [#16]
... do the book thing

i say that because i just ordered a book on the Torque engine written by one of the guys there...

just give it the right title... something like GAME DEV Write Your OWN FPS In 7 Days with Blitz3D...

... and get the rights to package the demo version on cd... along with a bunch of other tuts...

... tuts all written in html, and linked to other pages n the cd.

... and send me my 6% cut for advisory services when the money starts rollin in :)

--Mike


Rook Zimbabwe(Posted 2004) [#17]
I think I should get a 3% royalty just for saying that I should get a 3% royalty!

RD/rz


Akat(Posted 2004) [#18]
sswift... codes please, instead of book


Mustang(Posted 2004) [#19]
Code? Try this:

http://www.blitzbasic.com/Community/posts.php?topic=31460


sswift(Posted 2004) [#20]
Isn't that using particles for fog? I didn't take a close look at it but I saw something about modifying snow to make fog, and that indicates particles.

You can certainly use particles for fog, but you will get a lot more overdraw, which means less speed. And it won't look as convincing as real volumetric fog... the fog won't be of uniform density.

Maybe I should make a fog system. :-) But I'm working on something much cooler right now. And like I said I'm not sure you can do animated entities in fog well in Blitz.


Neochrome(Posted 2004) [#21]
sswift, your a gem! your fog system will be better than mine, prolly more efficient too!!


Mustang(Posted 2004) [#22]
Isn't that using particles for fog? I didn't take a close look at it but I saw something about modifying snow to make fog, and that indicates particles.

You can certainly use particles for fog, but you will get a lot more overdraw, which means less speed. And it won't look as convincing as real volumetric fog... the fog won't be of uniform density.


Yup, it uses particles, but looks darn nice... it probably gets a big speed hit when used in real complex game enviroment and might not cool that cool either because of the particle clipping etc... but this demo is nice.

True HW fog has all kind of limitations like that it don't work at all with alpha... and what you have described in this thread is just really complicated.

IMO there is no way to use any volumetric (or regular) HW fog in our games unless Blitz evolves or something...


Neochrome(Posted 2004) [#23]
bumber :( i guess that answers that one then,
Cheers guys anyway


sswift(Posted 2004) [#24]
HW fog doesn't work with alpha? What makes you say that? I've never heard any such thing, and I'd swear I've seen screenshots with it in use, and I thought I used it in my own 100,000 tree demo a long time ago.


Mustang(Posted 2004) [#25]
HW fog doesn't work with alpha? What makes you say that?


Experience? :) Anyways, I had alpha-ed tracks on my tank (demo below) and when I enabled fog, tracks didn't get fogged. BF1842 has this same problem too, when the trees switch to bollboard mode they use alpha and don't get fogged. "Altpha test" can be fogged IMO easily though... my demo was made with old Blitz3D so I don't know if it's been "fixed" now.

[edit]

Yup - fixed now... if you change the lines:

	Tank_L_Tracks = LoadTexture ( "obj\TankJagdpantherTrack.jpg")
	Tank_R_Tracks = LoadTexture ( "obj\TankJagdpantherTrack.jpg")

to:

	Tank_L_Tracks = LoadTexture ( "obj\TankJagdpantherTrack.tga",2)
	Tank_R_Tracks = LoadTexture ( "obj\TankJagdpantherTrack.tga",2)

and uncomment the fog lines in the end, you'll see that the alpha in the tracks works now. But multiplicative "shadows" don't...