Page 1 of 1

can Irrlicht load .fx files??

Posted: Fri Mar 14, 2008 9:02 pm
by mjoselli
I did a little search but i couldnĀ“t find the answer...

Can Irrlicht load .fx files generated from fx composer or rendermonkey or shader fx???

thanks

Posted: Fri Mar 14, 2008 9:08 pm
by Halifax
BlindSide wrote: Theres no support for FX files in terms of techniques/passes etc, so you'll have to implement/parse those yourself. Although the shader code itself inside FX files usually copy/pastes straight into an HLSL script.

Posted: Fri Mar 14, 2008 9:15 pm
by mjoselli
hey thanks...

But with Irrlicht do I have acess to all the variables that I need to implement a shader, like the world, worlviewprojection, view projection, view, etc ??

(the reson I am asking this is because I was currently using TGEA to work with shaders but I didint have acess to a lot of variables that I nedded in order to implement a shader on it)

Posted: Sat Mar 15, 2008 4:14 am
by Halifax

Code: Select all

class MyShaderCallBack : public video::IShaderConstantSetCallBack
{
public:

	virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
	{
		video::IVideoDriver* driver = services->getVideoDriver();

		// set inverted world matrix
		// if we are using highlevel shaders (the user can select this when
		// starting the program), we must set the constants by name.

		core::matrix4 invWorld = driver->getTransform(video::ETS_WORLD);
		invWorld.makeInverse();

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mInvWorld", invWorld.pointer(), 16);
		else
			services->setVertexShaderConstant(invWorld.pointer(), 0, 4);

		// set clip matrix

		core::matrix4 worldViewProj;
		worldViewProj = driver->getTransform(video::ETS_PROJECTION);			
		worldViewProj *= driver->getTransform(video::ETS_VIEW);
		worldViewProj *= driver->getTransform(video::ETS_WORLD);

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
		else
			services->setVertexShaderConstant(worldViewProj.pointer(), 4, 4);		

		// set camera position

		core::vector3df pos = device->getSceneManager()->
			getActiveCamera()->getAbsolutePosition();

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mLightPos", reinterpret_cast<f32*>(&pos), 3);
		else
			services->setVertexShaderConstant(reinterpret_cast<f32*>(&pos), 8, 1);

		// set light color 

		video::SColorf col(0.0f,1.0f,1.0f,0.0f);

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mLightColor", reinterpret_cast<f32*>(&col), 4);
		else
			services->setVertexShaderConstant(reinterpret_cast<f32*>(&col), 9, 1);

		// set transposed world matrix
			
		core::matrix4 world = driver->getTransform(video::ETS_WORLD);
		world = world.getTransposed();

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mTransWorld", world.pointer(), 16);
		else
			services->setVertexShaderConstant(world.pointer(), 10, 4);
	}
};
(This comes from Tutorial 10 on shaders.)

The answer to your question is yes. Irrlicht allows you to set the variables that you have defined in your shader file. Take note of how is gets the worldViewProj matrix.

Code: Select all

core::matrix4 worldViewProj;
		worldViewProj = driver->getTransform(video::ETS_PROJECTION);			
		worldViewProj *= driver->getTransform(video::ETS_VIEW);
		worldViewProj *= driver->getTransform(video::ETS_WORLD);

		if (UseHighLevelShaders)
			services->setVertexShaderConstant("mWorldViewProj", worldViewProj.pointer(), 16);
So with that code above, your variable would look something like:

Code: Select all

uniform mat4 mWorldViewProj;
You can basically get anything(from Irrlicht), and set anything(in your shader) that you need to for your shader. These shader callbacks are exactly what they sound like, they are called every time the shader is called upon.

Posted: Mon Mar 17, 2008 3:44 pm
by mjoselli
Thanks a lot...

I will probably change from TGEA to Irrlicht, now that I know that Irrlicht can do the things that I want to do...

Posted: Mon Mar 17, 2008 9:01 pm
by Halifax
mjoselli wrote:Thanks a lot...

I will probably change from TGEA to Irrlicht, now that I know that Irrlicht can do the things that I want to do...
That's great. I'm surprised that TGEA can not do this stuff...as I have seen people use a lot of complicated shaders with TGEA. But, eh, I have never used it.

Either way, welcome to the community!