Plxel Shader: run every pixel or screen pixel?

Started by
3 comments, last by 3Ddreamer 11 years, 2 months ago

Is the shader run once for every pixel a triangle covers or just the ones that are included in the screen?

The reason I'm asking is because I want to do a simple ground for a platformer, and I was thinking of using one giant pair of triangles (to make a rectangle) to do the ground, and then having the texture tile over it. If the pixel shader would only run for the pixels that appear on the screen, this would work fine, but if it is called for the entire rectangle, this could be a bad idea.

Advertisement
Shaders only run for what's on screen, due to how the graphical pipeline fills pixels (or fragments, as they're called, there's a small difference)

The shader optimization extends further, so to minimize what pixels need to be filled. In general:
a) Be on screen - what you're concerned about
b) Pass the depth test - this means that if you draw some object above ground first, and then draw the ground, the pixels of the ground that are hidden by the object will not be shaded (not rendered by shader). Note that if you draw ground first, and then the object, all the ground's pixels will be filled. In other words, if making huge optimizations, it pays off to draw nearby objects first, before drawing further away objects (or ground).
c) Pass the stencil test - unrelated to your question, but its yet another thing that is used to optimize which pixels get filled.

Edit: To add to that explanation, when you specify a triangle, there is no notion of a 'pixel' on the triangle.
Triangles are transformed into screen space, and those that lie partially outside the screen have their shape re-adjusted, as to 'clip' them. This means that no pixels that are off-screen will be rendered at all, which is what I meant by a) above.
After that they are rasterized into fragments/pixels and each fragment is subject to the two other tests (b and c above).

Cool, thanks for the quick response

To be a lot more clearer it only runs for every pixel that needs to be rasterized. So if you had scissor test enable and clip areas of the screen, then those part will not get process by the pixel shader.

Clip hint applies to every graphical element in existence which is meant to not be visible until needed, including all types of shaders. As you get more experience then you will learn to optimize clip hint efficiently.

Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software. The better the workflow pipeline, then the greater the potential output for a quality game. Completing projects is the last but finest order.

by Clinton, 3Ddreamer

This topic is closed to new replies.

Advertisement