representation d'une cubemap / envmap.
More...
#include <envmap.h>
representation d'une cubemap / envmap.
Definition at line 12 of file envmap.h.
◆ Envmap() [1/4]
Definition at line 14 of file envmap.h.
14: m_faces(), m_width(0) {}
◆ Envmap() [2/4]
| Envmap::Envmap |
( |
const int | size | ) |
|
|
inline |
Definition at line 16 of file envmap.h.
16 : m_faces(), m_width(size)
17 {
18 for(int i= 0; i < 6; i++)
19 m_faces[i]= Image(size, size);
20 }
◆ Envmap() [3/4]
| Envmap::Envmap |
( |
const Image & | image | ) |
|
|
inline |
extrait les 6 faces d'une image.
Definition at line 23 of file envmap.h.
23 : m_faces(), m_width(0)
24 {
25 int w= image.width() / 4;
26 int h= image.height() / 3;
27 if(w != h)
28 return;
29
30 m_width= w;
31
32
33 struct {
int x, y; }
faces[]= {
34 {0, 1},
35 {2, 1},
36 {1, 2},
37 {1, 0},
38 {1, 1},
39 {3, 1},
40 };
41
42 for(int i= 0; i < 6; i++)
44 }
Image flipY(const Image &image)
retourne l'image
Image flipX(const Image &image)
retourne l'image
Image copy(const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
renvoie un bloc de l'image
std::array< Image, 6 > faces() const
renvoie les 6 faces de la cubemap.
◆ Envmap() [4/4]
| Envmap::Envmap |
( |
const std::array< Image, 6 > & | faces | ) |
|
|
inline |
utilise les 6 faces.
Definition at line 47 of file envmap.h.
47 : m_faces()
48 {
49 for(int i= 0; i < 6; i++)
51
52 m_width= m_faces[0].
width();
53 for(int i= 0; i < 6; i++)
54 if(m_width != m_faces[i].
width() || m_width != m_faces[i].
height())
55 m_width= 0;
56 }
unsigned width() const
renvoie la largeur de l'image.
int height() const
hauteur d'une face.
int width() const
largeur d'une face.
◆ width()
| int Envmap::width |
( |
| ) |
const |
|
inline |
largeur d'une face.
Definition at line 58 of file envmap.h.
◆ height()
| int Envmap::height |
( |
| ) |
const |
|
inline |
hauteur d'une face.
Definition at line 59 of file envmap.h.
◆ empty()
| bool Envmap::empty |
( |
| ) |
const |
|
inline |
renvoie vrai si la cubemap est initialisee.
Definition at line 60 of file envmap.h.
◆ linear()
| void Envmap::linear |
( |
const float | gamma = 2.2f | ) |
|
|
inline |
applique une correction gamma inverse aux donnees de la cubemap.
Definition at line 63 of file envmap.h.
64 {
65 for(int i= 0; i < 6; i++)
66 for(int p= 0; p < int(m_faces[i].size()); p++)
67 {
68 Color pixel= m_faces[i](p);
69 m_faces[i](p)= Color(std::pow(pixel.r,
gamma), std::pow(pixel.g,
gamma), std::pow(pixel.b,
gamma));
70 }
71 }
void gamma(const float gamma=2.2f)
applique une correction gamma aux donnees de la cubemap.
◆ gamma()
| void Envmap::gamma |
( |
const float | gamma = 2.2f | ) |
|
|
inline |
applique une correction gamma aux donnees de la cubemap.
Definition at line 74 of file envmap.h.
75 {
76 for(int i= 0; i < 6; i++)
77 for(int p= 0; p < int(m_faces[i].size()); p++)
78 {
79 Color pixel= m_faces[i](p);
80 m_faces[i](p)= Color(std::pow(pixel.r, 1 /
gamma), std::pow(pixel.g, 1 /
gamma), std::pow(pixel.b, 1 /
gamma));
81 }
82 }
◆ cross()
| Image Envmap::cross |
( |
| ) |
const |
|
inline |
renvoie une image contenant les 6 faces de la cubemap.
Definition at line 85 of file envmap.h.
86 {
88 return Image();
89
90
91 struct {
int x, y; }
faces[]= {
92 {0, 1},
93 {2, 1},
94 {1, 2},
95 {1, 0},
96 {1, 1},
97 {3, 1},
98 };
99
100
102 for(int i= 0; i < 6; i++)
103 {
105
108 for(
int y= 0; y <
height(); y++)
109 for(
int x= 0; x <
width(); x++)
110 image(xmin+x, ymin+y)= face(x, y);
111 }
112
113 return image;
114 }
bool empty() const
renvoie vrai si la cubemap est initialisee.
◆ faces()
| std::array< Image, 6 > Envmap::faces |
( |
| ) |
const |
|
inline |
renvoie les 6 faces de la cubemap.
Definition at line 117 of file envmap.h.
118 {
120 return std::array<Image, 6>();
121
122 std::array<Image, 6>
faces;
123 for(int i= 0; i < 6; i++)
125
127 }
◆ operator()() [1/2]
| Color & Envmap::operator() |
( |
const int | face, |
|
|
const int | x, |
|
|
const int | y ) |
|
inline |
Definition at line 129 of file envmap.h.
130 {
131 return m_faces[face](x, y);
132 }
◆ operator()() [2/2]
| Color Envmap::operator() |
( |
const int | face, |
|
|
const int | x, |
|
|
const int | y ) const |
|
inline |
Definition at line 134 of file envmap.h.
135 {
136 return m_faces[face](x, y);
137 }
◆ texture()
renvoie la couleur de la cubemap dans la direction d, utilise les memes conventions qu'openGL / Renderman.
Definition at line 140 of file envmap.h.
141 {
142
143
144
145 float sm, tm;
146 int face= -1;
147 Vector m= Vector(std::abs(d.x), std::abs(d.y), std::abs(d.z));
148 if(m.x > m.y && m.x > m.z)
149 {
150
151 if(d.x > 0)
152 {
153 face= 0;
154 sm= -d.z / m.x;
155 tm= -d.y / m.x;
156 }
157 else
158 {
159 face= 1;
160 sm= d.z / m.x;
161 tm= -d.y / m.x;
162 }
163 }
164 else if(m.y > m.z)
165 {
166
167 if(d.y > 0)
168 {
169 face= 2;
170 sm= d.x / m.y;
171 tm= d.z / m.y;
172 }
173 else
174 {
175 face= 3;
176 sm= d.x / m.y;
177 tm= -d.z / m.y;
178 }
179 }
180 else
181 {
182
183 if(d.z > 0)
184 {
185 face= 4;
186 sm= d.x / m.z;
187 tm= -d.y / m.z;
188 }
189 else
190 {
191 face= 5;
192 sm= -d.x / m.z;
193 tm= -d.y / m.z;
194 }
195 }
196
197 assert(face != -1);
198 float s= (sm +1) / 2;
199 float t= (tm +1) / 2;
200 return m_faces[face].texture(s, t);
201 }
◆ envmap_pixel()
Definition at line 204 of file envmap.h.
204{ Vector texel= envmap_texel(d); return Vector(texel.x, texel.y * m_width, texel.z * m_width); }
◆ envmap_texel()
Definition at line 207 of file envmap.h.
208 {
209 float sm, tm;
210 int face= -1;
211 Vector m= Vector(std::abs(d.x), std::abs(d.y), std::abs(d.z));
212 if(m.x > m.y && m.x > m.z)
213 {
214
215 if(d.x > 0)
216 {
217 face= 0;
218 sm= -d.z / m.x;
219 tm= -d.y / m.x;
220 }
221 else
222 {
223 face= 1;
224 sm= d.z / m.x;
225 tm= -d.y / m.x;
226 }
227 }
228 else if(m.y > m.z)
229 {
230
231 if(d.y > 0)
232 {
233 face= 2;
234 sm= d.x / m.y;
235 tm= d.z / m.y;
236 }
237 else
238 {
239 face= 3;
240 sm= d.x / m.y;
241 tm= -d.z / m.y;
242 }
243 }
244 else
245 {
246
247 if(d.z > 0)
248 {
249 face= 4;
250 sm= d.x / m.z;
251 tm= -d.y / m.z;
252 }
253 else
254 {
255 face= 5;
256 sm= -d.x / m.z;
257 tm= -d.y / m.z;
258 }
259 }
260
261 assert(face != -1);
262 float s= (sm +1) / 2;
263 float t= (tm +1) / 2;
264 return Vector(face, s, t);
265 }
◆ envmap_pixel_direction()
Definition at line 268 of file envmap.h.
268{ return envmap_texel_direction(int(d.x), d.y / m_width, d.z / m_width); }
◆ envmap_texel_direction() [1/2]
Definition at line 270 of file envmap.h.
270{ return envmap_texel_direction(int(d.x), d.y, d.z); }
◆ envmap_texel_direction() [2/2]
| Vector Envmap::envmap_texel_direction |
( |
const int | face, |
|
|
const float | s, |
|
|
const float | t ) |
|
inline |
Definition at line 272 of file envmap.h.
273 {
274
275 float sm= 2 * s -1;
276 float tm= 2 * t -1;
277 if(face == 0)
278 {
279
280
281
282 return Vector(1, -tm, -sm);
283 }
284 else if(face == 1)
285 {
286
287
288
289 return Vector(-1, -tm, sm);
290 }
291 else if(face == 2)
292 {
293
294
295
296 return Vector(sm, 1, tm);
297 }
298 else if(face == 3)
299 {
300
301
302
303 return Vector(sm, -1, -tm);
304 }
305 else if(face == 4)
306 {
307
308
309
310 return Vector(sm, -tm, 1);
311 }
312 else
313 {
314
315
316
317 return Vector(-sm, -tm, -1);
318 }
319 }
◆ m_faces
| std::array<Image, 6> Envmap::m_faces |
|
protected |
◆ m_width
The documentation for this struct was generated from the following file: