Maniphest T82843

inverted GL_DEPTH_TEST behavior depending on object selection or presence of non-geo object
Closed, ResolvedBUG

Assigned To
None
Authored By
MACHIN3 (MACHIN3)
Nov 19 2020, 2:18 PM
Tags
  • BF Blender
  • EEVEE & Viewport
Subscribers
Germano Cavalcante (mano-wii)
MACHIN3 (MACHIN3)
Piotr (radi0n)

Description

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()

demo video

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

Related Objects

Mentioned In
T81334: viewport drawing with gpu module
Mentioned Here
T80730: BGL deprecation
rBad58999b0d46: Fix pin icon in Properties not right-aligned after zooming

Event Timeline

MACHIN3 (MACHIN3) created this task.Nov 19 2020, 2:18 PM
MACHIN3 (MACHIN3) updated the task description.
MACHIN3 (MACHIN3) updated the task description.
MACHIN3 (MACHIN3) updated the task description.Nov 19 2020, 2:21 PM
MACHIN3 (MACHIN3) updated the task description.
Piotr (radi0n) added a subscriber: Piotr (radi0n).Nov 19 2020, 6:37 PM

version: 2.91.0 Beta, branch: master, commit date: 2020-11-18 18:54, hash: ad58999b0d46, type: Release
build date: 2020-11-19, 00:04:58
platform: Windows

Exactly the same behavior as described.

Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Confirmed.Nov 20 2020, 3:34 PM
Germano Cavalcante (mano-wii) changed the subtype of this task from "Report" to "Bug".
Germano Cavalcante (mano-wii) added a project: EEVEE & Viewport.
Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).

Apparently the default status has changed and now you have to put a bgl.glDepthFunc(bgl.GL_LEQUAL) before :\
This change is inconvenient as it can break some addons and GL_LEQUAL is certainly more suitable as the default.
However, it is good to keep in mind that some addon callbacks can change the drawing status without warning.

Perhaps this is another problem to be considered in T80730: BGL deprecation.

MACHIN3 (MACHIN3) added a comment.Nov 20 2020, 3:56 PM

Thanks for pointing that out, much appreciated!

Jakub Uhlik (carbon14) mentioned this in T81334: viewport drawing with gpu module.Jan 28 2021, 10:23 AM
Campbell Barton (campbellbarton) changed the task status from Duplicate to Resolved.Jan 28 2021, 12:15 PM
Campbell Barton (campbellbarton) closed this task as a duplicate of T81334: viewport drawing with gpu module.