XEffects - (Indoor Soft-Shadows + Post-Processing)

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply
vectorcorpse
Posts: 86
Joined: Thu Feb 14, 2008 7:30 pm
Location: Portugal

Post by vectorcorpse »

ups, just noticed a mistake i made on the makefile
just add linuxtowin32 to the following line:
all_win32 clean_win32: SUF=.exe

it has to be like this:

all_win32 clean_win32 linuxtowin32: SUF=.exe

otherwise the windows build won't have the .exe extension

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

Post by BlindSide »

Great work vectorcorpse, it's appreciated :D
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
vectorcorpse
Posts: 86
Joined: Thu Feb 14, 2008 7:30 pm
Location: Portugal

Post by vectorcorpse »

:D thx
after all the doors open both ways, and this is the way i found to contribute back to the irr comunity and so the xeffects get a step closer to be integrated in irrlicht, has some have asked, and since irrlicht is crossplatform.

btw i'v been trying without success to activate bump mapping and parallax maping in xeffects, and i'm not understanding why. i donno if i have to load parallax before or after the sadows of if i have to load it inside the xeffects librarys the same way has with dinamic lightning. what i get is 1 of them does not work or i get a strange looking flat textures and no shadows.
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

vectorcorpse wrote::D thx
after all the doors open both ways, and this is the way i found to contribute back to the irr comunity and so the xeffects get a step closer to be integrated in irrlicht, has some have asked, and since irrlicht is crossplatform.
Glad to hear that, I am happy at the velocity that Irrlicht is progressing, it is just amazing and entusiastic!. :o.
Keep it up :).

I am since month ago to try to add someting usefull to irrlicht comunity and have several options, but when I start one then it is too late at night and I have to go to work or Uni :(. And even in work I am trying to learn a litle more to contribuite.
My greatest problem is cross plataform, I don't know how you do it, but I don't even know dx only opengl.
Nova
Competition winner
Posts: 99
Joined: Mon May 09, 2005 10:32 am

Post by Nova »

hi there blindside,

great effect. i implented it into a little test app of mine,
but look what happens, when don't addShadowToNode for the cube node:

Image

i don't know if it's a feature *g* but this does not happen, when the cube get's addShadowToNode'd

The texture is a plain .tga with a red and a yellow color...

just thought i'd mention it
(if this has been posted before, shame on me... too lazy to read the six pages :) )
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

How about reading the manual? :P

You are supposed to use "excludeNodeFromDepthPass()" on all scene nodes that do not cast or recieve shadows.

Cheers

EDIT: Although I can understand this may be a bit cumbersome and I found a way around it so I may update the wrapper with the new method sometime.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Nova
Competition winner
Posts: 99
Joined: Mon May 09, 2005 10:32 am

Post by Nova »

uhm, sorry about that :)

well i actually wanted it to cast shadows, but not to receive them...
but i found that a addNodeToDepthPass did just that.

sorry again *gg*
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Please don't apologise, I am happy to help :)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Tumbleweed
Posts: 6
Joined: Sat Dec 01, 2007 3:41 pm

Post by Tumbleweed »

I hope this isn't *too* dumb a question, but I'm still trying to understand C++ (and all the interesting language of the build log [MS Visual Studio 2005]) with me coming from a Visual Basic 6 background, lol!

First off, your demo runs flawlessly for me, and am very impressed! Appreciate all the hard work you put into it!

In VS2005, I created a new console project (File --> New --> Project From Existing Code) using the file from your source folder and with the Irrlicht.dll included. I've done this without problems for tutorials and such. After rebuilding the project, I get the following error flag on the build log:

Example.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class irr::IrrlichtDevice * __cdecl irr::createDevice(enum irr::video::E_DRIVER_TYPE,class irr::core::dimension2d const &,unsigned int,bool,bool,bool,class irr::IEventReceiver *,char const *)" (__imp_?createDevice@irr@@YAPAVIrrlichtDevice@1@W4E_DRIVER_TYPE@video@1@ABV?$dimension2d@H@core@1@I_N22PAVIEventReceiver@1@PBD@Z) referenced in function _main
Debug\XEffectsSln2.exe : fatal error LNK1120: 1 unresolved externals


Great ga'zooks! What the heck is all that about?!? I really hope it's a noobie thing I still need to learn about, lol!

Thanks for any thoughts on it.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Youre not linking Irrlicht. The tuts had a pragma comment for that, just paste it in there.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Is it possible to cast shadows on object (e.g terrain) that is rendered using shaders? I am asking it here, because I don't have time to test this.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Offcourse, if you have the experience to integrate the terrain shader into the shadow mapping shader, or vice-versa. I think you will be capable of that, elvman :wink:

(Or for a more robust, multiple light effect, render all geometry with full white no texture (Or with just diffuse lighting applied) with shadows in one pass + another pass with the normal scene with you own shader materials (make it fully lit if you had applied diffuse lighting in the previous pass), then multiply these two scenes with a post processing effect, this allows you to easily and realistically add as many shadow casting lights as you want, and it is independent of what materials your original scene nodes may have.

Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
cooljayman
Posts: 22
Joined: Wed Mar 05, 2008 8:25 am

Post by cooljayman »

Im trying to implement the shadows in my scene, but getting the following error on the console

errror: Tried to set a render target texture which is bigger than the screen

How can i resolve this??

Cheers
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Post by Nadro »

You have to install large RTT in DirectX patch to Irrlicht :) or change shadow map size to smaller than window size.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

hi,

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).

greets,
Halan

edit:

i just saw that the sturct also contains the material type... thats a problem
we must amke an array out of that
Post Reply