The Blender Python API by Chris Conlan

The Blender Python API by Chris Conlan

Author:Chris Conlan
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


To understand why Z-fighting occurs, we must understand how depth buffers function in renderers. In almost every case, the computations involved in rendering an object occur on graphics processing units (GPUs) with very standardized graphics APIs (e.g., OpenGL and DirectX). The standard protocol in these rendering APIs is to use the camera’s position relative to the meshes to determine which objects are visible and invisible to the user. This information is stored in the depth buffer. Before presenting a 2D image on the screen, the depth buffer tells the renderer which mesh pixel is closest to the camera and therefore visible to the user.

Given this information, why does the depth buffer not favor one mesh over another to prevent the glitchy Z-fighting effect? The depth buffer stores high-precision floating-point values, and renderers do not make adjustments to assess the equality of floating-point numbers. Low-level languages that drive graphics APIs maintain efficiency by making naive floating-point number comparisons. For the same reason that 0.1 * 0.1 > 0.01 returns True in Python, floating-point number comparisons behave inconsistently in renderers. The problems associated with floating-point arithmetic are well-studied in computer science, and floating-point equality is one of its most significant challenges.

How does one solve this problem given the tools in Blender and its Python API? There are a number of solutions, depending on the particular situation. Translate each object by a small and unnoticeable amount (around 0.000001 Blender units) such that the surfaces are no longer coplanar. If the translation has no effect, try translating it by a slightly larger distance.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.