Regression - depth buffer drawing go bonkers when selecting object on second collection #83482

Open
opened 2020-12-06 20:50:05 +01:00 by Jose Conseco · 14 comments

System Information
Operating system: Linux-5.8.18-1-MANJARO-x86_64-with-arch-Manjaro-Linux 64 Bits
Graphics card: GeForce GTX 1660 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 440.100

Blender Version
Broken: version: 2.91.0, branch: master, commit date: 2020-11-25 08:34, hash: 0f45cab862
Worked: 2.90

Short description of error
After drawing simple 3d lines with python script - depth buffer is drawn incorrectly when deselecting object that is placed on second collection.
Script itself is very generic - from blender gpu docs examples. It worked ok in all previous blender versions.

Linde_draw_depth_bug.mp4

Exact steps for others to reproduce the error

  • run script - it will draw 2 lines in 3d view for 8 seconds
  • if you select/deselect box which is placed on second layer/collection you will see those lines are drawn incorrectly on object deselect.

3d_view_lines_bug.blend

**System Information** Operating system: Linux-5.8.18-1-MANJARO-x86_64-with-arch-Manjaro-Linux 64 Bits Graphics card: GeForce GTX 1660 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 440.100 **Blender Version** Broken: version: 2.91.0, branch: master, commit date: 2020-11-25 08:34, hash: `0f45cab862` Worked: 2.90 **Short description of error** After drawing simple 3d lines with python script - depth buffer is drawn incorrectly when deselecting object that is placed on **second collection**. Script itself is very generic - from blender gpu docs examples. It worked ok in all previous blender versions. [Linde_draw_depth_bug.mp4](https://archive.blender.org/developer/F9480991/Linde_draw_depth_bug.mp4) **Exact steps for others to reproduce the error** - run script - it will draw 2 lines in 3d view for 8 seconds - if you select/deselect box which is placed on second layer/collection you will see those lines are drawn incorrectly on object deselect. [3d_view_lines_bug.blend](https://archive.blender.org/developer/F9480987/3d_view_lines_bug.blend)
Author

Added subscriber: @JoseConseco

Added subscriber: @JoseConseco

Added subscriber: @rjg

Added subscriber: @rjg

This is the same issue as reported in #82647 which is caused by a missing bgl.glDepthMask(bgl.GL_TRUE) in the script. Adding this before the bgl.glEnable(bgl.GL_DEPTH_TEST) to your script solves the problem.

This is the same issue as reported in #82647 which is caused by a missing `bgl.glDepthMask(bgl.GL_TRUE)` in the script. Adding this before the `bgl.glEnable(bgl.GL_DEPTH_TEST)` to your script solves the problem.

Closed as duplicate of #82647

Closed as duplicate of #82647
Author

@rjg Did you actually test the change?Adding bgl.glDepthMask(bgl.GL_TRUE) changed nothing for me. I cant reopen the task now.
From what I googled: glDepthMask - enables writing to depth buffer. But in my bug report - the problem is - depth buffer is messed up when drawing with bgl on second collection only when no object is selected Maybe I'm missing somehting. Update code that still wont work:

import bpy
import gpu
import bgl
from gpu_extras.batch import batch_for_shader

coords = [(1, 1, 1), (-2, 0, 0), (-2, -1, 3), (0, 1, 1)]
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": coords})


def draw():
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glDepthMask(bgl.GL_TRUE)
    bgl.glEnable(bgl.GL_DEPTH_TEST)
    
    shader.bind()
    shader.uniform_float("color", (1, 1, 0, 0.6))
    batch.draw(shader)
    bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glDisable(bgl.GL_BLEND)

args = ()
handle=bpy.types.SpaceView3D.draw_handler_add(draw, args, 'WINDOW', 'POST_VIEW')
def in_5_seconds():
    print("Hello World")
    bpy.types.SpaceView3D.draw_handler_remove(handle, 'WINDOW')


bpy.app.timers.register(in_5_seconds, first_interval=8)
@rjg Did you actually test the change?Adding **bgl.glDepthMask(bgl.GL_TRUE)** changed nothing for me. I cant reopen the task now. From what I googled: glDepthMask - enables writing to depth buffer. But in my bug report - the problem is - depth buffer is messed up when drawing with bgl **on second collection only when no object is selected** Maybe I'm missing somehting. Update code that still wont work: ``` import bpy import gpu import bgl from gpu_extras.batch import batch_for_shader coords = [(1, 1, 1), (-2, 0, 0), (-2, -1, 3), (0, 1, 1)] shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') batch = batch_for_shader(shader, 'LINES', {"pos": coords}) def draw(): bgl.glEnable(bgl.GL_BLEND) bgl.glDepthMask(bgl.GL_TRUE) bgl.glEnable(bgl.GL_DEPTH_TEST) shader.bind() shader.uniform_float("color", (1, 1, 0, 0.6)) batch.draw(shader) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glDisable(bgl.GL_BLEND) args = () handle=bpy.types.SpaceView3D.draw_handler_add(draw, args, 'WINDOW', 'POST_VIEW') def in_5_seconds(): print("Hello World") bpy.types.SpaceView3D.draw_handler_remove(handle, 'WINDOW') bpy.app.timers.register(in_5_seconds, first_interval=8) ```

@JoseConseco My bad, that was a misunderstanding and error on my part.

@JoseConseco My bad, that was a misunderstanding and error on my part.

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

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

Added subscriber: @fclem

Added subscriber: @fclem

My initial remark was nonsense since you don't attempt to clear the depth buffer. I've tested for a different use case than what you were attempting achieve.

The problem you're having happens when unselecting an object from a collection other than the first, while the first collection is hidden. The drawing issue can be avoided by setting the function for the depth test: bgl.glDepthFunc(bgl.GL_LEQUAL) .

import bpy
import gpu
import bgl
from gpu_extras.batch import batch_for_shader

coords = [(1, 1, 1), (-2, 0, 0), (-2, -1, 3), (0, 1, 1)]
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": coords})


def draw():
    bgl.glDepthFunc(bgl.GL_LEQUAL)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_DEPTH_TEST)
    shader.bind()
    shader.uniform_float("color", (1, 1, 0, 0.6))
    batch.draw(shader)
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    bgl.glDisable(bgl.GL_BLEND)

handle = bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')

def in_5_seconds():
    print("Hello World")
    bpy.types.SpaceView3D.draw_handler_remove(handle, 'WINDOW')


bpy.app.timers.register(in_5_seconds, first_interval=10)

@fclem this seems like a bug to me but my OpenGL is a little rusty. Could you check how this is supposed to work in 2.91? It seems that when the first collection is invisible, deselecting an object in another collection causes the comparison function for the depth buffer to be GL_GEQUAL or something with a similar effect.

My initial remark was nonsense since you don't attempt to clear the depth buffer. I've tested for a different use case than what you were attempting achieve. The problem you're having happens when unselecting an object from a collection other than the first, while the first collection is hidden. The drawing issue can be avoided by setting the function for the depth test: `bgl.glDepthFunc(bgl.GL_LEQUAL)` . ``` import bpy import gpu import bgl from gpu_extras.batch import batch_for_shader coords = [(1, 1, 1), (-2, 0, 0), (-2, -1, 3), (0, 1, 1)] shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR') batch = batch_for_shader(shader, 'LINES', {"pos": coords}) def draw(): bgl.glDepthFunc(bgl.GL_LEQUAL) bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_DEPTH_TEST) shader.bind() shader.uniform_float("color", (1, 1, 0, 0.6)) batch.draw(shader) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glDisable(bgl.GL_BLEND) handle = bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW') def in_5_seconds(): print("Hello World") bpy.types.SpaceView3D.draw_handler_remove(handle, 'WINDOW') bpy.app.timers.register(in_5_seconds, first_interval=10) ``` @fclem this seems like a bug to me but my OpenGL is a little rusty. Could you check how this is supposed to work in 2.91? It seems that when the first collection is invisible, deselecting an object in another collection causes the comparison function for the depth buffer to be `GL_GEQUAL` or something with a similar effect.

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Author

bgl.glDepthFunc(bgl.GL_LEQUAL) - indeed fixed the problem, but I still think this is a bug. Its weird first collection works ok, and it depends if object is selected or not

bgl.glDepthFunc(bgl.GL_LEQUAL) - indeed fixed the problem, but I still think this is a bug. Its weird first collection works ok, and it depends if object is selected or not

Changed status from 'Needs Developer To Reproduce' to: 'Confirmed'

Changed status from 'Needs Developer To Reproduce' to: 'Confirmed'

Since I can reproduce the problem and there doesn't seem to be any change in behavior documented in the release notes or manual, I will confirm this issue.

Since I can reproduce the problem and there doesn't seem to be any change in behavior documented in the release notes or manual, I will confirm this issue.

Added subscriber: @2046411367

Added subscriber: @2046411367
Philipp Oeser removed the
Interest
EEVEE & Viewport
label 2023-02-09 15:14:08 +01:00
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
3 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#83482
No description provided.