# how change branching logic to math equivalent glsl? [closed]

im totally newbie and this just for fun

afaik lot of best practice suggest to minimize usage of branching.

can you help me optimize below glsl especially on branch part? ( target 120 )

the bgcolor used for minimum color level, what i want is alpha outcome become 0.1 if the bgColor choosen on the current fragment otherwise it will get the data from uniform.

bgColor n uLightIntensity will same value for all fragment aplied within this shader.

the texcolor will be varies for each fragment ( depend on texture pixel presentation)


varying  vec3 v_fragmentColor;
varying  vec2 v_texCoord;

uniform sampler2D u_texture;
uniform  float u_lightIntensity;
uniform vec4 u_bgColor;

void main()
{

vec4 texColor = texture2D(u_texture,  v_texCoord);

// TODO POSIBLE OPTIMIZE FOR NON BRANCHING
if(step( u_bgColor.r, texColor.r) == 0.0)
{
texColor.a = 0.1;
}else
{
texColor.a =  u_lightIntensity/10.0;
}
texColor.rgb = max(texColor.rgb, u_bgColor.rgb);

gl_FragColor = texColor;

}



## closed as too broad by MichaelHouse♦May 11 '15 at 13:19

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

float vstep = step( u_bgColor.r, texColor.r);