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).
Edited by Milcho, 24 January 2013 - 09:39 AM.