Operating System: Linux
Render System: GL3Plus
Hello again! I have run into some more problems (still regarding clipping, but in a different way).
My goal is to have clipping done per pass, using a HlmsListener, but to let individual Renderables to switch clipping on and off.
In my previous post I was told it is better to have two different shaders, one that has clipping code and one that does not to promote portability. While portability is not my greatest concern I wanted to give it a try to "do it right".
I figured I should be able to do so without changing too much, and decided I wanted to add clipping as a property in the shader.
I managed to add the code in the shader using the preprocessor and it works fine (I'm leaving out the glsl code to save some space).
Here is what I did to set the property from C++ (as seen in multiple other posts):
Code: Select all
void OgreHlmsClipUnlit::calculateHashForPreCreate(Renderable* renderable, PiecesMap* inOutPieces)
{
Ogre::HlmsUnlit::calculateHashForPreCreate(renderable, inOutPieces);
if (renderable.hasCustomParameter(0)) // <- Always fails for some reason, despite setting it upon creation. Worked in fillBuffersFor.
setProperty( HlmsBaseProp::PsoClipDistances, 8 );
}
Just to be able to move on I instead count the calls to the function and I set the property for the first renderable, just to see that it does in fact create two shaders. So this will work fine once I figure out the problem with customParameter.
So what I have working is an inherited Hlms implementation that has two different shaders, where uniforms are set using an inherited HlmsListener.
As far as I can tell calculateHashForPreCreate is done once for each renderable (basically an initialization).
When the function is called the renderable gets "associated" with that specific shader (by hash I presume?). If I want to stop using clipping on a specific renderable I'm not sure how to tell the Hlms that the object should now be associated with the "other" shader.
So my question is:
How do I re-associate a renderable with a different shader during runtime?
Ps.
I haven't found any posts that do this exactly, many are "near" but I haven't been able to figure out how to translate it to my case.
While this post is very similar I don't really need to send per renderable data to the shader. I just want to be able to assign shaders to different objects during runtime. Perhaps it is the same in the end?