Adding Custom Parameter to Pbs for Items

So right now, items have an mCustomParameter attribute. I want to use this attribute and suck it into the pixel shader for use on a per item basis. This is easy to do though to do it we are going to modify a couple lines in ogre source.

So the first thing to do is change mCustomParameter from Ogre::uint8 to a float. This is easy, just locate mCustomParameter in Renderable and change to float.

public: float       mCustomParameter;   //NICKAK EDIT

By default, Pbs only writes mCustomParameter when the PlanarReflections component is built. We want it to always be sent.

OgreHlmsPbs.cpp line 3218

#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
        *( currentMappedConstBuffer+3u ) = queuedRenderable.renderable->mCustomParameter;
#endif

I replaced with:

*reinterpret_cast<float * RESTRICT_ALIAS>( currentMappedConstBuffer + 3u ) = queuedRenderable.renderable->mCustomParameter ;  //       NICKAK EDIT

That’s all the Ogre that needs modified. In order to use drawId in the pbs pixel shader, like I need to, we need to modify Hlms/Pbs/HLSL/VertexShader_vs.hlsl, and pass the drawId to the pixel shader:

struct PS_INPUT
{
@insertpiece( VStoPS_block )
float4 gl_Position: SV_Position;
uint drawID: DRAWID;

I just added the drawId below position.

And now in the custom shader code, mCustomParameter is accessed on a per item basis like so:

outPs_colour0.a = outPs_colour0.a * asfloat(worldMaterialIdx[drawId].a);

WorldMaterialIdx is all of the items being drawn, and drawId is the Index, .a refers to mCustomParameter. Note we need to use, “asfloat”, to interpret properly as a float.

%d bloggers like this: