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 = 4;
\r
285 //! Struct for holding parameters for a material renderer
\r
286 // Note for implementors: Serialization is in CNullDriver
\r
290 //! Default constructor. Creates a solid, lit material with white colors
\r
292 : MaterialType(EMT_SOLID), AmbientColor(255,255,255,255), DiffuseColor(255,255,255,255),
\r
293 EmissiveColor(0,0,0,0), SpecularColor(255,255,255,255),
\r
294 Shininess(0.0f), MaterialTypeParam(0.0f), MaterialTypeParam2(0.0f), Thickness(1.0f),
\r
295 ZBuffer(ECFN_LESSEQUAL), AntiAliasing(EAAM_SIMPLE), ColorMask(ECP_ALL),
\r
296 ColorMaterial(ECM_DIFFUSE), BlendOperation(EBO_NONE), BlendFactor(0.0f),
\r
297 PolygonOffsetFactor(0), PolygonOffsetDirection(EPO_FRONT),
\r
298 PolygonOffsetDepthBias(0.f), PolygonOffsetSlopeScale(0.f),
\r
299 Wireframe(false), PointCloud(false), GouraudShading(true),
\r
300 Lighting(true), ZWriteEnable(EZW_AUTO), BackfaceCulling(true), FrontfaceCulling(false),
\r
301 FogEnable(false), NormalizeNormals(false), UseMipMaps(true)
\r
304 //! Texture layer array.
\r
305 SMaterialLayer TextureLayer[MATERIAL_MAX_TEXTURES];
\r
307 //! Type of the material. Specifies how everything is blended together
\r
308 E_MATERIAL_TYPE MaterialType;
\r
310 //! How much ambient light (a global light) is reflected by this material.
\r
311 /** The default is full white, meaning objects are completely
\r
312 globally illuminated. Reduce this if you want to see diffuse
\r
313 or specular light effects. */
\r
314 SColor AmbientColor;
\r
316 //! How much diffuse light coming from a light source is reflected by this material.
\r
317 /** The default is full white. */
\r
318 SColor DiffuseColor;
\r
320 //! Light emitted by this material. Default is to emit no light.
\r
321 SColor EmissiveColor;
\r
323 //! How much specular light (highlights from a light) is reflected.
\r
324 /** The default is to reflect white specular light. See
\r
325 SMaterial::Shininess on how to enable specular lights. */
\r
326 SColor SpecularColor;
\r
328 //! Value affecting the size of specular highlights.
\r
329 /** A value of 20 is common. If set to 0, no specular
\r
330 highlights are being used. To activate, simply set the
\r
331 shininess of a material to a value in the range [0.5;128]:
\r
333 sceneNode->getMaterial(0).Shininess = 20.0f;
\r
336 You can change the color of the highlights using
\r
338 sceneNode->getMaterial(0).SpecularColor.set(255,255,255,255);
\r
341 The specular color of the dynamic lights
\r
342 (SLight::SpecularColor) will influence the the highlight color
\r
343 too, but they are set to a useful value by default when
\r
344 creating the light scene node.*/
\r
347 //! Free parameter, dependent on the material type.
\r
348 /** Mostly ignored, used for example in
\r
349 EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
\r
350 f32 MaterialTypeParam;
\r
352 //! Second free parameter, dependent on the material type.
\r
353 /** Mostly ignored. */
\r
354 f32 MaterialTypeParam2;
\r
356 //! Thickness of non-3dimensional elements such as lines and points.
\r
359 //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
\r
360 /** If you want to disable depth test for this material
\r
361 just set this parameter to ECFN_DISABLED.
\r
362 Values are from E_COMPARISON_FUNC. */
\r
365 //! Sets the antialiasing mode
\r
366 /** Values are chosen from E_ANTI_ALIASING_MODE. Default is
\r
367 EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
\r
370 //! Defines the enabled color planes
\r
371 /** Values are defined as or'ed values of the E_COLOR_PLANE enum.
\r
372 Only enabled color planes will be rendered to the current render
\r
373 target. Typical use is to disable all colors when rendering only to
\r
374 depth or stencil buffer, or using Red and Green for Stereo rendering. */
\r
377 //! Defines the interpretation of vertex color in the lighting equation
\r
378 /** Values should be chosen from E_COLOR_MATERIAL.
\r
379 When lighting is enabled, vertex color can be used instead of the
\r
380 material values for light modulation. This allows to easily change e.g. the
\r
381 diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in
\r
382 a very similar rendering as with lighting turned off, just with light shading. */
\r
383 u8 ColorMaterial:3;
\r
385 //! Store the blend operation of choice
\r
386 /** Values to be chosen from E_BLEND_OPERATION. */
\r
387 E_BLEND_OPERATION BlendOperation:4;
\r
389 //! Store the blend factors
\r
390 /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
\r
391 properly blending factors to this parameter.
\r
392 Due to historical reasons this parameter is not used for material type
\r
393 EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
\r
394 It's generally used only for materials without any blending otherwise (like EMT_SOLID).
\r
395 It's main use is to allow having shader materials which can enable/disable
\r
396 blending after they have been created.
\r
397 When you set this you usually also have to set BlendOperation to a value != EBO_NONE
\r
398 (setting it to EBO_ADD is probably the most common one value). */
\r
401 //! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead.
\r
402 /** Factor specifying how far the polygon offset should be made.
\r
403 Specifying 0 disables the polygon offset. The direction is specified separately.
\r
404 The factor can be from 0 to 7.
\r
405 Note: This probably never worked on Direct3D9 (was coded for D3D8 which had different value ranges) */
\r
406 u8 PolygonOffsetFactor:3;
\r
408 //! DEPRECATED. Will be removed after Irrlicht 1.9.
\r
409 /** Flag defining the direction the polygon offset is applied to.
\r
410 Can be to front or to back, specified by values from E_POLYGON_OFFSET. */
\r
411 E_POLYGON_OFFSET PolygonOffsetDirection:1;
\r
413 //! A constant z-buffer offset for a polygon/line/point
\r
414 /** The range of the value is driver specific.
\r
415 On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
\r
416 On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
\r
417 Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
\r
418 Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
\r
419 recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
\r
420 f32 PolygonOffsetDepthBias;
\r
422 //! Variable Z-Buffer offset based on the slope of the polygon.
\r
423 /** For polygons looking flat at a camera you could use 0 (for example in a 2D game)
\r
424 But in most cases you will have polygons rendered at a certain slope.
\r
425 The driver will calculate the slope for you and this value allows to scale that slope.
\r
426 The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias
\r
427 A good default here is to use 1.f if you want to push the polygons away from the camera
\r
428 and -1.f to pull them towards the camera. */
\r
429 f32 PolygonOffsetSlopeScale;
\r
431 //! Draw as wireframe or filled triangles? Default: false
\r
432 /** The user can access a material flag using
\r
433 \code material.Wireframe=true \endcode
\r
434 or \code material.setFlag(EMF_WIREFRAME, true); \endcode */
\r
437 //! Draw as point cloud or filled triangles? Default: false
\r
440 //! Flat or Gouraud shading? Default: true
\r
441 bool GouraudShading:1;
\r
443 //! Will this material be lighted? Default: true
\r
446 //! Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
\r
447 /** If this parameter is not EZW_OFF, you probably also want to set ZBuffer
\r
448 to values other than ECFN_DISABLED */
\r
449 E_ZWRITE ZWriteEnable:2;
\r
451 //! Is backface culling enabled? Default: true
\r
452 bool BackfaceCulling:1;
\r
454 //! Is frontface culling enabled? Default: false
\r
455 bool FrontfaceCulling:1;
\r
457 //! Is fog enabled? Default: false
\r
460 //! Should normals be normalized?
\r
461 /** Always use this if the mesh lit and scaled. Default: false */
\r
462 bool NormalizeNormals:1;
\r
464 //! Shall mipmaps be used if available
\r
465 /** Sometimes, disabling mipmap usage can be useful. Default: true */
\r
468 //! Gets the texture transformation matrix for level i
\r
469 /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
\r
470 \return Texture matrix for texture level i. */
\r
471 core::matrix4& getTextureMatrix(u32 i)
\r
473 return TextureLayer[i].getTextureMatrix();
\r
476 //! Gets the immutable texture transformation matrix for level i
\r
477 /** \param i The desired level.
\r
478 \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */
\r
479 const core::matrix4& getTextureMatrix(u32 i) const
\r
481 if (i<MATERIAL_MAX_TEXTURES)
\r
482 return TextureLayer[i].getTextureMatrix();
\r
484 return core::IdentityMatrix;
\r
487 //! Sets the i-th texture transformation matrix
\r
488 /** \param i The desired level.
\r
489 \param mat Texture matrix for texture level i. */
\r
490 void setTextureMatrix(u32 i, const core::matrix4& mat)
\r
492 if (i>=MATERIAL_MAX_TEXTURES)
\r
494 TextureLayer[i].setTextureMatrix(mat);
\r
497 //! Gets the i-th texture
\r
498 /** \param i The desired level.
\r
499 \return Texture for texture level i, if defined, else 0. */
\r
500 ITexture* getTexture(u32 i) const
\r
502 return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
\r
505 //! Sets the i-th texture
\r
506 /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.
\r
507 \param i The desired level.
\r
508 \param tex Texture for texture level i. */
\r
509 void setTexture(u32 i, ITexture* tex)
\r
511 if (i>=MATERIAL_MAX_TEXTURES)
\r
513 TextureLayer[i].Texture = tex;
\r
516 //! Sets the Material flag to the given value
\r
517 /** \param flag The flag to be set.
\r
518 \param value The new value for the flag. */
\r
519 void setFlag(E_MATERIAL_FLAG flag, bool value)
\r
523 case EMF_WIREFRAME:
\r
524 Wireframe = value; break;
\r
525 case EMF_POINTCLOUD:
\r
526 PointCloud = value; break;
\r
527 case EMF_GOURAUD_SHADING:
\r
528 GouraudShading = value; break;
\r
530 Lighting = value; break;
\r
532 ZBuffer = value; break;
\r
533 case EMF_ZWRITE_ENABLE:
\r
534 ZWriteEnable = value ? EZW_AUTO : EZW_OFF; break;
\r
535 case EMF_BACK_FACE_CULLING:
\r
536 BackfaceCulling = value; break;
\r
537 case EMF_FRONT_FACE_CULLING:
\r
538 FrontfaceCulling = value; break;
\r
539 case EMF_BILINEAR_FILTER:
\r
541 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
542 TextureLayer[i].BilinearFilter = value;
\r
545 case EMF_TRILINEAR_FILTER:
\r
547 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
548 TextureLayer[i].TrilinearFilter = value;
\r
551 case EMF_ANISOTROPIC_FILTER:
\r
554 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
555 TextureLayer[i].AnisotropicFilter = 0xFF;
\r
557 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
558 TextureLayer[i].AnisotropicFilter = 0;
\r
561 case EMF_FOG_ENABLE:
\r
562 FogEnable = value; break;
\r
563 case EMF_NORMALIZE_NORMALS:
\r
564 NormalizeNormals = value; break;
\r
565 case EMF_TEXTURE_WRAP:
\r
567 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
569 TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value;
\r
570 TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value;
\r
571 TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)value;
\r
575 case EMF_ANTI_ALIASING:
\r
576 AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
\r
577 case EMF_COLOR_MASK:
\r
578 ColorMask = value?ECP_ALL:ECP_NONE; break;
\r
579 case EMF_COLOR_MATERIAL:
\r
580 ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
\r
581 case EMF_USE_MIP_MAPS:
\r
582 UseMipMaps = value; break;
\r
583 case EMF_BLEND_OPERATION:
\r
584 BlendOperation = value?EBO_ADD:EBO_NONE; break;
\r
585 case EMF_BLEND_FACTOR:
\r
587 case EMF_POLYGON_OFFSET:
\r
588 PolygonOffsetFactor = value?1:0;
\r
589 PolygonOffsetDirection = EPO_BACK;
\r
590 PolygonOffsetSlopeScale = value?1.f:0.f;
\r
591 PolygonOffsetDepthBias = value?1.f:0.f;
\r
597 //! Gets the Material flag
\r
598 /** \param flag The flag to query.
\r
599 \return The current value of the flag. */
\r
600 bool getFlag(E_MATERIAL_FLAG flag) const
\r
604 case EMF_WIREFRAME:
\r
606 case EMF_POINTCLOUD:
\r
608 case EMF_GOURAUD_SHADING:
\r
609 return GouraudShading;
\r
613 return ZBuffer!=ECFN_DISABLED;
\r
614 case EMF_ZWRITE_ENABLE:
\r
615 return ZWriteEnable != EZW_OFF;
\r
616 case EMF_BACK_FACE_CULLING:
\r
617 return BackfaceCulling;
\r
618 case EMF_FRONT_FACE_CULLING:
\r
619 return FrontfaceCulling;
\r
620 case EMF_BILINEAR_FILTER:
\r
621 return TextureLayer[0].BilinearFilter;
\r
622 case EMF_TRILINEAR_FILTER:
\r
623 return TextureLayer[0].TrilinearFilter;
\r
624 case EMF_ANISOTROPIC_FILTER:
\r
625 return TextureLayer[0].AnisotropicFilter!=0;
\r
626 case EMF_FOG_ENABLE:
\r
628 case EMF_NORMALIZE_NORMALS:
\r
629 return NormalizeNormals;
\r
630 case EMF_TEXTURE_WRAP:
\r
631 return !(TextureLayer[0].TextureWrapU ||
\r
632 TextureLayer[0].TextureWrapV ||
\r
633 TextureLayer[0].TextureWrapW);
\r
634 case EMF_ANTI_ALIASING:
\r
635 return (AntiAliasing==1);
\r
636 case EMF_COLOR_MASK:
\r
637 return (ColorMask!=ECP_NONE);
\r
638 case EMF_COLOR_MATERIAL:
\r
639 return (ColorMaterial != ECM_NONE);
\r
640 case EMF_USE_MIP_MAPS:
\r
642 case EMF_BLEND_OPERATION:
\r
643 return BlendOperation != EBO_NONE;
\r
644 case EMF_BLEND_FACTOR:
\r
645 return BlendFactor != 0.f;
\r
646 case EMF_POLYGON_OFFSET:
\r
647 return PolygonOffsetFactor != 0 || PolygonOffsetDepthBias != 0.f;
\r
653 //! Inequality operator
\r
654 /** \param b Material to compare to.
\r
655 \return True if the materials differ, else false. */
\r
656 inline bool operator!=(const SMaterial& b) const
\r
659 MaterialType != b.MaterialType ||
\r
660 AmbientColor != b.AmbientColor ||
\r
661 DiffuseColor != b.DiffuseColor ||
\r
662 EmissiveColor != b.EmissiveColor ||
\r
663 SpecularColor != b.SpecularColor ||
\r
664 Shininess != b.Shininess ||
\r
665 MaterialTypeParam != b.MaterialTypeParam ||
\r
666 MaterialTypeParam2 != b.MaterialTypeParam2 ||
\r
667 Thickness != b.Thickness ||
\r
668 Wireframe != b.Wireframe ||
\r
669 PointCloud != b.PointCloud ||
\r
670 GouraudShading != b.GouraudShading ||
\r
671 Lighting != b.Lighting ||
\r
672 ZBuffer != b.ZBuffer ||
\r
673 ZWriteEnable != b.ZWriteEnable ||
\r
674 BackfaceCulling != b.BackfaceCulling ||
\r
675 FrontfaceCulling != b.FrontfaceCulling ||
\r
676 FogEnable != b.FogEnable ||
\r
677 NormalizeNormals != b.NormalizeNormals ||
\r
678 AntiAliasing != b.AntiAliasing ||
\r
679 ColorMask != b.ColorMask ||
\r
680 ColorMaterial != b.ColorMaterial ||
\r
681 BlendOperation != b.BlendOperation ||
\r
682 BlendFactor != b.BlendFactor ||
\r
683 PolygonOffsetFactor != b.PolygonOffsetFactor ||
\r
684 PolygonOffsetDirection != b.PolygonOffsetDirection ||
\r
685 PolygonOffsetDepthBias != b.PolygonOffsetDepthBias ||
\r
686 PolygonOffsetSlopeScale != b.PolygonOffsetSlopeScale ||
\r
687 UseMipMaps != b.UseMipMaps
\r
689 for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
\r
691 different |= (TextureLayer[i] != b.TextureLayer[i]);
\r
696 //! Equality operator
\r
697 /** \param b Material to compare to.
\r
698 \return True if the materials are equal, else false. */
\r
699 inline bool operator==(const SMaterial& b) const
\r
700 { return !(b!=*this); }
\r
702 //! Check if material needs alpha blending
\r
703 bool isAlphaBlendOperation() const
\r
705 if (BlendOperation != EBO_NONE && BlendFactor != 0.f)
\r
707 E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
\r
708 E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
\r
709 E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
\r
710 E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
\r
711 E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
\r
712 u32 alphaSource = 0;
\r
714 unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, BlendFactor);
\r
716 if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
\r
717 textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
\r
725 //! Check for some fixed-function transparent types. Still used internally, but might be deprecated soon.
\r
726 //! You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations
\r
727 //! as it asks the material renders directly what they do with the material.
\r
728 bool isTransparent() const
\r
730 if ( MaterialType==EMT_TRANSPARENT_ADD_COLOR ||
\r
731 MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL ||
\r
732 MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA ||
\r
733 MaterialType==EMT_TRANSPARENT_REFLECTION_2_LAYER )
\r
740 //! global const identity Material
\r
741 IRRLICHT_API extern SMaterial IdentityMaterial;
\r
742 } // end namespace video
\r
743 } // end namespace irr
\r