This is often a good solution if you will very rarely overlap objects, or if your object is against a surface such that no other transparent object will pass beneath it. Any other semi-transparent object drawn will either always be above, or always be behind, the object you’re drawing, meaning depth sorting between this object and other transparent ones will simply disappear. This does work, but does produce some artefacts. Another option is simply to write to the z-buffer anyway. The trade-offs here are in performance, and difficulty of implementation. Since the transparency sorting is on a per-mesh basis, this will allow the problem to become rarer, as each part of the object can be sorted individually. The idea is that instead of having one large mesh, you separate it into several small ones, each carrying a part of the texture. This is a little more difficult to get right, and is only an approximation. This is the most accurate solution, and for small, distant, or high-res textures, this is definitely the best one. The trade-off here is with smoothness - you will lose the nice, soft edges you get with transparent objects. This allows complex shapes to be drawn, and since no pixel is semi-transparent, the depth buffer to be used. Cutout shaders solve this problem by applying a filter to the texture, giving every pixel a boolean value: visible or not visible. There are, in fact, a few possible ones, though they all involve trade-offs. Now that we’ve discussed the cause, let’s talk about solutions. The practical upshot of this is that if the centre of your transparent object goes behind another object, then the entire object will be rendered behind it. In Unity, the sorting method just takes the centre point of the mesh, and assumes that the entire mesh lies at the same depth value. Naturally, this produces some sorting errors, because per-pixel sorting, as found in the depth buffer, is not feasible. Semi-transparent objects require multiple pixels to be drawn at the same point, and so they have to be drawn either before or after the rest of the image. This is because the z-buffer makes the assumption that only one object will need to be drawn in any one pixel on the screen, in exchange for extremely fast sorting. When objects are semi-transparent, they cannot be accurately written into the depth buffer. The problem occurs with transparent objects, or, more precisely, semi-transparent pixels. This ensures that only the closest pixel is drawn, so everything appears in the right order. Usually, objects are drawn using the z-buffer, which draws a depth image as it renders the scene. The problem is due to how transparent objects are sorted in Unity.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |