Grease Pencil depth merge is broken when multiple GP objects are displayed in viewport #102308

Closed
opened 2022-11-06 19:52:38 +01:00 by Mathias Kærlev · 7 comments

System Information

Operating system: Windows 11
CPU: AMD Ryzen Threadripper 3990X
Graphics card: NVIDIA GeForce RTX 3080

Also tested on

Operating system: macOS Monterey 12.5
Machine: MacBook Pro M1 (16-inch, 2021)

Blender Version
Broken: 3.5.0 4a313b8252 2022-11-04 22:28
Also broken in 3.1.0 c77597cd0e 2022-03-08 18:16, so this is a longstanding issue.

Short description of error
Creating multiple GP objects with "Stroke Depth Order: 3D Location" causes the GP objects to reorder randomly in the viewport.
Sometimes, an object will be partially shown behind/in front of another object.
Video of the issue:
https://dl.dropboxusercontent.com/s/upg3rx1yjxdm1fy/GUsPz2Qo.webm

Exact steps for others to reproduce the error

  1. Open the following .blend file: gp_depth_bug.blend
  2. Rotate the view in the viewport to see how the 3 GP objects do not get rendered correctly wrt depth.

Technical exploration & possible fix
I am not well-versed in Blender internals at all, but here is my analysis:

Using RenderDoc, it appears that the depth merge pass (draw pass merge_depth_ps) does not work correctly:

Source depth texture: https://dl.dropboxusercontent.com/s/0pjjai3mz2cl8s9/4hcRr0rQ.png
Output framebuffer: https://dl.dropboxusercontent.com/s/2mtur25jmkykbf8/eSt7UkHy.png

Also, the output from the VS stage for this pass doesn't seem correct at all.
Looking at the vertex shader for this pass (gpencil_depth_merge_vert.glsl):

void main()
{
  mat4 model_matrix = mat4(gpModelMatrix[0], gpModelMatrix[1], gpModelMatrix[2], gpModelMatrix[3]);
  int v = gl_VertexID % 3;
  float x = -1.0 + float((v & 1) << 2);
  float y = -1.0 + float((v & 2) << 1);
  gl_Position = drw_view.winmat * (drw_view.viewmat * (model_matrix * vec4(x, y, 0.0, 1.0)));
}

I suspect there is an optimization going on so only the area covered by the GP object needs to have its depth merged.

However, changing this to the following seems to fix the issue (i.e. switching to a fullscreen triangle):

void main()
{
  int v = gl_VertexID % 3;
  float x = -1.0 + float((v & 1) << 2);
  float y = -1.0 + float((v & 2) << 1);
  gl_Position = vec4(x, y, 1.0, 1.0);
}

Here is a video showing the fixed depth merge pass:
https://dl.dropboxusercontent.com/s/gq33i9ofjbj9y7c/SoCkR0XU.webm

I'm sure I'm missing the full picture, but at least this fixes things for this .blend file.

**System Information** Operating system: `Windows 11` CPU: `AMD Ryzen Threadripper 3990X` Graphics card: `NVIDIA GeForce RTX 3080` Also tested on Operating system: `macOS Monterey 12.5` Machine: `MacBook Pro M1 (16-inch, 2021)` **Blender Version** Broken: 3.5.0 4a313b82529b 2022-11-04 22:28 Also broken in 3.1.0 c77597cd0e15 2022-03-08 18:16, so this is a longstanding issue. **Short description of error** Creating multiple GP objects with "Stroke Depth Order: 3D Location" causes the GP objects to reorder randomly in the viewport. Sometimes, an object will be partially shown behind/in front of another object. Video of the issue: https://dl.dropboxusercontent.com/s/upg3rx1yjxdm1fy/GUsPz2Qo.webm **Exact steps for others to reproduce the error** 1) Open the following .blend file: [gp_depth_bug.blend](https://archive.blender.org/developer/F13861970/gp_depth_bug.blend) 2) Rotate the view in the viewport to see how the 3 GP objects do not get rendered correctly wrt depth. **Technical exploration & possible fix** I am not well-versed in Blender internals at all, but here is my analysis: Using RenderDoc, it appears that the depth merge pass (draw pass `merge_depth_ps`) does not work correctly: Source depth texture: https://dl.dropboxusercontent.com/s/0pjjai3mz2cl8s9/4hcRr0rQ.png Output framebuffer: https://dl.dropboxusercontent.com/s/2mtur25jmkykbf8/eSt7UkHy.png Also, the output from the VS stage for this pass doesn't seem correct at all. Looking at the vertex shader for this pass (`gpencil_depth_merge_vert.glsl`): ``` void main() { mat4 model_matrix = mat4(gpModelMatrix[0], gpModelMatrix[1], gpModelMatrix[2], gpModelMatrix[3]); int v = gl_VertexID % 3; float x = -1.0 + float((v & 1) << 2); float y = -1.0 + float((v & 2) << 1); gl_Position = drw_view.winmat * (drw_view.viewmat * (model_matrix * vec4(x, y, 0.0, 1.0))); } ``` I suspect there is an optimization going on so only the area covered by the GP object needs to have its depth merged. However, changing this to the following seems to fix the issue (i.e. switching to a fullscreen triangle): ``` void main() { int v = gl_VertexID % 3; float x = -1.0 + float((v & 1) << 2); float y = -1.0 + float((v & 2) << 1); gl_Position = vec4(x, y, 1.0, 1.0); } ``` Here is a video showing the fixed depth merge pass: https://dl.dropboxusercontent.com/s/gq33i9ofjbj9y7c/SoCkR0XU.webm I'm sure I'm missing the full picture, but at least this fixes things for this .blend file.

Added subscriber: @Mathias-Kaerlev

Added subscriber: @Mathias-Kaerlev
Member

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

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

Added subscribers: @antoniov, @fclem

Added subscribers: @antoniov, @fclem
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Miguel Pozo self-assigned this 2022-11-07 19:11:17 +01:00
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Member

This is an asset issue. I guess this was auto-generated from other software?

The dimensions of your environment object are (x = 511.7, y = 19708816.0, z = 6.7).
This was also causing the viewport navigation to behave incorrectly.

Selecting only the visible strokes and deleting the others results in correct behavior. gp_depth_bug.blend

This is an asset issue. I guess this was auto-generated from other software? The dimensions of your environment object are (x = 511.7, y = 19708816.0, z = 6.7). This was also causing the viewport navigation to behave incorrectly. Selecting only the visible strokes and deleting the others results in correct behavior. [gp_depth_bug.blend](https://archive.blender.org/developer/F13869396/gp_depth_bug.blend)
Member

Changed status from 'Resolved' to: 'Archived'

Changed status from 'Resolved' to: 'Archived'
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#102308
No description provided.