I'm writing a shader for rendering the sides of triangles with different colors. I have a value mediump float back = dot(V, N) which is positive if the normal faces away from the camera and negative if towards the camera.
To correctly select which diffuse color to shade a particular fragment, I need something like this:
lowp vec4 color = max(0.0, sign(-back)) * frontdiffuse + max(0.0, sign(back)) * back diffuse; It's more or less an "unrolled conditional"...
Which code produces faster instructions?
x * 0.5 + 0.5, ormax(0.0, x)?
The former may be better mathematically behaved than the latter, but maybe min/max/clamping is super efficient in hardware