Getting MaterialTypeParam

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Getting MaterialTypeParam

Post by sio2 »

I've created an HLSL shader in the standard way and using video::IShaderConstantSetCallBack to set the constants via OnSetConstants(). What I need to do is get MaterialTypeParam from the current material so I can set it as an HLSL constant, similar to the ParallaxMapRenderer.

Any ideas how to do this?

Or do I have to write my own version of CD3D9ParallaxMapRenderer?
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Anyone any ideas, or is this just a flaw in Irrlicht's design?
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post by TheC »

If you go into the Irrlicht source and find where OnSetMaterial is called for CD3D9HLSLShaderMaterialRenderer, you can call:

this->setVariable(true, "typeparam", reinterpret_cast<irr::f32*>(Material.typeParam), 1);

I hope thats useful ;)
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

TheC wrote:If you go into the Irrlicht source and find where OnSetMaterial is called for CD3D9HLSLShaderMaterialRenderer, you can call:

this->setVariable(true, "typeparam", reinterpret_cast<irr::f32*>(Material.typeParam), 1);

I hope thats useful ;)
video::IShaderConstantSetCallBack doesn't have setVariable(), a "Material" variable or OnSetMaterial(). You don't use CD3D9HLSLShaderMaterialRenderer to declare shaders - you inherit video::IShaderConstantSetCallBack, which is not specific to either GL or D3D. Take a look at my "Reflective Water" code snippet to see how high-level shaders are used.

My shader class was defined thus:

Code: Select all

class CMyShader : public video::IShaderConstantSetCallBack
I'm now giving the following a try as it has an OnSetMaterial callback:

Code: Select all

class CMyShader : public video::IMaterialRenderer, public video::IShaderConstantSetCallBack
Even this isn't working yet. Need to debug to find out why.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

After a bit of fiddling I seem to have got it to work.

You have to define your new shader like this:

Code: Select all

class CMyNewMaterialType : public video::IMaterialRenderer, public video::IShaderConstantSetCallBack
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post by TheC »

the setVariable method is a member of the CD3DHLSLMaterialRenderer class, In a previous project where my shaders required information from a material, I would set the constant within the OnSetMaterial method, then recompile irrlicht to use it.

My projects have only been D3D specific, so it worked perfectly for me.

Another method you could use is to add a "getMaterial" method to CD3D9Driver (or its GL Equivalent), since IMaterialRendererServices is simply the handle to your driver.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

TheC wrote:the setVariable method is a member of the CD3DHLSLMaterialRenderer class, In a previous project where my shaders required information from a material, I would set the constant within the OnSetMaterial method, then recompile irrlicht to use it.

My projects have only been D3D specific, so it worked perfectly for me.

Another method you could use is to add a "getMaterial" method to CD3D9Driver (or its GL Equivalent), since IMaterialRendererServices is simply the handle to your driver.
Not a bad idea. I've been tempted to hack into the source myself, but I was determined to try and find the "correct" method.

If you inherit from IMaterialRenderer, which I assume is the way it was designed to be done, you don't have to edit/recompile the dll and it works for both Direct3D and GL.

Also, my source is from svn so I'm not keen on resolving everytime I pull a new revision down. :wink:
Post Reply