can Irrlicht load .fx files??

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
mjoselli
Posts: 6
Joined: Fri Mar 14, 2008 8:57 pm

can Irrlicht load .fx files??

Post 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
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
mjoselli
Posts: 6
Joined: Fri Mar 14, 2008 8:57 pm

Post 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)
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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.
TheQuestion = 2B || !2B
mjoselli
Posts: 6
Joined: Fri Mar 14, 2008 8:57 pm

Post 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...
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post 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!
TheQuestion = 2B || !2B
Post Reply