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

Without any intended delay, is the code of a fragment-shader run once per frame? If not, how often will the code be executed? (I'm new to shaders: I'm talking about glsl if it makes any difference)

share|improve this question
Yes it is. beacuse thats basicly why you have frames, beacuse you clear the screen every frame, so the gpu has to redraw every thing again. – Tordin Jun 11 '13 at 14:17
"is the code of a fragment-shader run once per frame?" If you're asking this question, you probably need to find out what a fragment shader does first. Once you understand that, it should be obvious how often it runs. – Nicol Bolas Jun 11 '13 at 22:21
up vote 4 down vote accepted

After you bind your program (2 shaders) with useProgram function, shaders are run at every drawElements or drawArrays call.

You can call those functions at every frame, 1000 times per frame, or once an hour.

You can also examine the "work at the server" during the single drawElements call. Vertex (or fragment) shader should be run for every vertex (or fragment). It is usually done on massively parallel hardware systems with many cores. Tens, hundreds or even thousands of instances of the shader program can run at the same time. And those systems are in our pockets! :)

share|improve this answer
The fragment shader is executed each time a fragment is generated :D – gareththegeek Jun 11 '13 at 16:02
@gareththegeek - this is correct and you should make it an answer (expand a bit though) so it can get some proper +1s. – Le Comte du Merde-fou Jun 11 '13 at 21:48
@mh01 Agreed -- the OP seems to be lacking some basic understanding of the pipeline. I think a brief explanation about how the different shaders relate to the pipeline would help. – stephelton Jun 11 '13 at 22:28

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.