i added support for multiple materials and more material types. also i removed all compiler warnings
Code: Select all
#include "effectWrapper.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace irr;
using namespace scene;
using namespace gui;
using namespace video;
using namespace core;
using namespace io;
class DepthShaderCB : public video::IShaderConstantSetCallBack
{
public:
DepthShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
f32 maxdist = effect->getMaxShadowDistanceFromLight();
services->setPixelShaderConstant("MaxD", reinterpret_cast<f32*>(&maxdist), 1);
}
};
class ShadowShaderCB : public video::IShaderConstantSetCallBack
{
public:
ShadowShaderCB(effectHandler* effectIn) : effect(effectIn), Tex2(false), EnableLighting(0) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
bool Tex2;
float EnableLighting;
virtual void OnSetMaterial(const SMaterial& material)
{
Tex2 = (material.getTexture(2) == effect->getShadowMapTexture());
EnableLighting = material.Lighting;
}
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
worldViewProj = effect->getLightCamera()->getProjectionMatrix();
worldViewProj *= effect->getLightCamera()->getViewMatrix();
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj2", worldViewProj.pointer(), 16);
if(EnableLighting > 0.5f)
{
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
}
f32 shaddark = effect->getShadowDarkness();
services->setVertexShaderConstant("ShadDark", reinterpret_cast<f32*>(&shaddark), 1);
f32 maxdist = effect->getMaxShadowDistanceFromLight();
services->setVertexShaderConstant("MaxD", reinterpret_cast<f32*>(&maxdist), 1);
services->setVertexShaderConstant("EnableLighting", reinterpret_cast<f32*>(&EnableLighting), 1);
if(services->getVideoDriver()->getDriverType() == EDT_OPENGL)
{
int var0=0;
services->setPixelShaderConstant("ColoredTextureSampler", (float*)(&var0), 1);
if(Tex2)
{
int var1=1;
services->setPixelShaderConstant("DetailMap", (float*)(&var1), 1);
int var2=2;
services->setPixelShaderConstant("ShadowMapSampler", (float*)(&var2), 1);
}
else
{
int var1=1;
services->setPixelShaderConstant("ShadowMapSampler", (float*)(&var1), 1);
}
}
}
};
class LightShaderCB : public video::IShaderConstantSetCallBack
{
public:
LightShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
}
};
class WiggleShaderCB : public video::IShaderConstantSetCallBack
{
public:
WiggleShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("World", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_WORLD);
worldViewProj.getInverse(worldViewProj);
worldViewProj.getTransposed(worldViewProj);
services->setVertexShaderConstant("mInvWorld", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_VIEW);
worldViewProj.getInverse(worldViewProj);
services->setVertexShaderConstant("ViewI", worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
f32 currtime = effect->getTime();
services->setVertexShaderConstant("Timer", reinterpret_cast<f32*>(&currtime), 1);
}
};
class DepthWiggleShaderCB : public video::IShaderConstantSetCallBack
{
public:
DepthWiggleShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
f32 maxdist = effect->getMaxShadowDistanceFromLight();
services->setVertexShaderConstant("MaxD", reinterpret_cast<f32*>(&maxdist), 1);
f32 currtime = effect->getTime();
services->setVertexShaderConstant("Timer", reinterpret_cast<f32*>(&currtime), 1);
}
};
class AnisoShaderCB : public video::IShaderConstantSetCallBack
{
public:
AnisoShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("World", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_VIEW);
worldViewProj.getInverse(worldViewProj);
services->setVertexShaderConstant("ViewI", worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
}
};
class PhongShaderCB : public video::IShaderConstantSetCallBack
{
public:
PhongShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("World", worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
services->setVertexShaderConstant("CamPos", reinterpret_cast<f32*>(&lightPosOS), 4);
}
};
class BRDFShaderCB : public video::IShaderConstantSetCallBack
{
public:
BRDFShaderCB(effectHandler* effectIn) : effect(effectIn) {};
effectHandler* effect;
core::matrix4 worldViewProj;
core::matrix4 invWorld;
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
worldViewProj = driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("World", worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = effect->getLightCamera()->getPosition();
invWorld.transformVect(lightPosOS,lightPosOS);
services->setVertexShaderConstant("LightPos", reinterpret_cast<f32*>(&lightPosOS), 4);
services->setVertexShaderConstant("CamPos", reinterpret_cast<f32*>(&lightPosOS), 4);
if(services->getVideoDriver()->getDriverType() == EDT_OPENGL)
{
int var0=0;
services->setPixelShaderConstant("hmapSampler", (float*)(&var0), 1);
int var1=1;
services->setPixelShaderConstant("nmapSampler", (float*)(&var1), 1);
}
}
};
effectHandler::effectHandler(IrrlichtDevice* dev, dimension2d<s32> mapSize)
{
device = dev;
smgr = dev->getSceneManager();
driver = dev->getVideoDriver();
CShaderPreprocessor* sPP = new CShaderPreprocessor(driver);
sPP->addShaderDefine("MAPRES", mapSize.Height);
driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
ShadowMapTex = driver->createRenderTargetTexture(mapSize);
driver->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
cameraBuffer = smgr->getActiveCamera();
lightCam = smgr->addCameraSceneNode();
lightCam->setFarValue(200);
maxdist = 200;
ClearColour = SColor(0,0,0,0);
shadowsUnsupported = false;
smgr->setActiveCamera(cameraBuffer);
stringc platformExt = ".glsl";
if(driver->getDriverType() == EDT_DIRECT3D9)
platformExt = ".hlsl";
// For shadows
stringc DFNV = stringc("shaders/ShadowPass1V") + platformExt;
stringc DFNP = stringc("shaders/ShadowPass1P") + platformExt;
stringc SDFNV = stringc("shaders/ShadowPass2V") + platformExt;
stringc SDFNP = stringc("shaders/ShadowPass2P") + platformExt;
stringc GOOCHV = stringc("shaders/ShaderGoochPtV") + platformExt;
stringc WIGGLEV = stringc("shaders/ShaderMrWiggleV") + platformExt;
stringc DEPTHWIGGLEV = stringc("shaders/ShaderDepthWiggleV") + platformExt;
stringc ANISOV = stringc("shaders/ShaderAnisoV") + platformExt;
stringc PHONGV = stringc("shaders/ShaderPhongV") + platformExt;
stringc BRDFV = stringc("shaders/ShaderBRDFV") + platformExt;
stringc GOOCHP = stringc("shaders/ShaderGoochPtP") + platformExt;
stringc WIGGLEP = stringc("shaders/ShaderMrWiggleP") + platformExt;
stringc DEPTHWIGGLEP = stringc("shaders/ShaderDepthWiggleP") + platformExt;
stringc ANISOP = stringc("shaders/ShaderAnisoP") + platformExt;
stringc PHONGP = stringc("shaders/ShaderPhongP") + platformExt;
stringc BRDFP = stringc("shaders/ShaderBRDFP") + platformExt;
video::IGPUProgrammingServices* gpu = driver->getGPUProgrammingServices();
if(gpu && ((driver->getDriverType() == EDT_OPENGL && driver->queryFeature(EVDF_ARB_GLSL)) ||
(driver->getDriverType() == EDT_DIRECT3D9 && driver->queryFeature(EVDF_PIXEL_SHADER_1_4))))
{
DepthShaderCB* mc = new DepthShaderCB(this);
ShadowShaderCB* mc1 = new ShadowShaderCB(this);
BRDFShaderCB* mc4 = new BRDFShaderCB(this);
LightShaderCB* mc5 = new LightShaderCB(this);
WiggleShaderCB* mc6 = new WiggleShaderCB(this);
DepthWiggleShaderCB* mc7 = new DepthWiggleShaderCB(this);
AnisoShaderCB* mc8 = new AnisoShaderCB(this);
PhongShaderCB* mc9 = new PhongShaderCB(this);
Brdf = gpu->addHighLevelShaderMaterialFromFiles(
BRDFV.c_str(), "vertexMain", video::EVST_VS_1_1,
BRDFP.c_str(), "pixelMain", video::EPST_PS_1_4,
mc4, video::EMT_SOLID);
Gooch = gpu->addHighLevelShaderMaterialFromFiles(
GOOCHV.c_str(), "vertexMain", video::EVST_VS_1_1,
GOOCHP.c_str(), "pixelMain", video::EPST_PS_1_4,
mc5, video::EMT_SOLID);
Wiggle = gpu->addHighLevelShaderMaterialFromFiles(
WIGGLEV.c_str(), "vertexMain", video::EVST_VS_1_1,
WIGGLEP.c_str(), "pixelMain", video::EPST_PS_1_4,
mc6, video::EMT_SOLID);
Aniso = gpu->addHighLevelShaderMaterialFromFiles(
ANISOV.c_str(), "vertexMain", video::EVST_VS_1_1,
ANISOP.c_str(), "pixelMain", video::EPST_PS_1_4,
mc8, video::EMT_SOLID);
Phong = gpu->addHighLevelShaderMaterialFromFiles(
PHONGV.c_str(), "vertexMain", video::EVST_VS_1_1,
PHONGP.c_str(), "pixelMain", video::EPST_PS_1_4,
mc9, video::EMT_SOLID);
if(driver->queryFeature(EVDF_PIXEL_SHADER_2_0) || driver->getDriverType() == EDT_OPENGL)
{
Depth = gpu->addHighLevelShaderMaterialFromFiles(
DFNV.c_str(), "vertexMain", video::EVST_VS_2_0,
DFNP.c_str(), "pixelMain", video::EPST_PS_2_0,
mc, video::EMT_SOLID);
DepthWiggle = gpu->addHighLevelShaderMaterialFromFiles(
DEPTHWIGGLEV.c_str(), "vertexMain", video::EVST_VS_2_0,
DEPTHWIGGLEP.c_str(), "pixelMain", video::EPST_PS_2_0,
mc7, video::EMT_SOLID);
sPP->addShaderDefine("SAMPLE_AMOUNT",1);
Solid = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_SOLID);
sPP->addShaderDefine("SAMPLE_AMOUNT",4);
SolidPCF4 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_SOLID);
sPP->addShaderDefine("SAMPLE_AMOUNT",7);
SolidPCF8 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_SOLID);
sPP->addShaderDefine("SAMPLE_AMOUNT",12);
if(driver->queryFeature(EVDF_PIXEL_SHADER_3_0) || driver->getDriverType() == EDT_OPENGL)
SolidPCF12 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_3_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_3_0,
mc1, video::EMT_SOLID);
else
SolidPCF12 = SolidPCF8;
sPP->addShaderDefine("SAMPLE_AMOUNT",16);
if(driver->queryFeature(EVDF_PIXEL_SHADER_3_0) || driver->getDriverType() == EDT_OPENGL)
SolidPCF16 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_3_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_3_0,
mc1, video::EMT_SOLID);
else
SolidPCF16 = SolidPCF8;
// Enable 2 texture layers.
sPP->addShaderDefine("2_LAYER",1);
sPP->addShaderDefine("SAMPLE_AMOUNT",1);
Detail = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_DETAIL_MAP);
sPP->addShaderDefine("SAMPLE_AMOUNT",4);
DetailPCF4 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_DETAIL_MAP);
sPP->addShaderDefine("SAMPLE_AMOUNT",7);
DetailPCF8 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_2_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_2_0,
mc1, video::EMT_DETAIL_MAP);
sPP->addShaderDefine("SAMPLE_AMOUNT",12);
if(driver->queryFeature(EVDF_PIXEL_SHADER_3_0) || driver->getDriverType() == EDT_OPENGL)
DetailPCF12 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_3_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_3_0,
mc1, video::EMT_DETAIL_MAP);
else
DetailPCF12 = DetailPCF8;
sPP->addShaderDefine("SAMPLE_AMOUNT",16);
if(driver->queryFeature(EVDF_PIXEL_SHADER_3_0) || driver->getDriverType() == EDT_OPENGL)
DetailPCF16 = gpu->addHighLevelShaderMaterial(
sPP->ppShaderFF(SDFNV).c_str(), "vertexMain", video::EVST_VS_3_0,
sPP->ppShaderFF(SDFNP).c_str(), "pixelMain", video::EPST_PS_3_0,
mc1, video::EMT_DETAIL_MAP);
else
DetailPCF16 = DetailPCF8;
}
else
{
Depth = EMT_SOLID;
DepthWiggle = EMT_SOLID;
Solid = EMT_SOLID;
SolidPCF4 = EMT_SOLID;
SolidPCF8 = EMT_SOLID;
SolidPCF12 = EMT_SOLID;
SolidPCF16 = EMT_SOLID;
Detail = EMT_DETAIL_MAP;
DetailPCF4 = EMT_DETAIL_MAP;
DetailPCF8 = EMT_DETAIL_MAP;
DetailPCF12 = EMT_DETAIL_MAP;
DetailPCF16 = EMT_DETAIL_MAP;
std::cout << "ShadowMaps: Shadow maps not supported on this system." << std::endl;
shadowsUnsupported = true;
}
mc->drop();
mc1->drop();
mc4->drop();
mc5->drop();
mc6->drop();
mc7->drop();
mc8->drop();
mc9->drop();
}
else
{
Depth = EMT_SOLID;
Solid = EMT_SOLID;
SolidPCF4 = EMT_SOLID;
SolidPCF8 = EMT_SOLID;
SolidPCF12 = EMT_SOLID;
SolidPCF16 = EMT_SOLID;
Detail = EMT_DETAIL_MAP;
DetailPCF4 = EMT_DETAIL_MAP;
DetailPCF8 = EMT_DETAIL_MAP;
DetailPCF12 = EMT_DETAIL_MAP;
DetailPCF16 = EMT_DETAIL_MAP;
Brdf = EMT_SOLID;
Aniso = EMT_SOLID;
Phong = EMT_SOLID;
Wiggle = EMT_SOLID;
Gooch = EMT_SOLID;
std::cout << "ShadowMaps: Shadow maps not supported on this system." << std::endl;
std::cout << "Effects: Effects not supported on this system." << std::endl;
}
DepthShaderCB* mc = new DepthShaderCB(this);
Depth = gpu->addHighLevelShaderMaterialFromFiles(
DFNV.c_str(), "vertexMain", video::EVST_VS_2_0,
DFNP.c_str(), "pixelMain", video::EPST_PS_2_0,
mc, video::EMT_SOLID);
};
void effectHandler::addShadowToNode(irr::scene::ISceneNode *node, E_FILTER_TYPE filterType)
{
for(u32 u = 0; u < node->getMaterialCount(); u++)
{
SMaterial& material = node->getMaterial(u);
switch(material.MaterialType)
{
case EMT_DETAIL_MAP:
case EMT_LIGHTMAP:
case EMT_LIGHTMAP_LIGHTING_M2:
case EMT_LIGHTMAP_LIGHTING_M4:
case EMT_NORMAL_MAP_SOLID:
case EMT_NORMAL_MAP_TRANSPARENT_ADD_COLOR:
case EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA:
case EMT_REFLECTION_2_LAYER:
case EMT_PARALLAX_MAP_SOLID:
case EMT_PARALLAX_MAP_TRANSPARENT_ADD_COLOR:
case EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA:
//! Set shadowMapTexture as texture
material.TextureLayer[2].Texture = ShadowMapTex;
//! Need to disable bilinear for 16-bit depth precision.
material.TextureLayer[2].BilinearFilter = false;
break;
case EMT_SOLID:
//! Set shadowMapTexture as texture
material.TextureLayer[1].Texture = ShadowMapTex;
//! Need to disable bilinear for 16-bit depth precision.
material.TextureLayer[1].BilinearFilter = false;
break;
default:
return; //! unknown type
break;
}
}
shadowNode snode;
snode.node = node;
snode.filterType = filterType;
snode.materialType = ((IAnimatedMeshSceneNode*)node)->getMaterial(0).MaterialType;
snode.depthOnly = false;
snode.exclude = false;
shadowNodeArray.push_back(snode);
}
void effectHandler::addNodeToDepthPass(irr::scene::ISceneNode *node)
{
shadowNode snode;
snode.node = node;
snode.materialType = node->getMaterial(0).MaterialType;
snode.depthOnly = true;
snode.exclude = false;
shadowNodeArray.push_back(snode);
}
void effectHandler::excludeNodeFromDepthPass(irr::scene::ISceneNode *node)
{
shadowNode snode;
snode.node = node;
snode.exclude = true;
shadowNodeArray.push_back(snode);
}
void effectHandler::removeShadowFromNode(irr::scene::ISceneNode *node)
{
s32 i = 0;
while(shadowNodeArray[i].node != node && i < (s32)shadowNodeArray.size())
i++;
if(i < (s32)shadowNodeArray.size())
shadowNodeArray.erase(i);
}
void effectHandler::addEffectToNode(ISceneNode* node, E_EFFECT_TYPE etype)
{
switch(etype)
{
case EET_GOOCH:
node->setMaterialType((E_MATERIAL_TYPE)Gooch);
return;
case EET_MRWIGGLE:
node->setMaterialType((E_MATERIAL_TYPE)Wiggle);
return;
case EET_ANISO:
node->setMaterialType((E_MATERIAL_TYPE)Aniso);
return;
case EET_PHONG:
node->setMaterialType((E_MATERIAL_TYPE)Phong);
return;
case EET_BRDF:
node->setMaterialType((E_MATERIAL_TYPE)Brdf);
return;
case EET_COUNT:
return;//!FIXWARNING
}
}
void effectHandler::update()
{
if(shadowsUnsupported)
return;
cameraBuffer = smgr->getActiveCamera();
smgr->setActiveCamera(lightCam);
driver->setRenderTarget(ShadowMapTex,true,true,SColor(255,255,255,255));
for(u32 i = 0;i < shadowNodeArray.size(); i++)
{
if(shadowNodeArray[i].exclude)
{
shadowNodeArray[i].node->setVisible(false);
}
else
{
if(shadowNodeArray[i].materialType == Wiggle)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)DepthWiggle);
else
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)Depth);
}
}
smgr->drawAll();
driver->setRenderTarget(0,true,true,ClearColour);
smgr->setActiveCamera(cameraBuffer);
for(u32 i = 0;i < shadowNodeArray.size(); i++)
{
if(shadowNodeArray[i].exclude)
{
shadowNodeArray[i].node->setVisible(true);
}
else
{
if(shadowNodeArray[i].depthOnly)
{
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)shadowNodeArray[i].materialType);
}
else
{
if(shadowNodeArray[i].materialType == EMT_SOLID)
{
if(shadowNodeArray[i].filterType == EFT_NONE)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)Solid);
else if(shadowNodeArray[i].filterType == EFT_4PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)SolidPCF4);
else if(shadowNodeArray[i].filterType == EFT_8PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)SolidPCF8);
else if(shadowNodeArray[i].filterType == EFT_12PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)SolidPCF12);
else if(shadowNodeArray[i].filterType == EFT_16PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)SolidPCF16);
}
else if(shadowNodeArray[i].materialType == EMT_DETAIL_MAP || shadowNodeArray[i].materialType == EMT_LIGHTMAP)
{
if(shadowNodeArray[i].filterType == EFT_NONE)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)Detail);
else if(shadowNodeArray[i].filterType == EFT_4PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)DetailPCF4);
else if(shadowNodeArray[i].filterType == EFT_8PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)DetailPCF8);
else if(shadowNodeArray[i].filterType == EFT_12PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)DetailPCF12);
else if(shadowNodeArray[i].filterType == EFT_16PCF)
shadowNodeArray[i].node->setMaterialType((E_MATERIAL_TYPE)DetailPCF16);
}
}
}
}
}
void effectHandler::setMaxShadowDistanceFromLight(irr::u32 distance)
{
lightCam->setFarValue(distance);
maxdist = distance;
}
void effectHandler::setShadowDarkness(irr::f32 shadalpha)
{
shaddark = shadalpha;
}
// Copyright (C) Ahmed Hilali 2007-2008
problem is my textures are flipped (OpenGL) and i dont have any diffuse materials(with or without these changes).
i just saw that the sturct also contains the material type... thats a problem