28 |
*/ |
*/ |
29 |
class LightParam { |
class LightParam { |
30 |
public: |
public: |
31 |
/** Paper coordinate system basis vectors and origin in object coordinates |
/** Paper coordinate system basis vectors and origin in object coordinates. |
32 |
* Paper coordinates x, y, (and z) are mapped to |
* Paper coordinates x, y, (and z) are mapped to |
33 |
* object position (orig + x e0 + y e1 + z e2). |
* object position (orig + x e0 + y e1 + z e2). |
34 |
* For the eye-linear TexGens, the basis and origin vectors are transformed |
* For the eye-linear TexGens, the basis and origin vectors are transformed |
39 |
* e0, e1, and e2 should be orthogonal and the same length. */ |
* e0, e1, and e2 should be orthogonal and the same length. */ |
40 |
ZVec e0, e1, e2, orig; |
ZVec e0, e1, e2, orig; |
41 |
|
|
42 |
/** Light position in object coordinates |
/** Light position in object coordinates. |
43 |
* Light position should be given in the same coordinate system as |
* Light position should be given in the same coordinate system as |
44 |
* the basis vectors above. */ |
* the basis vectors above. */ |
45 |
ZVec Light; |
ZVec Light; |
46 |
/** Light position w component |
|
47 |
|
/** Light position w component. |
48 |
* Basically, Light_w should be 1.0 for finite light and |
* Basically, Light_w should be 1.0 for finite light and |
49 |
* 0.0 for infinite light */ |
* 0.0 for infinite light */ |
50 |
float Light_w; |
float Light_w; |
71 |
} |
} |
72 |
}; |
}; |
73 |
|
|
74 |
/** Simple, non-lighting-dependent TexGen. |
/** Computes light direction in paper texture coordinates |
75 |
* Transforms paper coordinates into texture coordinates using |
* into the primary color. |
76 |
* the given matrix. |
* Used for DOT3 bump mapping with infinite light. |
77 |
|
* The tex_mat parameter is the TexGen matrix of the paper texture |
78 |
*/ |
*/ |
79 |
class TexGen : public LightSetup { |
class LightDirSetup : public LightSetup { |
80 |
protected: |
protected: |
81 |
// XXX: Currently the last four values are always initialized to 0,0,0,1 |
float mat[4]; |
|
float tex_mat[16]; |
|
82 |
|
|
83 |
public: |
public: |
84 |
/** Create a new texgen. |
LightDirSetup(const float *tex_mat) ; |
|
* @param tex_mat A float vector of 12 elements, components of |
|
|
* s, t and r vectors, respectively. |
|
|
*/ |
|
|
TexGen(const float *tex_mat) ; |
|
|
virtual void setUp(LightParam *param) ; |
|
85 |
|
|
86 |
virtual void setUp_VP(int unit, LightParam * param); |
virtual void setUp(LightParam *param) ; |
|
virtual string getVPCode(int unit); |
|
87 |
}; |
}; |
88 |
|
|
89 |
/** TexGen for embossing. |
/** Simple, non-lighting-dependent TexGen. |
90 |
* Shifts the texture towards the light by an amount proportional to eps. |
* Transforms paper coordinates into texture coordinates using |
91 |
* Take the difference of the filtered values generated by two emboss |
* the given matrix. |
92 |
* texgens using the same texture with +eps and -eps parameters |
*/ |
93 |
* to obtain an approximation of the diffuse dot product. |
class TexGen { |
94 |
*/ |
protected: |
95 |
class TexGenEmboss : public TexGen { |
/** Matrix used to convert paper coordinates into texture coordinates. */ |
96 |
protected: |
// XXX: Currently the last four values are always initialized to 0,0,0,1 |
97 |
float eps; |
float tex_mat[16]; |
98 |
|
|
99 |
public: |
public: |
100 |
TexGenEmboss(const float *tex_mat, float eps) |
/** Pointer to current texture matrix used in setUp_explicit */ |
101 |
: TexGen(tex_mat), eps(eps) {} |
const float *explicit_mat; |
102 |
|
|
103 |
|
/** Creates a new TexGen. |
104 |
|
* @param tex_mat A float vector of 12 elements, |
105 |
|
* components of s, t and r vectors, respectively. |
106 |
|
*/ |
107 |
|
TexGen(const float *tex_mat); |
108 |
|
|
109 |
|
/*** TexGen version of the TexGen setUp. */ |
110 |
|
virtual void setUp_texgen(LightParam *param); |
111 |
|
/*** Vertex program version of the TexGen setUp. */ |
112 |
|
virtual void setUp_VP(int unit, LightParam * param); |
113 |
|
/*** Explicit version of the TexGen setUp. */ |
114 |
|
virtual void setUp_explicit(LightParam *param); |
115 |
|
|
116 |
|
/*** Generates a vertex program for requested unit */ |
117 |
|
virtual string getVPCode(int unit); |
118 |
|
}; |
119 |
|
|
120 |
virtual void setUp(LightParam *param) ; |
/** TexGen for embossing. |
121 |
|
* Shifts the texture towards the light by an amount proportional to eps. |
122 |
|
* Take the difference of the filtered values generated by two emboss |
123 |
|
* texgens using the same texture with +eps and -eps parameters |
124 |
|
* to obtain an approximation of the diffuse dot product. |
125 |
|
*/ |
126 |
|
class TexGenEmboss : public TexGen { |
127 |
|
protected: |
128 |
|
/** ??? */ |
129 |
|
float eps; |
130 |
|
/** Inverted tex_mat is needed by vertex_explicit() when |
131 |
|
* handling TexGenEmbosses. |
132 |
|
*/ |
133 |
|
float inv_tex_mat[16]; |
134 |
|
|
135 |
virtual void setUp_VP(int unit, LightParam * param); |
public: |
136 |
}; |
/** Creates a new TexGen for embossing. |
137 |
|
* @param tex_mat A float vector of 12 elements, |
138 |
|
* components of s, t and r vectors, respectively. |
139 |
|
* @param eps ??? |
140 |
|
*/ |
141 |
|
TexGenEmboss(const float *tex_mat, float eps) |
142 |
|
: TexGen(tex_mat), eps(eps) {} |
143 |
|
|
144 |
|
/*** TexGen version of the TexGenEmboss setUp. */ |
145 |
|
virtual void setUp_texgen(LightParam *param) ; |
146 |
|
/*** Vertex program version of the TexGenEmboss setUp. */ |
147 |
|
virtual void setUp_VP(int unit, LightParam * param); |
148 |
|
/*** Explicit version of the TexGenEmboss setUp. */ |
149 |
|
virtual void setUp_explicit(LightParam * param); |
150 |
|
}; |
151 |
|
|
152 |
/** TexGen for transforming light intensity or direction map |
/** TexGen for transforming light intensity or direction map |
153 |
* into paper texture coordinates for a light at a finite distance. |
* into paper texture coordinates for a light at a finite distance. |
166 |
virtual void setUp(LightParam *param) ; |
virtual void setUp(LightParam *param) ; |
167 |
}; |
}; |
168 |
|
|
169 |
/** Compute light direction in paper texture coordinates |
/** A single rendering pass. |
|
* into the primary color. |
|
|
* Used for DOT3 bump mapping with infinite light. |
|
|
* The tex_mat parameter is the TexGen matrix of the paper texture |
|
|
*/ |
|
|
class LightDirSetup : public LightSetup { |
|
|
protected: |
|
|
float mat[4]; |
|
|
|
|
|
public: |
|
|
LightDirSetup(const float *tex_mat) ; |
|
|
|
|
|
virtual void setUp(LightParam *param) ; |
|
|
}; |
|
|
|
|
|
/** A single rendering pass. |
|
170 |
* The data members are public to allow modification, |
* The data members are public to allow modification, |
171 |
* but when using a ready-made PaperPass, _choose one_ |
* but when using a ready-made PaperPass, _choose one_ |
172 |
* (and only one) of the following ways to use it: |
* (and only one) of the following ways to use it: |
179 |
* 2) using a vertex program |
* 2) using a vertex program |
180 |
* - call setUp_VP with LightParam to use |
* - call setUp_VP with LightParam to use |
181 |
* - call glTexCoord*() and glVertex*() directly from |
* - call glTexCoord*() and glVertex*() directly from |
182 |
* the context, use vertex arrays _or_ call vector_VP() |
* the context _or_ call vertex_VP() with position |
183 |
* with vertex and texture coordinates in arrays |
* within the paper in array of 4 floats |
|
* of 4 floats. |
|
184 |
* - call teardown_VP() |
* - call teardown_VP() |
185 |
* |
* |
186 |
* 3) using explicit coordinates |
* 3) using explicit coordinates |
187 |
* - call setUp_explicit with LightParam to use |
* - call setUp_explicit with LightParam to use |
188 |
* - ???? without? with texcoords? with texcoord and vertex? |
* - call vertex_explicit() with paper coordinates in |
189 |
|
* arrays of 4 floats and call glVertex*() directly |
190 |
|
* from the context. |
191 |
* - call teardown_explicit() |
* - call teardown_explicit() |
192 |
*/ |
*/ |
193 |
class PaperPass { |
class PaperPass { |
197 |
* unless it's already loaded. |
* unless it's already loaded. |
198 |
*/ |
*/ |
199 |
void loadVP(); |
void loadVP(); |
200 |
|
|
201 |
public: |
public: |
202 |
/** The code to call before beginning to render the pass. */ |
/** The code to call before beginning to render the pass. */ |
203 |
CallGLCode setupcode; |
CallGLCode setupcode; |
204 |
/** The code to call after rendering the pass. */ |
/** The code to call after rendering the pass. */ |
205 |
CallGLCode teardowncode; |
CallGLCode teardowncode; |
206 |
|
|
207 |
/** The TexGen objects for the different texture units. */ |
/** The TexGen objects for the different texture units. */ |
208 |
vector<shared_ptr<TexGen> > texgen; |
vector<shared_ptr<TexGen> > texgen; |
209 |
/** The non-texgen light setup routines. */ |
/** The non-texgen light setup routines. */ |
210 |
vector<shared_ptr<LightSetup> > setup; |
vector<shared_ptr<LightSetup> > setup; |
211 |
|
|
212 |
/*** Texgen version of the renderinf interface. */ |
/*** TexGen version of the renderinf interface. */ |
213 |
/** Calls setupcode, texgen and setup for the texture. |
/** Calls setupcode, texgen and setup for the texture. |
214 |
* |
* |
215 |
* @param param light parameters (LightParam object) |
* @param param light parameters (LightParam object) |
220 |
*/ |
*/ |
221 |
void tearDown_texgen () { teardowncode(); } |
void tearDown_texgen () { teardowncode(); } |
222 |
|
|
223 |
/*** Vertex program version of the rendering interface */ |
/*** Vertex program version of the rendering interface. */ |
224 |
/** Calls setupcode, texgen and setup for the texture. |
/** Calls setupcode, texgen and setup for the texture. |
225 |
* |
* |
226 |
* @param param light parameters (LightParam object) |
* @param param light parameters (LightParam object) |
231 |
*/ |
*/ |
232 |
void tearDown_VP(); |
void tearDown_VP(); |
233 |
|
|
234 |
/** Vertex program version of the paperpass vertex |
/** Vertex program version of the paperpass vertex. |
235 |
* Calling vertex_VP() is optional. It's possible to call |
* Calling vertex_VP() is optional. It's possible to call |
236 |
* glTexCoord*() and glVertex*() directly from the context |
* glTexCoord*() and glVertex*() directly from the context |
237 |
* and choose the best function variant or use vertex arrays |
* and choose the best function variant - ie. use vertex arrays |
238 |
* (vertex_VP() forces to pass coordinates in arrays of 4 floats). |
* (vertex_VP() forces to pass coordinates in arrays of 4 floats). |
239 |
* |
* |
240 |
* @param pos vertex position (array of 4 floats) |
* @param pos vertex position (array of 4 floats) |
245 |
glVertex4fv(pos); |
glVertex4fv(pos); |
246 |
} |
} |
247 |
|
|
248 |
/*** Explicit version of the rendering interface */ |
/*** Explicit version of the rendering interface. */ |
249 |
/** Calls setupcode, texgen and setup for the texture. |
/** Calls setupcode, texgen and setup for the texture. |
250 |
* |
* |
251 |
* @param param light parameters (LightParam object) |
* @param param light parameters (LightParam object) |
252 |
*/ |
*/ |
253 |
void setUp_explicit(LightParam *param) {} |
void setUp_explicit(LightParam *param); |
254 |
|
|
255 |
/** Calls teardowncode. |
/** Calls teardowncode. |
256 |
*/ |
*/ |
257 |
void tearDown_explicit() {} |
void tearDown_explicit () { teardowncode(); } |
258 |
|
|
259 |
/** Explicit version of the paperpass vertex |
/** Explicit version of the PaperPass vertex. |
260 |
*/ |
*/ |
261 |
void vertex_explicit() {} |
void vertex_explicit(float *ppos); |
|
void vertex_explicit(float *ppos) {} |
|
|
void vertex_explicit(float *pos, float *ppos) {} |
|
262 |
|
|
263 |
protected: |
protected: |
264 |
/* Vertex program code */ |
/* Vertex program code. */ |
265 |
VPCode texgenvp; |
VPCode texgenvp; |
266 |
}; |
}; |
267 |
|
|