Page MenuHome

BLI: new 'projmat_depth_offset' utility
Needs ReviewPublic

Authored by Germano Cavalcante (mano-wii) on Aug 3 2021, 11:32 PM.
Tags
None
Subscribers
None
Tokens
"Party Time" token, awarded by Jules."Love" token, awarded by franMarz."Like" token, awarded by campbellbarton.

Details

Summary

This patch fixes T90207, T81266 and T90901.

This patch reworks the polygon offset algorithm used in blender.

The solution is to create a new projmat_depth_offset utility that edits the projection matrix based on the desired depth range.

This allows a much simpler and more precise control of the offset that is intended to be obtained with a new projection matrix.

Diff Detail

Repository
rB Blender
Branch
tmp-drw-offset (branched from master)
Build Status
Buildable 16343
Build 16343: arc lint + arc unit

Event Timeline

Germano Cavalcante (mano-wii) requested review of this revision.Aug 3 2021, 11:32 PM
Germano Cavalcante (mano-wii) created this revision.
  • Simplify ortho computing
  • Add BLI_math utilities
  • Rename DRW_view_create_with_zpixel_offset --> DRW_view_create_with_zoffset_px
  • Compute better epsilon depth in perspective view
Germano Cavalcante (mano-wii) planned changes to this revision.Aug 10 2021, 8:00 PM

Using a 1/4 depth range epsilon can be too much in some cases.

  • Use the epsilon of clip_min
  • Remove offset related to pixel distance (use only epsilon)
  • Find the best values to multiply and add to the depth value in perspective mode
  • Replace all calls from the existing DRW_view_create_with_zoffset

Choosing a depth multiplication factor in perspective mode proved to be a challenge because there is no single factor that when multiplying results in a constant offset that is independent of depth.

But this problem was solved by not finding just a multiplication factor, but a factor to multiply and an offset to add to the depth.

With this change, the offset result was constant in geometries with different depths.

In fact, it turned out even better than blender 2.79 (which I'm not mistaken uses glPolygonOffset).

Also the new change now only uses the epsilon value as a reference and not the pixel size (best match with glPolygonOffset).

  • Disregard pixelsize
  • Decrease epsilon
  • Rebase on master
  • Silence warnings

Updated to test if it would make any difference on T94981.

  • Improve comment
  • Move documentation to header
  • Correct comment description
  • BLI: new 'projmat_zoffset' utility

The algorithm has been reworked and simplified.

The new projmat_depth_offset utility works by editing the projection matrix to match the new depth range submitted.

The offset equivalent to the size of 1 pixel was used to better match the old method.

Here are some images comparing the old and the new method:

Before:After:
Germano Cavalcante (mano-wii) retitled this revision from DRAW: new "polygon offset" algorithm to BLI: new 'projmat_depth_offset' utility.Nov 9 2022, 4:02 PM
Germano Cavalcante (mano-wii) edited the summary of this revision. (Show Details)
  • Simplify logic (use real distance values)
  • Remove minimum epsilon value to resolve all 24-bit depth buffer cases. This complicates the code and can bring unpredictable results.