Page MenuHome

Fix: Avoid FP error to accumulate when creating mesh primitives
ClosedPublic

Authored by Mattias Fredriksson (Osares) on Aug 5 2021, 12:06 PM.

Details

Summary

Problem

Mesh primitives created using geometry nodes uses loops to create vertices and accumulates positions/angles in FP variables. This allows FP rounding errors to accumulate and can introduce significant errors.

Solution

To minimize changes from original implementation, variables allowing errors to accumulate are replaced by: delta * index.

Affected 'Mesh Primitives' nodes: Line, Grid, Cylinder, Circle, Cone, UV-Sphere.

Limitations

It is possible to further improve precision in the generated vertex coordinates. However this patch is only concerned with resolving the bug in the current algorithms. Example of further improvements is available in T87779 and the attempted fix rB5946352ae2c.

The issue only significant for large number of vertices, this also implies that performance is not affected (vertex count is small) or performance is affected but accuracy is improved (vertex count is large).

Related issues

T87779, D11772

Test

A test file to reproduce the issues are available in the file below. Objects are placed at an offset of 10k and uses ~20k verts at which errors are visible (see below). Results may vary depending on the compiler/system.

Basic sys to produce test results:
Operating system: Windows 10
Blender version: 3.0.0 hash: c18d91918fbb, master, 2021-08-04

Node setup:


master

Errors are clearly visible in encircled areas, circular primitives create overlapping geometry (this will occur for large vertex counts even if radius is small), and the grid/line primitive does not reach their intended size.


solution

Overlapping geometry is no longer visible and grid/line primitive reach their intended size. However, the grid/line only does not match the intended size exactly and circle primitives are not perfectly symmetric due to FP rounding errors (i.e. algorithms can be improved further).

Diff Detail

Repository
rB Blender
Branch
fix-mesh-prim-error-acc (branched from master)
Build Status
Buildable 16237
Build 16237: arc lint + arc unit

Event Timeline

Mattias Fredriksson (Osares) requested review of this revision.Aug 5 2021, 12:06 PM
Mattias Fredriksson (Osares) created this revision.
Mattias Fredriksson (Osares) retitled this revision from Fixed grid primitive to Fix: Avoid FP error to accumulate when creating mesh primitives.Aug 5 2021, 1:05 PM
Mattias Fredriksson (Osares) edited the summary of this revision. (Show Details)
Mattias Fredriksson (Osares) edited the summary of this revision. (Show Details)
Mattias Fredriksson (Osares) edited the summary of this revision. (Show Details)

Thanks! We can probably improve the precision by using doubles in some parts of the calculations (obviously not the stored data though).

This revision is now accepted and ready to land.Aug 5 2021, 4:23 PM

For circular shapes it could be useful, but I'm not sure if the precision sought in the mentioned bug report is achievable using a 32-bit FP representation. One could use 8-way symmetry of a circle in combination with a look-up-table (LUT) to ensure the geometry is 'symmetrical', but during transformation geometry would still be deformed (so using a LUT would probably be over the top). Utilizing the circle symmetry could be used to speed-up the algorithm though as it would reduce number of trigonometric function calls by roughly 1/8, but would only be possible when the segment count is a power of 2 (so shapes would be 'subdivided'). But yeah, thought about relevance for the idea and determined it is a 'for another time' problem.