Skip to content

Shift and scale VBO when precision requires it.

David Thompson requested to merge dcthomp/vtk:vbo-shift-scale into master

This change identifies datasets that are far from their origins (relative to their bounds), which can result in precision problems when rendering. Problem datasets have their VBO modified and transforms concatenated to the view/display transforms sent to the shaders by the mapper to correct the problem.

OpenGL drivers often use reduced-precision point coordinates; if the most significant bits are all used by a large translation then renderings are often misleading and frame-to-frame differences exaggerated. To counter this, this commit makes each VBO store shift and scale vectors generated when CreateVBO is called. If the origin is more than 10,000 bounding-box lengths away, transform the points as they are written to the VBO (this condition forces a slow-path where the VBO is generated, not copied directly from the vtkPoints array). When this occurs, the VBO presents a flag that informs the mapper to concatenate an inverse transform to the model-to-display and model-to-viewport matrices. Since these transformations include the camera projection and are done on the CPU with high precision, the translation is factored out of the data when the camera is nearby.

This change also makes the VBO objects that the mappers own publicly accessible so that applications can override the behavior, either to manually set the shift and scale (as calling AppendVBO multiple times cannot compute a proper shift and scale) or to disable it should it cause issues.

Thanks to Ken Martin for suggesting this approach.

Merge request reports