[2.1] Adding custom texture to PBS HLMS

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


al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

[2.1] Adding custom texture to PBS HLMS

Post by al2950 »

I am pretty sure the answer is no, however I am currently seeing how much I could do with the HLMS customisation without changing any Ogre code (C++ or Shaders).

My goal is to add surface water shader 'pieces' for when it rains, and so I want to add a noise texture to define where puddles form. As I said I dont think this can currently be done with the HLMS listener, but could it be easily added? (NB This would NOT be a different texture per object) I could of course just generate some perlin noise on the fly, which actually would be preferable but this is an exercise to see what can be done, and hopefully might lead to some tutorials :)
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5446
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1348

Re: [2.1] Adding custom texture to PBS HLMS

Post by dark_sylinc »

Yes, it can be done.

Override preparePassBuffer to set a property that would cause your shader template customizations to include these droplet codes.
Override shaderCacheEntryCreated so that in GLSL code, you can set your uniform samplers to the right texture unit.
Override hlmsTypeChanged to add the rain texture doing

Code: Select all

*commandBuffer->addCommand<CbTexture>() =
        CbTexture( fixedTexUnit, true, texture.get(), samplerBlock );
And of course, override the custom_ps* pieces to actually insert your code where you need it.
I prefer using fixedTexUnit to a high value to avoid collisions, but not too high to prevent the driver from going haywire in performance (I personally pick a value of 10-11 and works fine). Note that OpenGL doesn't allow more than 16 texture units.
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: [2.1] Adding custom texture to PBS HLMS

Post by al2950 »

Awesome :D. I was a little unsure about that listener function.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 169

Re: [2.1] Adding custom texture to PBS HLMS

Post by xrgo »

dark_sylinc wrote: Override preparePassBuffer to set a property that would cause your shader template customizations to include these droplet codes.
how can I use setProperty in preparePassBuffer? do I have to inherit from Ogre::Hlms also?