Variable to Irrlicht shader?
BlitzMax Forums/BlitzMax Programming/Variable to Irrlicht shader?
| ||
| Hiho, how can i send a variable to a Shader in Irrlicht, at Time I use Hlsl shader, but i don't found out, how i can send a variable to them, without a variable, shaders are not so powerfull. |
| ||
| greetings Jan_ :) im far from an expert but check out the Shaders demo if you havent already. i believe you need to extend the T_irrIShaderConstantSetCallback type and implement the OnSetConstants() method. i think the command to set the variables you are looking for is setVertexShaderConstant(). in gg.IrrBMAX this translates into setVertexShaderConstantFromName() and setVertexShaderConstant() and they reside in T_irrIMaterialRendererServices. here is the section from the Irrlicht manual under IMaterialRendererServices.setVertexShaderConstant() (this is C++ code): Sets a constant for the vertex shader based on a name. This can be used if you used a high level shader language like CG or HLSL to create a shader. Example: If you created a shader which has variables named 'mWorldViewProj' (containing the WorldViewProjection matrix) and another one named 'fTime' containing one float, you can set them in your IShaderConstantSetCallBack derived class like this:
virtual void OnSetConstants(video::IMaterialRendererServices* services)
{
video::IVideoDriver* driver = services->getVideoDriver();
float time = (float)os::Timer::getTime()/100000.0f;
services->setVertexShaderConstant("fTime", &time, 1);
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("mWorldViewProj", worldViewProj.M, 16);
}
Parameters: name,: Name of the variable floats,: Pointer to array of floats count,: Amount of floats in array. Returns: : Returns true if successful. hope i gave a direction to persue. the Shaders sample (available for download from my worklog) shows a gg.IrrBMAX implementation including the extended type and use of the setVertexShaderConstantFromName() method. |
| ||
| Wow, it function 100 thx, my first Watershader is now done :-) |
| ||
| glad i could give you a direction :) |
| ||
| can we see it J... --Mike |
| ||
| Yeah Jan! Show us! Its always good to see success stories! |
| ||
| jep, sure, It's nothing greate, it looks like water in Unreal1 :-) http://www.blitz-pasting.net/uploads/useruploads/LZKoJ17181605548567_water1.zip it's 2.3 MB, with Irrlciht Dll's & source |
| ||
| It's nothing greate, it looks like water in Unreal1 :-) great job! thx for sharing :) |