Code: Select all
struct SOverrideMaterial
{
//! The Material values
SMaterial Material;
//! Which values are taken for override
/** OR'ed values from E_MATERIAL_FLAGS. */
u32 EnableFlags;
//! Set in which render passes the material override is active.
/** OR'ed values from E_SCENE_NODE_RENDER_PASS. */
u16 EnablePasses;
//! Global enable flag, overwritten by the SceneManager in each pass
/** The Scenemanager uses the EnablePass array and sets Enabled to
true if the Override material is enabled in the current pass. */
bool Enabled;
//! Default constructor
SOverrideMaterial() : EnableFlags(0), EnablePasses(0), Enabled(false) {}
//! Apply the enabled overrides
void apply(SMaterial& material)
{
if (Enabled)
{
//This is something a bit bold, but it works for me
material.MaterialType = Material.MaterialType;
//This is something a bit bold, but it works for me
for (u32 i=0; i<32; ++i)
{
const u32 num=(1<<i);
if (EnableFlags & num)
{
switch (num)
{
case EMF_WIREFRAME: material.Wireframe = Material.Wireframe; break;
case EMF_POINTCLOUD: material.PointCloud = Material.PointCloud; break;
case EMF_GOURAUD_SHADING: material.GouraudShading = Material.GouraudShading; break;
case EMF_LIGHTING: material.Lighting = Material.Lighting; break;
case EMF_ZBUFFER: material.ZBuffer = Material.ZBuffer; break;
case EMF_ZWRITE_ENABLE: material.ZWriteEnable = Material.ZWriteEnable; break;
case EMF_BACK_FACE_CULLING: material.BackfaceCulling = Material.BackfaceCulling; break;
case EMF_FRONT_FACE_CULLING: material.FrontfaceCulling = Material.FrontfaceCulling; break;
case EMF_FOG_ENABLE: material.FogEnable = Material.FogEnable; break;
case EMF_NORMALIZE_NORMALS: material.NormalizeNormals = Material.NormalizeNormals; break;
case EMF_ANTI_ALIASING: material.AntiAliasing = Material.AntiAliasing; break;
case EMF_COLOR_MASK: material.ColorMask = Material.ColorMask; break;
case EMF_USE_MIP_MAPS: material.UseMipMaps = Material.UseMipMaps; break;
case EMF_BILINEAR_FILTER: material.TextureLayer[0].BilinearFilter = Material.TextureLayer[0].BilinearFilter; break;
case EMF_TRILINEAR_FILTER: material.TextureLayer[0].TrilinearFilter = Material.TextureLayer[0].TrilinearFilter; break;
case EMF_ANISOTROPIC_FILTER: material.TextureLayer[0].AnisotropicFilter = Material.TextureLayer[0].AnisotropicFilter; break;
case EMF_TEXTURE_WRAP:
material.TextureLayer[0].TextureWrapU = Material.TextureLayer[0].TextureWrapU;
material.TextureLayer[0].TextureWrapV = Material.TextureLayer[0].TextureWrapV;
break;
}
}
}
}
}
};
A word of caution: You have to disable all the passes after when you don't need the override anymore! Or else, it may work unexpectedly.
This is a quick patch, and i don't give any explicit warranty for it.
After you change the material override, you have to recompile. Make sure you may step back the changes done if things get out of hands!!.