the problem with drawing the sky last and MSAA

shuipi

Newcomer
modern games draw the sky last because it's pretty expensive and we want to depth reject as many pixels as possible. however there's a problem when using msaa. Because msaa will give the edge of objects the blended color between the object and its background (the clear color), and the edge also has a depth that's similar to the object. When drawing the sky, it's depth tested against the edge, and hence is not drawn on it since the sky is further than the edge. This leaves a very annoying edge with some component of the clear color around objects. What's the best way to solve this?
 
Depth test is done per sample, not per pixel, so there's absolutely no problem with MSAA and drawing the skybox last, unless you're talking about a specific problem with your code.
 
I understand depth test is done on per sample basis. But what I still don't understand is, since the when drawing the object, the sky was not there yet, so the background of the object is the clear color (in my case, white), so when drawing the object with AA, the edge of the object will blend in the white (not the sky color since it's not there yet). Later when I draw the sky, it won't be drawn on the edge since the edge has a depth that's coloer than the sky. So now if the sky is pretty dark, I get a very obvious contrast with the white edge.
 
The MSAA samples are not "resolved" (blended/averaged) until all rendering to a render target has finished. Thus by the time you're doing the averaging, the sky is there :)

Note that draw ordering does occasionally pose a "problem" for NVIDIA's CSAA modes, in that they will produce no benefit if stuff is drawn in a certain order. However I can't remember which case works best and which one fails offhand :)
 
I see. It's the problem of our code again. It renders the scene first and then resolve, then draw the sky as a post effect. Thanks!
 
The blending of the samples is done when the the MSAA buffer is resolved, after all the samples are written. If this wasn't so you'd have to force a back to front render order for everything to avoid artifacts on pretty much every edge.

If you're seeing edge artifacts, it's surely for some other reason?
 
Note that draw ordering does occasionally pose a "problem" for NVIDIA's CSAA modes, in that they will produce no benefit if stuff is drawn in a certain order. However I can't remember which case works best and which one fails offhand :)

True. The only problem I found with drawing sky last was CSAA. Sometimes CSAA will even be a bit worse than the MSAA mode due to less optimal real sample position.

According to their patents, I think basically drawing from foreground to background will cause problem for CSAA, which is really bad as most games I think will be drawing in that order.
 
Back
Top