XEffects - Reloaded - New Release (V 1.4)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Nice to know you're going to polish the bloom and DOF code. I'd like to play around with the HDR code I added recently and see if I can get HDR postprocess working on XEffects. That'd be cool.

By the way, not sure if touching the following code will do any good, tho. Do you have any opinion about changing the FVF definition for EVT_TANGENTS?

Code: Select all

void CD3D9Driver::setVertexShader(E_VERTEX_TYPE newType)
{
	if (newType != LastVertexType)
	{
		LastVertexType = newType;
		HRESULT hr = 0;

		switch(newType)
		{
		case EVT_STANDARD:
			hr = pID3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1);
			break;
		case EVT_2TCOORDS:
			hr = pID3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX2);
			break;
		case EVT_TANGENTS:
			hr = pID3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX3 |
				D3DFVF_TEXCOORDSIZE2(0) | // real texture coord
				D3DFVF_TEXCOORDSIZE3(1) | // misuse texture coord 2 for tangent
				D3DFVF_TEXCOORDSIZE3(2)   // misuse texture coord 3 for binormal
				);
			break;
		}

		if (FAILED(hr))
		{
			os::Printer::log("Could not set vertex Shader.", ELL_ERROR);
			return;
		}
	}
}
Image
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

I hope you achieve a good effect with the bloom shader. I've seen some which are really awesome!

By the way, i have found a trouble you might not have noticed, or at least, the demos you have don't fall into this trouble because it is a simple stage, but when you have a nice stage, with hundreds of polygons, the logic step is to accelerate the render process through an octree, well, then happens a thing, and is that non visible polygon disappear, BUT the shadow also goes with the polygon, and suddenly start appearing white holes where, before there were not. I've come to the conclusion that it must be a trouble of the polygon rendering. Maybe you needed another way to fill the shadow buffers. :/
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Ah yes, the octree scene nodes (And terrain scene nodes) would have to be updated to suit the new camera position when I'm rendering to the shadow map, it wasn't a problem before when I used a smgr->drawAll() to render them but since now I just use ->render() this problem appears, thanks for pointing that out.

I wouldn't recommend using the Irrlicht octree in it's current state however, instead you will get much better performance just using hardware buffers. (MeshBuffer->setHardwareMappingHit(EHM_STATIC);, or something like that.)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
WorldSmith
Posts: 13
Joined: Sat Apr 19, 2008 5:05 pm
Location: Switzerland
Contact:

Post by WorldSmith »

Rendering a scene consisting of models with about 1800 Polys, 3 different shadow lights and the terrain render off the examples source.

Using 30 Models I get about
4-5 Frames @ 380'000 Polys when using OpenGL
20-21 Frames @ 385'000 Polys using Direct3D9

And now the wicked thing with lesser polys - 10 Models (astonished about D3D)

10-11 Frames @ 165'000 Polys with OpenGL
11-12 Frames @ 165'000 Polys using D3D9

Finally 3 Models
41-47 Frames @ 42'900 Polys with OGL
41-47 Frames @ 42'900 Polys with OGL
30 Frames @ 42'9000 Polys with D3D9

Last but not least: rendering 30 Models with the standard Scene Manager
23-25 Frames @ 54600 Polys with OGL
123-124 Frames @ 54600 Polys with D3D9

With XEffects active I am using the 8_PCF Filter and 1024x1024 shadow
map at a 1024x768 screen resolution.

Machine specs are:
Intel Core2 @ 2.40GHz
2GByte Ram
ATI Radeon X1950Pro
Windows XP SP3

To note is, that I get trouble with drawing to the RenderTargetTexture with D3D - Texture bigger than ScreenRTT. Perhaps that could boost some frames too, if I wasn't that lazy to fix it. *shrugs*
Furthermore, my animation system lags and kills a good handful of frames too. But I hope you see the difference.

By the way, can someone recommand any precise code profiling tools?

Now to my questions that are buzzing my brains;
For each model that has a shadowNode attached to it, the polycount increases for this model by the approximate factor of ten. I didn't got deep into your code but how can I reduce the polycount for your shadow maps - if even possible?

Also I tried to simulate some day/night change using an orthogonal light. The light is placed relatively far outside the map and it produces strange artifacts when the map is stretched too far and over too many planes blurs the shadows. May this be change by the fov or the near and far value?
I'll post a screen shot, when needed.

Code: Select all

effect->addShadowLight(
	SShadowLight(
		vector3df(0,0,0),	// position
		vector3df(5, 0, 5), 	// target
		SColor(255, 120, 120, 230),	
		50.0f,	// nearValue
		500.0f,	// farValue
		90.0f * DEGTORAD,	// field of view
		true				// directional
	)
);

matrix4 projMat;
projMat.buildProjectionMatrixOrthoLH(1024,768,10,1000);
effect->getShadowLight(0).setProjectionMatrix(projMat);

// adding a simple fly straight animator for testing purpose
light2->addAnimator(smgr->createFlyStraightAnimator(vector3df(0,280,-300), vector3df(0,280,300), 60*1000, true));

// this is encapsulated in the main loop to set the light's position similar to the examples provided
vMat.makeIdentity();
vMat.buildCameraLookAtMatrixLH(light2->getPosition(), models[0].getPosition(), vector3df(0,1,0));
effect->getShadowLight(2).setViewMatrix(vMat);

Then my very plea to you blindside - appreciating your hard work and great research - why, o why rendering lights in a frustrating frustum?!? Can't you override this and handle shadowing each object in a global space?
It's indeed great for demos or small interior environments. But then imagine a room with a single torch in its middle touching the whole room in its light...

Anyway, keep your creations up! You're doing good dude. ;)
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Maybe it is a wise idea to set the frustum of the camera as the frustum of the lights, that way, closer objects to the camera would always get nice defined shadows, while the objects which are far from the camera would get less definition in shadows, and the shadow lights would behave the same in any situation and direction. Dunno, just pointing an idea.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Mel wrote:Maybe it is a wise idea to set the frustum of the camera as the frustum of the lights, that way, closer objects to the camera would always get nice defined shadows, while the objects which are far from the camera would get less definition in shadows, and the shadow lights would behave the same in any situation and direction. Dunno, just pointing an idea.
I'm afraid you sound confused, check this out for a basic introduction on the technique of shadow mapping.

That being said, there are ways to calculate an optimal light frustum for the current view frustum, particularly for directional lights. Google PSM shadow maps, CSM shadow maps, TSM shadow maps, or PSSM shadow maps (And theres a few more techniques), for more info.

@WorldSmith: I think my current directional light implementation is a little screwy. The thing with orthogonal projections is that the depth values are totally different from perspective projections. I recommend trying far values around 1.0 and near values around 0.001 when using directional lights. Try to emulate the settings I used in this (Outdated version of XEffects) tutorial. If speed is a concern you might just wanna use that old version of XEffects included, it's less capable but performance is slightly better.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Specs:
dual core 1.6
1gig RAM
Nvidia 7900 GS 256mb
Ubuntu 8.04

Example 1 - everything maxed
26-32 FPS

Example 2 - everything maxed
2-4 FPS

Example 2 - 512x512 shadowmap, PCF maxed
11-14 FPS

Example 2 - 512x512 shadowmap, 4 PCF
~20FPS


Really nice effects Blindside :D
WorldSmith
Posts: 13
Joined: Sat Apr 19, 2008 5:05 pm
Location: Switzerland
Contact:

Post by WorldSmith »

Hey there BlindSide, thanks for the swift reply. I managed to screw up my scene with some unthoughtful changes, realizing that I really need a global scale variable. :P

Sure, I already took anything off the Orthogonal Shadows Demo and made it work with the new XEffects Reloaded. The problem indeed lies in the near and far values - got rid of the artifacts with a near value of 0.001f and far of 10.0f - but there are still many tweakings ahead.

Anyway, is there any fallof for the lights possible, so that you could use it as kind of flashlight?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I added falloff in but I took it out because I thought it didn't look that good, but that's just taste. Of course thinking about it now it would've been a good idea to add an option for that.

Anyway, if you want fall off, in Direct3D, change line 54 of ShadowPass2P.hlsl to:

Code: Select all

finalCol = LightColour * lightFactor * MVar[1] * (1.0 - realDistance);
And for OpenGL, change line 48 of ShadowPass2P.glsl to:

Code: Select all

finalCol = LightColour * lightFactor * MVar.y * (1.0 - realDist);
Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

Great job Blindside, I am loving it. :)
Though I do get quite a low fps..

System:
Ubuntu x86_64 8.10
Nvidia 8800 GT 512 MB
3.0 Ghz Dual Core

I am using OpenGL (linux)

I get about 40 Fps.

Anyway, GREAT stuff regardless of performance

EDIT: now that I have implemented XEffects myself, performance seems better :? Though no shadows are cast
Last edited by catron on Sun Nov 09, 2008 3:43 am, edited 1 time in total.
Image
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

I'm currently adding XEffects code to a sample underground complex. I'm getting weird shader effect at the moment, but once I get them fixed a screenshot will posted later.

Let me know if anyone has work on any Irrlicht+Bullet+Xeffects coding lately, I need advice on integrating these three.
Last edited by dlangdev on Sun Nov 09, 2008 4:13 am, edited 2 times in total.
Image
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

I can't get shadows casting on other objects... I have no idea what is wrong. (yes, I have ESM_BOTH set)

Code: Select all

#include "DPSE.h"
#include <string>

int main(int argc, char* argv[])
{
    DPSEInternalUtils().changeDir("../../data");
    DPSEResourceMap<std::string, std::string> map = DPSEXml("resources.xml").getResourceList().toString().toMap();

    DPSEWindowSettings* t_WinSet = new DPSEWindowSettings;
    t_WinSet->AntiAlias = true;
    t_WinSet->Fullscreen = false;
    t_WinSet->WindowSize = DPSEDeminsion2D(640, 480);
    t_WinSet->DriverType = irr::video::EDT_OPENGL;
    DPSEWindow* m_Win = new DPSEWindow(t_WinSet);
    m_Win->init("shaders", &map, DPSEDeminsion2D(2048, 2048));
    DPSEScene*  m_Scene  = new DPSEScene (m_Win);
    DPSEVideo*  m_Video  = new DPSEVideo (m_Win);
    DPSEGui*    m_Gui    = new DPSEGui   (m_Win);
    DPSEEffect* m_Effect = new DPSEEffect(m_Win);
    DPSELight* m_Light = new DPSELight(m_Effect, m_Scene, DPSEPosition3D(10, 10, 0), DPSEPosition3D(0, 0, 0), DPSEColor(255, 255, 255, 255), 10000.0f, 89.99f, true);
    DPSEMesh* mesh = new DPSEMesh("torus", &map, m_Scene);
    DPSEMesh* mesh1 = new DPSEMesh("platform", &map, m_Scene);
    DPSEObject obj(mesh);
    DPSEObject obj1(mesh1);
    m_Effect->addObjectShadow(&obj1);
    m_Effect->addObjectShadow(&obj);
    obj.getNode()->setPosition(DPSEPosition3D(0, 1, 0));
    obj1.getNode()->setPosition(DPSEPosition3D(30, -1, 0));
    obj1.getNode()->setScale(DPSEPosition3D(100, 1, 100));
    m_Effect->setAmbientLight(DPSEColor(10, 10, 10, 10));
    m_Effect->addPostProcessing("blurH_shader", &map);
    m_Effect->addPostProcessing("blurV_shader", &map);
    m_Effect->addPostProcessing("bloom_shader", &map);
    DPSECamera* m_Camera = new DPSECamera(m_Scene);
    m_Camera->getNode()->setPosition(DPSEPosition3D(-10, 0, 0));
    m_Camera->getNode()->setTarget(DPSEPosition3D(0, 0, 0));
    irr::u32 oldFps = -1;
    while(m_Win->run())
    {
        if(oldFps != m_Video->getVideo()->getFPS())
		{
			irr::core::stringw windowCaption = L"DPSE FPS: ";
			windowCaption += m_Video->getVideo()->getFPS();
			m_Win->getDevice()->setWindowCaption(windowCaption.c_str());
			oldFps = m_Video->getVideo()->getFPS();
		}
		//m_Light->update(DPSEPosition3D(5, 0, 5), DPSEPosition3D(0, 1, 0));
    }
    delete m_Win;
    delete mesh;
    delete mesh1;
    delete m_Scene;
    delete m_Video;
    delete m_Gui;
    delete m_Camera;
    return 0;
}
Also, My resolution looks crappy regarless of what the actual resolution is.. I am certain this has something to do with my integration of XEffects. This screenshot also shows my problem of no shadows. Though I am pleased with the 500 FPS, even though I have many of your post-processing shaders enabled in that scene.

Image
Image
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Ok first of all, the bad resolution is obviously because you are not passing a high resolution value to the "screenres" parameter when initialising XEffects. If you want to make it the same as the screen resolution just pass (0,0) and XEffects will take care of the rest. (Your code snippet does not show the actual initialization of XEffects, just some kind of proxy framework, so I am assuming this is the case.)

For the shadows problem, take a look at this:

Code: Select all

new DPSELight(m_Effect, m_Scene, DPSEPosition3D(10, 10, 0), DPSEPosition3D(0, 0, 0), DPSEColor(255, 255, 255, 255), 10000.0f, 89.99f, true); 
Although this function looks different from the original, I can still sort of guess what's going on. I really should post a basic "Trouble shooting shadows FAQ", since it seems alot of people seem to have trouble understanding what it takes to make shadow maps work. Now shadow maps have a 3d resolution, you have your x and y which are the dimensions for the texture of course, but also you have the depth resolution. This means that for good quality, you need not only cover as little area as possible within the texture resolution, but also as little volume as possible with regards to the depth. Also note that the "directional", or orthographic shadows are mostly untested and require slightly different farvalues than one would normally expect (Usually in the range of 0.0 - 1.0). Ok, keeping all of this in mind, a couple of suggestions:

1. Disable directional shadows first, when you get it working normally than you can turn directional back on and mess around with that.

2. Play around with the Far and Near values. They are both important. The far value should not be too big. I see you might have 10000.0 in your function as the far value, that is way too big since your scene is placing stuff at like 100, 300 etc, it does not need that big a far value, and setting it this high might cause artifacts/missing shadows. So try to reduce this to "tightly enclose" your scene at all times.

3. Look at the shadow map texture. You can obtain this from XEffects, there is a getter function for the shadow map texture (Make sure to look at the shadow map texture, not the depth map texture, the depth map texture is a seperate thing for use in post processing effects). Stick to one light when you are doing this, since it will only contain the depth info for the last light added.

Try these and post back with results.

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
catron
Posts: 158
Joined: Mon Feb 19, 2007 1:54 am

Post by catron »

The far value caused the lack of a shadow, thanks.

Code: Select all

void DPSEWindow::init(std::string t_Key, DPSEResourceMap<std::string, std::string>* t_Map, DPSEDeminsion2D t_Shadow)
{
    if (m_Device) m_Device->drop();
    m_Device = createDeviceEx(DPSE_SICP*m_SetWin);
    m_SceneMgr = m_Device->getSceneManager();
    m_VideoMgr = m_Device->getVideoDriver();
    m_GuiMgr   = m_Device->getGUIEnvironment();
    m_EffectMgr = new effectHandler(m_Device,t_Shadow, t_Map->getData(t_Key).c_str(), m_SetWin->WindowSize);
    m_Init = true;
    printf("DPSEngine Version %d.%d Init Complete.\n", DPSE_ENGINE_VERSION_MAJOR, DPSE_ENGINE_VERSION_MINOR);
}
As you can kind of see, I pass the resolution of my window directly to the constructor. I am unsure of what I am doing wrong.

EDIT: I have now tried passing the resolution I want directly to it, via Deminsion2d, still no avail.

EDIT: It seems that multiplying the resolution by two gives you the resolution you want... is this the correct way to go about this?

Thanks again
Image
Image
vectorcorpse
Posts: 86
Joined: Thu Feb 14, 2008 7:30 pm
Location: Portugal

Post by vectorcorpse »

System:
dual boot on 2 HDs
Ubuntu x86_64 8.10
windows XP (testing only)
amd athlon 64 3400+ (skt939)
2Gb ddr400 dual channel
sapphire ati Radeon HD4850 512MB ddr3

example 1 on any resolution under linux or windows with ogl or dx runs always at 95fps
(i think ati frame rate limiter is kicking in)
:shock:
example 2 under linux or windows with ogl or dx runs always at low res runs at 38fps and all max at 17fps
(something is wrong here... probably the fact that i can't use the pci express 2 of my card because the motherboard only support pci express 1)

besides that, congratz for your great work

(note: btw how do u do multi pass?? i am studing shaders with render monkey since lumina doesn't work with ati cards and i don't see how to get multi pass working with irr, on the forums alot of ppl say it isn't supported but u seamed to find a way arround it. thx in advance :D )
Post Reply