Which will be faster? Switching shaders or ignore that some cases don't need full code?

I have two types of 2d objects:

In first case (for about 70% of objects), I need that code in the shader:

float2 texCoord = input.TexCoord + textureCoord.xy


But in the second case I have to use:

float2 texCoord = fmod(input.TexCoord, texCoordM.xy - textureCoord.xy) + textureCoord.xy


I can use second code also for first case, but it will be a little slower (fmod is useless here, input.TexCoord will be always lower than textureCoord.xy - textureCoord.xy for sure).

My question is, which way will be faster:

1. Making two independent shaders for both types of rectangles, group rectangles by types and switch shaders during rendering.
2. Make one shader and use some if statement.
3. Make one shader and ignore that sometimes (70% of cases) I don't need to use fmod.
• Why don't you try all the methods, profile them and find out? Whatever answer you get here will be speculation at best anyways, since this is highly dependent upon the rest of your shader code. – Richard Marskell - Drackir Dec 13 '12 at 5:37
• Have you benchmarked anything yet? Until you have, go for option 3. There is no need for any of the complexity you are trying to add until you know what is slow. – sam hocevar Dec 13 '12 at 8:24
• Option three does allow you front to back sorting and batching which will probably give you a much higher benefit than using a shader with one or two instructions less. If this is done in the vertex shader, dont bother with profiling, take option 3. If done in the fragment shader you will have to draw a whole lot of fragments to get a measureable difference. – Archy Dec 13 '12 at 9:35
• Possible duplicate of gamedev.stackexchange.com/questions/22216/… and related to: gamedev.stackexchange.com/questions/28407/… – MichaelHouse Dec 13 '12 at 14:17