0
votes

From my own trial-and-error experience, it seems that DirectX pixel shaders only run for pixels/fragments that are within the bounds of some geometric primitive rendered by DirectX, and are not run for pixels of the frame that are simply the clear-color.

MSDN says:

Pixel shaders work in concert with vertex shaders; the output of a vertex shader provides the inputs for a pixel shader.

This stands in contrast to WPF pixel shaders, which are run for every pixel of the frame, because WPF doesn't render 3D primitives and therefore doesn't know or care what it means to be a geometric primitive pixel or clear-color pixel.

So for the following image, a DirectX pixel shader would only be run for the area in white, because it corresponds to a geometric primitive output by the vertex shader, but not for the black area, because that's the clear-color. A WPF pixel shader, on the other hand, would be run for every pixel of the frame, both white and black.

Is this understanding correct?

1
if i remember correctly from my university course (2 years ago) you have both a vertex shader and a pixel shader. you pass into the vertex shader and then through to the pixel shader, so yes in that part you apply effects to only pixels in that geometry. if you want the pixel shader to effect the whole scene then you pass in the whole scene on a texture. so if you think about it, you do pass it a square geometry in this caseSam

1 Answers

1
votes

Your understanding is mostly correct - pixel shader invocations are triggered by drawing primitives (e.g. triangles). In fact, a pixel in the window may end up getting more than one pixel shader invocation, if for example a second triangle is drawn on top of the first. This is referred to as overdraw and is generally something to avoid, with the most common method of avoidance being using z-culling.

If you want to trigger a pixel shader for every pixel in the window, simply draw two triangles that make up a "full screen quad", i.e. coordinates (-1,-1) to (1,1). Behind the scenes, this is what WPF essentially does.