Question

If I have multiple overlapping triangles in the same draw call, is my pixel shader entered for each pixel once per primitive that covers it? Or is the depth test performed first, and the shader is only entered exactly once per pixel, regardless of the number of primitives?

I am working in DirectX 9 and using shader model 4.0 level 9_1.

Thanks!

Was it helpful?

Solution

Depth testing occurs after the pixel shader. See this question.

Also, its clear that the pixel shader runs more than once per pixel. Consider alpha blending: the opaque pixels must be rendered first, and then transparent pixels are blended with the already rendered opaque pixels. This could never happen if the pixel shader was only entered once per pixel.

"Once per primitive" is not the correct terminology. A single primitive will most likey cover multiple pixels, so a single primitive will cause the pixel shader to be run for each pixel that the primitive covers.

To prevent the pixel shader from being run on primitives that are obscured by other objects, you must implement some form of occlusion culling. Alternatively, some drivers may do this for you to a certain extent. See this link and comment below.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top