I've tried to make the XEffects example run with Trunk SVN 5017.
No compilation error, work correctly with the directX driver.
But if you try OPENGL the rendering is bad as this
Is the way openGL work has changed and must be handled differently from the DirectX driver? I was able to "fix" a little the problems with the post process shader by changing the shader constant from f32 to int. But the lightmapping doesn't work at all, I don't see any light source rendered. Is there something in the GLSL shader that is not supported from the current version of Irrlicht?
Do we have to set the constant differently when we use DirectX and OpenGL?
EDIT: Really strange. I've tried the other examples and they run fine. It's only the first example that give this problem.
Here is the "fixed" EffectCB.h for using it with Irrlicht 1.9 SVN. The changes are mostly for defining the shader constants. This work in DirectX and GL with my version of Irrlicht SVN 1.9. Only example 1 fail to work.
Code: Select all
#ifndef H_XEFFECTS_CB
#define H_XEFFECTS_CB
#include "EffectHandler.h"
using namespace irr;
using namespace scene;
using namespace video;
using namespace core;
class DepthShaderCB : public video::IShaderConstantSetCallBack
{
public:
DepthShaderCB(EffectHandler* effectIn) : effect(effectIn) {};
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(services->getVertexShaderConstantID("mWorldViewProj"), worldViewProj.pointer(), 16);
services->setVertexShaderConstant(services->getVertexShaderConstantID("MaxD"), &FarLink, 1);
}
EffectHandler* effect;
f32 FarLink;
core::matrix4 worldViewProj;
};
class ShadowShaderCB : public video::IShaderConstantSetCallBack
{
public:
ShadowShaderCB(EffectHandler* effectIn) : effect(effectIn) {};
virtual void OnSetMaterial(const SMaterial& material) {}
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
IVideoDriver* driver = services->getVideoDriver();
matrix4 worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant(services->getVertexShaderConstantID("mWorldViewProj"), worldViewProj.pointer(), 16);
worldViewProj = ProjLink;
worldViewProj *= ViewLink;
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant(services->getVertexShaderConstantID("mWorldViewProj2"), worldViewProj.pointer(), 16);
driver->getTransform(video::ETS_WORLD).getInverse(invWorld);
vector3df lightPosOS = LightLink;
invWorld.transformVect(lightPosOS);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LightPos"), reinterpret_cast<f32*>(&lightPosOS.X), 4);
services->setVertexShaderConstant(services->getVertexShaderConstantID("MaxD"), reinterpret_cast<f32*>(&FarLink), 1);
services->setVertexShaderConstant(services->getVertexShaderConstantID("MAPRES"), &MapRes, 1);
services->setPixelShaderConstant(services->getPixelShaderConstantID("LightColour"), reinterpret_cast<f32*>(&LightColour.r), 4);
}
EffectHandler* effect;
core::matrix4 invWorld;
video::SColorf LightColour;
core::matrix4 ProjLink;
core::matrix4 ViewLink;
core::vector3df LightLink;
f32 FarLink, MapRes;
};
class ScreenQuadCB : public irr::video::IShaderConstantSetCallBack
{
public:
ScreenQuadCB(EffectHandler* effectIn, bool defaultV = true)
: effect(effectIn), defaultVertexShader(defaultV) {};
EffectHandler* effect;
bool defaultVertexShader;
virtual void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData)
{
if(services->getVideoDriver()->getDriverType() == irr::video::EDT_OPENGL)
{
irr::f32 TexVar = 0;
services->setPixelShaderConstant(services->getPixelShaderConstantID("ColorMapSampler"), (const f32*)(&TexVar), 1);
TexVar = 1;
services->setPixelShaderConstant(services->getPixelShaderConstantID("ScreenMapSampler"), (const f32*)(&TexVar), 1);
TexVar = 2;
services->setPixelShaderConstant(services->getPixelShaderConstantID("DepthMapSampler"), (const f32*)(&TexVar), 1);
TexVar = 3;
services->setPixelShaderConstant(services->getPixelShaderConstantID("UserMapSampler"), (const f32*)(&TexVar), 1);
}
if(defaultVertexShader)
{
const irr::core::dimension2du currentRTTSize = services->getVideoDriver()->getCurrentRenderTargetSize();
const irr::f32 screenX = (irr::f32)currentRTTSize.Width, screenY = (irr::f32)currentRTTSize.Height;
services->setVertexShaderConstant(services->getVertexShaderConstantID("screenX"), &screenX, 1);
services->setVertexShaderConstant(services->getVertexShaderConstantID("screenY"), &screenY, 1);
irr::scene::ISceneManager* smgr = effect->getActiveSceneManager();
irr::scene::ICameraSceneNode* cam = smgr->getActiveCamera();
const irr::core::position2di tLeft = services->getVideoDriver()->getViewPort().UpperLeftCorner;
const irr::core::position2di bRight = services->getVideoDriver()->getViewPort().LowerRightCorner;
const irr::core::line3df sLines[4] =
{
smgr->getSceneCollisionManager()->getRayFromScreenCoordinates
(irr::core::position2di(tLeft.X, tLeft.Y), cam),
smgr->getSceneCollisionManager()->getRayFromScreenCoordinates
(irr::core::position2di(bRight.X, tLeft.Y), cam),
smgr->getSceneCollisionManager()->getRayFromScreenCoordinates
(irr::core::position2di(tLeft.X, bRight.Y), cam),
smgr->getSceneCollisionManager()->getRayFromScreenCoordinates
(irr::core::position2di(bRight.X, bRight.Y), cam)
};
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineStarts0"), &sLines[0].start.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineStarts1"), &sLines[1].start.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineStarts2"), &sLines[2].start.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineStarts3"), &sLines[3].start.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineEnds0"), &sLines[0].end.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineEnds1"), &sLines[1].end.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineEnds2"), &sLines[2].end.X, 3);
services->setVertexShaderConstant(services->getVertexShaderConstantID("LineEnds3"), &sLines[3].end.X, 3);
}
if(uniformDescriptors.size())
{
irr::core::map<irr::core::stringc, SUniformDescriptor>::Iterator mapIter = uniformDescriptors.getIterator();
for(;!mapIter.atEnd();mapIter++)
{
if(mapIter.getNode()->getValue().fPointer == 0)
continue;
services->setPixelShaderConstant(services->getPixelShaderConstantID(mapIter.getNode()->getKey().c_str()), mapIter.getNode()->getValue().fPointer,
mapIter.getNode()->getValue().paramCount);
}
}
}
struct SUniformDescriptor
{
SUniformDescriptor() : fPointer(0), paramCount(0) {}
SUniformDescriptor(const irr::f32* fPointerIn, irr::u32 paramCountIn)
: fPointer(fPointerIn), paramCount(paramCountIn) {}
const irr::f32* fPointer;
irr::u32 paramCount;
};
irr::core::map<irr::core::stringc, SUniformDescriptor> uniformDescriptors;
};
#endif