Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm coding my first Shader in my little game engine, and I have some questions about it's performance and common approaches.

  1. Is the Shader code processed by the video card instead of the PC processor? Just so I know if it's possible to share some calculations to save some processor power.

  2. Generally, should I do the math calculations in my code or the Shader? I could calculate them all (lightning for example) and just send the final values to be multiplied/used to the Shader, but what's the best approach?

  3. Shaders as far as I could understand are the main party responsible for visual effects, so for example, if I want to add a "blur" effect to only one object on screen, should I use an if/switch statement in the Shader or should I have different Shader/ProgramIDs and I just switch the call glUseProgram(programID)?

Sorry if some questions seems stupid, and thanks for your time!

share|improve this question
Keep in mind that most modern GPUs have many cores, which allow for some monster parallel computations. I'd go into some more depth and actually answer your questions, but I'm typing this from my phone in the car. – rodrigo-silveira Apr 3 '13 at 3:41

Shader code is uploaded to the video card and compiled by it, usually at the beginning of your program. The video card uses one of it's hundreds (or thousands) of cores to run through your shaders for each vertex or fragment (etc).

You should avoid doing work multiple times. If you can calculate something once on the CPU and make the calculation available to the shader, that's a lot better than asking the shader to calculate it multiple times.

Conditional logic (loops, if statement, etc) can cause some really nasty performance hits in your shaders, so avoid using them whenever you can. I would expect you to be changing the shader program many times as you draw a scene.

share|improve this answer

For performance issues, you might want to check out the AMD ShaderAnalyzer. Its free software, and helps you see the bottleneck of your shader, as well as approximate performance with ATI/AMD cards. I don't know if it supports Nvidia cards tough.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.