inverted GL_DEPTH_TEST behavior depending on object selection or presence of non-geo object #82843

Closed
opened 2020-11-19 14:18:45 +01:00 by MACHIN3 · 9 comments

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: ad58999b0d
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
inverted GL_DEPTH_TEST behavior depending on object selection or non-geo object presence.blend

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
**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: `ad58999b0d` 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 ](https://www.youtube.com/watch?v=oy3PDDSdSdY) [inverted GL_DEPTH_TEST behavior depending on object selection or non-geo object presence.blend](https://archive.blender.org/developer/F9325495/inverted_GL_DEPTH_TEST_behavior_depending_on_object_selection_or_non-geo_object_presence.blend) **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
Author

Added subscriber: @MACHIN3

Added subscriber: @MACHIN3

Added subscriber: @Pinnhead

Added subscriber: @Pinnhead

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

Exactly the same behavior as described.

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.

Added subscriber: @mano-wii

Added subscriber: @mano-wii

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

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 blender/blender-addons#80730 (BGL deprecation).

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 blender/blender-addons#80730 (BGL deprecation).
Author

Thanks for pointing that out, much appreciated!

Thanks for pointing that out, much appreciated!

Closed as duplicate of #81334

Closed as duplicate of #81334

Changed status from 'Duplicate' to: 'Resolved'

Changed status from 'Duplicate' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#82843
No description provided.