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?
Getting MaterialTypeParam
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.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
My shader class was defined thus:
Code: Select all
class CMyShader : public video::IShaderConstantSetCallBack
Code: Select all
class CMyShader : public video::IMaterialRenderer, public video::IShaderConstantSetCallBack
After a bit of fiddling I seem to have got it to work.
You have to define your new shader like this:
You have to define your new shader like this:
Code: Select all
class CMyNewMaterialType : public video::IMaterialRenderer, public video::IShaderConstantSetCallBack
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.
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.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.
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.