Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page49/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   45   46   47   48   49   50   51   52   ...   106
GLIDEPGM
guFogTableIndexToW(int i)

guFogTableIndexToW() returns the floating point eye-space w value associated with entry i in a fog table. Because fog table entries are non-linear in w, it is not straight forward to initialize a fog table. guFogTableIndexToW() assists by converting fog table indices to eye-space w, and returns the following:
pow(2.0, 3.0+(double)(i>>2)) / (8-(i&3))
An exponential fog table can be generated by computing (1–ekw)·255 where k is the fog density and w is world distance. It is usually best to normalize the fog table so that the last entry is 255.
Example Special Effects.2 Creating a fog table.
The two code segments below each create a fog table. The first code segment shows a linear fog table that has a steep ramp at the beginning and end, with slow growing values in the middle.
const GrFog_t fog[63];
int i;

fog [0] = 0;


for (i=1; i<12; i++) fog[i]= fog[i-1]+ 12;
for (i=12; i<56; i++) fog[i]= fog[i-1] + 1;
for (i=56; i<63; i++) fog[i]= fog[i-1] + 7;
fog[63] = 255;


The second table is an exponential fog table. It computes w from i using guFogTableIndexToW() and then computes the fog table entries as fog[i]=(1–e-kw)·255 where k is a user-defined constant, FOG_DENSITY.
#define FOG_DENSITY .5
const GrFog_t fog[GR_FOG_TABLE_SIZE];
int i;

for (i=0; i
fog[i] = (1 - exp((- FOG_DENSITY) * guFogTableIndexToW(i))) * 255;
}
fog[GR_FOG_TABLE_SIZE] = 255;

Example Special Effects.3 Fogging with 1/w and a fog table.


The code segment below assumes that a fog table has been defined. It is loaded using grFogTable(), a fog color is defined, and the appropriate fog mode set. All that remains is to draw the scene.
const GrFog_t fog[GR_TABLE_SIZE];
int i;

/* load the fog table */


grFogTable(fog);

/* set a fog color - how about smoke? */


grFogColorValue(0);

/* set mode to fog table */


grFogMode(GR_FOG_WITH_TABLE);

/* draw the scene */





Download 6.22 Mb.

Share with your friends:
1   ...   45   46   47   48   49   50   51   52   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page