1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_MATERIAL_H_INCLUDED__
\r
6 #define __S_MATERIAL_H_INCLUDED__
\r
10 #include "irrArray.h"
\r
11 #include "irrMath.h"
\r
12 #include "EMaterialTypes.h"
\r
13 #include "EMaterialFlags.h"
\r
14 #include "SMaterialLayer.h"
\r
22 //! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor
\r
23 //! BlendFunc = source * sourceFactor + dest * destFactor
\r
26 EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0)
\r
27 EBF_ONE, //!< src & dest (1, 1, 1, 1)
\r
28 EBF_DST_COLOR, //!< src (destR, destG, destB, destA)
\r
29 EBF_ONE_MINUS_DST_COLOR, //!< src (1-destR, 1-destG, 1-destB, 1-destA)
\r
30 EBF_SRC_COLOR, //!< dest (srcR, srcG, srcB, srcA)
\r
31 EBF_ONE_MINUS_SRC_COLOR, //!< dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
\r
32 EBF_SRC_ALPHA, //!< src & dest (srcA, srcA, srcA, srcA)
\r
33 EBF_ONE_MINUS_SRC_ALPHA, //!< src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
\r
34 EBF_DST_ALPHA, //!< src & dest (destA, destA, destA, destA)
\r
35 EBF_ONE_MINUS_DST_ALPHA, //!< src & dest (1-destA, 1-destA, 1-destA, 1-destA)
\r
36 EBF_SRC_ALPHA_SATURATE //!< src (min(srcA, 1-destA), idem, ...)
\r
39 //! Values defining the blend operation
\r
40 enum E_BLEND_OPERATION
\r
42 EBO_NONE = 0, //!< No blending happens
\r
43 EBO_ADD, //!< Default blending adds the color values
\r
44 EBO_SUBTRACT, //!< This mode subtracts the color values
\r
45 EBO_REVSUBTRACT,//!< This modes subtracts destination from source
\r
46 EBO_MIN, //!< Choose minimum value of each color channel
\r
47 EBO_MAX, //!< Choose maximum value of each color channel
\r
48 EBO_MIN_FACTOR, //!< Choose minimum value of each color channel after applying blend factors, not widely supported
\r
49 EBO_MAX_FACTOR, //!< Choose maximum value of each color channel after applying blend factors, not widely supported
\r
50 EBO_MIN_ALPHA, //!< Choose minimum value of each color channel based on alpha value, not widely supported
\r
51 EBO_MAX_ALPHA //!< Choose maximum value of each color channel based on alpha value, not widely supported
\r
54 //! MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X
\r
55 enum E_MODULATE_FUNC
\r
57 EMFN_MODULATE_1X = 1,
\r
58 EMFN_MODULATE_2X = 2,
\r
59 EMFN_MODULATE_4X = 4
\r
62 //! Comparison function, e.g. for depth buffer test
\r
63 enum E_COMPARISON_FUNC
\r
65 //! Depth test disabled (disable also write to depth buffer)
\r
67 //! <= test, default for e.g. depth test
\r
71 //! exclusive less comparison, i.e. <
\r
73 //! Succeeds almost always, except for exact equality
\r
79 //! test succeeds always
\r
81 //! Test never succeeds
\r
85 //! Enum values for enabling/disabling color planes for rendering
\r
88 //! No color enabled
\r
98 //! All colors, no alpha
\r
100 //! All planes enabled
\r
104 //! Source of the alpha value to take
\r
105 /** This is currently only supported in EMT_ONETEXTURE_BLEND. You can use an
\r
106 or'ed combination of values. Alpha values are modulated (multiplied). */
\r
107 enum E_ALPHA_SOURCE
\r
109 //! Use no alpha, somewhat redundant with other settings
\r
111 //! Use vertex color alpha
\r
113 //! Use texture alpha channel
\r
117 //! Pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam or BlendFactor
\r
118 /** alpha source can be an OR'ed combination of E_ALPHA_SOURCE values. */
\r
119 inline f32 pack_textureBlendFunc(const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact,
\r
120 const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE)
\r
122 const u32 tmp = (alphaSource << 20) | (modulate << 16) | (srcFact << 12) | (dstFact << 8) | (srcFact << 4) | dstFact;
\r
126 //! Pack srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, Modulate and alpha source to MaterialTypeParam or BlendFactor
\r
127 /** alpha source can be an OR'ed combination of E_ALPHA_SOURCE values. */
\r
128 inline f32 pack_textureBlendFuncSeparate(const E_BLEND_FACTOR srcRGBFact, const E_BLEND_FACTOR dstRGBFact,
\r
129 const E_BLEND_FACTOR srcAlphaFact, const E_BLEND_FACTOR dstAlphaFact,
\r
130 const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE)
\r
132 const u32 tmp = (alphaSource << 20) | (modulate << 16) | (srcAlphaFact << 12) | (dstAlphaFact << 8) | (srcRGBFact << 4) | dstRGBFact;
\r
136 //! Unpack srcFact, dstFact, modulo and alphaSource factors
\r
137 /** The fields don't use the full byte range, so we could pack even more... */
\r
138 inline void unpack_textureBlendFunc(E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact,
\r
139 E_MODULATE_FUNC &modulo, u32& alphaSource, const f32 param)
\r
141 const u32 state = IR(param);
\r
142 alphaSource = (state & 0x00F00000) >> 20;
\r
143 modulo = E_MODULATE_FUNC( ( state & 0x000F0000 ) >> 16 );
\r
144 srcFact = E_BLEND_FACTOR ( ( state & 0x000000F0 ) >> 4 );
\r
145 dstFact = E_BLEND_FACTOR ( ( state & 0x0000000F ) );
\r
148 //! Unpack srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo and alphaSource factors
\r
149 /** The fields don't use the full byte range, so we could pack even more... */
\r
150 inline void unpack_textureBlendFuncSeparate(E_BLEND_FACTOR &srcRGBFact, E_BLEND_FACTOR &dstRGBFact,
\r
151 E_BLEND_FACTOR &srcAlphaFact, E_BLEND_FACTOR &dstAlphaFact,
\r
152 E_MODULATE_FUNC &modulo, u32& alphaSource, const f32 param)
\r
154 const u32 state = IR(param);
\r
155 alphaSource = (state & 0x00F00000) >> 20;
\r
156 modulo = E_MODULATE_FUNC( ( state & 0x000F0000 ) >> 16 );
\r
157 srcAlphaFact = E_BLEND_FACTOR ( ( state & 0x0000F000 ) >> 12 );
\r
158 dstAlphaFact = E_BLEND_FACTOR ( ( state & 0x00000F00 ) >> 8 );
\r
159 srcRGBFact = E_BLEND_FACTOR ( ( state & 0x000000F0 ) >> 4 );
\r
160 dstRGBFact = E_BLEND_FACTOR ( ( state & 0x0000000F ) );
\r
163 //! has blend factor alphablending
\r
164 inline bool textureBlendFunc_hasAlpha ( const E_BLEND_FACTOR factor )
\r
168 case EBF_SRC_ALPHA:
\r
169 case EBF_ONE_MINUS_SRC_ALPHA:
\r
170 case EBF_DST_ALPHA:
\r
171 case EBF_ONE_MINUS_DST_ALPHA:
\r
172 case EBF_SRC_ALPHA_SATURATE:
\r
180 //! These flags are used to specify the anti-aliasing and smoothing modes
\r
181 /** Techniques supported are multisampling, geometry smoothing, and alpha
\r
183 Some drivers don't support a per-material setting of the anti-aliasing
\r
184 modes. In those cases, FSAA/multisampling is defined by the device mode
\r
185 chosen upon creation via irr::SIrrCreationParameters.
\r
187 enum E_ANTI_ALIASING_MODE
\r
189 //! Use to turn off anti-aliasing for this material
\r
191 //! Default anti-aliasing mode
\r
193 //! High-quality anti-aliasing, not always supported, automatically enables SIMPLE mode
\r
196 //! Careful, enabling this can lead to software emulation under OpenGL
\r
197 EAAM_LINE_SMOOTH=4,
\r
198 //! point smoothing, often in software and slow, only with OpenGL
\r
199 EAAM_POINT_SMOOTH=8,
\r
200 //! All typical anti-alias and smooth modes
\r
201 EAAM_FULL_BASIC=15,
\r
202 //! Enhanced anti-aliasing for transparent materials
\r
203 /** Usually used with EMT_TRANSPARENT_ALPHA_CHANNEL_REF and multisampling. */
\r
204 EAAM_ALPHA_TO_COVERAGE=16
\r
207 //! These flags allow to define the interpretation of vertex color when lighting is enabled
\r
208 /** Without lighting being enabled the vertex color is the only value defining the fragment color.
\r
209 Once lighting is enabled, the four values for diffuse, ambient, emissive, and specular take over.
\r
210 With these flags it is possible to define which lighting factor shall be defined by the vertex color
\r
211 instead of the lighting factor which is the same for all faces of that material.
\r
212 The default is to use vertex color for the diffuse value, another pretty common value is to use
\r
213 vertex color for both diffuse and ambient factor. */
\r
214 enum E_COLOR_MATERIAL
\r
216 //! Don't use vertex color for lighting
\r
218 //! Use vertex color for diffuse light, this is default
\r
220 //! Use vertex color for ambient light
\r
222 //! Use vertex color for emissive light
\r
224 //! Use vertex color for specular light
\r
226 //! Use vertex color for both diffuse and ambient light
\r
227 ECM_DIFFUSE_AND_AMBIENT
\r
230 //! DEPRECATED. Will be removed after Irrlicht 1.9.
\r
231 /** Flags for the definition of the polygon offset feature. These flags define whether the offset should be into the screen, or towards the eye. */
\r
232 enum E_POLYGON_OFFSET
\r
234 //! Push pixel towards the far plane, away from the eye
\r
235 /** This is typically used for rendering inner areas. */
\r
237 //! Pull pixels towards the camera.
\r
238 /** This is typically used for polygons which should appear on top
\r
239 of other elements, such as decals. */
\r
243 //! Names for polygon offset direction
\r
244 const c8* const PolygonOffsetDirectionNames[] =
\r
251 //! For SMaterial.ZWriteEnable
\r
254 //! zwrite always disabled for this material
\r
257 //! This is the default setting for SMaterial and tries to handle things automatically.
\r
258 //! This is also the value which is set when SMaterial::setFlag(EMF_ZWRITE_ENABLE) is enabled.
\r
259 //! Usually zwriting is enabled non-transparent materials - as far as Irrlicht can recognize those.
\r
260 //! Basically Irrlicht tries to handle the zwriting for you and assumes transparent materials don't need it.
\r
261 //! This is addionally affected by IVideoDriver::setAllowZWriteOnTransparent
\r
264 //! zwrite always enabled for this material
\r
268 //! Names for E_ZWRITE
\r
269 const c8* const ZWriteNames[] =
\r
279 //! Maximum number of texture an SMaterial can have.
\r
280 /** SMaterial might ignore some textures in most function, like assignment and comparison,
\r
281 when SIrrlichtCreationParameters::MaxTextureUnits is set to a lower number.
\r
283 const u32 MATERIAL_MAX_TEXTURES = _IRR_MATERIAL_MAX_TEXTURES_;
\r
285 //! By default this is identical to MATERIAL_MAX_TEXTURES
\r
286 /** Users can modify this value if they are certain they don't need all
\r
287 available textures per material in their application. For example if you
\r
288 never need more than 2 textures per material you can set this to 2.
\r
290 We (mostly) avoid dynamic memory in SMaterial, so the extra memory
\r
291 will still be allocated. But by lowering MATERIAL_MAX_TEXTURES_USED the
\r
292 material comparisons and assignments can be faster. Also several other
\r
293 places in the engine can be faster when reducing this value to the limit
\r
296 NOTE: This should only be changed once and before any call to createDevice.
\r
297 NOTE: Do not set it below 1 or above the value of _IRR_MATERIAL_MAX_TEXTURES_.
\r
298 NOTE: Going below 4 is usually not worth it.
\r
300 IRRLICHT_API extern u32 MATERIAL_MAX_TEXTURES_USED;
\r
302 //! Struct for holding parameters for a material renderer
\r
303 // Note for implementors: Serialization is in CNullDriver
\r
307 //! Default constructor. Creates a solid, lit material with white colors
\r
309 : MaterialType(EMT_SOLID), AmbientColor(255,255,255,255), DiffuseColor(255,255,255,255),
\r
310 EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255),
\r
311 Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f),
\r
312 ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL),
\r
313 ColorMaterial(ECM_DIFFUSE), BlendOperation(EBO_NONE), BlendFactor(0.0f),
\r
314 PolygonOffsetFactor(0), PolygonOffsetDirection(EPO_FRONT),
\r
315 PolygonOffsetDepthBias(0.f), PolygonOffsetSlopeScale(0.f),
\r
316 Wireframe(false), PointCloud(false), GouraudShading(true),
\r
317 Lighting(true), ZWriteEnable(EZW_AUTO), BackfaceCulling(true), FrontfaceCulling(false),
\r
318 FogEnable(false), NormalizeNormals(false), UseMipMaps(true)
\r
321 //! Copy constructor
\r
322 /** \param other Material to copy from. */
\r
323 SMaterial(const SMaterial& other)
\r
325 // These pointers are checked during assignment
\r
326 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
327 TextureLayer[i].TextureMatrix = 0;
\r
331 //! Texture layer array.
\r
332 SMaterialLayer TextureLayer[MATERIAL_MAX_TEXTURES];
\r
334 //! Type of the material. Specifies how everything is blended together
\r
335 E_MATERIAL_TYPE MaterialType;
\r
337 //! How much ambient light (a global light) is reflected by this material.
\r
338 /** The default is full white, meaning objects are completely
\r
339 globally illuminated. Reduce this if you want to see diffuse
\r
340 or specular light effects. */
\r
341 SColor AmbientColor;
\r
343 //! How much diffuse light coming from a light source is reflected by this material.
\r
344 /** The default is full white. */
\r
345 SColor DiffuseColor;
\r
347 //! Light emitted by this material. Default is to emit no light.
\r
348 SColor EmissiveColor;
\r
350 //! How much specular light (highlights from a light) is reflected.
\r
351 /** The default is to reflect white specular light. See
\r
352 SMaterial::Shininess on how to enable specular lights. */
\r
353 SColor SpecularColor;
\r
355 //! Value affecting the size of specular highlights.
\r
356 /** A value of 20 is common. If set to 0, no specular
\r
357 highlights are being used. To activate, simply set the
\r
358 shininess of a material to a value in the range [0.5;128]:
\r
360 sceneNode->getMaterial(0).Shininess = 20.0f;
\r
363 You can change the color of the highlights using
\r
365 sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);
\r
368 The specular color of the dynamic lights
\r
369 (SLight::SpecularColor) will influence the the highlight color
\r
370 too, but they are set to a useful value by default when
\r
371 creating the light scene node. Here is a simple example on how
\r
372 to use specular highlights:
\r
374 // load and display mesh
\r
375 scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(
\r
376 smgr->getMesh("data/faerie.md2"));
\r
377 node->setMaterialTexture(0, driver->getTexture("data/Faerie2.pcx")); // set diffuse texture
\r
378 node->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
\r
379 node->getMaterial(0).Shininess = 20.0f; // set size of specular highlights
\r
382 scene::ILightSceneNode* light = smgr->addLightSceneNode(0,
\r
383 core::vector3df(5,5,5), video::SColorf(1.0f, 1.0f, 1.0f));
\r
387 //! Free parameter, dependent on the material type.
\r
388 /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID,
\r
389 EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
\r
390 f32 MaterialTypeParam;
\r
392 //! Second free parameter, dependent on the material type.
\r
393 /** Mostly ignored. */
\r
394 f32 MaterialTypeParam2;
\r
396 //! Thickness of non-3dimensional elements such as lines and points.
\r
399 //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
\r
400 /** If you want to disable depth test for this material
\r
401 just set this parameter to ECFN_DISABLED.
\r
402 Values are from E_COMPARISON_FUNC. */
\r
405 //! Sets the antialiasing mode
\r
406 /** Values are chosen from E_ANTI_ALIASING_MODE. Default is
\r
407 EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
\r
410 //! Defines the enabled color planes
\r
411 /** Values are defined as or'ed values of the E_COLOR_PLANE enum.
\r
412 Only enabled color planes will be rendered to the current render
\r
413 target. Typical use is to disable all colors when rendering only to
\r
414 depth or stencil buffer, or using Red and Green for Stereo rendering. */
\r
417 //! Defines the interpretation of vertex color in the lighting equation
\r
418 /** Values should be chosen from E_COLOR_MATERIAL.
\r
419 When lighting is enabled, vertex color can be used instead of the
\r
420 material values for light modulation. This allows to easily change e.g. the
\r
421 diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in
\r
422 a very similar rendering as with lighting turned off, just with light shading. */
\r
423 u8 ColorMaterial:3;
\r
425 //! Store the blend operation of choice
\r
426 /** Values to be chosen from E_BLEND_OPERATION. */
\r
427 E_BLEND_OPERATION BlendOperation:4;
\r
429 //! Store the blend factors
\r
430 /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
\r
431 properly blending factors to this parameter.
\r
432 Due to historical reasons this parameter is not used for material type
\r
433 EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
\r
434 It's generally used only for materials without any blending otherwise (like EMT_SOLID).
\r
435 It's main use is to allow having shader materials which can enable/disable
\r
436 blending after they have been created.
\r
437 When you set this you usually also have to set BlendOperation to a value != EBO_NONE
\r
438 (setting it to EBO_ADD is probably the most common one value). */
\r
441 //! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead.
\r
442 /** Factor specifying how far the polygon offset should be made.
\r
443 Specifying 0 disables the polygon offset. The direction is specified separately.
\r
444 The factor can be from 0 to 7.
\r
445 Note: This probably never worked on Direct3D9 (was coded for D3D8 which had different value ranges) */
\r
446 u8 PolygonOffsetFactor:3;
\r
448 //! DEPRECATED. Will be removed after Irrlicht 1.9.
\r
449 /** Flag defining the direction the polygon offset is applied to.
\r
450 Can be to front or to back, specified by values from E_POLYGON_OFFSET. */
\r
451 E_POLYGON_OFFSET PolygonOffsetDirection:1;
\r
453 //! A constant z-buffer offset for a polygon/line/point
\r
454 /** The range of the value is driver specific.
\r
455 On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
\r
456 On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
\r
457 Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
\r
458 Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
\r
459 recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
\r
460 f32 PolygonOffsetDepthBias;
\r
462 //! Variable Z-Buffer offset based on the slope of the polygon.
\r
463 /** For polygons looking flat at a camera you could use 0 (for example in a 2D game)
\r
464 But in most cases you will have polygons rendered at a certain slope.
\r
465 The driver will calculate the slope for you and this value allows to scale that slope.
\r
466 The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias
\r
467 A good default here is to use 1.f if you want to push the polygons away from the camera
\r
468 and -1.f to pull them towards the camera. */
\r
469 f32 PolygonOffsetSlopeScale;
\r
471 //! Draw as wireframe or filled triangles? Default: false
\r
472 /** The user can access a material flag using
\r
473 \code material.Wireframe=true \endcode
\r
474 or \code material.setFlag(EMF_WIREFRAME, true); \endcode */
\r
477 //! Draw as point cloud or filled triangles? Default: false
\r
480 //! Flat or Gouraud shading? Default: true
\r
481 bool GouraudShading:1;
\r
483 //! Will this material be lighted? Default: true
\r
486 //! Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
\r
487 /** If this parameter is not EZW_OFF, you probably also want to set ZBuffer
\r
488 to values other than ECFN_DISABLED */
\r
489 E_ZWRITE ZWriteEnable:2;
\r
491 //! Is backface culling enabled? Default: true
\r
492 bool BackfaceCulling:1;
\r
494 //! Is frontface culling enabled? Default: false
\r
495 bool FrontfaceCulling:1;
\r
497 //! Is fog enabled? Default: false
\r
500 //! Should normals be normalized?
\r
501 /** Always use this if the mesh lit and scaled. Default: false */
\r
502 bool NormalizeNormals:1;
\r
504 //! Shall mipmaps be used if available
\r
505 /** Sometimes, disabling mipmap usage can be useful. Default: true */
\r
508 //! Gets the texture transformation matrix for level i
\r
509 /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
\r
510 \return Texture matrix for texture level i. */
\r
511 core::matrix4& getTextureMatrix(u32 i)
\r
513 return TextureLayer[i].getTextureMatrix();
\r
516 //! Gets the immutable texture transformation matrix for level i
\r
517 /** \param i The desired level.
\r
518 \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */
\r
519 const core::matrix4& getTextureMatrix(u32 i) const
\r
521 if (i<MATERIAL_MAX_TEXTURES)
\r
522 return TextureLayer[i].getTextureMatrix();
\r
524 return core::IdentityMatrix;
\r
527 //! Sets the i-th texture transformation matrix
\r
528 /** \param i The desired level.
\r
529 \param mat Texture matrix for texture level i. */
\r
530 void setTextureMatrix(u32 i, const core::matrix4& mat)
\r
532 if (i>=MATERIAL_MAX_TEXTURES)
\r
534 TextureLayer[i].setTextureMatrix(mat);
\r
537 //! Gets the i-th texture
\r
538 /** \param i The desired level.
\r
539 \return Texture for texture level i, if defined, else 0. */
\r
540 ITexture* getTexture(u32 i) const
\r
542 return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
\r
545 //! Sets the i-th texture
\r
546 /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.
\r
547 \param i The desired level.
\r
548 \param tex Texture for texture level i. */
\r
549 void setTexture(u32 i, ITexture* tex)
\r
551 if (i>=MATERIAL_MAX_TEXTURES)
\r
553 TextureLayer[i].Texture = tex;
\r
556 //! Sets the Material flag to the given value
\r
557 /** \param flag The flag to be set.
\r
558 \param value The new value for the flag. */
\r
559 void setFlag(E_MATERIAL_FLAG flag, bool value)
\r
563 case EMF_WIREFRAME:
\r
564 Wireframe = value; break;
\r
565 case EMF_POINTCLOUD:
\r
566 PointCloud = value; break;
\r
567 case EMF_GOURAUD_SHADING:
\r
568 GouraudShading = value; break;
\r
570 Lighting = value; break;
\r
572 ZBuffer = value; break;
\r
573 case EMF_ZWRITE_ENABLE:
\r
574 ZWriteEnable = value ? EZW_AUTO : EZW_OFF; break;
\r
575 case EMF_BACK_FACE_CULLING:
\r
576 BackfaceCulling = value; break;
\r
577 case EMF_FRONT_FACE_CULLING:
\r
578 FrontfaceCulling = value; break;
\r
579 case EMF_BILINEAR_FILTER:
\r
581 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
582 TextureLayer[i].BilinearFilter = value;
\r
585 case EMF_TRILINEAR_FILTER:
\r
587 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
588 TextureLayer[i].TrilinearFilter = value;
\r
591 case EMF_ANISOTROPIC_FILTER:
\r
594 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
595 TextureLayer[i].AnisotropicFilter = 0xFF;
\r
597 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
598 TextureLayer[i].AnisotropicFilter = 0;
\r
601 case EMF_FOG_ENABLE:
\r
602 FogEnable = value; break;
\r
603 case EMF_NORMALIZE_NORMALS:
\r
604 NormalizeNormals = value; break;
\r
605 case EMF_TEXTURE_WRAP:
\r
607 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
609 TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value;
\r
610 TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value;
\r
611 TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)value;
\r
615 case EMF_ANTI_ALIASING:
\r
616 AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
\r
617 case EMF_COLOR_MASK:
\r
618 ColorMask = value?ECP_ALL:ECP_NONE; break;
\r
619 case EMF_COLOR_MATERIAL:
\r
620 ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
\r
621 case EMF_USE_MIP_MAPS:
\r
622 UseMipMaps = value; break;
\r
623 case EMF_BLEND_OPERATION:
\r
624 BlendOperation = value?EBO_ADD:EBO_NONE; break;
\r
625 case EMF_BLEND_FACTOR:
\r
627 case EMF_POLYGON_OFFSET:
\r
628 PolygonOffsetFactor = value?1:0;
\r
629 PolygonOffsetDirection = EPO_BACK;
\r
630 PolygonOffsetSlopeScale = value?1.f:0.f;
\r
631 PolygonOffsetDepthBias = value?1.f:0.f;
\r
637 //! Gets the Material flag
\r
638 /** \param flag The flag to query.
\r
639 \return The current value of the flag. */
\r
640 bool getFlag(E_MATERIAL_FLAG flag) const
\r
644 case EMF_WIREFRAME:
\r
646 case EMF_POINTCLOUD:
\r
648 case EMF_GOURAUD_SHADING:
\r
649 return GouraudShading;
\r
653 return ZBuffer!=ECFN_DISABLED;
\r
654 case EMF_ZWRITE_ENABLE:
\r
655 return ZWriteEnable != EZW_OFF;
\r
656 case EMF_BACK_FACE_CULLING:
\r
657 return BackfaceCulling;
\r
658 case EMF_FRONT_FACE_CULLING:
\r
659 return FrontfaceCulling;
\r
660 case EMF_BILINEAR_FILTER:
\r
661 return TextureLayer[0].BilinearFilter;
\r
662 case EMF_TRILINEAR_FILTER:
\r
663 return TextureLayer[0].TrilinearFilter;
\r
664 case EMF_ANISOTROPIC_FILTER:
\r
665 return TextureLayer[0].AnisotropicFilter!=0;
\r
666 case EMF_FOG_ENABLE:
\r
668 case EMF_NORMALIZE_NORMALS:
\r
669 return NormalizeNormals;
\r
670 case EMF_TEXTURE_WRAP:
\r
671 return !(TextureLayer[0].TextureWrapU ||
\r
672 TextureLayer[0].TextureWrapV ||
\r
673 TextureLayer[0].TextureWrapW);
\r
674 case EMF_ANTI_ALIASING:
\r
675 return (AntiAliasing==1);
\r
676 case EMF_COLOR_MASK:
\r
677 return (ColorMask!=ECP_NONE);
\r
678 case EMF_COLOR_MATERIAL:
\r
679 return (ColorMaterial != ECM_NONE);
\r
680 case EMF_USE_MIP_MAPS:
\r
682 case EMF_BLEND_OPERATION:
\r
683 return BlendOperation != EBO_NONE;
\r
684 case EMF_BLEND_FACTOR:
\r
685 return BlendFactor != 0.f;
\r
686 case EMF_POLYGON_OFFSET:
\r
687 return PolygonOffsetFactor != 0 || PolygonOffsetDepthBias != 0.f;
\r
693 //! Inequality operator
\r
694 /** \param b Material to compare to.
\r
695 \return True if the materials differ, else false. */
\r
696 inline bool operator!=(const SMaterial& b) const
\r
699 MaterialType != b.MaterialType ||
\r
700 AmbientColor != b.AmbientColor ||
\r
701 DiffuseColor != b.DiffuseColor ||
\r
702 EmissiveColor != b.EmissiveColor ||
\r
703 SpecularColor != b.SpecularColor ||
\r
704 Shininess != b.Shininess ||
\r
705 MaterialTypeParam != b.MaterialTypeParam ||
\r
706 MaterialTypeParam2 != b.MaterialTypeParam2 ||
\r
707 Thickness != b.Thickness ||
\r
708 Wireframe != b.Wireframe ||
\r
709 PointCloud != b.PointCloud ||
\r
710 GouraudShading != b.GouraudShading ||
\r
711 Lighting != b.Lighting ||
\r
712 ZBuffer != b.ZBuffer ||
\r
713 ZWriteEnable != b.ZWriteEnable ||
\r
714 BackfaceCulling != b.BackfaceCulling ||
\r
715 FrontfaceCulling != b.FrontfaceCulling ||
\r
716 FogEnable != b.FogEnable ||
\r
717 NormalizeNormals != b.NormalizeNormals ||
\r
718 AntiAliasing != b.AntiAliasing ||
\r
719 ColorMask != b.ColorMask ||
\r
720 ColorMaterial != b.ColorMaterial ||
\r
721 BlendOperation != b.BlendOperation ||
\r
722 BlendFactor != b.BlendFactor ||
\r
723 PolygonOffsetFactor != b.PolygonOffsetFactor ||
\r
724 PolygonOffsetDirection != b.PolygonOffsetDirection ||
\r
725 PolygonOffsetDepthBias != b.PolygonOffsetDepthBias ||
\r
726 PolygonOffsetSlopeScale != b.PolygonOffsetSlopeScale ||
\r
727 UseMipMaps != b.UseMipMaps
\r
729 for (u32 i=0; (i<MATERIAL_MAX_TEXTURES_USED) && !different; ++i)
\r
731 different |= (TextureLayer[i] != b.TextureLayer[i]);
\r
736 //! Equality operator
\r
737 /** \param b Material to compare to.
\r
738 \return True if the materials are equal, else false. */
\r
739 inline bool operator==(const SMaterial& b) const
\r
740 { return !(b!=*this); }
\r
742 //! Check if material needs alpha blending
\r
743 bool isAlphaBlendOperation() const
\r
745 if (BlendOperation != EBO_NONE && BlendFactor != 0.f)
\r
747 E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
\r
748 E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
\r
749 E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
\r
750 E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
\r
751 E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
\r
752 u32 alphaSource = 0;
\r
754 unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, BlendFactor);
\r
756 if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
\r
757 textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
\r
765 //! Check for some fixed-function transparent types. Still used internally, but might be deprecated soon.
\r
766 //! You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations
\r
767 //! as it asks the material renders directly what they do with the material.
\r
768 bool isTransparent() const
\r
770 if ( MaterialType==EMT_TRANSPARENT_ADD_COLOR ||
\r
771 MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL ||
\r
772 MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA ||
\r
773 MaterialType==EMT_TRANSPARENT_REFLECTION_2_LAYER )
\r
780 //! global const identity Material
\r
781 IRRLICHT_API extern SMaterial IdentityMaterial;
\r
782 } // end namespace video
\r
783 } // end namespace irr
\r