I have several object to render. Some of them have textures and some of them are transparent.
To achieve transparency, I implemented the depth peeling tecnique.
I was wondering if I could use just a single shader (for each step, init/peel/blen/final) that handles objects with texture and objects without.
My idea was something like that (init):
#version 330
out vec4 outputColor;
in vec2 oUV;
uniform sampler2D texture0;
uniform int enableTexture;
uniform float alpha;
vec4 ShadeFragment() {
vec4 color;
color.rgb = vec3(.4,.85,.0);
color.a = alpha;
return color;
}
void main(void)
{
vec4 color = ShadeFragment();
color = (1 - enableTexture) * color + enableTexture * texture(texture0, oUV);
outputColor = vec4(color.rgb * color.a, 1.0 - color.a);
}
If enableTexture is 1 I grab the result from the texture, if it is 0 I dont evaluate it at all. I wrote that in order to avoid branching.
Is it worth/has sense an approach like this?