1 // Copyright (C) 2017 Michael Zeilfelder
\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_OVERRIDE_MATERIAL_H_INCLUDED__
\r
6 #define __S_OVERRIDE_MATERIAL_H_INCLUDED__
\r
8 #include "SMaterial.h"
\r
15 struct SOverrideMaterial
\r
17 //! The Material values
\r
20 //! Which values are overridden
\r
21 /** OR'ed values from E_MATERIAL_FLAGS. */
\r
24 //! For those flags in EnableFlags which affect layers, set which of the layers are affected
\r
25 bool EnableLayerFlags[MATERIAL_MAX_TEXTURES];
\r
27 //! Which textures are overridden
\r
28 bool EnableTextures[MATERIAL_MAX_TEXTURES];
\r
30 //! Overwrite complete layers (settings of EnableLayerFlags and EnableTextures don't matter then for layer data)
\r
31 bool EnableLayers[MATERIAL_MAX_TEXTURES];
\r
33 //! Set in which render passes the material override is active.
\r
34 /** OR'ed values from E_SCENE_NODE_RENDER_PASS. */
\r
37 //! Global enable flag, overwritten by the SceneManager in each pass
\r
38 /** NOTE: This is generally _not_ set by users of the engine, but the
\r
39 Scenemanager uses the EnablePass array and sets Enabled to true if the
\r
40 Override material is enabled in the current pass.
\r
41 As user you generally _only_ set EnablePasses.
\r
42 The exception is when rendering without SceneManager but using draw calls in the VideoDriver. */
\r
45 struct SMaterialTypeReplacement
\r
47 SMaterialTypeReplacement(s32 original, u32 replacement) : Original(original), Replacement(replacement) {}
\r
48 SMaterialTypeReplacement(u32 replacement) : Original(-1), Replacement(replacement) {}
\r
50 //! SMaterial.MaterialType to replace.
\r
51 //! -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)
\r
54 //! MaterialType to used to override Original (either one of E_MATERIAL_TYPE or a shader material id)
\r
58 //! To overwrite SMaterial::MaterialType
\r
59 core::array<SMaterialTypeReplacement> MaterialTypes;
\r
61 //! Default constructor
\r
62 SOverrideMaterial() : EnableFlags(0), EnablePasses(0), Enabled(false)
\r
66 //! disable overrides and reset all flags
\r
72 for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
\r
74 EnableLayerFlags[i] = true; // doesn't do anything unless EnableFlags is set, just saying by default all texture layers are affected by flags
\r
75 EnableTextures[i] = false;
\r
76 EnableLayers[i] = false;
\r
78 MaterialTypes.clear();
\r
81 //! Apply the enabled overrides
\r
82 void apply(SMaterial& material)
\r
86 for (u32 i = 0; i < MaterialTypes.size(); ++i)
\r
88 const SMaterialTypeReplacement& mtr = MaterialTypes[i];
\r
89 if (mtr.Original < 0 || (s32)mtr.Original == material.MaterialType)
\r
90 material.MaterialType = (E_MATERIAL_TYPE)mtr.Replacement;
\r
92 for (u32 f=0; f<32; ++f)
\r
94 const u32 num=(1<<f);
\r
95 if (EnableFlags & num)
\r
99 case EMF_WIREFRAME: material.Wireframe = Material.Wireframe; break;
\r
100 case EMF_POINTCLOUD: material.PointCloud = Material.PointCloud; break;
\r
101 case EMF_GOURAUD_SHADING: material.GouraudShading = Material.GouraudShading; break;
\r
102 case EMF_LIGHTING: material.Lighting = Material.Lighting; break;
\r
103 case EMF_ZBUFFER: material.ZBuffer = Material.ZBuffer; break;
\r
104 case EMF_ZWRITE_ENABLE: material.ZWriteEnable = Material.ZWriteEnable; break;
\r
105 case EMF_BACK_FACE_CULLING: material.BackfaceCulling = Material.BackfaceCulling; break;
\r
106 case EMF_FRONT_FACE_CULLING: material.FrontfaceCulling = Material.FrontfaceCulling; break;
\r
107 case EMF_BILINEAR_FILTER:
\r
108 for ( u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
110 if ( EnableLayerFlags[i] )
\r
112 material.TextureLayer[i].BilinearFilter = Material.TextureLayer[i].BilinearFilter;
\r
116 case EMF_TRILINEAR_FILTER:
\r
117 for ( u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
119 if ( EnableLayerFlags[i] )
\r
121 material.TextureLayer[i].TrilinearFilter = Material.TextureLayer[i].TrilinearFilter;
\r
125 case EMF_ANISOTROPIC_FILTER:
\r
126 for ( u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
128 if ( EnableLayerFlags[i] )
\r
130 material.TextureLayer[i].AnisotropicFilter = Material.TextureLayer[i].AnisotropicFilter;
\r
134 case EMF_FOG_ENABLE: material.FogEnable = Material.FogEnable; break;
\r
135 case EMF_NORMALIZE_NORMALS: material.NormalizeNormals = Material.NormalizeNormals; break;
\r
136 case EMF_TEXTURE_WRAP:
\r
137 for ( u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i)
\r
139 if ( EnableLayerFlags[i] )
\r
141 material.TextureLayer[i].TextureWrapU = Material.TextureLayer[i].TextureWrapU;
\r
142 material.TextureLayer[i].TextureWrapV = Material.TextureLayer[i].TextureWrapV;
\r
143 material.TextureLayer[i].TextureWrapW = Material.TextureLayer[i].TextureWrapW;
\r
147 case EMF_ANTI_ALIASING: material.AntiAliasing = Material.AntiAliasing; break;
\r
148 case EMF_COLOR_MASK: material.ColorMask = Material.ColorMask; break;
\r
149 case EMF_COLOR_MATERIAL: material.ColorMaterial = Material.ColorMaterial; break;
\r
150 case EMF_USE_MIP_MAPS: material.UseMipMaps = Material.UseMipMaps; break;
\r
151 case EMF_BLEND_OPERATION: material.BlendOperation = Material.BlendOperation; break;
\r
152 case EMF_BLEND_FACTOR: material.BlendFactor = Material.BlendFactor; break;
\r
153 case EMF_POLYGON_OFFSET:
\r
154 material.PolygonOffsetDirection = Material.PolygonOffsetDirection;
\r
155 material.PolygonOffsetFactor = Material.PolygonOffsetFactor;
\r
156 material.PolygonOffsetDepthBias = Material.PolygonOffsetDepthBias;
\r
157 material.PolygonOffsetSlopeScale = Material.PolygonOffsetSlopeScale;
\r
162 for(u32 i=0; i<MATERIAL_MAX_TEXTURES; ++i )
\r
164 if ( EnableLayers[i] )
\r
166 material.TextureLayer[i] = Material.TextureLayer[i];
\r
168 else if ( EnableTextures[i] )
\r
170 material.TextureLayer[i].Texture = Material.TextureLayer[i].Texture;
\r
178 } // end namespace video
\r
179 } // end namespace irr
\r
181 #endif // __S_OVERRIDE_MATERIAL_H_INCLUDED__
\r