1 // Copyright (C) 2017 Michael Zeilfelder
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
15 struct SOverrideMaterial
17 //! The Material values
20 //! Which values are overridden
21 /** OR'ed values from E_MATERIAL_PROPS. */
24 //! For those properties in EnableProps which affect layers, set which of the layers are affected
25 bool EnableLayerProps
[MATERIAL_MAX_TEXTURES
];
27 //! Which textures are overridden
28 bool EnableTextures
[MATERIAL_MAX_TEXTURES
];
30 //! Overwrite complete layers (settings of EnableLayerProps and EnableTextures don't matter then for layer data)
31 bool EnableLayers
[MATERIAL_MAX_TEXTURES
];
33 //! Set in which render passes the material override is active.
34 /** OR'ed values from E_SCENE_NODE_RENDER_PASS. */
37 //! Global enable flag, overwritten by the SceneManager in each pass
38 /** NOTE: This is generally _not_ set by users of the engine, but the
39 Scenemanager uses the EnablePass array and sets Enabled to true if the
40 Override material is enabled in the current pass.
41 As user you generally _only_ set EnablePasses.
42 The exception is when rendering without SceneManager but using draw calls in the VideoDriver. */
45 struct SMaterialTypeReplacement
47 SMaterialTypeReplacement(s32 original
, u32 replacement
) :
48 Original(original
), Replacement(replacement
) {}
49 SMaterialTypeReplacement(u32 replacement
) :
50 Original(-1), Replacement(replacement
) {}
52 //! SMaterial.MaterialType to replace.
53 //! -1 for all types or a specific value to only replace that one (which is either one of E_MATERIAL_TYPE or a shader material id)
56 //! MaterialType to used to override Original (either one of E_MATERIAL_TYPE or a shader material id)
60 //! To overwrite SMaterial::MaterialType
61 std::vector
<SMaterialTypeReplacement
> MaterialTypes
;
63 //! Default constructor
65 EnableProps(0), EnablePasses(0), Enabled(false)
69 //! disable overrides and reset all properties
75 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
76 EnableLayerProps
[i
] = true; // doesn't do anything unless EnableProps is set, just saying by default all texture layers are affected by properties
77 EnableTextures
[i
] = false;
78 EnableLayers
[i
] = false;
80 MaterialTypes
.clear();
83 //! Apply the enabled overrides
84 void apply(SMaterial
&material
)
87 for (const auto &mtr
: MaterialTypes
) {
88 if (mtr
.Original
< 0 || mtr
.Original
== (s32
)material
.MaterialType
)
89 material
.MaterialType
= (E_MATERIAL_TYPE
)mtr
.Replacement
;
91 for (u32 f
= 0; f
< 32; ++f
) {
92 const u32 num
= (1 << f
);
93 if (EnableProps
& num
) {
96 material
.Wireframe
= Material
.Wireframe
;
99 material
.PointCloud
= Material
.PointCloud
;
102 material
.ZBuffer
= Material
.ZBuffer
;
104 case EMP_ZWRITE_ENABLE
:
105 material
.ZWriteEnable
= Material
.ZWriteEnable
;
107 case EMP_BACK_FACE_CULLING
:
108 material
.BackfaceCulling
= Material
.BackfaceCulling
;
110 case EMP_FRONT_FACE_CULLING
:
111 material
.FrontfaceCulling
= Material
.FrontfaceCulling
;
114 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
115 if (EnableLayerProps
[i
]) {
116 material
.TextureLayers
[i
].MinFilter
= Material
.TextureLayers
[i
].MinFilter
;
121 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
122 if (EnableLayerProps
[i
]) {
123 material
.TextureLayers
[i
].MagFilter
= Material
.TextureLayers
[i
].MagFilter
;
127 case EMP_ANISOTROPIC_FILTER
:
128 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
129 if (EnableLayerProps
[i
]) {
130 material
.TextureLayers
[i
].AnisotropicFilter
= Material
.TextureLayers
[i
].AnisotropicFilter
;
135 material
.FogEnable
= Material
.FogEnable
;
137 case EMP_TEXTURE_WRAP
:
138 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
139 if (EnableLayerProps
[i
]) {
140 material
.TextureLayers
[i
].TextureWrapU
= Material
.TextureLayers
[i
].TextureWrapU
;
141 material
.TextureLayers
[i
].TextureWrapV
= Material
.TextureLayers
[i
].TextureWrapV
;
142 material
.TextureLayers
[i
].TextureWrapW
= Material
.TextureLayers
[i
].TextureWrapW
;
146 case EMP_ANTI_ALIASING
:
147 material
.AntiAliasing
= Material
.AntiAliasing
;
150 material
.ColorMask
= Material
.ColorMask
;
152 case EMP_USE_MIP_MAPS
:
153 material
.UseMipMaps
= Material
.UseMipMaps
;
155 case EMP_BLEND_OPERATION
:
156 material
.BlendOperation
= Material
.BlendOperation
;
158 case EMP_BLEND_FACTOR
:
159 material
.BlendFactor
= Material
.BlendFactor
;
161 case EMP_POLYGON_OFFSET
:
162 material
.PolygonOffsetDepthBias
= Material
.PolygonOffsetDepthBias
;
163 material
.PolygonOffsetSlopeScale
= Material
.PolygonOffsetSlopeScale
;
168 for (u32 i
= 0; i
< MATERIAL_MAX_TEXTURES
; ++i
) {
169 if (EnableLayers
[i
]) {
170 material
.TextureLayers
[i
] = Material
.TextureLayers
[i
];
171 } else if (EnableTextures
[i
]) {
172 material
.TextureLayers
[i
].Texture
= Material
.TextureLayers
[i
].Texture
;
179 } // end namespace video
180 } // end namespace irr