Page 1 of 1

Getting MaterialTypeParam

Posted: Wed Nov 22, 2006 5:16 pm
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?

Posted: Sun Dec 03, 2006 5:31 pm
by sio2
Anyone any ideas, or is this just a flaw in Irrlicht's design?

Posted: Sun Dec 03, 2006 9:10 pm
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 ;)

Posted: Sun Dec 03, 2006 11:00 pm
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.

Posted: Sun Dec 03, 2006 11:12 pm
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

Posted: Sun Dec 03, 2006 11:15 pm
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.

Posted: Mon Dec 04, 2006 12:01 am
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: