I’ve been googlin this problem for a while and I don’t know what is true anymore.
Let’s say I have a fragment shader like this:
//pseudocode
norm=genNormal(tex0);
tang=genTangent(norm);
bnor=genBinormal(norm);
color=mixTextures(tex1, tex2, tex3, tex4, tex5, tex6, tex7, tex8, tex9);
norm=mixNormalMaps(norm, tang, bnorm, tex9, tex10, tex11, tex12, tex13, tex14, tex15, tex16, tex17, tex18);
color=doLight(gl_lightThing, norm, color);
gl_FragColor=mix(color, fog_color, fog_factor);
The shader would do a lot of texture lookups and some math and in the end mix it all with a constant fog color based on a ‘fog_factor’ calculated in a vert shader.
Now if the fog_factor is 1.0 then all the math and texture lookups do nothing -would it make sense to rewrite the shader like this:
//pseudocode
if(fog_factor>0.996)
{
gl_fragColor=fog_color;
}
else
{
norm=genNormal(tex0);
tang=genTangent(norm);
bnor=genBinormal(norm);
color=mixTextures(tex1, tex2, tex3, tex4, tex5, tex6, tex7, tex8, tex9);
norm=mixNormalMaps(norm, tang, bnorm, tex9, tex10, tex11, tex12, tex13, tex14, tex15, tex16, tex17, tex18);
color=doLight(gl_lightThing, norm, color);
gl_FragColor=mix(color, fog_color, fog_factor);
}
Let’s say the top 1/3 of the screen has a fog_factor of 1.0 will the gpu ‘cores’ for (some of?) these pixels execute both branches or just the ‘lite’ version?