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 //! Assignment operator
\r
332 /** \param other Material to copy from. */
\r
333 SMaterial& operator=(const SMaterial& other)
\r
335 // Check for self-assignment!
\r
336 if (this == &other)
\r
339 MaterialType = other.MaterialType;
\r
341 AmbientColor = other.AmbientColor;
\r
342 DiffuseColor = other.DiffuseColor;
\r
343 EmissiveColor = other.EmissiveColor;
\r
344 SpecularColor = other.SpecularColor;
\r
345 Shininess = other.Shininess;
\r
346 MaterialTypeParam = other.MaterialTypeParam;
\r
347 MaterialTypeParam2 = other.MaterialTypeParam2;
\r
348 Thickness = other.Thickness;
\r
349 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
351 TextureLayer[i] = other.TextureLayer[i];
\r
354 Wireframe = other.Wireframe;
\r
355 PointCloud = other.PointCloud;
\r
356 GouraudShading = other.GouraudShading;
\r
357 Lighting = other.Lighting;
\r
358 ZWriteEnable = other.ZWriteEnable;
\r
359 BackfaceCulling = other.BackfaceCulling;
\r
360 FrontfaceCulling = other.FrontfaceCulling;
\r
361 FogEnable = other.FogEnable;
\r
362 NormalizeNormals = other.NormalizeNormals;
\r
363 ZBuffer = other.ZBuffer;
\r
364 AntiAliasing = other.AntiAliasing;
\r
365 ColorMask = other.ColorMask;
\r
366 ColorMaterial = other.ColorMaterial;
\r
367 BlendOperation = other.BlendOperation;
\r
368 BlendFactor = other.BlendFactor;
\r
369 PolygonOffsetFactor = other.PolygonOffsetFactor;
\r
370 PolygonOffsetDirection = other.PolygonOffsetDirection;
\r
371 PolygonOffsetDepthBias = other.PolygonOffsetDepthBias;
\r
372 PolygonOffsetSlopeScale = other.PolygonOffsetSlopeScale;
\r
373 UseMipMaps = other.UseMipMaps;
\r
378 //! Texture layer array.
\r
379 SMaterialLayer TextureLayer[MATERIAL_MAX_TEXTURES];
\r
381 //! Type of the material. Specifies how everything is blended together
\r
382 E_MATERIAL_TYPE MaterialType;
\r
384 //! How much ambient light (a global light) is reflected by this material.
\r
385 /** The default is full white, meaning objects are completely
\r
386 globally illuminated. Reduce this if you want to see diffuse
\r
387 or specular light effects. */
\r
388 SColor AmbientColor;
\r
390 //! How much diffuse light coming from a light source is reflected by this material.
\r
391 /** The default is full white. */
\r
392 SColor DiffuseColor;
\r
394 //! Light emitted by this material. Default is to emit no light.
\r
395 SColor EmissiveColor;
\r
397 //! How much specular light (highlights from a light) is reflected.
\r
398 /** The default is to reflect white specular light. See
\r
399 SMaterial::Shininess on how to enable specular lights. */
\r
400 SColor SpecularColor;
\r
402 //! Value affecting the size of specular highlights.
\r
403 /** A value of 20 is common. If set to 0, no specular
\r
404 highlights are being used. To activate, simply set the
\r
405 shininess of a material to a value in the range [0.5;128]:
\r
407 sceneNode->getMaterial(0).Shininess = 20.0f;
\r
410 You can change the color of the highlights using
\r
412 sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);
\r
415 The specular color of the dynamic lights
\r
416 (SLight::SpecularColor) will influence the the highlight color
\r
417 too, but they are set to a useful value by default when
\r
418 creating the light scene node. Here is a simple example on how
\r
419 to use specular highlights:
\r
421 // load and display mesh
\r
422 scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(
\r
423 smgr->getMesh("data/faerie.md2"));
\r
424 node->setMaterialTexture(0, driver->getTexture("data/Faerie2.pcx")); // set diffuse texture
\r
425 node->setMaterialFlag(video::EMF_LIGHTING, true); // enable dynamic lighting
\r
426 node->getMaterial(0).Shininess = 20.0f; // set size of specular highlights
\r
429 scene::ILightSceneNode* light = smgr->addLightSceneNode(0,
\r
430 core::vector3df(5,5,5), video::SColorf(1.0f, 1.0f, 1.0f));
\r
434 //! Free parameter, dependent on the material type.
\r
435 /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID,
\r
436 EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
\r
437 f32 MaterialTypeParam;
\r
439 //! Second free parameter, dependent on the material type.
\r
440 /** Mostly ignored. */
\r
441 f32 MaterialTypeParam2;
\r
443 //! Thickness of non-3dimensional elements such as lines and points.
\r
446 //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
\r
447 /** If you want to disable depth test for this material
\r
448 just set this parameter to ECFN_DISABLED.
\r
449 Values are from E_COMPARISON_FUNC. */
\r
452 //! Sets the antialiasing mode
\r
453 /** Values are chosen from E_ANTI_ALIASING_MODE. Default is
\r
454 EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
\r
457 //! Defines the enabled color planes
\r
458 /** Values are defined as or'ed values of the E_COLOR_PLANE enum.
\r
459 Only enabled color planes will be rendered to the current render
\r
460 target. Typical use is to disable all colors when rendering only to
\r
461 depth or stencil buffer, or using Red and Green for Stereo rendering. */
\r
464 //! Defines the interpretation of vertex color in the lighting equation
\r
465 /** Values should be chosen from E_COLOR_MATERIAL.
\r
466 When lighting is enabled, vertex color can be used instead of the
\r
467 material values for light modulation. This allows to easily change e.g. the
\r
468 diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in
\r
469 a very similar rendering as with lighting turned off, just with light shading. */
\r
470 u8 ColorMaterial:3;
\r
472 //! Store the blend operation of choice
\r
473 /** Values to be chosen from E_BLEND_OPERATION. */
\r
474 E_BLEND_OPERATION BlendOperation:4;
\r
476 //! Store the blend factors
\r
477 /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
\r
478 properly blending factors to this parameter.
\r
479 Due to historical reasons this parameter is not used for material type
\r
480 EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
\r
481 It's generally used only for materials without any blending otherwise (like EMT_SOLID).
\r
482 It's main use is to allow having shader materials which can enable/disable
\r
483 blending after they have been created.
\r
484 When you set this you usually also have to set BlendOperation to a value != EBO_NONE
\r
485 (setting it to EBO_ADD is probably the most common one value). */
\r
488 //! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead.
\r
489 /** Factor specifying how far the polygon offset should be made.
\r
490 Specifying 0 disables the polygon offset. The direction is specified separately.
\r
491 The factor can be from 0 to 7.
\r
492 Note: This probably never worked on Direct3D9 (was coded for D3D8 which had different value ranges) */
\r
493 u8 PolygonOffsetFactor:3;
\r
495 //! DEPRECATED. Will be removed after Irrlicht 1.9.
\r
496 /** Flag defining the direction the polygon offset is applied to.
\r
497 Can be to front or to back, specified by values from E_POLYGON_OFFSET. */
\r
498 E_POLYGON_OFFSET PolygonOffsetDirection:1;
\r
500 //! A constant z-buffer offset for a polygon/line/point
\r
501 /** The range of the value is driver specific.
\r
502 On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
\r
503 On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
\r
504 Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
\r
505 Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
\r
506 recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
\r
507 f32 PolygonOffsetDepthBias;
\r
509 //! Variable Z-Buffer offset based on the slope of the polygon.
\r
510 /** For polygons looking flat at a camera you could use 0 (for example in a 2D game)
\r
511 But in most cases you will have polygons rendered at a certain slope.
\r
512 The driver will calculate the slope for you and this value allows to scale that slope.
\r
513 The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias
\r
514 A good default here is to use 1.f if you want to push the polygons away from the camera
\r
515 and -1.f to pull them towards the camera. */
\r
516 f32 PolygonOffsetSlopeScale;
\r
518 //! Draw as wireframe or filled triangles? Default: false
\r
519 /** The user can access a material flag using
\r
520 \code material.Wireframe=true \endcode
\r
521 or \code material.setFlag(EMF_WIREFRAME, true); \endcode */
\r
524 //! Draw as point cloud or filled triangles? Default: false
\r
527 //! Flat or Gouraud shading? Default: true
\r
528 bool GouraudShading:1;
\r
530 //! Will this material be lighted? Default: true
\r
533 //! Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
\r
534 /** If this parameter is not EZW_OFF, you probably also want to set ZBuffer
\r
535 to values other than ECFN_DISABLED */
\r
536 E_ZWRITE ZWriteEnable:2;
\r
538 //! Is backface culling enabled? Default: true
\r
539 bool BackfaceCulling:1;
\r
541 //! Is frontface culling enabled? Default: false
\r
542 bool FrontfaceCulling:1;
\r
544 //! Is fog enabled? Default: false
\r
547 //! Should normals be normalized?
\r
548 /** Always use this if the mesh lit and scaled. Default: false */
\r
549 bool NormalizeNormals:1;
\r
551 //! Shall mipmaps be used if available
\r
552 /** Sometimes, disabling mipmap usage can be useful. Default: true */
\r
555 //! Gets the texture transformation matrix for level i
\r
556 /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
\r
557 \return Texture matrix for texture level i. */
\r
558 core::matrix4& getTextureMatrix(u32 i)
\r
560 return TextureLayer[i].getTextureMatrix();
\r
563 //! Gets the immutable texture transformation matrix for level i
\r
564 /** \param i The desired level.
\r
565 \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */
\r
566 const core::matrix4& getTextureMatrix(u32 i) const
\r
568 if (i<MATERIAL_MAX_TEXTURES)
\r
569 return TextureLayer[i].getTextureMatrix();
\r
571 return core::IdentityMatrix;
\r
574 //! Sets the i-th texture transformation matrix
\r
575 /** \param i The desired level.
\r
576 \param mat Texture matrix for texture level i. */
\r
577 void setTextureMatrix(u32 i, const core::matrix4& mat)
\r
579 if (i>=MATERIAL_MAX_TEXTURES)
\r
581 TextureLayer[i].setTextureMatrix(mat);
\r
584 //! Gets the i-th texture
\r
585 /** \param i The desired level.
\r
586 \return Texture for texture level i, if defined, else 0. */
\r
587 ITexture* getTexture(u32 i) const
\r
589 return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
\r
592 //! Sets the i-th texture
\r
593 /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.
\r
594 \param i The desired level.
\r
595 \param tex Texture for texture level i. */
\r
596 void setTexture(u32 i, ITexture* tex)
\r
598 if (i>=MATERIAL_MAX_TEXTURES)
\r
600 TextureLayer[i].Texture = tex;
\r
603 //! Sets the Material flag to the given value
\r
604 /** \param flag The flag to be set.
\r
605 \param value The new value for the flag. */
\r
606 void setFlag(E_MATERIAL_FLAG flag, bool value)
\r
610 case EMF_WIREFRAME:
\r
611 Wireframe = value; break;
\r
612 case EMF_POINTCLOUD:
\r
613 PointCloud = value; break;
\r
614 case EMF_GOURAUD_SHADING:
\r
615 GouraudShading = value; break;
\r
617 Lighting = value; break;
\r
619 ZBuffer = value; break;
\r
620 case EMF_ZWRITE_ENABLE:
\r
621 ZWriteEnable = value ? EZW_AUTO : EZW_OFF; break;
\r
622 case EMF_BACK_FACE_CULLING:
\r
623 BackfaceCulling = value; break;
\r
624 case EMF_FRONT_FACE_CULLING:
\r
625 FrontfaceCulling = value; break;
\r
626 case EMF_BILINEAR_FILTER:
\r
628 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
629 TextureLayer[i].BilinearFilter = value;
\r
632 case EMF_TRILINEAR_FILTER:
\r
634 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
635 TextureLayer[i].TrilinearFilter = value;
\r
638 case EMF_ANISOTROPIC_FILTER:
\r
641 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
642 TextureLayer[i].AnisotropicFilter = 0xFF;
\r
644 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
645 TextureLayer[i].AnisotropicFilter = 0;
\r
648 case EMF_FOG_ENABLE:
\r
649 FogEnable = value; break;
\r
650 case EMF_NORMALIZE_NORMALS:
\r
651 NormalizeNormals = value; break;
\r
652 case EMF_TEXTURE_WRAP:
\r
654 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
656 TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value;
\r
657 TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value;
\r
658 TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)value;
\r
662 case EMF_ANTI_ALIASING:
\r
663 AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
\r
664 case EMF_COLOR_MASK:
\r
665 ColorMask = value?ECP_ALL:ECP_NONE; break;
\r
666 case EMF_COLOR_MATERIAL:
\r
667 ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
\r
668 case EMF_USE_MIP_MAPS:
\r
669 UseMipMaps = value; break;
\r
670 case EMF_BLEND_OPERATION:
\r
671 BlendOperation = value?EBO_ADD:EBO_NONE; break;
\r
672 case EMF_BLEND_FACTOR:
\r
674 case EMF_POLYGON_OFFSET:
\r
675 PolygonOffsetFactor = value?1:0;
\r
676 PolygonOffsetDirection = EPO_BACK;
\r
677 PolygonOffsetSlopeScale = value?1.f:0.f;
\r
678 PolygonOffsetDepthBias = value?1.f:0.f;
\r
684 //! Gets the Material flag
\r
685 /** \param flag The flag to query.
\r
686 \return The current value of the flag. */
\r
687 bool getFlag(E_MATERIAL_FLAG flag) const
\r
691 case EMF_WIREFRAME:
\r
693 case EMF_POINTCLOUD:
\r
695 case EMF_GOURAUD_SHADING:
\r
696 return GouraudShading;
\r
700 return ZBuffer!=ECFN_DISABLED;
\r
701 case EMF_ZWRITE_ENABLE:
\r
702 return ZWriteEnable != EZW_OFF;
\r
703 case EMF_BACK_FACE_CULLING:
\r
704 return BackfaceCulling;
\r
705 case EMF_FRONT_FACE_CULLING:
\r
706 return FrontfaceCulling;
\r
707 case EMF_BILINEAR_FILTER:
\r
708 return TextureLayer[0].BilinearFilter;
\r
709 case EMF_TRILINEAR_FILTER:
\r
710 return TextureLayer[0].TrilinearFilter;
\r
711 case EMF_ANISOTROPIC_FILTER:
\r
712 return TextureLayer[0].AnisotropicFilter!=0;
\r
713 case EMF_FOG_ENABLE:
\r
715 case EMF_NORMALIZE_NORMALS:
\r
716 return NormalizeNormals;
\r
717 case EMF_TEXTURE_WRAP:
\r
718 return !(TextureLayer[0].TextureWrapU ||
\r
719 TextureLayer[0].TextureWrapV ||
\r
720 TextureLayer[0].TextureWrapW);
\r
721 case EMF_ANTI_ALIASING:
\r
722 return (AntiAliasing==1);
\r
723 case EMF_COLOR_MASK:
\r
724 return (ColorMask!=ECP_NONE);
\r
725 case EMF_COLOR_MATERIAL:
\r
726 return (ColorMaterial != ECM_NONE);
\r
727 case EMF_USE_MIP_MAPS:
\r
729 case EMF_BLEND_OPERATION:
\r
730 return BlendOperation != EBO_NONE;
\r
731 case EMF_BLEND_FACTOR:
\r
732 return BlendFactor != 0.f;
\r
733 case EMF_POLYGON_OFFSET:
\r
734 return PolygonOffsetFactor != 0 || PolygonOffsetDepthBias != 0.f;
\r
740 //! Inequality operator
\r
741 /** \param b Material to compare to.
\r
742 \return True if the materials differ, else false. */
\r
743 inline bool operator!=(const SMaterial& b) const
\r
746 MaterialType != b.MaterialType ||
\r
747 AmbientColor != b.AmbientColor ||
\r
748 DiffuseColor != b.DiffuseColor ||
\r
749 EmissiveColor != b.EmissiveColor ||
\r
750 SpecularColor != b.SpecularColor ||
\r
751 Shininess != b.Shininess ||
\r
752 MaterialTypeParam != b.MaterialTypeParam ||
\r
753 MaterialTypeParam2 != b.MaterialTypeParam2 ||
\r
754 Thickness != b.Thickness ||
\r
755 Wireframe != b.Wireframe ||
\r
756 PointCloud != b.PointCloud ||
\r
757 GouraudShading != b.GouraudShading ||
\r
758 Lighting != b.Lighting ||
\r
759 ZBuffer != b.ZBuffer ||
\r
760 ZWriteEnable != b.ZWriteEnable ||
\r
761 BackfaceCulling != b.BackfaceCulling ||
\r
762 FrontfaceCulling != b.FrontfaceCulling ||
\r
763 FogEnable != b.FogEnable ||
\r
764 NormalizeNormals != b.NormalizeNormals ||
\r
765 AntiAliasing != b.AntiAliasing ||
\r
766 ColorMask != b.ColorMask ||
\r
767 ColorMaterial != b.ColorMaterial ||
\r
768 BlendOperation != b.BlendOperation ||
\r
769 BlendFactor != b.BlendFactor ||
\r
770 PolygonOffsetFactor != b.PolygonOffsetFactor ||
\r
771 PolygonOffsetDirection != b.PolygonOffsetDirection ||
\r
772 PolygonOffsetDepthBias != b.PolygonOffsetDepthBias ||
\r
773 PolygonOffsetSlopeScale != b.PolygonOffsetSlopeScale ||
\r
774 UseMipMaps != b.UseMipMaps
\r
776 for (u32 i=0; (i<MATERIAL_MAX_TEXTURES_USED) && !different; ++i)
\r
778 different |= (TextureLayer[i] != b.TextureLayer[i]);
\r
783 //! Equality operator
\r
784 /** \param b Material to compare to.
\r
785 \return True if the materials are equal, else false. */
\r
786 inline bool operator==(const SMaterial& b) const
\r
787 { return !(b!=*this); }
\r
789 //! Check if material needs alpha blending
\r
790 bool isAlphaBlendOperation() const
\r
792 if (BlendOperation != EBO_NONE && BlendFactor != 0.f)
\r
794 E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
\r
795 E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
\r
796 E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
\r
797 E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
\r
798 E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
\r
799 u32 alphaSource = 0;
\r
801 unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, BlendFactor);
\r
803 if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
\r
804 textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
\r
812 //! Check for some fixed-function transparent types. Still used internally, but might be deprecated soon.
\r
813 //! You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations
\r
814 //! as it asks the material renders directly what they do with the material.
\r
815 bool isTransparent() const
\r
817 if ( MaterialType==EMT_TRANSPARENT_ADD_COLOR ||
\r
818 MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL ||
\r
819 MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA ||
\r
820 MaterialType==EMT_TRANSPARENT_REFLECTION_2_LAYER )
\r
827 //! global const identity Material
\r
828 IRRLICHT_API extern SMaterial IdentityMaterial;
\r
829 } // end namespace video
\r
830 } // end namespace irr
\r