Irrlicht 3D Engine
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
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
16
namespace
irr
17
{
18
namespace
video
19
{
20
class
ITexture;
21
23
enum
E_BLEND_FACTOR
24
{
25
EBF_ZERO
= 0,
26
EBF_ONE
,
27
EBF_DST_COLOR
,
28
EBF_ONE_MINUS_DST_COLOR
,
29
EBF_SRC_COLOR
,
30
EBF_ONE_MINUS_SRC_COLOR
,
31
EBF_SRC_ALPHA
,
32
EBF_ONE_MINUS_SRC_ALPHA
,
33
EBF_DST_ALPHA
,
34
EBF_ONE_MINUS_DST_ALPHA
,
35
EBF_SRC_ALPHA_SATURATE
36
};
37
39
enum
E_BLEND_OPERATION
40
{
41
EBO_NONE
= 0,
42
EBO_ADD
,
43
EBO_SUBTRACT
,
44
EBO_REVSUBTRACT
,
45
EBO_MIN
,
46
EBO_MAX
,
47
EBO_MIN_FACTOR
,
48
EBO_MAX_FACTOR
,
49
EBO_MIN_ALPHA
,
50
EBO_MAX_ALPHA
51
};
52
54
enum
E_MODULATE_FUNC
55
{
56
EMFN_MODULATE_1X
= 1,
57
EMFN_MODULATE_2X
= 2,
58
EMFN_MODULATE_4X
= 4
59
};
60
62
enum
E_COMPARISON_FUNC
63
{
65
ECFN_NEVER
=0,
67
ECFN_LESSEQUAL
=1,
69
ECFN_EQUAL
=2,
71
ECFN_LESS
,
73
ECFN_NOTEQUAL
,
75
ECFN_GREATEREQUAL
,
77
ECFN_GREATER
,
79
ECFN_ALWAYS
80
};
81
83
enum
E_COLOR_PLANE
84
{
86
ECP_NONE
=0,
88
ECP_ALPHA
=1,
90
ECP_RED
=2,
92
ECP_GREEN
=4,
94
ECP_BLUE
=8,
96
ECP_RGB
=14,
98
ECP_ALL
=15
99
};
100
102
104
enum
E_ALPHA_SOURCE
105
{
107
EAS_NONE
=0,
109
EAS_VERTEX_COLOR
,
111
EAS_TEXTURE
112
};
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
:
140
case
EBF_ONE_MINUS_SRC_ALPHA
:
141
case
EBF_DST_ALPHA
:
142
case
EBF_ONE_MINUS_DST_ALPHA
:
143
case
EBF_SRC_ALPHA_SATURATE
:
144
return
true
;
145
default
:
146
return
false
;
147
}
148
}
149
150
152
158
enum
E_ANTI_ALIASING_MODE
159
{
161
EAAM_OFF
=0,
163
EAAM_SIMPLE
=1,
165
EAAM_QUALITY
=3,
167
EAAM_LINE_SMOOTH
=4,
169
EAAM_POINT_SMOOTH
=8,
171
EAAM_FULL_BASIC
=15,
173
174
EAAM_ALPHA_TO_COVERAGE
=16
175
};
176
178
184
enum
E_COLOR_MATERIAL
185
{
187
ECM_NONE
=0,
189
ECM_DIFFUSE
,
191
ECM_AMBIENT
,
193
ECM_EMISSIVE
,
195
ECM_SPECULAR
,
197
ECM_DIFFUSE_AND_AMBIENT
198
};
199
201
202
enum
E_POLYGON_OFFSET
203
{
205
206
EPO_BACK
=0,
208
210
EPO_FRONT
=1
211
};
212
214
const
c8
*
const
PolygonOffsetDirectionNames
[] =
215
{
216
"Back"
,
217
"Front"
,
218
0
219
};
220
221
223
const
u32
MATERIAL_MAX_TEXTURES
=
_IRR_MATERIAL_MAX_TEXTURES_
;
224
226
class
SMaterial
227
{
228
public
:
230
SMaterial
()
231
:
MaterialType
(
EMT_SOLID
),
AmbientColor
(255,255,255,255),
DiffuseColor
(255,255,255,255),
232
EmissiveColor
(0,0,0,0),
SpecularColor
(255,255,255,255),
233
Shininess
(0.0f),
MaterialTypeParam
(0.0f),
MaterialTypeParam2
(0.0f),
Thickness
(1.0f),
234
ZBuffer
(
ECFN_LESSEQUAL
),
AntiAliasing
(
EAAM_SIMPLE
),
ColorMask
(
ECP_ALL
),
235
ColorMaterial
(
ECM_DIFFUSE
),
BlendOperation
(
EBO_NONE
),
236
PolygonOffsetFactor
(0),
PolygonOffsetDirection
(
EPO_FRONT
),
237
Wireframe
(false),
PointCloud
(false),
GouraudShading
(true),
238
Lighting
(true),
ZWriteEnable
(true),
BackfaceCulling
(true),
FrontfaceCulling
(false),
239
FogEnable
(false),
NormalizeNormals
(false),
UseMipMaps
(true)
240
{ }
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
254
SMaterial
&
operator=
(
const
SMaterial
& other)
255
{
256
// Check for self-assignment!
257
if
(
this
== &other)
258
return
*
this
;
259
260
MaterialType
= other.
MaterialType
;
261
262
AmbientColor
= other.
AmbientColor
;
263
DiffuseColor
= other.
DiffuseColor
;
264
EmissiveColor
= other.
EmissiveColor
;
265
SpecularColor
= other.
SpecularColor
;
266
Shininess
= other.
Shininess
;
267
MaterialTypeParam
= other.
MaterialTypeParam
;
268
MaterialTypeParam2
= other.
MaterialTypeParam2
;
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
;
277
GouraudShading
= other.
GouraudShading
;
278
Lighting
= other.
Lighting
;
279
ZWriteEnable
= other.
ZWriteEnable
;
280
BackfaceCulling
= other.
BackfaceCulling
;
281
FrontfaceCulling
= other.
FrontfaceCulling
;
282
FogEnable
= other.
FogEnable
;
283
NormalizeNormals
= other.
NormalizeNormals
;
284
ZBuffer
= other.
ZBuffer
;
285
AntiAliasing
= other.
AntiAliasing
;
286
ColorMask
= other.
ColorMask
;
287
ColorMaterial
= other.
ColorMaterial
;
288
BlendOperation
= other.
BlendOperation
;
289
PolygonOffsetFactor
= other.
PolygonOffsetFactor
;
290
PolygonOffsetDirection
= other.
PolygonOffsetDirection
;
291
UseMipMaps
= other.
UseMipMaps
;
292
293
return
*
this
;
294
}
295
297
SMaterialLayer
TextureLayer
[
MATERIAL_MAX_TEXTURES
];
298
300
E_MATERIAL_TYPE
MaterialType
;
301
303
306
SColor
AmbientColor
;
307
309
310
SColor
DiffuseColor
;
311
313
SColor
EmissiveColor
;
314
316
318
SColor
SpecularColor
;
319
321
350
f32
Shininess
;
351
353
355
f32
MaterialTypeParam
;
356
358
359
f32
MaterialTypeParam2
;
360
362
f32
Thickness
;
363
365
366
u8
ZBuffer
;
367
369
372
u8
AntiAliasing
;
373
375
379
u8
ColorMask
:4;
380
382
387
u8
ColorMaterial
:3;
388
390
392
E_BLEND_OPERATION
BlendOperation
:4;
393
395
397
u8
PolygonOffsetFactor
:3;
398
400
401
E_POLYGON_OFFSET
PolygonOffsetDirection
:1;
402
404
407
bool
Wireframe
:1;
408
410
bool
PointCloud
:1;
411
413
bool
GouraudShading
:1;
414
416
bool
Lighting
:1;
417
419
422
bool
ZWriteEnable
:1;
423
425
bool
BackfaceCulling
:1;
426
428
bool
FrontfaceCulling
:1;
429
431
bool
FogEnable
:1;
432
434
435
bool
NormalizeNormals
:1;
436
438
439
bool
UseMipMaps
:1;
440
442
444
core::matrix4
&
getTextureMatrix
(
u32
i)
445
{
446
return
TextureLayer
[i].
getTextureMatrix
();
447
}
448
450
452
const
core::matrix4
&
getTextureMatrix
(
u32
i)
const
453
{
454
if
(i<
MATERIAL_MAX_TEXTURES
)
455
return
TextureLayer
[i].
getTextureMatrix
();
456
else
457
return
core::IdentityMatrix
;
458
}
459
461
463
void
setTextureMatrix
(
u32
i,
const
core::matrix4
& mat)
464
{
465
if
(i>=
MATERIAL_MAX_TEXTURES
)
466
return
;
467
TextureLayer
[i].
setTextureMatrix
(mat);
468
}
469
471
473
ITexture
*
getTexture
(
u32
i)
const
474
{
475
return
i <
MATERIAL_MAX_TEXTURES
?
TextureLayer
[i].
Texture
: 0;
476
}
477
479
482
void
setTexture
(
u32
i,
ITexture
* tex)
483
{
484
if
(i>=
MATERIAL_MAX_TEXTURES
)
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
;
500
case
EMF_GOURAUD_SHADING
:
501
GouraudShading
= value;
break
;
502
case
EMF_LIGHTING
:
503
Lighting
= value;
break
;
504
case
EMF_ZBUFFER
:
505
ZBuffer
= value;
break
;
506
case
EMF_ZWRITE_ENABLE
:
507
ZWriteEnable
= value;
break
;
508
case
EMF_BACK_FACE_CULLING
:
509
BackfaceCulling
= value;
break
;
510
case
EMF_FRONT_FACE_CULLING
:
511
FrontfaceCulling
= value;
break
;
512
case
EMF_BILINEAR_FILTER
:
513
{
514
for
(
u32
i=0; i<
MATERIAL_MAX_TEXTURES
; ++i)
515
TextureLayer
[i].BilinearFilter = value;
516
}
517
break
;
518
case
EMF_TRILINEAR_FILTER
:
519
{
520
for
(
u32
i=0; i<
MATERIAL_MAX_TEXTURES
; ++i)
521
TextureLayer
[i].TrilinearFilter = value;
522
}
523
break
;
524
case
EMF_ANISOTROPIC_FILTER
:
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
;
536
case
EMF_NORMALIZE_NORMALS
:
537
NormalizeNormals
= value;
break
;
538
case
EMF_TEXTURE_WRAP
:
539
{
540
for
(
u32
i=0; i<
MATERIAL_MAX_TEXTURES
; ++i)
541
{
542
TextureLayer
[i].
TextureWrapU
= (
E_TEXTURE_CLAMP
)value;
543
TextureLayer
[i].
TextureWrapV
= (
E_TEXTURE_CLAMP
)value;
544
}
545
}
546
break
;
547
case
EMF_ANTI_ALIASING
:
548
AntiAliasing
= value?
EAAM_SIMPLE
:
EAAM_OFF
;
break
;
549
case
EMF_COLOR_MASK
:
550
ColorMask
= value?
ECP_ALL
:
ECP_NONE
;
break
;
551
case
EMF_COLOR_MATERIAL
:
552
ColorMaterial
= value?
ECM_DIFFUSE
:
ECM_NONE
;
break
;
553
case
EMF_USE_MIP_MAPS
:
554
UseMipMaps
= value;
break
;
555
case
EMF_BLEND_OPERATION
:
556
BlendOperation
= value?
EBO_ADD
:
EBO_NONE
;
break
;
557
case
EMF_POLYGON_OFFSET
:
558
PolygonOffsetFactor
= value?1:0;
559
PolygonOffsetDirection
=
EPO_BACK
;
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
;
577
case
EMF_GOURAUD_SHADING
:
578
return
GouraudShading
;
579
case
EMF_LIGHTING
:
580
return
Lighting
;
581
case
EMF_ZBUFFER
:
582
return
ZBuffer
!=
ECFN_NEVER
;
583
case
EMF_ZWRITE_ENABLE
:
584
return
ZWriteEnable
;
585
case
EMF_BACK_FACE_CULLING
:
586
return
BackfaceCulling
;
587
case
EMF_FRONT_FACE_CULLING
:
588
return
FrontfaceCulling
;
589
case
EMF_BILINEAR_FILTER
:
590
return
TextureLayer
[0].
BilinearFilter
;
591
case
EMF_TRILINEAR_FILTER
:
592
return
TextureLayer
[0].
TrilinearFilter
;
593
case
EMF_ANISOTROPIC_FILTER
:
594
return
TextureLayer
[0].
AnisotropicFilter
!=0;
595
case
EMF_FOG_ENABLE
:
596
return
FogEnable
;
597
case
EMF_NORMALIZE_NORMALS
:
598
return
NormalizeNormals
;
599
case
EMF_TEXTURE_WRAP
:
600
return
!(
TextureLayer
[0].
TextureWrapU
||
601
TextureLayer
[0].
TextureWrapV
||
602
TextureLayer
[1].
TextureWrapU
||
603
TextureLayer
[1].
TextureWrapV
||
604
TextureLayer
[2].
TextureWrapU
||
605
TextureLayer
[2].
TextureWrapV
||
606
TextureLayer
[3].
TextureWrapU
||
607
TextureLayer
[3].
TextureWrapV
);
608
case
EMF_ANTI_ALIASING
:
609
return
(
AntiAliasing
==1);
610
case
EMF_COLOR_MASK
:
611
return
(
ColorMask
!=
ECP_NONE
);
612
case
EMF_COLOR_MATERIAL
:
613
return
(
ColorMaterial
!=
ECM_NONE
);
614
case
EMF_USE_MIP_MAPS
:
615
return
UseMipMaps
;
616
case
EMF_BLEND_OPERATION
:
617
return
BlendOperation
!=
EBO_NONE
;
618
case
EMF_POLYGON_OFFSET
:
619
return
PolygonOffsetFactor
!= 0;
620
}
621
622
return
false
;
623
}
624
626
628
inline
bool
operator!=
(
const
SMaterial
& b)
const
629
{
630
bool
different =
631
MaterialType
!= b.
MaterialType
||
632
AmbientColor
!= b.
AmbientColor
||
633
DiffuseColor
!= b.
DiffuseColor
||
634
EmissiveColor
!= b.
EmissiveColor
||
635
SpecularColor
!= b.
SpecularColor
||
636
Shininess
!= b.
Shininess
||
637
MaterialTypeParam
!= b.
MaterialTypeParam
||
638
MaterialTypeParam2
!= b.
MaterialTypeParam2
||
639
Thickness
!= b.
Thickness
||
640
Wireframe
!= b.
Wireframe
||
641
PointCloud
!= b.
PointCloud
||
642
GouraudShading
!= b.
GouraudShading
||
643
Lighting
!= b.
Lighting
||
644
ZBuffer
!= b.
ZBuffer
||
645
ZWriteEnable
!= b.
ZWriteEnable
||
646
BackfaceCulling
!= b.
BackfaceCulling
||
647
FrontfaceCulling
!= b.
FrontfaceCulling
||
648
FogEnable
!= b.
FogEnable
||
649
NormalizeNormals
!= b.
NormalizeNormals
||
650
AntiAliasing
!= b.
AntiAliasing
||
651
ColorMask
!= b.
ColorMask
||
652
ColorMaterial
!= b.
ColorMaterial
||
653
BlendOperation
!= b.
BlendOperation
||
654
PolygonOffsetFactor
!= b.
PolygonOffsetFactor
||
655
PolygonOffsetDirection
!= b.
PolygonOffsetDirection
||
656
UseMipMaps
!= b.
UseMipMaps
;
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
670
bool
isTransparent
()
const
671
{
672
return
MaterialType
==
EMT_TRANSPARENT_ADD_COLOR
||
673
MaterialType
==
EMT_TRANSPARENT_ALPHA_CHANNEL
||
674
MaterialType
==
EMT_TRANSPARENT_VERTEX_ALPHA
||
675
MaterialType
==
EMT_TRANSPARENT_REFLECTION_2_LAYER
;
676
}
677
};
678
680
IRRLICHT_API
extern
SMaterial
IdentityMaterial
;
681
682
}
// end namespace video
683
}
// end namespace irr
684
685
#endif
Irrlicht Engine
Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Sun Apr 21 2019 20:57:28 for Irrlicht 3D Engine by
Doxygen
1.8.1.2