Volumes have an offset in viewport, Eevee and Cycles. #85312

Closed
opened 2021-02-02 16:06:33 +01:00 by Jacques Lucke · 10 comments
Member

We store volumes in OpenVDB grids. Voxels in those grids can be accessed using signed integer coordinates. In most cases a voxel can be thought of as a cube. The main question this task tries to answer is where the cube of the voxel with the coordinate (0, 0, 0) should be displayed and rendered.

Currently, the voxel (0, 0, 0) is rendered in the cube [0, 1]^3 (assuming no other transforms are applied). The "origin" voxel is not centered around (0, 0, 0) in world space. This can be seen in the image below.

image.png

The issue is, that OpenVDBs tools seem to expect that the (0, 0, 0) voxel is centered in world space. This can be seen when running the following code:

auto my_grid = openvdb::FloatGrid::create(0.0f);
auto accessor = my_grid->getAccessor();
accessor.setValueOn({0, 0, 0}, 1);


std::vectoropenvdb::Vec3s verts;
std::vectoropenvdb::Vec3I tris;
std::vectoropenvdb::Vec4I quads;
openvdb::tools::volumeToMesh(*my_grid, verts, tris, quads, 0.001f, 0.0f);


for (int i = 0; i < verts.size(); i++) {
std::cout << i << ": " << verts[i] << "\n";
}

This outputs:

0: [-0.333, -0.333, -0.333]
1: [-0.333, -0.333, 0.333]
2: [-0.333, 0.333, -0.333]
3: [-0.333, 0.333, 0.333]
4: [0.333, -0.333, -0.333]
5: [0.333, -0.333, 0.333]
6: [0.333, 0.333, -0.333]
7: [0.333, 0.333, 0.333]

When using these computed coordinates as vertex positions, the generated mesh will not be aligned correctly with the volume grid. Therefore, to correct the alignment, we currently have to add an offset every time we convert between volumes and meshes.

To me it seems like the best solution would be to change the rendering code, instead of adding the offset in many places. I haven't checked how other software handles this yet.

We store volumes in OpenVDB grids. Voxels in those grids can be accessed using signed integer coordinates. In most cases a voxel can be thought of as a cube. The main question this task tries to answer is where the cube of the voxel with the coordinate `(0, 0, 0)` should be displayed and rendered. Currently, the voxel `(0, 0, 0)` is rendered in the cube `[0, 1]^3` (assuming no other transforms are applied). The "origin" voxel is **not** centered around `(0, 0, 0)` in world space. This can be seen in the image below. ![image.png](https://archive.blender.org/developer/F9609392/image.png) The issue is, that OpenVDBs tools seem to expect that the `(0, 0, 0)` voxel is centered in world space. This can be seen when running the following code: ```lang=c++ ``` auto my_grid = openvdb::FloatGrid::create(0.0f); auto accessor = my_grid->getAccessor(); accessor.setValueOn({0, 0, 0}, 1); ``` ``` std::vector<openvdb::Vec3s> verts; std::vector<openvdb::Vec3I> tris; std::vector<openvdb::Vec4I> quads; openvdb::tools::volumeToMesh(*my_grid, verts, tris, quads, 0.001f, 0.0f); ``` ``` for (int i = 0; i < verts.size(); i++) { std::cout << i << ": " << verts[i] << "\n"; } ``` ``` This outputs: ``` 0: [-0.333, -0.333, -0.333] 1: [-0.333, -0.333, 0.333] 2: [-0.333, 0.333, -0.333] 3: [-0.333, 0.333, 0.333] 4: [0.333, -0.333, -0.333] 5: [0.333, -0.333, 0.333] 6: [0.333, 0.333, -0.333] 7: [0.333, 0.333, 0.333] ``` When using these computed coordinates as vertex positions, the generated mesh will not be aligned correctly with the volume grid. Therefore, to correct the alignment, we currently have to add an offset every time we convert between volumes and meshes. To me it seems like the best solution would be to change the rendering code, instead of adding the offset in many places. I haven't checked how other software handles this yet.
Author
Member

Added subscribers: @JacquesLucke, @brecht

Added subscribers: @JacquesLucke, @brecht
Member

Added subscriber: @HooglyBoogly

Added subscriber: @HooglyBoogly

Added subscriber: @kevindietrich

Added subscriber: @kevindietrich

I'm fine with changing the rendering code to be offset by half a voxel, it shouldn't really break compatibility much.

I couldn't find a convention in the OpenVDB docs, they give examples of how to handle both. But if the tools work this way I think it's a good choice.

@kevindietrich @JacquesLucke can either of you implement this for Cycles/Eevee/workbench?

I'm fine with changing the rendering code to be offset by half a voxel, it shouldn't really break compatibility much. I couldn't find a convention in the OpenVDB docs, they give examples of how to handle both. But if the tools work this way I think it's a good choice. @kevindietrich @JacquesLucke can either of you implement this for Cycles/Eevee/workbench?
Member

Added subscriber: @jta

Added subscriber: @jta
Author
Member

I'll make a patch for it.

I'll make a patch for it.
Jacques Lucke self-assigned this 2021-02-03 15:18:31 +01:00
Author
Member

I uploaded a patch in D10295. It's still work in progress. I also found a couple of issues in existing drawing code along the way (incorrect bounding box computation that lead to incorrect renders; dimensions of a bounding box were one unit too small; multiple_transforms is always set to true).

I uploaded a patch in [D10295](https://archive.blender.org/developer/D10295). It's still work in progress. I also found a couple of issues in existing drawing code along the way (incorrect bounding box computation that lead to incorrect renders; dimensions of a bounding box were one unit too small; `multiple_transforms` is always set to true).
Member

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

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

Added subscriber: @Raimund58

Added subscriber: @Raimund58
Philipp Oeser removed the
Interest
Render & Cycles
label 2023-02-09 14:01:56 +01:00
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-02-17 16:35:19 +01:00

Hello.
Has this been fixed already in 3.5? Why was this closed? I see a reference to this issue in blenkernel/intern/volume_to_mesh.cc from 3 years ago, but I still have a similar issue in 3.5 (specifically, VolumeToMesh node results in a slightly offset mesh, by approximately 1 voxel).

Hello. Has this been fixed already in 3.5? Why was this closed? I see a reference to this issue in blenkernel/intern/volume_to_mesh.cc from 3 years ago, but I still have a similar issue in 3.5 (specifically, VolumeToMesh node results in a slightly offset mesh, by approximately 1 voxel).
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
8 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#85312
No description provided.