Graphics Reference
In-Depth Information
14
15
16
17
18
19
20
21
Color3 () : r(0), g(0), b(0) {}
Color3 ( float r, float g, float b) : r(r), g(g), b(b);
Color3 operator * ( float s) const {
return Color3 (s * r, s * g, s * b);
}
...
};
One could use the type system to help track units by creating distinct classes
for power, radiance, etc. However, it is often convenient to reduce the complexity
of the types in a program by simply aliasing these to the common “color” 5 class,
as shown, for example, in Listing 14.2.
Listing 14.2: Aliases of Color3 with unit semantics.
1
2
3
4
typedef Color3 Power3 ;
typedef Color3 Radiosity3 ;
typedef Color3 Radiance3 ;
typedef Color3 Biradiance3 ;
Because bandwidth and total storage space are often limited resources, it is
common to employ the fewest bits practical for your needs for each frequency-
varying quantity. One implementation strategy is to parameterize the class, as
shown in Listing 14.3.
Listing 14.3: A templated Color class and instantiations.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
template < class T>
class Color3 {
public :
Tr,g,b;
Color3 () : r(0), g(0), b(0) {}
...
};
/ ** Matches GL_RGB8 format * /
typedef Color3 <unint8> Color3un8;
/ ** Matches GL_RGB32F format * /
typedef Color3 < float > Color3f32;
/ ** Matches GL_RGB16I format * /
typedef Color3 < unsigned short > Color3ui16;
14.4.2 Emitters
Emitters are fairly straightforward to model accurately. They create and cast
photons into the scene. The photons have locations, propagation directions, and
frequencies (i.e., “colors”), and are emitted at some rate. Given probability dis-
tributions for those parameters, we can generate many representative photons and
5. We discuss why color is not a quantifiable phenomenon in Chapter 28; here we use the
term in a nontechnical fashion that is casual jargon in the field.
 
 
 
Search WWH ::




Custom Search