Perlin Fog
For the Perlin fog we decided to implement the processing
on the CPU. To do this, we sampled
points in the 3D texture space, separated by a stride associated with each
octave-the longer the stride, the more heavily weighted the octave was in the
total texture.
Each of these sample points was mapped to a pseudo randomly
chosen gradient, using a permutation table full of normalized gradients from a
given point and a hash function.1 The value of each pixel was then determined by the weight contributions of its surrounding
gradient samples. All of these separate octaves were then summed to achieve a
result that has smoothed organic noise on both a near and far perspective.
This result was successful; however, we wanted to achieve
an even more smoothed effect and have only subtle noise visible. We then applied a simple Gaussian blur algorithm (also
during preprocessing).
Our implementation blurred the pixels using
factors supplied by Pascal's triangle constants, i.e., {(1), (1,1), (1,2,1),
(1,3,3,1) . . . }, as weights and averaging those weighted sums (a type of
convolution filter). We also took advantage of calculating blur independently
in each axis direction to improve efficiency.2
At this point the result was much
closer to the desired outcome; however, seams were visible at the edges of the
texture because the Gaussian blur algorithm was sampling points beyond the
texture's scope, so we used a mod operator to wrap the sampling space.
In the shader, we first calculated the fog coefficient f,
which is a factor for the amount of light absorbed and scattered from a ray
through fog volume.3 We calculated this value using the equation
f = e-(ρ*d*n)
where p=density, d=camera distance, and n=noise. We then
used this coefficient to interpolate between the surface color Coriginal at any point and the fog color Cfog,
using the equation This interpolation approximates the light absorption of a
ray from any point to the camera4 at low CPU utilization cost.
Cfinal = Coriginal*f + Cfog*(1-f)
Finally, we applied animation to the fog by sampling the
fog texture according to a linear function that progresses with time. This is a
simple ray function with the slope set as a constant vector.
This method was successful, but it produced fog that
appeared glued to the geometry surface rather than moving through the air. For
this reason, we used a 3D texture for the blurry noise-when this texture is
animated along a ray, the fog moves through world space rather than crawling
along the surface's 2D texture coordinates.
This was successful from a
bird's-eye perspective, but unconvincing at other perspectives. To adjust for
this, we applied a quadratic falloff for our noise, dependent on the height of
the fog; that is, it made the fog clearer at the height of the viewer to give
the impression that clouds appeared above and below, rather than simply on all
surfaces, with the equation
n = n*(ΔY2)/2 + 0.001
where n=noise and ∆Y=camera Y position - vertex Y
position. As a result, we are able to mimic volumetric fog quite convincingly,
although all fog is in fact projected onto the scene surfaces.
---
1 Johanson, Claes. "Real-time water rendering-introducing the projected grid
concept." Master of Science thesis in computer graphics, March 2004.
http://graphics.cs.lth.se/theses/projects/projgrid/,
http://graphics.cs.lth.se/theses/projects/projgrid/projgrid-hq.pdf (PDF)
2 Gustavson,
Stefan, "Simplex Noise Demystified." Gabrielle Zachmann Personal Homepage, 22
Mar 2005. Linköping University, Sweden. 15 Jul 2008.
http://zach.in.tu-clausthal.de/teaching/cg2_08/literatur/simplexnoise.pdf
(PDF)
3 Zdrojewska,
Dorota, "Real time rendering of heterogeneous fog based on the graphics
hardware acceleration." Central European Seminar on Computer Graphics for
students. 3 Mar 2004.
Technical University of Szczecin. 10 Jul 2008. http://www.cescg.org/CESCG-2004/web/Zdrojewska-Dorota/
4 Waltz, Frederick M. and John W. V. Miller.
"An efficient algorithm for Gaussian blur using finite-state machines." SPIE
Conf. on Machine Vision Systems for Inspection and Metrology VII., 1 Nov. 1998.
ECE Department, Univ. of Michigan-Dearborn. 5 Aug. 2008. http://www-personal.engin.umd.umich.edu/~jwvm/ece581/21_GBlur.pdf
(PDF)
|