Objects fade in / fade out Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


CbbK
Gnoblar
Posts: 11
Joined: Sun Nov 22, 2020 3:29 pm
x 1

Objects fade in / fade out

Post by CbbK »

Hello,
Right now to handle objects fading in/out with transparency I clone the datablock, affect it to the object and update the datablock's colour every frame until fading is complete, this works well but I don't think it's really fancy.
In the same time I'd like to learn more about HLMS so I digged into it. I found how to add properties per renderable to customize the shader code (HlmsPbs::calculateHashForPreCreate), how to add custom values to datablocks (HlmsListener::getPassBufferSize and HlmsListener::preparePassBuffer) but how can I customize what is sent to the shader per renderable?
I'm looking for something like ACT_CUSTOM from Ogre 1 where we can retrieve in the shader a customParameter set on a Renderable.
I believe it could be achieved with Hlms::fillBuffersFor, but it gets really complicated at this point, between commandbuffer, texbuffer, constbuffer, etc..

Doing that in Ogre 1 was fairly quick, so did I dig too much in HLMS and missed something obvious in the way? How would you achieve such effect otherwise? Thanks.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5435
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1342

Re: Objects fade in / fade out

Post by dark_sylinc »

Cloning the datablock sounds about right, actually.

Any other alternative would require the datablock to be alpha blended all the time (even for alpha = 1.0) and that would also conflict with parameters such as depth_write (which should be on while opaque, and false while fading), which is expensive.

That'd be true for old Ogre1 materials as well, which would require for you to clone them.

In the same time I'd like to learn more about HLMS so I digged into it. I found how to add properties per renderable to customize the shader code (HlmsPbs::calculateHashForPreCreate), how to add custom values to datablocks (HlmsListener::getPassBufferSize and HlmsListener::preparePassBuffer) but how can I customize what is sent to the shader per renderable?

See the new samples Tutorial_Hlms01_Customization, Tutorial_Hlms02_CustomizationPerObj, Tutorial_Hlms03_AlwaysOnTopA, and Tutorial_Hlms04_AlwaysOnTopB that were recently added to the master branch.

The tutorial Tutorial_Hlms02_CustomizationPerObj shows you how to have a particular object (or objects) running custom shader code, which all share the same extra parameters.

However if what you want to do is to send arbitrary custom data per object, that will be difficult without heavier customization of HlmsPbs class because by design we avoid this, as it has quite the performance cost.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5435
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1342

Re: Objects fade in / fade out

Post by dark_sylinc »

After some consideration, I added Tutorial_Hlms05_CustomizationPerObjArbitraryData to show exactly what you requested.

Please take in mind that given your particular case would still need to toggle the blendblock to enable alpha blending (and likely the macroblock to disable depth writes) you're possibly better off just cloning the datablock.

CbbK
Gnoblar
Posts: 11
Joined: Sun Nov 22, 2020 3:29 pm
x 1

Re: Objects fade in / fade out

Post by CbbK »

Thank you for the tutorials.
I'll follow your advice and stick to cloning the datablock then. There's so many ways to achieve different results it's not obvious which is the best so thanks for your inputs here.