Which will be faster? Switching shaders or ignore that some cases don't need full code?
Posted
by
PolGraphic
on Game Development
See other posts from Game Development
or by PolGraphic
Published on 2012-12-13T05:24:23Z
Indexed on
2012/12/13
11:22 UTC
Read the original article
Hit count: 281
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:
- Making two independent shaders for both types of rectangles, group rectangles by types and switch shaders during rendering.
- Make one shader and use some if statement.
- Make one shader and ignore that sometimes (70% of cases) I don't need to use
fmod
.
© Game Development or respective owner