The experiment of shader programming with if-condition instruction

Today I make an experiment to talk about the if-else syntax in shader codes, how this way influences my application performance.
  1. The first one has three shaders are one point light, two point lights, and three point lights. We apply them to three different surface model.
  2. The second one, we use a shader code which writes three if condition instructions to show three types light which also be applied to three different surface model(same with upper experiment).
Finally, the experiment results show us the first one has 2639 FPS, the other is 1762 FPS. Although the second one use the same code, we can avoid reset shader to device. It tells us the if instruction will effect our performance, and it hurts degree more than reset shader to device. So all we can do is avoid to use if instruction possibly.

Comments

Popular posts from this blog

董事長您好

After reading Steve Jobs Autobiography

Drawing textured cube with Vulkan on Android