XEffects - Reloaded - New Release (V 1.4)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: XEffects - Reloaded - New Release (V 1.3)

Post by christianclavet »

Strange.
I've tried to make the XEffects example run with Trunk SVN 5017.
No compilation error, work correctly with the directX driver.
Image

But if you try OPENGL the rendering is bad as this
Image

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
Last edited by christianclavet on Sun Jan 11, 2015 5:06 am, edited 4 times in total.
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by mongoose7 »

Did you change

Code: Select all

irr::f32 TexVar
to

Code: Select all

irr::u32 TexVar
in all the shader callbacks. This only affects OpenGL.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: XEffects - Reloaded - New Release (V 1.3)

Post by christianclavet »

I've tried it and it now work (except the first example). I was able to make it work then in IRB. But I have some little problems with it, hope someone has tricks...

The "lights" cover a little area. I've tried to expand the light angle radius from the default of 30 degrees to a 89 degrees. but still, I need to cover terrain tiles of 4096x4096 units to try to simulate the shadowing from the sun. Not sure XEffect is good for that kind of job. A light will cover around 200 units max.

Seen that it give lots of clipping issues, when we look farther in the distance, in a near range (as in the examples, it doesn't show). Putting XEffect off, there is no clipping issues.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by hendu »

The sun is a directional light, not point, and using a point for it is unnecessary calculations.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: XEffects - Reloaded - New Release (V 1.3)

Post by christianclavet »

From what I see in the examples, the shadowing system use only spot lights. To have a "point light" they need to use 6 lights covering each 90 degrees. Is there a way to have a directional light with this shadow mapping solution or it need another system?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by hendu »

I don't use xeffects so don't know, sorry. Shadow mapping for directional lights is easy in general.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by robmar »

There is a direction flag, when set XEffects creates a light-camera orthogonal projection matrix, so I imagine its supported.

The shadow map is rendered from the light position, creating a height map, when a pixel is then rendered, it looks to see if it is above or below the height of the pixel at the same position (using the same projection matrix as the light-camera).

If the light is directional, then the pixel will be outside of the projection area, and therefore in shadow.

Well, I´m sorta sure that´s how it works :)
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: XEffects - Reloaded - New Release (V 1.3)

Post by christianclavet »

Thanks Robmar! I did not read enough the information in the examples. The projection of the light frustum can be orthographic. But I had to put some really big parameter to get the scene. At least now for the IRB project needs it can be used. The last parameter that I did not used is when set to true will make the light directional! :oops: Before the angle limit that was 30 define the radius of the light, so instead of 30, I changed it to this big number.

Here is the current parameter of the light that I'm using:

Code: Select all

effect->addShadowLight(SShadowLight(4096, vector3df(35, 480, -50), vector3df(0, 0, 0), SColor(255, 255, 255, 255), 20.0f, 5000.0f, 320000.0f * DEGTORAD, true));
Light must be put in a high limit because the terrain can reach 4096 units of height. Currently without moving this light we can go out of the light frustum zone. So when the player is moving, I'm using it's position as a reference point to move the light and it's target (the angle must not change). The only problem, is that I can't make the angle low because we would see the limit of the light frustum zone. But with the current settings, it's ok.

Here is a screen with XEffect working with IRB on a terrain using the directional light.
Image

Even if the trees are not added to the shadow map; since there are not instanced the frame rate is really low! At least now it's working.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by robmar »

Nice looking shadows! :)

Yes, the light must be high or the fov very wide to cover your scene area. If you use 90 degrees then maybe your light needs to be higher, ... but of course the sun also is very high! :D
Harch
Posts: 75
Joined: Wed Oct 08, 2014 9:01 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by Harch »

This library is working on OpenGL? And with irrlicht 1.8.1?
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Re: XEffects - Reloaded - New Release (V 1.3)

Post by christianclavet »

Hi!

It work here with minor fixes with Irrlicht 1.9 SVN (Trunk). The fixes are all posted on this thread. The only problem I have using it, is with specific meshes. Some meshes for an unknown reason completely disable the shadow rendering.
Harch
Posts: 75
Joined: Wed Oct 08, 2014 9:01 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by Harch »

Specifically on 1.8.1 works? Or only 1.9?

What about OpenGL?

Thx!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by mongoose7 »

Works on all version in DX, I think. OpenGL needs a patch for 1.8 and later versions (setting the sampler).
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by Seven »

it has been a while since this came out, and reading through all of it there appear to be a few changes that are suggested. Tried them all and still nothing. just a black screen.

can someone who has this working with 1.8.1 post the steps they took to get it working?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: XEffects - Reloaded - New Release (V 1.3)

Post by mongoose7 »

Look for TexVar in EffectCB.h. It is defined as u32 I think. Remove the cast from the call to setPixelShaderConstant when setting samplers from TexVar. I think there are 7 places where you must make this change. TexVar *must* be passed as an integer (pointer) and not cast to a float (pointer).
Post Reply