Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
2  
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
3  
"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

1 Answer 1

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
2  
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. –  Darth Satan Jun 11 '13 at 21:48
1  
@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

 
discard

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.