Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / ffb / ffb_fog.c
1
2 /* FFB fog support:
3 *
4 * There are two levels of support for FOG in the Creator3D series.
5 * Both involve a depth cue unit and 1 or 4 slope factors and scales
6 * for varying the pixel intensity.
7 *
8 * Chips prior to FFB2 only have a single set of such settings, FFB2
9 * and later have 4 settings.
10 *
11 * The basic depth cueing equation is:
12 *
13 * C_final = dcsf(z) * C_orig + (1 - dcsf(z)) * C_fog
14 *
15 * C_final -- The final color passed to blend unit or frame
16 * buffer (if blending is disabled).
17 *
18 * C_orig -- The color we start with, which comes either from
19 * the raster processor or cpu writes to the smart
20 * framebuffer aperture.
21 *
22 * C_fog -- This is the "fog" color, ie. the desired color
23 * at the deepest Z.
24 *
25 * dcsf(z) -- The depth cue scale as a function of Z.
26 *
27 * With pre-FFB2 chips there are four parameters to control the depth
28 * cue scaling. Here is a diagram:
29 *
30 * 1.0 -------------
31 * | | | |
32 * | | | |
33 * Sfront XXXXX---+---+
34 * | |X | |
35 * dcsf(z) | | X | |
36 * | | X| |
37 * Sback +---+---XXXXX
38 * | | | |
39 * 0.0 -------------
40 * 0.0 Zf Zb 1.0
41 *
42 * z
43 * Therefore:
44 *
45 * for Zf < z < Zb
46 *
47 * dcsf(z) = Sback + ((Sfront - Sback) / (Zf - Zb)) * (Zb - z)
48 *
49 * for z <= Zf
50 *
51 * dcsf(z) = Sfront
52 *
53 * for z >= Zb
54 *
55 * dcsf(z) = Sback
56 *
57 * With FFB2 and later, 3 more slope regions are provided, the first of
58 * them starts at the end of the region defined above and ends at a
59 * specified depth value, the next slop region starts there and ends
60 * at the next specified depth value, and so on. Each of the 3 slope
61 * regions also have scale and slope settings of their own.
62 *
63 * The C_fog color is programmed into the alpha blending unit color1
64 * and color2 registers as follows:
65 *
66 * color1: -(C_fog)
67 * color2: C_fog - bg
68 *
69 * If alpha blending is disabled, the bg factor is zero. Note that
70 * the alpha blending color registers specify each of the RGB values
71 * as 9 bit 1:8 signed numbers in the range -1.00 to 0.ff inclusive.
72 * (ie. 0x100 == -1.00 and 0x0ff == +0.ff)
73 */