Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
SMaterial.h
Go to the documentation of this file.
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __S_MATERIAL_H_INCLUDED__
6#define __S_MATERIAL_H_INCLUDED__
7
8#include "SColor.h"
9#include "matrix4.h"
10#include "irrArray.h"
11#include "irrMath.h"
12#include "EMaterialTypes.h"
13#include "EMaterialFlags.h"
14#include "SMaterialLayer.h"
15
16namespace irr
17{
18namespace video
19{
20 class ITexture;
21
37
52
60
81
100
102
113
115
116 inline f32 pack_textureBlendFunc ( const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE )
117 {
118 const u32 tmp = (alphaSource << 12) | (modulate << 8) | (srcFact << 4) | dstFact;
119 return FR(tmp);
120 }
121
123
124 inline void unpack_textureBlendFunc ( E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact,
125 E_MODULATE_FUNC &modulo, u32& alphaSource, const f32 param )
126 {
127 const u32 state = IR(param);
128 alphaSource = (state & 0x0000F000) >> 12;
129 modulo = E_MODULATE_FUNC( ( state & 0x00000F00 ) >> 8 );
130 srcFact = E_BLEND_FACTOR ( ( state & 0x000000F0 ) >> 4 );
131 dstFact = E_BLEND_FACTOR ( ( state & 0x0000000F ) );
132 }
133
135 inline bool textureBlendFunc_hasAlpha ( const E_BLEND_FACTOR factor )
136 {
137 switch ( factor )
138 {
139 case EBF_SRC_ALPHA:
141 case EBF_DST_ALPHA:
144 return true;
145 default:
146 return false;
147 }
148 }
149
150
152
176
178
199
201
203 {
205
208
210 EPO_FRONT=1
211 };
212
215 {
216 "Back",
217 "Front",
218 0
219 };
220
221
224
227 {
228 public:
241
243
244 SMaterial(const SMaterial& other)
245 {
246 // These pointers are checked during assignment
247 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
248 TextureLayer[i].TextureMatrix = 0;
249 *this = other;
250 }
251
253
255 {
256 // Check for self-assignment!
257 if (this == &other)
258 return *this;
259
261
266 Shininess = other.Shininess;
269 Thickness = other.Thickness;
270 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
271 {
272 TextureLayer[i] = other.TextureLayer[i];
273 }
274
275 Wireframe = other.Wireframe;
276 PointCloud = other.PointCloud;
278 Lighting = other.Lighting;
282 FogEnable = other.FogEnable;
284 ZBuffer = other.ZBuffer;
286 ColorMask = other.ColorMask;
291 UseMipMaps = other.UseMipMaps;
292
293 return *this;
294 }
295
298
301
303
307
309
311
314
316
319
321
351
353
356
358
360
363
365
367
369
373
375
380
382
388
390
393
395
398
400
402
404
407 bool Wireframe:1;
408
411
414
416 bool Lighting:1;
417
419
423
426
429
431 bool FogEnable:1;
432
434
436
438
440
442
448
450
453 {
455 return TextureLayer[i].getTextureMatrix();
456 else
458 }
459
461
464 {
466 return;
468 }
469
471
474 {
475 return i < MATERIAL_MAX_TEXTURES ? TextureLayer[i].Texture : 0;
476 }
477
479
482 void setTexture(u32 i, ITexture* tex)
483 {
485 return;
486 TextureLayer[i].Texture = tex;
487 }
488
490
492 void setFlag(E_MATERIAL_FLAG flag, bool value)
493 {
494 switch (flag)
495 {
496 case EMF_WIREFRAME:
497 Wireframe = value; break;
498 case EMF_POINTCLOUD:
499 PointCloud = value; break;
501 GouraudShading = value; break;
502 case EMF_LIGHTING:
503 Lighting = value; break;
504 case EMF_ZBUFFER:
505 ZBuffer = value; break;
507 ZWriteEnable = value; break;
509 BackfaceCulling = value; break;
511 FrontfaceCulling = value; break;
513 {
514 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
515 TextureLayer[i].BilinearFilter = value;
516 }
517 break;
519 {
520 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
521 TextureLayer[i].TrilinearFilter = value;
522 }
523 break;
525 {
526 if (value)
527 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
528 TextureLayer[i].AnisotropicFilter = 0xFF;
529 else
530 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
531 TextureLayer[i].AnisotropicFilter = 0;
532 }
533 break;
534 case EMF_FOG_ENABLE:
535 FogEnable = value; break;
537 NormalizeNormals = value; break;
538 case EMF_TEXTURE_WRAP:
539 {
540 for (u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
541 {
544 }
545 }
546 break;
548 AntiAliasing = value?EAAM_SIMPLE:EAAM_OFF; break;
549 case EMF_COLOR_MASK:
550 ColorMask = value?ECP_ALL:ECP_NONE; break;
552 ColorMaterial = value?ECM_DIFFUSE:ECM_NONE; break;
553 case EMF_USE_MIP_MAPS:
554 UseMipMaps = value; break;
556 BlendOperation = value?EBO_ADD:EBO_NONE; break;
558 PolygonOffsetFactor = value?1:0;
560 break;
561 default:
562 break;
563 }
564 }
565
567
569 bool getFlag(E_MATERIAL_FLAG flag) const
570 {
571 switch (flag)
572 {
573 case EMF_WIREFRAME:
574 return Wireframe;
575 case EMF_POINTCLOUD:
576 return PointCloud;
578 return GouraudShading;
579 case EMF_LIGHTING:
580 return Lighting;
581 case EMF_ZBUFFER:
582 return ZBuffer!=ECFN_NEVER;
584 return ZWriteEnable;
586 return BackfaceCulling;
588 return FrontfaceCulling;
594 return TextureLayer[0].AnisotropicFilter!=0;
595 case EMF_FOG_ENABLE:
596 return FogEnable;
598 return NormalizeNormals;
599 case EMF_TEXTURE_WRAP:
600 return !(TextureLayer[0].TextureWrapU ||
609 return (AntiAliasing==1);
610 case EMF_COLOR_MASK:
611 return (ColorMask!=ECP_NONE);
613 return (ColorMaterial != ECM_NONE);
614 case EMF_USE_MIP_MAPS:
615 return UseMipMaps;
617 return BlendOperation != EBO_NONE;
619 return PolygonOffsetFactor != 0;
620 }
621
622 return false;
623 }
624
626
628 inline bool operator!=(const SMaterial& b) const
629 {
630 bool different =
636 Shininess != b.Shininess ||
639 Thickness != b.Thickness ||
640 Wireframe != b.Wireframe ||
641 PointCloud != b.PointCloud ||
643 Lighting != b.Lighting ||
644 ZBuffer != b.ZBuffer ||
648 FogEnable != b.FogEnable ||
651 ColorMask != b.ColorMask ||
657 for (u32 i=0; (i<MATERIAL_MAX_TEXTURES) && !different; ++i)
658 {
659 different |= (TextureLayer[i] != b.TextureLayer[i]);
660 }
661 return different;
662 }
663
665
667 inline bool operator==(const SMaterial& b) const
668 { return !(b!=*this); }
669
677 };
678
680 IRRLICHT_API extern SMaterial IdentityMaterial;
681
682} // end namespace video
683} // end namespace irr
684
685#endif
#define _IRR_MATERIAL_MAX_TEXTURES_
Maximum number of texture an SMaterial can have, up to 8 are supported by Irrlicht.
#define IRRLICHT_API
Set FPU settings.
4x4 matrix. Mostly used as transformation matrix for 3d calculations.
Definition matrix4.h:46
Interface of a Video Driver dependent Texture.
Definition ITexture.h:99
Class representing a 32 bit ARGB color.
Definition SColor.h:202
Struct for holding parameters for a material renderer.
Definition SMaterial.h:227
SColor EmissiveColor
Light emitted by this material. Default is to emit no light.
Definition SMaterial.h:313
bool ZWriteEnable
Is the zbuffer writeable or is it read-only. Default: true.
Definition SMaterial.h:422
u8 ColorMaterial
Defines the interpretation of vertex color in the lighting equation.
Definition SMaterial.h:387
SColor SpecularColor
How much specular light (highlights from a light) is reflected.
Definition SMaterial.h:318
SMaterialLayer TextureLayer[MATERIAL_MAX_TEXTURES]
Texture layer array.
Definition SMaterial.h:297
bool isTransparent() const
Definition SMaterial.h:670
bool operator==(const SMaterial &b) const
Equality operator.
Definition SMaterial.h:667
const core::matrix4 & getTextureMatrix(u32 i) const
Gets the immutable texture transformation matrix for level i.
Definition SMaterial.h:452
bool getFlag(E_MATERIAL_FLAG flag) const
Gets the Material flag.
Definition SMaterial.h:569
f32 MaterialTypeParam2
Second free parameter, dependent on the material type.
Definition SMaterial.h:359
SColor AmbientColor
How much ambient light (a global light) is reflected by this material.
Definition SMaterial.h:306
void setTexture(u32 i, ITexture *tex)
Sets the i-th texture.
Definition SMaterial.h:482
bool PointCloud
Draw as point cloud or filled triangles? Default: false.
Definition SMaterial.h:410
void setFlag(E_MATERIAL_FLAG flag, bool value)
Sets the Material flag to the given value.
Definition SMaterial.h:492
core::matrix4 & getTextureMatrix(u32 i)
Gets the texture transformation matrix for level i.
Definition SMaterial.h:444
u8 ColorMask
Defines the enabled color planes.
Definition SMaterial.h:379
f32 Thickness
Thickness of non-3dimensional elements such as lines and points.
Definition SMaterial.h:362
SMaterial(const SMaterial &other)
Copy constructor.
Definition SMaterial.h:244
void setTextureMatrix(u32 i, const core::matrix4 &mat)
Sets the i-th texture transformation matrix.
Definition SMaterial.h:463
bool Wireframe
Draw as wireframe or filled triangles? Default: false.
Definition SMaterial.h:407
u8 ZBuffer
Is the ZBuffer enabled? Default: ECFN_LESSEQUAL.
Definition SMaterial.h:366
f32 Shininess
Value affecting the size of specular highlights.
Definition SMaterial.h:350
E_MATERIAL_TYPE MaterialType
Type of the material. Specifies how everything is blended together.
Definition SMaterial.h:300
u8 AntiAliasing
Sets the antialiasing mode.
Definition SMaterial.h:372
bool UseMipMaps
Shall mipmaps be used if available.
Definition SMaterial.h:439
SMaterial & operator=(const SMaterial &other)
Assignment operator.
Definition SMaterial.h:254
bool FrontfaceCulling
Is frontface culling enabled? Default: false.
Definition SMaterial.h:428
bool FogEnable
Is fog enabled? Default: false.
Definition SMaterial.h:431
ITexture * getTexture(u32 i) const
Gets the i-th texture.
Definition SMaterial.h:473
E_POLYGON_OFFSET PolygonOffsetDirection
Flag defining the direction the polygon offset is applied to.
Definition SMaterial.h:401
bool GouraudShading
Flat or Gouraud shading? Default: true.
Definition SMaterial.h:413
SColor DiffuseColor
How much diffuse light coming from a light source is reflected by this material.
Definition SMaterial.h:310
SMaterial()
Default constructor. Creates a solid, lit material with white colors.
Definition SMaterial.h:230
bool operator!=(const SMaterial &b) const
Inequality operator.
Definition SMaterial.h:628
bool NormalizeNormals
Should normals be normalized?
Definition SMaterial.h:435
f32 MaterialTypeParam
Free parameter, dependent on the material type.
Definition SMaterial.h:355
bool BackfaceCulling
Is backface culling enabled? Default: true.
Definition SMaterial.h:425
u8 PolygonOffsetFactor
Factor specifying how far the polygon offset should be made.
Definition SMaterial.h:397
E_BLEND_OPERATION BlendOperation
Store the blend operation of choice.
Definition SMaterial.h:392
bool Lighting
Will this material be lighted? Default: true.
Definition SMaterial.h:416
Struct for holding material parameters which exist per texture layer.
void setTextureMatrix(const core::matrix4 &mat)
Sets the texture transformation matrix to mat.
bool BilinearFilter
Is bilinear filtering enabled? Default: true.
core::matrix4 & getTextureMatrix()
Gets the texture transformation matrix.
bool TrilinearFilter
Is trilinear filtering enabled? Default: false.
u8 AnisotropicFilter
Is anisotropic filtering enabled? Default: 0, disabled.
ITexture * Texture
Texture.
u8 TextureWrapU
Texture Clamp Mode.
IRRLICHT_API const matrix4 IdentityMatrix
global const identity matrix
E_ALPHA_SOURCE
Source of the alpha value to take.
Definition SMaterial.h:105
@ EAS_NONE
Use no alpha, somewhat redundant with other settings.
Definition SMaterial.h:107
@ EAS_VERTEX_COLOR
Use vertex color alpha.
Definition SMaterial.h:109
@ EAS_TEXTURE
Use texture alpha channel.
Definition SMaterial.h:111
E_MODULATE_FUNC
MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X.
Definition SMaterial.h:55
@ EMFN_MODULATE_2X
Definition SMaterial.h:57
@ EMFN_MODULATE_1X
Definition SMaterial.h:56
@ EMFN_MODULATE_4X
Definition SMaterial.h:58
E_COLOR_MATERIAL
These flags allow to define the interpretation of vertex color when lighting is enabled.
Definition SMaterial.h:185
@ ECM_NONE
Don't use vertex color for lighting.
Definition SMaterial.h:187
@ ECM_EMISSIVE
Use vertex color for emissive light.
Definition SMaterial.h:193
@ ECM_DIFFUSE_AND_AMBIENT
Use vertex color for both diffuse and ambient light.
Definition SMaterial.h:197
@ ECM_SPECULAR
Use vertex color for specular light.
Definition SMaterial.h:195
@ ECM_DIFFUSE
Use vertex color for diffuse light, this is default.
Definition SMaterial.h:189
@ ECM_AMBIENT
Use vertex color for ambient light.
Definition SMaterial.h:191
const c8 *const PolygonOffsetDirectionNames[]
Names for polygon offset direction.
Definition SMaterial.h:214
E_TEXTURE_CLAMP
Texture coord clamp mode outside [0.0, 1.0].
bool textureBlendFunc_hasAlpha(const E_BLEND_FACTOR factor)
EMT_ONETEXTURE_BLEND: has BlendFactor Alphablending.
Definition SMaterial.h:135
IRRLICHT_API SMaterial IdentityMaterial
global const identity Material
void unpack_textureBlendFunc(E_BLEND_FACTOR &srcFact, E_BLEND_FACTOR &dstFact, E_MODULATE_FUNC &modulo, u32 &alphaSource, const f32 param)
EMT_ONETEXTURE_BLEND: unpack srcFact & dstFact and Modulo to MaterialTypeParam.
Definition SMaterial.h:124
E_BLEND_OPERATION
Values defining the blend operation used when blend is enabled.
Definition SMaterial.h:40
@ EBO_NONE
No blending happens.
Definition SMaterial.h:41
@ EBO_MIN
Choose minimum value of each color channel.
Definition SMaterial.h:45
@ EBO_REVSUBTRACT
This modes subtracts destination from source.
Definition SMaterial.h:44
@ EBO_MIN_FACTOR
Choose minimum value of each color channel after applying blend factors, not widely supported.
Definition SMaterial.h:47
@ EBO_SUBTRACT
This mode subtracts the color values.
Definition SMaterial.h:43
@ EBO_MAX_ALPHA
Choose maximum value of each color channel based on alpha value, not widely supported.
Definition SMaterial.h:50
@ EBO_MAX_FACTOR
Choose maximum value of each color channel after applying blend factors, not widely supported.
Definition SMaterial.h:48
@ EBO_ADD
Default blending adds the color values.
Definition SMaterial.h:42
@ EBO_MIN_ALPHA
Choose minimum value of each color channel based on alpha value, not widely supported.
Definition SMaterial.h:49
@ EBO_MAX
Choose maximum value of each color channel.
Definition SMaterial.h:46
E_POLYGON_OFFSET
Flags for the definition of the polygon offset feature.
Definition SMaterial.h:203
@ EPO_BACK
Push pixel towards the far plane, away from the eye.
Definition SMaterial.h:206
@ EPO_FRONT
Pull pixels towards the camera.
Definition SMaterial.h:210
E_MATERIAL_FLAG
Material flags.
@ EMF_FRONT_FACE_CULLING
Is frontface culling enabled? Default: false.
@ EMF_POINTCLOUD
Draw as point cloud or filled triangles? Default: false.
@ EMF_NORMALIZE_NORMALS
Normalizes normals. Default: false.
@ EMF_ZBUFFER
Is the ZBuffer enabled? Default: true.
@ EMF_ZWRITE_ENABLE
May be written to the zbuffer or is it readonly. Default: true.
@ EMF_FOG_ENABLE
Is fog enabled? Default: false.
@ EMF_COLOR_MASK
ColorMask bits, for enabling the color planes.
@ EMF_TRILINEAR_FILTER
Is trilinear filtering enabled? Default: false.
@ EMF_TEXTURE_WRAP
Access to all layers texture wrap settings. Overwrites separate layer settings.
@ EMF_COLOR_MATERIAL
ColorMaterial enum for vertex color interpretation.
@ EMF_GOURAUD_SHADING
Flat or Gouraud shading? Default: true.
@ EMF_USE_MIP_MAPS
Flag for enabling/disabling mipmap usage.
@ EMF_ANISOTROPIC_FILTER
Is anisotropic filtering? Default: false.
@ EMF_ANTI_ALIASING
AntiAliasing mode.
@ EMF_BLEND_OPERATION
Flag for blend operation.
@ EMF_WIREFRAME
Draw as wireframe or filled triangles? Default: false.
@ EMF_POLYGON_OFFSET
Flag for polygon offset.
@ EMF_LIGHTING
Will this material be lighted? Default: true.
@ EMF_BACK_FACE_CULLING
Is backface culling enabled? Default: true.
@ EMF_BILINEAR_FILTER
Is bilinear filtering enabled? Default: true.
E_ANTI_ALIASING_MODE
These flags are used to specify the anti-aliasing and smoothing modes.
Definition SMaterial.h:159
@ EAAM_SIMPLE
Default anti-aliasing mode.
Definition SMaterial.h:163
@ EAAM_QUALITY
High-quality anti-aliasing, not always supported, automatically enables SIMPLE mode.
Definition SMaterial.h:165
@ EAAM_LINE_SMOOTH
Line smoothing.
Definition SMaterial.h:167
@ EAAM_POINT_SMOOTH
point smoothing, often in software and slow, only with OpenGL
Definition SMaterial.h:169
@ EAAM_OFF
Use to turn off anti-aliasing for this material.
Definition SMaterial.h:161
@ EAAM_ALPHA_TO_COVERAGE
Enhanced anti-aliasing for transparent materials.
Definition SMaterial.h:174
@ EAAM_FULL_BASIC
All typical anti-alias and smooth modes.
Definition SMaterial.h:171
E_COLOR_PLANE
Enum values for enabling/disabling color planes for rendering.
Definition SMaterial.h:84
@ ECP_GREEN
Green enabled.
Definition SMaterial.h:92
@ ECP_BLUE
Blue enabled.
Definition SMaterial.h:94
@ ECP_RED
Red enabled.
Definition SMaterial.h:90
@ ECP_RGB
All colors, no alpha.
Definition SMaterial.h:96
@ ECP_ALL
All planes enabled.
Definition SMaterial.h:98
@ ECP_NONE
No color enabled.
Definition SMaterial.h:86
@ ECP_ALPHA
Alpha enabled.
Definition SMaterial.h:88
E_MATERIAL_TYPE
Abstracted and easy to use fixed function/programmable pipeline material modes.
@ EMT_TRANSPARENT_ADD_COLOR
A transparent material.
@ EMT_TRANSPARENT_VERTEX_ALPHA
Makes the material transparent based on the vertex alpha value.
@ EMT_TRANSPARENT_REFLECTION_2_LAYER
A transparent reflecting material with an optional additional non reflecting texture layer.
@ EMT_SOLID
Standard solid material.
@ EMT_TRANSPARENT_ALPHA_CHANNEL
Makes the material transparent based on the texture alpha channel.
E_BLEND_FACTOR
Flag for EMT_ONETEXTURE_BLEND, ( BlendFactor ) BlendFunc = source * sourceFactor + dest * destFactor.
Definition SMaterial.h:24
@ EBF_ONE_MINUS_DST_COLOR
src (1-destR, 1-destG, 1-destB, 1-destA)
Definition SMaterial.h:28
@ EBF_SRC_ALPHA_SATURATE
src (min(srcA, 1-destA), idem, ...)
Definition SMaterial.h:35
@ EBF_SRC_ALPHA
src & dest (srcA, srcA, srcA, srcA)
Definition SMaterial.h:31
@ EBF_ONE
src & dest (1, 1, 1, 1)
Definition SMaterial.h:26
@ EBF_ONE_MINUS_DST_ALPHA
src & dest (1-destA, 1-destA, 1-destA, 1-destA)
Definition SMaterial.h:34
@ EBF_SRC_COLOR
dest (srcR, srcG, srcB, srcA)
Definition SMaterial.h:29
@ EBF_DST_ALPHA
src & dest (destA, destA, destA, destA)
Definition SMaterial.h:33
@ EBF_ZERO
src & dest (0, 0, 0, 0)
Definition SMaterial.h:25
@ EBF_ONE_MINUS_SRC_ALPHA
src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
Definition SMaterial.h:32
@ EBF_DST_COLOR
src (destR, destG, destB, destA)
Definition SMaterial.h:27
@ EBF_ONE_MINUS_SRC_COLOR
dest (1-srcR, 1-srcG, 1-srcB, 1-srcA)
Definition SMaterial.h:30
const u32 MATERIAL_MAX_TEXTURES
Maximum number of texture an SMaterial can have.
Definition SMaterial.h:223
f32 pack_textureBlendFunc(const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE)
EMT_ONETEXTURE_BLEND: pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam.
Definition SMaterial.h:116
E_COMPARISON_FUNC
Comparison function, e.g. for depth buffer test.
Definition SMaterial.h:63
@ ECFN_LESS
exclusive less comparison, i.e. <
Definition SMaterial.h:71
@ ECFN_GREATER
inverse of <=
Definition SMaterial.h:77
@ ECFN_GREATEREQUAL
>= test
Definition SMaterial.h:75
@ ECFN_NEVER
Test never succeeds, this equals disable.
Definition SMaterial.h:65
@ ECFN_LESSEQUAL
<= test, default for e.g. depth test
Definition SMaterial.h:67
@ ECFN_ALWAYS
test succeeds always
Definition SMaterial.h:79
@ ECFN_EQUAL
Exact equality.
Definition SMaterial.h:69
@ ECFN_NOTEQUAL
Succeeds almost always, except for exact equality.
Definition SMaterial.h:73
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.h:18
char c8
8 bit character variable.
Definition irrTypes.h:31