I have a very simple project which renders a few triangles on the xy plane.
Some of them overlap and the first drawn always occludes the others. I had added depth testing and tried with .less and .lessequal with no change. I have tried changing the alpha parameter in their colours to 0.5 hoping they would share the overlap, but no change either.
Is there a way to do this?
When setting up the depth stencil state, you can do:
func buildDepthStencilState() {
let depthStencilDescriptor = MTLDepthStencilDescriptor()
depthStencilDescriptor.depthCompareFunction = .less
depthStencilDescriptor.isDepthWriteEnabled = false
depthStencilState = device.makeDepthStencilState(descriptor: depthStencilDescriptor)
}
This will draw the triangles in the order they appear in the vertex buffer.
Hello!
Depth testing alone won’t blend overlapping triangles—alpha values only work if blending is enabled. The fix is to turn on blending (glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)) and render transparent objects after opaque ones, ideally sorted back‑to‑front, so overlaps share correctly.