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)

  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Tordin
    Jun 11, 2013 at 14:17
  • 3
    \$\begingroup\$ "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. \$\endgroup\$ Jun 11, 2013 at 22:21

1 Answer 1


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! :)

  • 2
    \$\begingroup\$ The fragment shader is executed each time a fragment is generated :D \$\endgroup\$ Jun 11, 2013 at 16:02
  • \$\begingroup\$ @gareththegeek - this is correct and you should make it an answer (expand a bit though) so it can get some proper +1s. \$\endgroup\$ Jun 11, 2013 at 21:48
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – notlesh
    Jun 11, 2013 at 22:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .