Spherical Volume Fog
Turnbull describes spherical volume fog and how to implement it.
Now we have some coordinates to fog we are now able to calculate the intensity at each point. This involves casting a ray from the viewing position to the vertex we want to fog. If this ray intersects the fog volume then we are able to calculate the depth of the volume which is penetrated by the ray. This invloves finding the two intersection points of the sphere and the ray, and the calculating the distance between the points.
I apologise in advance for the mathematical symbols I have used but there are no instantly available square or square root symbols. I have therefore used the ^ symbol to represent indices, therefore ^2 is squared, and ^1/2 is the square root. The first step is to calculate the intersection points. For this example V is the view position and D is the destination vertex.
The ray R is defined as:
R = V + (D-V)*tR.x = V.x + (D.x - V.x)*t
R.y = V.y + (D.y - V.y)*t
R.z = V.z + (D.z - V.z)*ti=(D.x - V.x)
j=(D.y - V.y)
k=(D.z - V.z)
R.x = V.x + it
R.y = V.y + jt
R.z = V.z + kt(R.x - l)^2 + (R.y - m)^2 + (R.z - n)^2 = r^2at^2 + bt + c = 0a = i^2 + j^2 + k^2
b = 2*( i*(V.x - l) + j*(V.y - m) + k*(V.z - n))
c = (V.x - l)^2 + (V.y - m)^2 + (V.z - n)^2 - r^2b^2 - 4acIf you don't know this already, the quadratic discriminant is part of the quadratic formula and therefore if the result is greater than zero can be used to find the intersection points, save having to calculate them again. The quadratic formula is defined as:
t = (-b +- (b^2 - 4ac) ^ 1/2) / 2adistance = ((B.x-A.x)^2 + (B.y-A.y)^2 + (B.z-A.z)^2)^1/2This distance can be appropriately scaled to affect the alpha component of the vertex, or could be used to alter the RGB components if this is not applicable. As you can see, there are a lot of calculations involved and this is therefore quite a demanding algorithm. The trick is to precompute as much as you can, and try and limit the number of vertices fogged.
By Richard Turnbull
[email="rt71@hotmail.com"]rt71@hotmail.com[/email] http://www.gameznet.com/acidreign
Related Tutorials
Procedural Generation of 2D Tile Maps in Games
The article explains how to build a procedural 2D cave map generator using cellular automata. It covers map representat…
Localizing A Game Into French — Which Variant Should You Choose?
So, you’re making an awesome indie game, and now you’re thinking about localizing it into French? Great idea! There ar…
How Long Does It Take To Localize An Indie Game?
So you’re planning on localizing your indie game, but you’re not sure how much time to schedule in. While the timing o…
Creating game videos: best practices and pitfalls to avoid
Game video production: practical tips on how to create a game trailer or teaser that you can be proud of. Give your aud…
Adopting CI/CD: How Midwinter Entertainment iterates at speed with the help of IMS
Game development was once like one long sprint: a huge effort until you reached the finish line — at which point you co…
GameDev.net
5 Things to Consider When Making a Video to Promote Your App or Game
How can you show an app or game in your video in a way that attracts new users? Let’s take a look at what to go by when…
Discussion
More from Richard Turnbull
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion