diff options
author | David Walter Seikel | 2016-03-28 22:28:34 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-03-28 22:28:34 +1000 |
commit | 7028cbe09c688437910a25623098762bf0fa592d (patch) | |
tree | 10b5af58277d9880380c2251f109325542c4e6eb /src/others/irrlicht-1.8.1/include/SMaterial.h | |
parent | Move lemon to the src/others directory. (diff) | |
download | SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.zip SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.gz SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.bz2 SledjHamr-7028cbe09c688437910a25623098762bf0fa592d.tar.xz |
Move Irrlicht to src/others.
Diffstat (limited to 'src/others/irrlicht-1.8.1/include/SMaterial.h')
-rw-r--r-- | src/others/irrlicht-1.8.1/include/SMaterial.h | 685 |
1 files changed, 685 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/include/SMaterial.h b/src/others/irrlicht-1.8.1/include/SMaterial.h new file mode 100644 index 0000000..3172241 --- /dev/null +++ b/src/others/irrlicht-1.8.1/include/SMaterial.h | |||
@@ -0,0 +1,685 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #ifndef __S_MATERIAL_H_INCLUDED__ | ||
6 | #define __S_MATERIAL_H_INCLUDED__ | ||
7 | |||
8 | #include "SColor.h" | ||
9 | #include "matrix4.h" | ||
10 | #include "irrArray.h" | ||
11 | #include "irrMath.h" | ||
12 | #include "EMaterialTypes.h" | ||
13 | #include "EMaterialFlags.h" | ||
14 | #include "SMaterialLayer.h" | ||
15 | |||
16 | namespace irr | ||
17 | { | ||
18 | namespace video | ||
19 | { | ||
20 | class ITexture; | ||
21 | |||
22 | //! Flag for EMT_ONETEXTURE_BLEND, ( BlendFactor ) BlendFunc = source * sourceFactor + dest * destFactor | ||
23 | enum E_BLEND_FACTOR | ||
24 | { | ||
25 | EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0) | ||
26 | EBF_ONE, //!< src & dest (1, 1, 1, 1) | ||
27 | EBF_DST_COLOR, //!< src (destR, destG, destB, destA) | ||
28 | EBF_ONE_MINUS_DST_COLOR, //!< src (1-destR, 1-destG, 1-destB, 1-destA) | ||
29 | EBF_SRC_COLOR, //!< dest (srcR, srcG, srcB, srcA) | ||
30 | EBF_ONE_MINUS_SRC_COLOR, //!< dest (1-srcR, 1-srcG, 1-srcB, 1-srcA) | ||
31 | EBF_SRC_ALPHA, //!< src & dest (srcA, srcA, srcA, srcA) | ||
32 | EBF_ONE_MINUS_SRC_ALPHA, //!< src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA) | ||
33 | EBF_DST_ALPHA, //!< src & dest (destA, destA, destA, destA) | ||
34 | EBF_ONE_MINUS_DST_ALPHA, //!< src & dest (1-destA, 1-destA, 1-destA, 1-destA) | ||
35 | EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...) | ||
36 | }; | ||
37 | |||
38 | //! Values defining the blend operation used when blend is enabled | ||
39 | enum E_BLEND_OPERATION | ||
40 | { | ||
41 | EBO_NONE = 0, //!< No blending happens | ||
42 | EBO_ADD, //!< Default blending adds the color values | ||
43 | EBO_SUBTRACT, //!< This mode subtracts the color values | ||
44 | EBO_REVSUBTRACT,//!< This modes subtracts destination from source | ||
45 | EBO_MIN, //!< Choose minimum value of each color channel | ||
46 | EBO_MAX, //!< Choose maximum value of each color channel | ||
47 | EBO_MIN_FACTOR, //!< Choose minimum value of each color channel after applying blend factors, not widely supported | ||
48 | EBO_MAX_FACTOR, //!< Choose maximum value of each color channel after applying blend factors, not widely supported | ||
49 | EBO_MIN_ALPHA, //!< Choose minimum value of each color channel based on alpha value, not widely supported | ||
50 | EBO_MAX_ALPHA //!< Choose maximum value of each color channel based on alpha value, not widely supported | ||
51 | }; | ||
52 | |||
53 | //! MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X | ||
54 | enum E_MODULATE_FUNC | ||
55 | { | ||
56 | EMFN_MODULATE_1X = 1, | ||
57 | EMFN_MODULATE_2X = 2, | ||
58 | EMFN_MODULATE_4X = 4 | ||
59 | }; | ||
60 | |||
61 | //! Comparison function, e.g. for depth buffer test | ||
62 | enum E_COMPARISON_FUNC | ||
63 | { | ||
64 | //! Test never succeeds, this equals disable | ||
65 | ECFN_NEVER=0, | ||
66 | //! <= test, default for e.g. depth test | ||
67 | ECFN_LESSEQUAL=1, | ||
68 | //! Exact equality | ||
69 | ECFN_EQUAL=2, | ||
70 | //! exclusive less comparison, i.e. < | ||
71 | ECFN_LESS, | ||
72 | //! Succeeds almost always, except for exact equality | ||
73 | ECFN_NOTEQUAL, | ||
74 | //! >= test | ||
75 | ECFN_GREATEREQUAL, | ||
76 | //! inverse of <= | ||
77 | ECFN_GREATER, | ||
78 | //! test succeeds always | ||
79 | ECFN_ALWAYS | ||
80 | }; | ||
81 | |||
82 | //! Enum values for enabling/disabling color planes for rendering | ||
83 | enum E_COLOR_PLANE | ||
84 | { | ||
85 | //! No color enabled | ||
86 | ECP_NONE=0, | ||
87 | //! Alpha enabled | ||
88 | ECP_ALPHA=1, | ||
89 | //! Red enabled | ||
90 | ECP_RED=2, | ||
91 | //! Green enabled | ||
92 | ECP_GREEN=4, | ||
93 | //! Blue enabled | ||
94 | ECP_BLUE=8, | ||
95 | //! All colors, no alpha | ||
96 | ECP_RGB=14, | ||
97 | //! All planes enabled | ||
98 | ECP_ALL=15 | ||
99 | }; | ||
100 | |||
101 | //! Source of the alpha value to take | ||
102 | /** This is currently only supported in EMT_ONETEXTURE_BLEND. You can use an | ||
103 | or'ed combination of values. Alpha values are modulated (multiplicated). */ | ||
104 | enum E_ALPHA_SOURCE | ||
105 | { | ||
106 | //! Use no alpha, somewhat redundant with other settings | ||
107 | EAS_NONE=0, | ||
108 | //! Use vertex color alpha | ||
109 | EAS_VERTEX_COLOR, | ||
110 | //! Use texture alpha channel | ||
111 | EAS_TEXTURE | ||
112 | }; | ||
113 | |||
114 | //! EMT_ONETEXTURE_BLEND: pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam | ||
115 | /** alpha source can be an OR'ed combination of E_ALPHA_SOURCE values. */ | ||
116 | inline f32 pack_textureBlendFunc ( const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE ) | ||
117 | { | ||
118 | const u32 tmp = (alphaSource << 12) | (modulate << 8) | (srcFact << 4) | dstFact; | ||
119 | return FR(tmp); | ||
120 | } | ||
121 | |||
122 | //! EMT_ONETEXTURE_BLEND: unpack srcFact & dstFact and Modulo to MaterialTypeParam | ||
123 | /** The fields don't use the full byte range, so we could pack even more... */ | ||
124 | inline void unpack_textureBlendFunc ( E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact, | ||
125 | E_MODULATE_FUNC &modulo, u32& alphaSource, const f32 param ) | ||
126 | { | ||
127 | const u32 state = IR(param); | ||
128 | alphaSource = (state & 0x0000F000) >> 12; | ||
129 | modulo = E_MODULATE_FUNC( ( state & 0x00000F00 ) >> 8 ); | ||
130 | srcFact = E_BLEND_FACTOR ( ( state & 0x000000F0 ) >> 4 ); | ||
131 | dstFact = E_BLEND_FACTOR ( ( state & 0x0000000F ) ); | ||
132 | } | ||
133 | |||
134 | //! EMT_ONETEXTURE_BLEND: has BlendFactor Alphablending | ||
135 | inline bool textureBlendFunc_hasAlpha ( const E_BLEND_FACTOR factor ) | ||
136 | { | ||
137 | switch ( factor ) | ||
138 | { | ||
139 | case EBF_SRC_ALPHA: | ||
140 | case EBF_ONE_MINUS_SRC_ALPHA: | ||
141 | case EBF_DST_ALPHA: | ||
142 | case EBF_ONE_MINUS_DST_ALPHA: | ||
143 | case EBF_SRC_ALPHA_SATURATE: | ||
144 | return true; | ||
145 | default: | ||
146 | return false; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | |||
151 | //! These flags are used to specify the anti-aliasing and smoothing modes | ||
152 | /** Techniques supported are multisampling, geometry smoothing, and alpha | ||
153 | to coverage. | ||
154 | Some drivers don't support a per-material setting of the anti-aliasing | ||
155 | modes. In those cases, FSAA/multisampling is defined by the device mode | ||
156 | chosen upon creation via irr::SIrrCreationParameters. | ||
157 | */ | ||
158 | enum E_ANTI_ALIASING_MODE | ||
159 | { | ||
160 | //! Use to turn off anti-aliasing for this material | ||
161 | EAAM_OFF=0, | ||
162 | //! Default anti-aliasing mode | ||
163 | EAAM_SIMPLE=1, | ||
164 | //! High-quality anti-aliasing, not always supported, automatically enables SIMPLE mode | ||
165 | EAAM_QUALITY=3, | ||
166 | //! Line smoothing | ||
167 | EAAM_LINE_SMOOTH=4, | ||
168 | //! point smoothing, often in software and slow, only with OpenGL | ||
169 | EAAM_POINT_SMOOTH=8, | ||
170 | //! All typical anti-alias and smooth modes | ||
171 | EAAM_FULL_BASIC=15, | ||
172 | //! Enhanced anti-aliasing for transparent materials | ||
173 | /** Usually used with EMT_TRANSPARENT_ALPHA_REF and multisampling. */ | ||
174 | EAAM_ALPHA_TO_COVERAGE=16 | ||
175 | }; | ||
176 | |||
177 | //! These flags allow to define the interpretation of vertex color when lighting is enabled | ||
178 | /** Without lighting being enabled the vertex color is the only value defining the fragment color. | ||
179 | Once lighting is enabled, the four values for diffuse, ambient, emissive, and specular take over. | ||
180 | With these flags it is possible to define which lighting factor shall be defined by the vertex color | ||
181 | instead of the lighting factor which is the same for all faces of that material. | ||
182 | The default is to use vertex color for the diffuse value, another pretty common value is to use | ||
183 | vertex color for both diffuse and ambient factor. */ | ||
184 | enum E_COLOR_MATERIAL | ||
185 | { | ||
186 | //! Don't use vertex color for lighting | ||
187 | ECM_NONE=0, | ||
188 | //! Use vertex color for diffuse light, this is default | ||
189 | ECM_DIFFUSE, | ||
190 | //! Use vertex color for ambient light | ||
191 | ECM_AMBIENT, | ||
192 | //! Use vertex color for emissive light | ||
193 | ECM_EMISSIVE, | ||
194 | //! Use vertex color for specular light | ||
195 | ECM_SPECULAR, | ||
196 | //! Use vertex color for both diffuse and ambient light | ||
197 | ECM_DIFFUSE_AND_AMBIENT | ||
198 | }; | ||
199 | |||
200 | //! Flags for the definition of the polygon offset feature | ||
201 | /** These flags define whether the offset should be into the screen, or towards the eye. */ | ||
202 | enum E_POLYGON_OFFSET | ||
203 | { | ||
204 | //! Push pixel towards the far plane, away from the eye | ||
205 | /** This is typically used for rendering inner areas. */ | ||
206 | EPO_BACK=0, | ||
207 | //! Pull pixels towards the camera. | ||
208 | /** This is typically used for polygons which should appear on top | ||
209 | of other elements, such as decals. */ | ||
210 | EPO_FRONT=1 | ||
211 | }; | ||
212 | |||
213 | //! Names for polygon offset direction | ||
214 | const c8* const PolygonOffsetDirectionNames[] = | ||
215 | { | ||
216 | "Back", | ||
217 | "Front", | ||
218 | 0 | ||
219 | }; | ||
220 | |||
221 | |||
222 | //! Maximum number of texture an SMaterial can have. | ||
223 | const u32 MATERIAL_MAX_TEXTURES = _IRR_MATERIAL_MAX_TEXTURES_; | ||
224 | |||
225 | //! Struct for holding parameters for a material renderer | ||
226 | class SMaterial | ||
227 | { | ||
228 | public: | ||
229 | //! Default constructor. Creates a solid, lit material with white colors | ||
230 | SMaterial() | ||
231 | : MaterialType(EMT_SOLID), AmbientColor(255,255,255,255), DiffuseColor(255,255,255,255), | ||
232 | EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255), | ||
233 | Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f), | ||
234 | ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL), | ||
235 | ColorMaterial(ECM_DIFFUSE), BlendOperation(EBO_NONE), | ||
236 | PolygonOffsetFactor(0), PolygonOffsetDirection(EPO_FRONT), | ||
237 | Wireframe(false), PointCloud(false), GouraudShading(true), | ||
238 | Lighting(true), ZWriteEnable(true), BackfaceCulling(true), FrontfaceCulling(false), | ||
239 | FogEnable(false), NormalizeNormals(false), UseMipMaps(true) | ||
240 | { } | ||
241 | |||
242 | //! Copy constructor | ||
243 | /** \param other Material to copy from. */ | ||
244 | SMaterial(const SMaterial& other) | ||
245 | { | ||
246 | // These pointers are checked during assignment | ||
247 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
248 | TextureLayer[i].TextureMatrix = 0; | ||
249 | *this = other; | ||
250 | } | ||
251 | |||
252 | //! Assignment operator | ||
253 | /** \param other Material to copy from. */ | ||
254 | SMaterial& operator=(const SMaterial& other) | ||
255 | { | ||
256 | // Check for self-assignment! | ||
257 | if (this == &other) | ||
258 | return *this; | ||
259 | |||
260 | MaterialType = other.MaterialType; | ||
261 | |||
262 | AmbientColor = other.AmbientColor; | ||
263 | DiffuseColor = other.DiffuseColor; | ||
264 | EmissiveColor = other.EmissiveColor; | ||
265 | SpecularColor = other.SpecularColor; | ||
266 | Shininess = other.Shininess; | ||
267 | MaterialTypeParam = other.MaterialTypeParam; | ||
268 | MaterialTypeParam2 = other.MaterialTypeParam2; | ||
269 | Thickness = other.Thickness; | ||
270 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
271 | { | ||
272 | TextureLayer[i] = other.TextureLayer[i]; | ||
273 | } | ||
274 | |||
275 | Wireframe = other.Wireframe; | ||
276 | PointCloud = other.PointCloud; | ||
277 | GouraudShading = other.GouraudShading; | ||
278 | Lighting = other.Lighting; | ||
279 | ZWriteEnable = other.ZWriteEnable; | ||
280 | BackfaceCulling = other.BackfaceCulling; | ||
281 | FrontfaceCulling = other.FrontfaceCulling; | ||
282 | FogEnable = other.FogEnable; | ||
283 | NormalizeNormals = other.NormalizeNormals; | ||
284 | ZBuffer = other.ZBuffer; | ||
285 | AntiAliasing = other.AntiAliasing; | ||
286 | ColorMask = other.ColorMask; | ||
287 | ColorMaterial = other.ColorMaterial; | ||
288 | BlendOperation = other.BlendOperation; | ||
289 | PolygonOffsetFactor = other.PolygonOffsetFactor; | ||
290 | PolygonOffsetDirection = other.PolygonOffsetDirection; | ||
291 | UseMipMaps = other.UseMipMaps; | ||
292 | |||
293 | return *this; | ||
294 | } | ||
295 | |||
296 | //! Texture layer array. | ||
297 | SMaterialLayer TextureLayer[MATERIAL_MAX_TEXTURES]; | ||
298 | |||
299 | //! Type of the material. Specifies how everything is blended together | ||
300 | E_MATERIAL_TYPE MaterialType; | ||
301 | |||
302 | //! How much ambient light (a global light) is reflected by this material. | ||
303 | /** The default is full white, meaning objects are completely | ||
304 | globally illuminated. Reduce this if you want to see diffuse | ||
305 | or specular light effects. */ | ||
306 | SColor AmbientColor; | ||
307 | |||
308 | //! How much diffuse light coming from a light source is reflected by this material. | ||
309 | /** The default is full white. */ | ||
310 | SColor DiffuseColor; | ||
311 | |||
312 | //! Light emitted by this material. Default is to emit no light. | ||
313 | SColor EmissiveColor; | ||
314 | |||
315 | //! How much specular light (highlights from a light) is reflected. | ||
316 | /** The default is to reflect white specular light. See | ||
317 | SMaterial::Shininess on how to enable specular lights. */ | ||
318 | SColor SpecularColor; | ||
319 | |||
320 | //! Value affecting the size of specular highlights. | ||
321 | /** A value of 20 is common. If set to 0, no specular | ||
322 | highlights are being used. To activate, simply set the | ||
323 | shininess of a material to a value in the range [0.5;128]: | ||
324 | \code | ||
325 | sceneNode->getMaterial(0).Shininess = 20.0f; | ||
326 | \endcode | ||
327 | |||
328 | You can change the color of the highlights using | ||
329 | \code | ||
330 | sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255); | ||
331 | \endcode | ||
332 | |||
333 | The specular color of the dynamic lights | ||
334 | (SLight::SpecularColor) will influence the the highlight color | ||
335 | too, but they are set to a useful value by default when | ||
336 | creating the light scene node. Here is a simple example on how | ||
337 | to use specular highlights: | ||
338 | \code | ||
339 | // load and display mesh | ||
340 | scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( | ||
341 | smgr->getMesh("data/faerie.md2")); | ||
342 | node->setMaterialTexture(0, driver->getTexture("data/Faerie2.pcx")); // set diffuse texture | ||
343 | node->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting | ||
344 | node->getMaterial(0).Shininess = 20.0f; // set size of specular highlights | ||
345 | |||
346 | // add white light | ||
347 | scene::ILightSceneNode* light = smgr->addLightSceneNode(0, | ||
348 | core::vector3df(5,5,5), video::SColorf(1.0f, 1.0f, 1.0f)); | ||
349 | \endcode */ | ||
350 | f32 Shininess; | ||
351 | |||
352 | //! Free parameter, dependent on the material type. | ||
353 | /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID | ||
354 | and EMT_TRANSPARENT_ALPHA_CHANNEL. */ | ||
355 | f32 MaterialTypeParam; | ||
356 | |||
357 | //! Second free parameter, dependent on the material type. | ||
358 | /** Mostly ignored. */ | ||
359 | f32 MaterialTypeParam2; | ||
360 | |||
361 | //! Thickness of non-3dimensional elements such as lines and points. | ||
362 | f32 Thickness; | ||
363 | |||
364 | //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL | ||
365 | /** Values are from E_COMPARISON_FUNC. */ | ||
366 | u8 ZBuffer; | ||
367 | |||
368 | //! Sets the antialiasing mode | ||
369 | /** Values are chosen from E_ANTI_ALIASING_MODE. Default is | ||
370 | EAAM_SIMPLE|EAAM_LINE_SMOOTH, i.e. simple multi-sample | ||
371 | anti-aliasing and lime smoothing is enabled. */ | ||
372 | u8 AntiAliasing; | ||
373 | |||
374 | //! Defines the enabled color planes | ||
375 | /** Values are defined as or'ed values of the E_COLOR_PLANE enum. | ||
376 | Only enabled color planes will be rendered to the current render | ||
377 | target. Typical use is to disable all colors when rendering only to | ||
378 | depth or stencil buffer, or using Red and Green for Stereo rendering. */ | ||
379 | u8 ColorMask:4; | ||
380 | |||
381 | //! Defines the interpretation of vertex color in the lighting equation | ||
382 | /** Values should be chosen from E_COLOR_MATERIAL. | ||
383 | When lighting is enabled, vertex color can be used instead of the | ||
384 | material values for light modulation. This allows to easily change e.g. the | ||
385 | diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in | ||
386 | a very similar rendering as with lighting turned off, just with light shading. */ | ||
387 | u8 ColorMaterial:3; | ||
388 | |||
389 | //! Store the blend operation of choice | ||
390 | /** Values to be chosen from E_BLEND_OPERATION. The actual way to use this value | ||
391 | is not yet determined, so ignore it for now. */ | ||
392 | E_BLEND_OPERATION BlendOperation:4; | ||
393 | |||
394 | //! Factor specifying how far the polygon offset should be made | ||
395 | /** Specifying 0 disables the polygon offset. The direction is specified spearately. | ||
396 | The factor can be from 0 to 7.*/ | ||
397 | u8 PolygonOffsetFactor:3; | ||
398 | |||
399 | //! Flag defining the direction the polygon offset is applied to. | ||
400 | /** Can be to front or to back, specififed by values from E_POLYGON_OFFSET. */ | ||
401 | E_POLYGON_OFFSET PolygonOffsetDirection:1; | ||
402 | |||
403 | //! Draw as wireframe or filled triangles? Default: false | ||
404 | /** The user can access a material flag using | ||
405 | \code material.Wireframe=true \endcode | ||
406 | or \code material.setFlag(EMF_WIREFRAME, true); \endcode */ | ||
407 | bool Wireframe:1; | ||
408 | |||
409 | //! Draw as point cloud or filled triangles? Default: false | ||
410 | bool PointCloud:1; | ||
411 | |||
412 | //! Flat or Gouraud shading? Default: true | ||
413 | bool GouraudShading:1; | ||
414 | |||
415 | //! Will this material be lighted? Default: true | ||
416 | bool Lighting:1; | ||
417 | |||
418 | //! Is the zbuffer writeable or is it read-only. Default: true. | ||
419 | /** This flag is forced to false if the MaterialType is a | ||
420 | transparent type and the scene parameter | ||
421 | ALLOW_ZWRITE_ON_TRANSPARENT is not set. */ | ||
422 | bool ZWriteEnable:1; | ||
423 | |||
424 | //! Is backface culling enabled? Default: true | ||
425 | bool BackfaceCulling:1; | ||
426 | |||
427 | //! Is frontface culling enabled? Default: false | ||
428 | bool FrontfaceCulling:1; | ||
429 | |||
430 | //! Is fog enabled? Default: false | ||
431 | bool FogEnable:1; | ||
432 | |||
433 | //! Should normals be normalized? | ||
434 | /** Always use this if the mesh lit and scaled. Default: false */ | ||
435 | bool NormalizeNormals:1; | ||
436 | |||
437 | //! Shall mipmaps be used if available | ||
438 | /** Sometimes, disabling mipmap usage can be useful. Default: true */ | ||
439 | bool UseMipMaps:1; | ||
440 | |||
441 | //! Gets the texture transformation matrix for level i | ||
442 | /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES. | ||
443 | \return Texture matrix for texture level i. */ | ||
444 | core::matrix4& getTextureMatrix(u32 i) | ||
445 | { | ||
446 | return TextureLayer[i].getTextureMatrix(); | ||
447 | } | ||
448 | |||
449 | //! Gets the immutable texture transformation matrix for level i | ||
450 | /** \param i The desired level. | ||
451 | \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */ | ||
452 | const core::matrix4& getTextureMatrix(u32 i) const | ||
453 | { | ||
454 | if (i<MATERIAL_MAX_TEXTURES) | ||
455 | return TextureLayer[i].getTextureMatrix(); | ||
456 | else | ||
457 | return core::IdentityMatrix; | ||
458 | } | ||
459 | |||
460 | //! Sets the i-th texture transformation matrix | ||
461 | /** \param i The desired level. | ||
462 | \param mat Texture matrix for texture level i. */ | ||
463 | void setTextureMatrix(u32 i, const core::matrix4& mat) | ||
464 | { | ||
465 | if (i>=MATERIAL_MAX_TEXTURES) | ||
466 | return; | ||
467 | TextureLayer[i].setTextureMatrix(mat); | ||
468 | } | ||
469 | |||
470 | //! Gets the i-th texture | ||
471 | /** \param i The desired level. | ||
472 | \return Texture for texture level i, if defined, else 0. */ | ||
473 | ITexture* getTexture(u32 i) const | ||
474 | { | ||
475 | return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0; | ||
476 | } | ||
477 | |||
478 | //! Sets the i-th texture | ||
479 | /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored. | ||
480 | \param i The desired level. | ||
481 | \param tex Texture for texture level i. */ | ||
482 | void setTexture(u32 i, ITexture* tex) | ||
483 | { | ||
484 | if (i>=MATERIAL_MAX_TEXTURES) | ||
485 | return; | ||
486 | TextureLayer[i].Texture = tex; | ||
487 | } | ||
488 | |||
489 | //! Sets the Material flag to the given value | ||
490 | /** \param flag The flag to be set. | ||
491 | \param value The new value for the flag. */ | ||
492 | void setFlag(E_MATERIAL_FLAG flag, bool value) | ||
493 | { | ||
494 | switch (flag) | ||
495 | { | ||
496 | case EMF_WIREFRAME: | ||
497 | Wireframe = value; break; | ||
498 | case EMF_POINTCLOUD: | ||
499 | PointCloud = value; break; | ||
500 | case EMF_GOURAUD_SHADING: | ||
501 | GouraudShading = value; break; | ||
502 | case EMF_LIGHTING: | ||
503 | Lighting = value; break; | ||
504 | case EMF_ZBUFFER: | ||
505 | ZBuffer = value; break; | ||
506 | case EMF_ZWRITE_ENABLE: | ||
507 | ZWriteEnable = value; break; | ||
508 | case EMF_BACK_FACE_CULLING: | ||
509 | BackfaceCulling = value; break; | ||
510 | case EMF_FRONT_FACE_CULLING: | ||
511 | FrontfaceCulling = value; break; | ||
512 | case EMF_BILINEAR_FILTER: | ||
513 | { | ||
514 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
515 | TextureLayer[i].BilinearFilter = value; | ||
516 | } | ||
517 | break; | ||
518 | case EMF_TRILINEAR_FILTER: | ||
519 | { | ||
520 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
521 | TextureLayer[i].TrilinearFilter = value; | ||
522 | } | ||
523 | break; | ||
524 | case EMF_ANISOTROPIC_FILTER: | ||
525 | { | ||
526 | if (value) | ||
527 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
528 | TextureLayer[i].AnisotropicFilter = 0xFF; | ||
529 | else | ||
530 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
531 | TextureLayer[i].AnisotropicFilter = 0; | ||
532 | } | ||
533 | break; | ||
534 | case EMF_FOG_ENABLE: | ||
535 | FogEnable = value; break; | ||
536 | case EMF_NORMALIZE_NORMALS: | ||
537 | NormalizeNormals = value; break; | ||
538 | case EMF_TEXTURE_WRAP: | ||
539 | { | ||
540 | for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i) | ||
541 | { | ||
542 | TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value; | ||
543 | TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value; | ||
544 | } | ||
545 | } | ||
546 | break; | ||
547 | case EMF_ANTI_ALIASING: | ||
548 | AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break; | ||
549 | case EMF_COLOR_MASK: | ||
550 | ColorMask = value?ECP_ALL:ECP_NONE; break; | ||
551 | case EMF_COLOR_MATERIAL: | ||
552 | ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break; | ||
553 | case EMF_USE_MIP_MAPS: | ||
554 | UseMipMaps = value; break; | ||
555 | case EMF_BLEND_OPERATION: | ||
556 | BlendOperation = value?EBO_ADD:EBO_NONE; break; | ||
557 | case EMF_POLYGON_OFFSET: | ||
558 | PolygonOffsetFactor = value?1:0; | ||
559 | PolygonOffsetDirection = EPO_BACK; | ||
560 | break; | ||
561 | default: | ||
562 | break; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | //! Gets the Material flag | ||
567 | /** \param flag The flag to query. | ||
568 | \return The current value of the flag. */ | ||
569 | bool getFlag(E_MATERIAL_FLAG flag) const | ||
570 | { | ||
571 | switch (flag) | ||
572 | { | ||
573 | case EMF_WIREFRAME: | ||
574 | return Wireframe; | ||
575 | case EMF_POINTCLOUD: | ||
576 | return PointCloud; | ||
577 | case EMF_GOURAUD_SHADING: | ||
578 | return GouraudShading; | ||
579 | case EMF_LIGHTING: | ||
580 | return Lighting; | ||
581 | case EMF_ZBUFFER: | ||
582 | return ZBuffer!=ECFN_NEVER; | ||
583 | case EMF_ZWRITE_ENABLE: | ||
584 | return ZWriteEnable; | ||
585 | case EMF_BACK_FACE_CULLING: | ||
586 | return BackfaceCulling; | ||
587 | case EMF_FRONT_FACE_CULLING: | ||
588 | return FrontfaceCulling; | ||
589 | case EMF_BILINEAR_FILTER: | ||
590 | return TextureLayer[0].BilinearFilter; | ||
591 | case EMF_TRILINEAR_FILTER: | ||
592 | return TextureLayer[0].TrilinearFilter; | ||
593 | case EMF_ANISOTROPIC_FILTER: | ||
594 | return TextureLayer[0].AnisotropicFilter!=0; | ||
595 | case EMF_FOG_ENABLE: | ||
596 | return FogEnable; | ||
597 | case EMF_NORMALIZE_NORMALS: | ||
598 | return NormalizeNormals; | ||
599 | case EMF_TEXTURE_WRAP: | ||
600 | return !(TextureLayer[0].TextureWrapU || | ||
601 | TextureLayer[0].TextureWrapV || | ||
602 | TextureLayer[1].TextureWrapU || | ||
603 | TextureLayer[1].TextureWrapV || | ||
604 | TextureLayer[2].TextureWrapU || | ||
605 | TextureLayer[2].TextureWrapV || | ||
606 | TextureLayer[3].TextureWrapU || | ||
607 | TextureLayer[3].TextureWrapV); | ||
608 | case EMF_ANTI_ALIASING: | ||
609 | return (AntiAliasing==1); | ||
610 | case EMF_COLOR_MASK: | ||
611 | return (ColorMask!=ECP_NONE); | ||
612 | case EMF_COLOR_MATERIAL: | ||
613 | return (ColorMaterial != ECM_NONE); | ||
614 | case EMF_USE_MIP_MAPS: | ||
615 | return UseMipMaps; | ||
616 | case EMF_BLEND_OPERATION: | ||
617 | return BlendOperation != EBO_NONE; | ||
618 | case EMF_POLYGON_OFFSET: | ||
619 | return PolygonOffsetFactor != 0; | ||
620 | } | ||
621 | |||
622 | return false; | ||
623 | } | ||
624 | |||
625 | //! Inequality operator | ||
626 | /** \param b Material to compare to. | ||
627 | \return True if the materials differ, else false. */ | ||
628 | inline bool operator!=(const SMaterial& b) const | ||
629 | { | ||
630 | bool different = | ||
631 | MaterialType != b.MaterialType || | ||
632 | AmbientColor != b.AmbientColor || | ||
633 | DiffuseColor != b.DiffuseColor || | ||
634 | EmissiveColor != b.EmissiveColor || | ||
635 | SpecularColor != b.SpecularColor || | ||
636 | Shininess != b.Shininess || | ||
637 | MaterialTypeParam != b.MaterialTypeParam || | ||
638 | MaterialTypeParam2 != b.MaterialTypeParam2 || | ||
639 | Thickness != b.Thickness || | ||
640 | Wireframe != b.Wireframe || | ||
641 | PointCloud != b.PointCloud || | ||
642 | GouraudShading != b.GouraudShading || | ||
643 | Lighting != b.Lighting || | ||
644 | ZBuffer != b.ZBuffer || | ||
645 | ZWriteEnable != b.ZWriteEnable || | ||
646 | BackfaceCulling != b.BackfaceCulling || | ||
647 | FrontfaceCulling != b.FrontfaceCulling || | ||
648 | FogEnable != b.FogEnable || | ||
649 | NormalizeNormals != b.NormalizeNormals || | ||
650 | AntiAliasing != b.AntiAliasing || | ||
651 | ColorMask != b.ColorMask || | ||
652 | ColorMaterial != b.ColorMaterial || | ||
653 | BlendOperation != b.BlendOperation || | ||
654 | PolygonOffsetFactor != b.PolygonOffsetFactor || | ||
655 | PolygonOffsetDirection != b.PolygonOffsetDirection || | ||
656 | UseMipMaps != b.UseMipMaps; | ||
657 | for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i) | ||
658 | { | ||
659 | different |= (TextureLayer[i] != b.TextureLayer[i]); | ||
660 | } | ||
661 | return different; | ||
662 | } | ||
663 | |||
664 | //! Equality operator | ||
665 | /** \param b Material to compare to. | ||
666 | \return True if the materials are equal, else false. */ | ||
667 | inline bool operator==(const SMaterial& b) const | ||
668 | { return !(b!=*this); } | ||
669 | |||
670 | bool isTransparent() const | ||
671 | { | ||
672 | return MaterialType==EMT_TRANSPARENT_ADD_COLOR || | ||
673 | MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL || | ||
674 | MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA || | ||
675 | MaterialType==EMT_TRANSPARENT_REFLECTION_2_LAYER; | ||
676 | } | ||
677 | }; | ||
678 | |||
679 | //! global const identity Material | ||
680 | IRRLICHT_API extern SMaterial IdentityMaterial; | ||
681 | |||
682 | } // end namespace video | ||
683 | } // end namespace irr | ||
684 | |||
685 | #endif | ||