WIP: Use a different method for overlay edit mesh bias #104921

Closed
Jorijn de Graaf wants to merge 1 commits from bonj/blender:overlay-edit-mesh-offset into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

This is the same way I did it for retopology, and it works there.
Don't merge this, it's just a proof of concept.

This is the same way I did it for retopology, and it works there. Don't merge this, it's just a proof of concept.
Jorijn de Graaf added 1 commit 2023-02-18 14:47:02 +01:00
1d92979411 Use a different method for overlay edit mesh bias
This is the same way I did it for retopology, and it works there.
Jorijn de Graaf requested review from Clément Foucault 2023-02-18 16:43:38 +01:00

So, I now remember where this offset comes from.

It was originally using glPolygonOffset(1)(2) for that. I don't remember the values used at the time, but I remember the guideline was to get the same result with the new implementation. ED_view3d_polygon_offset was then used to emulate the glPolygonOffset when moving to GL 3.3 (3).

glPolygonOffset has 2 parameters:

  • factor, which gives you a bias equal to factor * Z_delta. This wasn't used in the previous implementation and isn't emulated in the current one for performance and accuracy reason (it can make edges poke trough surfaces that are parallels to the view plane).
  • units is basically a factor to an epsilon value chosen by the implementation. I remember vaguely that we only used 1 unit of bias.

This presentation (4) gives a good derivation to what the bias should be. The espilon value should be as low as possible in normal case and adjustable in the retopo case. Note that the slide 21 state Z_ndc = ... + epsilon. Since we are biasing in clip space this epsilon value becomes epsilon * W_clip. Note that W_clip = gl_Position.w in the code.
The abs(W_clip) comes from me not wanting to change the bias sign for (questionable) clarity.

There are confusion about NDC Space vs Clip Space coordinate throughout the codebase. I am to blame as I conflated both terms for a long time. I created #105070 for tracking this issue.

References:

  1. https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml
  2. https://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm
  3. 87a0770bb9/source/blender/gpu/intern/gpu_matrix.cc (L690)
  4. http://www.terathon.com/gdc07_lengyel.pdf (p. 18 Depth Modification)
So, I now remember where this offset comes from. It was originally using `glPolygonOffset`(1)(2) for that. I don't remember the values used at the time, but I remember the guideline was to get the same result with the new implementation. `ED_view3d_polygon_offset` was then used to emulate the `glPolygonOffset` when moving to GL 3.3 (3). `glPolygonOffset` has 2 parameters: - `factor`, which gives you a bias equal to `factor * Z_delta`. This wasn't used in the previous implementation and isn't emulated in the current one for performance and accuracy reason (it can make edges poke trough surfaces that are parallels to the view plane). - `units` is basically a factor to an epsilon value chosen by the implementation. I remember vaguely that we only used 1 unit of bias. This presentation (4) gives a good derivation to what the bias should be. The espilon value should be as low as possible in normal case and adjustable in the retopo case. Note that the slide 21 state `Z_ndc = ... + epsilon`. Since we are biasing in clip space this epsilon value becomes `epsilon * W_clip`. Note that `W_clip = gl_Position.w` in the code. The `abs(W_clip)` comes from me not wanting to change the bias sign for (questionable) clarity. There are confusion about NDC Space vs Clip Space coordinate throughout the codebase. I am to blame as I conflated both terms for a long time. I created #105070 for tracking this issue. References: 1. https://registry.khronos.org/OpenGL-Refpages/gl4/html/glPolygonOffset.xhtml 2. https://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm 3. https://github.com/dfelinto/blender/blob/87a0770bb969ce37d9a41a04c1658ea09c63933a/source/blender/gpu/intern/gpu_matrix.cc#L690 4. http://www.terathon.com/gdc07_lengyel.pdf (p. 18 Depth Modification)
Author
Contributor

I've gotten a response and talked about it further on the Blender Chat, and I've learned more about matrix math; basically this PR is no longer needed, so I'll close it now.
Here's the resources that helped me the most:

I've gotten a response and talked about it further on the Blender Chat, and I've learned more about matrix math; basically this PR is no longer needed, so I'll close it now. Here's the resources that helped me the most: * https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/projection-matrix-introduction.html (and subsequent pages) * http://www.terathon.com/gdc07_lengyel.pdf (pages 18-26)
Jorijn de Graaf closed this pull request 2023-02-26 18:39:55 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
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
2 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#104921
No description provided.