System Information
Operating system: Linux-4.15.0-117-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GTX 1050/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21
Blender Version
Broken: version: 2.91.0 Beta, branch: master, commit date: 2020-11-18 18:54, hash: rBad58999b0d46
Worked: 2.90.1
Short description of error
Drawing anything using the GPU shader module and using bgl.GL_DEPTH_TEST produces odd behavior in 2.91.
In the example below bgl.GL_DEPTH_TEST is enabled to have geometry occlude what is drawn. This worked fine in the past.
In 2.91, this only works if geometry is selected(and so the selection outline overlay is drawn). With the object not selected, the depth test occlusion will behave inverted: Drawing when occluded and not drawing when revealed.
In addition to selecting, having an empty or other non-geo objects present will also correct this behavior.
import bpy
from mathutils import Vector
import gpu
from gpu_extras.batch import batch_for_shader
import bgl
def draw():
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
shader.bind()
shader.uniform_float("color", (1, 0, 0, 0.5))
bgl.glEnable(bgl.GL_DEPTH_TEST)
bgl.glPointSize(10)
batch = batch_for_shader(shader, 'POINTS', {"pos": [Vector((0, 0, 1))]})
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')
bpy.context.area.tag_redraw()Exact steps for others to reproduce the error
- open the blend file in a recent 2.91 beta build
- run the script, a red dot will be drawn in the 3d view (move the viewport to force the area to redraw)
- the dot should be occluded, but isn't
- select the cube and it will be occluded, move it to reveal the dot
- deselect the cube and the dot will be hidden, even though its outside the cube now
- create an empty and the dot will again be drawn when outside the cube, and hidden when occluded by it, no matter what your selection is, as you'd expect