title: LibGDX nearby rectangles in 3D renders blocky/incorrectly
body: <p>I am using LibGDX, constructing rectangles in 3D space with <code>ModelBuilder#createRect</code>, placing them in a 3D environment, and rendering them with <code>ModelBatch</code>. Everything works almost right. The issue arises when two rectangles are near each other. It seems to have ranges of depth where some of the rectangles that are actually behind are rendered in front.</p>
  <p>To help illustrate what I mean, here are some examples:</p>
  <p>Even though we have 2 rectangles (the bush and the figure) both vertically angled the same, when the model instances are close to each other, parts of one is rendered in front even though the rectangle is flat and one should fully be in front of the other instead of a small stripe of the bush in front of the figure.</p>
  <p><a href="https://i.stack.imgur.com/GuyaQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GuyaQ.png" alt="enter image description here" /></a></p>
  <p>Here we have 2 intersecting rectangles (the wall and the figure). I would expect to see a clean cut between the 2 rectangles, but instead I get a staircase. This would lead me to believe it's keeping ranges of areas where one rectangle is always in front of another in that range even though there might be an intersection in that range, or it's omitting parts of the rectangle thinking that it doesn't need to render it.</p>
  <p><a href="https://i.stack.imgur.com/K4sY5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K4sY5.png" alt="enter image description here" /></a></p>
  <p>I believe these two examples stem from the same issue.</p>
  <p>When I render the rectangle, here is the code for the material.</p>
  <pre><code>material.set(BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA),
                  FloatAttribute(AlphaTest, 0.5f))
  </code></pre>
  <p>Adding a <code>FloatAttribute</code> with an arbitrary float seems to mitigate the issue, but not entirely. (The examples above are with the float attribute.)</p>
  <p>I am using <code>Environment</code>, <code>ModelBatch</code>, etc. from <code>com.badlogic.gdx.graphics.g3d</code> to render the rectangles.</p>
  <p>How can I use LibGDX to render the rectangles in 3D properly?</p>