Shader basics

Started by
8 comments, last by KumGame07 16 years, 7 months ago
I have a damn basic question about shaders. Say I'm rendering a rectangle and I'm using vertex & pixel shaders. glBegin(GL_QUADS); .... glEnd(); My question is how many times the shaders will be exicuted ? I think Vertex shader will be exicuted 4 times (once for a vertex). But what about pixel shader ?
Best Regards,KumGame07
Advertisement
Once for each pixel of this quad.
It depends on how much space your quad represents on the screen (backbuffer). If you make your quad so large that it fills the entire screen the pixel shader will be executed once for each pixel.
Correct me if I am wrong but AFAIK the pixel shader is executed once for each fragment, which does not necessarily equate to a pixel. In any case, this a small detail.
Quote:Original post by Morrandir
Correct me if I am wrong but AFAIK the pixel shader is executed once for each fragment, which does not necessarily equate to a pixel. In any case, this a small detail.


The only difference is when you perform FSAA, right? Otherwise, it's always one pixel, texel, fragment etc.
Quote:Original post by rozz666
The only difference is when you perform FSAA, right? Otherwise, it's always one pixel, texel, fragment etc.


Yes, in most cases the number of fragments processed by the shader equals to the number of pixels.
heh actually fragment shader is executed as many times as many fragments is being processed for a scene, so if you got lots of overdraw and its not handled by early-z rejecting then shader is executed many times for a single pixel of a screen(and this is why we are using pre-z pass and near to far drawing order). The curious question is what 'fragment' actually mean? ;)
Fragment is made of color, depth, stencil, position on screen.
What does pixel mean?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Last I heard a fragment was actually 4 pixels on the screen? Or the article I read was bad. Regardless, I think they meant it took the memory space for 4 pixels on the screen, or 16 bytes (RGBA*4).
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Thanks a lot for the replies. Now things are clear.
Best Regards,KumGame07

This topic is closed to new replies.

Advertisement