# If-clause in GLSL

I read a few thing about, that in GLSL both sides of the if-clause is executed, so do you have any idea for a workaround for this one:

uniform int uses_bones;
uniform mat4[] bone_transformations;

void main()
{

vec4 worldPosition = transformationMatrix * vec4(position, 1);
if(uses_bones == 1)
worldPosition = transformationMatrix * vec4(position, 1) * (bone_transformations[bone_pointer] *  bone_intensity);
vec4 pos =  projectionMatrix * worldPosition;


The int uses_bones represents a bool, because LWJGL does not support loading booleans to the shader. 1 = true, 0 = false

• What problem are you trying to solve? Maybe it's fine as-is. (Yes, implementations of GLSL might execute both parts of the IF. ) You could profile it as-is, and then force always-bones and never-bones, and compare those results, to get a sense of how expensive it it. – david van brink Feb 14 '15 at 20:26