Issue
When rendering this cube, I'm using the moderngl DEPTH_TEST to properly draw in the faces at the correct depth, which works fine as shown:
However, I want to make the cube transparent. After giving it a slightly transparent texture, it renders like this:
For some reason, the part of the cube behind the front face is ignored, causing it just to be tinted red.
This is what it looks like when spun:
Some angles it works, others it doesn't.
When I disable the depth test, everything is properly rendered but in the wrong order. Is there anyway to fix this? (Using python moderngl)
Solution
Blending doesn't work properly when Depth Test is enabled, because the fragments behind already drawn objects are discarded by depth test before they can be blended. You must draw the primitives in the correct order from back to front to make it work properly. See also OpenGL depth sorting and OpenGL: Transparent texture issue.
Note that OpenGL is not a game engine, it is just a low-level API that does exactly what you tell it to do in this exact order in which you tell it to do it.
Answered By - Rabbid76
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.