I know that branching in a shader slows it down. How about running a loop with some IFs? I need to pick a texture based on face normal angle. I will compute vector angle and then I need to pick a texture based on its value. This will require "for" loop and some "ifs". The code will not branch into some "else" statement. Is this fast?
You should prepare for the worst case scenario in that all code in the if conditions is executed. Then again, this allows for almost free blending between the textures. For example: Code (csharp): float4 score = 0.0; score.x = dot(normal, angle1); score.y = dot(normal, angle2); score.z = dot(normal, angle3); score.w = dot(normal, angle4); score = saturate(3.0 * score - 2.0); // For example, other weighting options can be done here of course float totalScore = dot(score, float4(1.0, 1.0, 1.0, 1.0)); score /= totalScore; float4 result = score.x * tex2D(texture1, uv1); result = score.y * tex2D(texture2, uv2) + result; // MAD order instead of += result = score.z * tex2D(texture3, uv3) + result; // MAD order instead of += result = score.w * tex2D(texture4, uv4) + result; // MAD order instead of += return result; Pretty close to blended triplanar mapping like this. It depends on the number of textures and the platform whether this is feasible of course.