In cone-beam mode, gVXR's L-buffer interpolates the object-space position affinely in detector coordinates, so path lengths through objects are biased. On a test with exact slab-intersection truth, the relative log-transmission error is 1.6%. A one-line change to the vertex shaders reduces it to about 4e-5 and leaves parallel-beam output bit-identical.
Tested with the gVXR 2.1.0 Python wheel on an NVIDIA RTX 4070 Laptop GPU (OpenGL 4.3, EGL). The source I read is commit 826f947, files gvxr/resources/l_buffer_gl2.vert, l_buffer_gl3.vert and l_buffer_gl4.vert.
The vertex shader computes where each vertex projects onto the detector, writes that point directly as normalized screen x and y, and sets the clip-space w to 1. The object position that it passes to the fragment shader is therefore interpolated linearly in screen space. The fragment shader treats that value as the physical point where the ray meets the surface. For a parallel beam the two agree. For a cone beam the projection is perspective, so the interpolation has to be perspective-correct. The error does not shrink on a finer detector raster, which rules out detector offset, the spectrum, voxelization and any reconstruction step as its source.
After assigning the clip position, scale all four components by the positive source-to-vertex depth along the detector normal, for cone beam only:
if (g_projection_type == PERSPECTIVE_PROJECTION)
gl_Position *= abs(dot(transformed_vertex.xyz - g_source_position,
normalize(g_detector_plane.xyz)));
The normalized detector coordinates are unchanged, and the GPU's interpolation then uses the correct reciprocal-depth weights. All three vertex shader variants need the same change. In my test every object lay strictly between the source and the detector; I did not test clipping behind the source.
Two disjoint, asymmetric cuboids, imaged at twelve shifted poses: tilts of 0, -35 and +35 degrees combined with rotation angles of 0, 31, 92 and 177 degrees. The detector has 37 x 43 pixels at a 0.29 mm pitch, centred at (0.37, -0.23) mm. The source is 35 mm from the rotation axis and 70 mm from the detector. Exact slab intersections give each material's path length without using gVXR or any voxel projector. I compared log transmission with a monochromatic beam and with a three-bin photon-counting spectrum, using 1 and 2 sub-pixels per pixel side, on a raster 5 times finer than the detector that keeps the exact sub-ray centres. The fine raster separates fixed-point rasterization error from this interpolation error.
| Case | Relative log-L2 error |
|---|---|
| Cone, monochromatic, 1 sub-pixel, unpatched | 0.0162123 |
| Cone, monochromatic, 1 sub-pixel, patched | 0.0000394274 |
| Cone, polychromatic, 1 sub-pixel, patched | 0.0000398646 |
| Cone, monochromatic, 2 sub-pixels, patched | 0.0000221683 |
| Cone, polychromatic, 2 sub-pixels, patched | 0.0000229261 |
Parallel-beam output is bit-identical with and without the change. After the fix the remaining error is dominated by raster precision: with an 11 times finer raster the worst cone error is 1.7e-5.
I can share the test script if that would help.
Comparison image for one of the test poses (-35 degree tilt, 31 degree view, nonzero detector and object offsets). Top row: stock gVXR 2.1.0, exact slab-intersection truth, and the patched shader. Bottom row: each minus the truth, on the same signed scale. The stock error has broad positive and negative lobes of up to about 0.03 in log units; the patched result is indistinguishable from the truth at this scale. The colour bar labelled "log transmission" shows the line integral, minus log transmission.