[osg-users] Pragmatic shader - a new #pragma directive proposition

Robert Milharcic robert.milharcic at ib-caddy.si
Thu Jan 14 02:56:57 PST 2016


On 14.1.2016 9:52, Sebastian Messerschmidt wrote:
> Hi Robert,
>
> This seems more complicated than needed.
> Why not pass the number of lights as a compile time constant
>
> #pragma import_defines (NUM_LIGHTS)
>
> shader_state->setDefine("NUM_LIGHTS",12);
>
> and use uniform arrays:
>
> uniform vec4 u_LightColor[NUM_LIGHTS];
>
> for (int i = 0; i < NUM_LIGHTS;++i)
> {
>     light+=calcLight(u_LightColor[i], ...):
> }
>
> I feel your approach will bloat the preprocessor code path and will complicate the use. 

Hi Sebastian,

First, thank you for your input. Yes, that is more or less the same approach I'm currently using. The downside of this approach is that it requires additional nontrivial code logic for the uniform array management (u_LightColor) and that is why I started to look at the alternatives. There is also an upper limit for the size of the array that needs to be taken into account.  Also, the loop represents unnecessary overhead (though, this is not a problem on a never hardware). On the other hand, my suggestion fits well into existing pragmatic shader composition logic and probably has less downsides.

Cheers,
Robert Milharcic


More information about the osg-users mailing list