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.*/
\r
374 //! Free parameter, dependent on the material type.
\r
375 /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID,
\r
376 EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */
\r
377 f32 MaterialTypeParam;
\r
379 //! Second free parameter, dependent on the material type.
\r
380 /** Mostly ignored. */
\r
381 f32 MaterialTypeParam2;
\r
383 //! Thickness of non-3dimensional elements such as lines and points.
\r
386 //! Is the ZBuffer enabled? Default: ECFN_LESSEQUAL
\r
387 /** If you want to disable depth test for this material
\r
388 just set this parameter to ECFN_DISABLED.
\r
389 Values are from E_COMPARISON_FUNC. */
\r
392 //! Sets the antialiasing mode
\r
393 /** Values are chosen from E_ANTI_ALIASING_MODE. Default is
\r
394 EAAM_SIMPLE, i.e. simple multi-sample anti-aliasing. */
\r
397 //! Defines the enabled color planes
\r
398 /** Values are defined as or'ed values of the E_COLOR_PLANE enum.
\r
399 Only enabled color planes will be rendered to the current render
\r
400 target. Typical use is to disable all colors when rendering only to
\r
401 depth or stencil buffer, or using Red and Green for Stereo rendering. */
\r
404 //! Defines the interpretation of vertex color in the lighting equation
\r
405 /** Values should be chosen from E_COLOR_MATERIAL.
\r
406 When lighting is enabled, vertex color can be used instead of the
\r
407 material values for light modulation. This allows to easily change e.g. the
\r
408 diffuse light behavior of each face. The default, ECM_DIFFUSE, will result in
\r
409 a very similar rendering as with lighting turned off, just with light shading. */
\r
410 u8 ColorMaterial:3;
\r
412 //! Store the blend operation of choice
\r
413 /** Values to be chosen from E_BLEND_OPERATION. */
\r
414 E_BLEND_OPERATION BlendOperation:4;
\r
416 //! Store the blend factors
\r
417 /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write
\r
418 properly blending factors to this parameter.
\r
419 Due to historical reasons this parameter is not used for material type
\r
420 EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor.
\r
421 It's generally used only for materials without any blending otherwise (like EMT_SOLID).
\r
422 It's main use is to allow having shader materials which can enable/disable
\r
423 blending after they have been created.
\r
424 When you set this you usually also have to set BlendOperation to a value != EBO_NONE
\r
425 (setting it to EBO_ADD is probably the most common one value). */
\r
428 //! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead.
\r
429 /** Factor specifying how far the polygon offset should be made.
\r
430 Specifying 0 disables the polygon offset. The direction is specified separately.
\r
431 The factor can be from 0 to 7.
\r
432 Note: This probably never worked on Direct3D9 (was coded for D3D8 which had different value ranges) */
\r
433 u8 PolygonOffsetFactor:3;
\r
435 //! DEPRECATED. Will be removed after Irrlicht 1.9.
\r
436 /** Flag defining the direction the polygon offset is applied to.
\r
437 Can be to front or to back, specified by values from E_POLYGON_OFFSET. */
\r
438 E_POLYGON_OFFSET PolygonOffsetDirection:1;
\r
440 //! A constant z-buffer offset for a polygon/line/point
\r
441 /** The range of the value is driver specific.
\r
442 On OpenGL you get units which are multiplied by the smallest value that is guaranteed to produce a resolvable offset.
\r
443 On D3D9 you can pass a range between -1 and 1. But you should likely divide it by the range of the depthbuffer.
\r
444 Like dividing by 65535.0 for a 16 bit depthbuffer. Thought it still might produce too large of a bias.
\r
445 Some article (https://aras-p.info/blog/2008/06/12/depth-bias-and-the-power-of-deceiving-yourself/)
\r
446 recommends multiplying by 2.0*4.8e-7 (and strangely on both 16 bit and 24 bit). */
\r
447 f32 PolygonOffsetDepthBias;
\r
449 //! Variable Z-Buffer offset based on the slope of the polygon.
\r
450 /** For polygons looking flat at a camera you could use 0 (for example in a 2D game)
\r
451 But in most cases you will have polygons rendered at a certain slope.
\r
452 The driver will calculate the slope for you and this value allows to scale that slope.
\r
453 The complete polygon offset is: PolygonOffsetSlopeScale*slope + PolygonOffsetDepthBias
\r
454 A good default here is to use 1.f if you want to push the polygons away from the camera
\r
455 and -1.f to pull them towards the camera. */
\r
456 f32 PolygonOffsetSlopeScale;
\r
458 //! Draw as wireframe or filled triangles? Default: false
\r
459 /** The user can access a material flag using
\r
460 \code material.Wireframe=true \endcode
\r
461 or \code material.setFlag(EMF_WIREFRAME, true); \endcode */
\r
464 //! Draw as point cloud or filled triangles? Default: false
\r
467 //! Flat or Gouraud shading? Default: true
\r
468 bool GouraudShading:1;
\r
470 //! Will this material be lighted? Default: true
\r
473 //! Is the zbuffer writable or is it read-only. Default: EZW_AUTO.
\r
474 /** If this parameter is not EZW_OFF, you probably also want to set ZBuffer
\r
475 to values other than ECFN_DISABLED */
\r
476 E_ZWRITE ZWriteEnable:2;
\r
478 //! Is backface culling enabled? Default: true
\r
479 bool BackfaceCulling:1;
\r
481 //! Is frontface culling enabled? Default: false
\r
482 bool FrontfaceCulling:1;
\r
484 //! Is fog enabled? Default: false
\r
487 //! Should normals be normalized?
\r
488 /** Always use this if the mesh lit and scaled. Default: false */
\r
489 bool NormalizeNormals:1;
\r
491 //! Shall mipmaps be used if available
\r
492 /** Sometimes, disabling mipmap usage can be useful. Default: true */
\r
495 //! Gets the texture transformation matrix for level i
\r
496 /** \param i The desired level. Must not be larger than MATERIAL_MAX_TEXTURES
\r
497 \return Texture matrix for texture level i. */
\r
498 core::matrix4& getTextureMatrix(u32 i)
\r
500 return TextureLayer[i].getTextureMatrix();
\r
503 //! Gets the immutable texture transformation matrix for level i
\r
504 /** \param i The desired level.
\r
505 \return Texture matrix for texture level i, or identity matrix for levels larger than MATERIAL_MAX_TEXTURES. */
\r
506 const core::matrix4& getTextureMatrix(u32 i) const
\r
508 if (i<MATERIAL_MAX_TEXTURES)
\r
509 return TextureLayer[i].getTextureMatrix();
\r
511 return core::IdentityMatrix;
\r
514 //! Sets the i-th texture transformation matrix
\r
515 /** \param i The desired level.
\r
516 \param mat Texture matrix for texture level i. */
\r
517 void setTextureMatrix(u32 i, const core::matrix4& mat)
\r
519 if (i>=MATERIAL_MAX_TEXTURES)
\r
521 TextureLayer[i].setTextureMatrix(mat);
\r
524 //! Gets the i-th texture
\r
525 /** \param i The desired level.
\r
526 \return Texture for texture level i, if defined, else 0. */
\r
527 ITexture* getTexture(u32 i) const
\r
529 return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
\r
532 //! Sets the i-th texture
\r
533 /** If i>=MATERIAL_MAX_TEXTURES this setting will be ignored.
\r
534 \param i The desired level.
\r
535 \param tex Texture for texture level i. */
\r
536 void setTexture(u32 i, ITexture* tex)
\r
538 if (i>=MATERIAL_MAX_TEXTURES)
\r
540 TextureLayer[i].Texture = tex;
\r
543 //! Sets the Material flag to the given value
\r
544 /** \param flag The flag to be set.
\r
545 \param value The new value for the flag. */
\r
546 void setFlag(E_MATERIAL_FLAG flag, bool value)
\r
550 case EMF_WIREFRAME:
\r
551 Wireframe = value; break;
\r
552 case EMF_POINTCLOUD:
\r
553 PointCloud = value; break;
\r
554 case EMF_GOURAUD_SHADING:
\r
555 GouraudShading = value; break;
\r
557 Lighting = value; break;
\r
559 ZBuffer = value; break;
\r
560 case EMF_ZWRITE_ENABLE:
\r
561 ZWriteEnable = value ? EZW_AUTO : EZW_OFF; break;
\r
562 case EMF_BACK_FACE_CULLING:
\r
563 BackfaceCulling = value; break;
\r
564 case EMF_FRONT_FACE_CULLING:
\r
565 FrontfaceCulling = value; break;
\r
566 case EMF_BILINEAR_FILTER:
\r
568 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
569 TextureLayer[i].BilinearFilter = value;
\r
572 case EMF_TRILINEAR_FILTER:
\r
574 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
575 TextureLayer[i].TrilinearFilter = value;
\r
578 case EMF_ANISOTROPIC_FILTER:
\r
581 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
582 TextureLayer[i].AnisotropicFilter = 0xFF;
\r
584 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
585 TextureLayer[i].AnisotropicFilter = 0;
\r
588 case EMF_FOG_ENABLE:
\r
589 FogEnable = value; break;
\r
590 case EMF_NORMALIZE_NORMALS:
\r
591 NormalizeNormals = value; break;
\r
592 case EMF_TEXTURE_WRAP:
\r
594 for (u32 i=0; i<MATERIAL_MAX_TEXTURES_USED; ++i)
\r
596 TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)value;
\r
597 TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)value;
\r
598 TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)value;
\r
602 case EMF_ANTI_ALIASING:
\r
603 AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
\r
604 case EMF_COLOR_MASK:
\r
605 ColorMask = value?ECP_ALL:ECP_NONE; break;
\r
606 case EMF_COLOR_MATERIAL:
\r
607 ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
\r
608 case EMF_USE_MIP_MAPS:
\r
609 UseMipMaps = value; break;
\r
610 case EMF_BLEND_OPERATION:
\r
611 BlendOperation = value?EBO_ADD:EBO_NONE; break;
\r
612 case EMF_BLEND_FACTOR:
\r
614 case EMF_POLYGON_OFFSET:
\r
615 PolygonOffsetFactor = value?1:0;
\r
616 PolygonOffsetDirection = EPO_BACK;
\r
617 PolygonOffsetSlopeScale = value?1.f:0.f;
\r
618 PolygonOffsetDepthBias = value?1.f:0.f;
\r
624 //! Gets the Material flag
\r
625 /** \param flag The flag to query.
\r
626 \return The current value of the flag. */
\r
627 bool getFlag(E_MATERIAL_FLAG flag) const
\r
631 case EMF_WIREFRAME:
\r
633 case EMF_POINTCLOUD:
\r
635 case EMF_GOURAUD_SHADING:
\r
636 return GouraudShading;
\r
640 return ZBuffer!=ECFN_DISABLED;
\r
641 case EMF_ZWRITE_ENABLE:
\r
642 return ZWriteEnable != EZW_OFF;
\r
643 case EMF_BACK_FACE_CULLING:
\r
644 return BackfaceCulling;
\r
645 case EMF_FRONT_FACE_CULLING:
\r
646 return FrontfaceCulling;
\r
647 case EMF_BILINEAR_FILTER:
\r
648 return TextureLayer[0].BilinearFilter;
\r
649 case EMF_TRILINEAR_FILTER:
\r
650 return TextureLayer[0].TrilinearFilter;
\r
651 case EMF_ANISOTROPIC_FILTER:
\r
652 return TextureLayer[0].AnisotropicFilter!=0;
\r
653 case EMF_FOG_ENABLE:
\r
655 case EMF_NORMALIZE_NORMALS:
\r
656 return NormalizeNormals;
\r
657 case EMF_TEXTURE_WRAP:
\r
658 return !(TextureLayer[0].TextureWrapU ||
\r
659 TextureLayer[0].TextureWrapV ||
\r
660 TextureLayer[0].TextureWrapW);
\r
661 case EMF_ANTI_ALIASING:
\r
662 return (AntiAliasing==1);
\r
663 case EMF_COLOR_MASK:
\r
664 return (ColorMask!=ECP_NONE);
\r
665 case EMF_COLOR_MATERIAL:
\r
666 return (ColorMaterial != ECM_NONE);
\r
667 case EMF_USE_MIP_MAPS:
\r
669 case EMF_BLEND_OPERATION:
\r
670 return BlendOperation != EBO_NONE;
\r
671 case EMF_BLEND_FACTOR:
\r
672 return BlendFactor != 0.f;
\r
673 case EMF_POLYGON_OFFSET:
\r
674 return PolygonOffsetFactor != 0 || PolygonOffsetDepthBias != 0.f;
\r
680 //! Inequality operator
\r
681 /** \param b Material to compare to.
\r
682 \return True if the materials differ, else false. */
\r
683 inline bool operator!=(const SMaterial& b) const
\r
686 MaterialType != b.MaterialType ||
\r
687 AmbientColor != b.AmbientColor ||
\r
688 DiffuseColor != b.DiffuseColor ||
\r
689 EmissiveColor != b.EmissiveColor ||
\r
690 SpecularColor != b.SpecularColor ||
\r
691 Shininess != b.Shininess ||
\r
692 MaterialTypeParam != b.MaterialTypeParam ||
\r
693 MaterialTypeParam2 != b.MaterialTypeParam2 ||
\r
694 Thickness != b.Thickness ||
\r
695 Wireframe != b.Wireframe ||
\r
696 PointCloud != b.PointCloud ||
\r
697 GouraudShading != b.GouraudShading ||
\r
698 Lighting != b.Lighting ||
\r
699 ZBuffer != b.ZBuffer ||
\r
700 ZWriteEnable != b.ZWriteEnable ||
\r
701 BackfaceCulling != b.BackfaceCulling ||
\r
702 FrontfaceCulling != b.FrontfaceCulling ||
\r
703 FogEnable != b.FogEnable ||
\r
704 NormalizeNormals != b.NormalizeNormals ||
\r
705 AntiAliasing != b.AntiAliasing ||
\r
706 ColorMask != b.ColorMask ||
\r
707 ColorMaterial != b.ColorMaterial ||
\r
708 BlendOperation != b.BlendOperation ||
\r
709 BlendFactor != b.BlendFactor ||
\r
710 PolygonOffsetFactor != b.PolygonOffsetFactor ||
\r
711 PolygonOffsetDirection != b.PolygonOffsetDirection ||
\r
712 PolygonOffsetDepthBias != b.PolygonOffsetDepthBias ||
\r
713 PolygonOffsetSlopeScale != b.PolygonOffsetSlopeScale ||
\r
714 UseMipMaps != b.UseMipMaps
\r
716 for (u32 i=0; (i<MATERIAL_MAX_TEXTURES_USED) && !different; ++i)
\r
718 different |= (TextureLayer[i] != b.TextureLayer[i]);
\r
723 //! Equality operator
\r
724 /** \param b Material to compare to.
\r
725 \return True if the materials are equal, else false. */
\r
726 inline bool operator==(const SMaterial& b) const
\r
727 { return !(b!=*this); }
\r
729 //! Check if material needs alpha blending
\r
730 bool isAlphaBlendOperation() const
\r
732 if (BlendOperation != EBO_NONE && BlendFactor != 0.f)
\r
734 E_BLEND_FACTOR srcRGBFact = EBF_ZERO;
\r
735 E_BLEND_FACTOR dstRGBFact = EBF_ZERO;
\r
736 E_BLEND_FACTOR srcAlphaFact = EBF_ZERO;
\r
737 E_BLEND_FACTOR dstAlphaFact = EBF_ZERO;
\r
738 E_MODULATE_FUNC modulo = EMFN_MODULATE_1X;
\r
739 u32 alphaSource = 0;
\r
741 unpack_textureBlendFuncSeparate(srcRGBFact, dstRGBFact, srcAlphaFact, dstAlphaFact, modulo, alphaSource, BlendFactor);
\r
743 if (textureBlendFunc_hasAlpha(srcRGBFact) || textureBlendFunc_hasAlpha(dstRGBFact) ||
\r
744 textureBlendFunc_hasAlpha(srcAlphaFact) || textureBlendFunc_hasAlpha(dstAlphaFact))
\r
752 //! Check for some fixed-function transparent types. Still used internally, but might be deprecated soon.
\r
753 //! You probably should not use this anymore, IVideoDriver::needsTransparentRenderPass is more useful in most situations
\r
754 //! as it asks the material renders directly what they do with the material.
\r
755 bool isTransparent() const
\r
757 if ( MaterialType==EMT_TRANSPARENT_ADD_COLOR ||
\r
758 MaterialType==EMT_TRANSPARENT_ALPHA_CHANNEL ||
\r
759 MaterialType==EMT_TRANSPARENT_VERTEX_ALPHA ||
\r
760 MaterialType==EMT_TRANSPARENT_REFLECTION_2_LAYER )
\r
767 //! global const identity Material
\r
768 IRRLICHT_API extern SMaterial IdentityMaterial;
\r
769 } // end namespace video
\r
770 } // end namespace irr
\r