Shader optimization - cg/hlsl pseudo and via multiplication

Posted by teodron on Game Development See other posts from Game Development or by teodron
Published on 2012-03-27T16:11:29Z Indexed on 2012/03/27 17:44 UTC
Read the original article Hit count: 367

Filed under:
|
|

Since HLSL/Cg do not allow texture fetching inside conditional blocks, I am first checking a variable and performing some computations, afterwards setting a float flag to 0.0 or 1.0, depending on the computations. I'd like to trigger a texture fetch only if the flag is 1.0 or not null, for that matter of fact. I kind of hoped this would do the trick:

    float4 TU0_atlas_colour = pseudoBool * tex2Dlod(TU0_texture, float4(tileCoord, 0, mipLevel));

That is, if pseudoBool is 0, will the texture fetch function still be called and produce overhead? I was hoping to prevent it from getting executed via this trick that usually works in plain C/C++.

© Game Development or respective owner

Related posts about shaders

Related posts about hlsl