Quantcast
Viewing latest article 12
Browse Latest Browse All 90

Answer by Noise crime

With zWrite on polygon depths are written to the zbuffer effectively giving you perfecting sorting (avoiding the painters algorithm issues - look it up). So if you had a polygon at z=100 any future polygons that are further than z=100 will not be rendered.

However this does not mean it prevents overdraw as it depends upon the order of models/meshes/polygons being rendered. I.e if you render a polygon at z =100 then one at z=80 you'll still have rendered the further one, even though the closer one obscures.

So when applied to transparent models, its down to pure luck or careful orchestration of the render order to ensure that object maintains its transparency with other models or its own polygons. For example if you have two transparent polygons, the first is rendered at z =80, then the second at z=100 will not be rendered as its further than the depth in the zbuffer, meaning it will not be visible.

When turning zWrite Off, the polygons do not write their depth to the zbuffer, meaning without sorting transparent object and their polygons you will likely get incorrect draw orders, which is what you saw (again this is due to the issue from the 'painters algorithm').

However its impractical to sort per polygon, even more so if two models with different materials overlap, performance will simply nose-dive.

Often the way around this, at least for vegetation, foliage, trees & bushes is to fall back on the alpha test. Here are a boolean alpha test is carried out to see if the pixel should be drawn (and I guess write to the zbuffer, thus giving correct draw order for transparent materials). The drawback is being a boolean operation is that you get aliasing/jagged borders. To reduce this effect the vegetation is normally rendered again, but this time blended with zwrite off. It suffers the draworder problems as before, but as only the edges will render it helps to give a smoother transition than the boolean.

Oh and I should point out that the counterpart zRead is required for correct rendering not just zwrite.

Once you understand zWrite and zRead you can do some funky stuff with it, especially in conjunction with colorMask.


Viewing latest article 12
Browse Latest Browse All 90

Trending Articles