Ray precision in IAS

Hi,

I am working with a very large mesh that contains both large coordinate values and extremely small triangles. To reduce vertex precision issues caused by the large coordinates, I partitioned the mesh into multiple chunks, built a separate GAS for each chunk, and then assembled them into an IAS.

While this helps with geometry precision, I am still encountering ray precision issues. As I understand it, optixTrace() requires ray origins and directions to be specified in world space. However, my application requires tracing very short rays whose origins are computed by offsetting a point on the surface by a small epsilon. Because this epsilon is added to a large world-space coordinate, much of the offset can be lost due to floating-point precision limitations. As a result, the effective precision of both the ray origin and the ray length is significantly reduced.

Do you have any recommendations for mitigating this issue that tracing very short rays in scenes with large world-space coordinates?

Thank you for your help.

Hi @whix, very interesting question!

Yes once your ray origin has large absolute values, you lose precision before you even trace the ray, and OptiX can’t do anything to help. We do have a few tricks for reducing precision errors, but based on your description I don’t think they will solve your problem. It might help if we better understood what precision problems you’re running into exactly, and what precision you need, either in absolute world coords or relative to your camera ray origin. It might also help to better understand the scale of your scene, so we can discuss whether it’s close enough to fp32 limits that tightening up the math has hope of addressing your issue, or if it’s fundamentally beyond the scope of fp32 math.

The main approaches that comes to mind would be to manually do your own world space to object space conversions, and manage tracing the ray separately through each phase, or to use a double precision BVH & ray tracing library. Both come with extra work and tradeoffs, of course. In practice, managing your own object & world spaces would mean building an IAS with proxy bounds for your GASes, and then transforming the ray and casting new object-space rays in the “real” separate GASes. Something like this might help with issues like self-intersection, but you’re still going to lose precision when transforming the ray, so whether this works really depends on what kind of precision you need in the scene and what problems you need solved.

The other option would be to forego the fp32 hardware accelerated traversal and intersectors, and instead use a CUDA-based software double precision traversal. There’s one I know of available here: GitHub - NVIDIA/deepeeRT: A Library for Double Precision Ray Tracing · GitHub, but aside from losing RTX acceleration, it comes with the caveat that it’s fairly barebones and might not offer some of the features you’re using in OptiX.

–
David.

Hi @dhart ,

One of the 3D meshes I’m processing contains 1,264,847 vertices and 2,517,782 faces. The smallest triangle area is approximately (10^{-3}), while its bounding box spans from [225.8540, -388.3661, -605.8855] to [1155.5186, 145.3015, 991.0704].

When I generate a ray, I compute its origin by offsetting a vertex position with an epsilon. The epsilon is determined from the height of the triangle incident to that vertex. However, adding such a small epsilon to the vertex coordinates results in an inaccurate ray origin due to floating-point precision limitations.

Since I’m trying to use the RT cores for acceleration, switching to a double-precision ray tracing solution is probably not an option. And your manual approach may not work as the world-space ray origin has already lost precision before any world-to-object transformation is applied?

Your ray origin offsest from the triangle vertex is away from the triangle surface in face normal direction to avoid self-intersections in 3D?
In that case the offset should not be dependent on the triangle size but its coordinates. The coordinate range of your GAS is not outrageously big so this should work.

This sticky post about the OptiX Toolkit on github https://forums.developer.nvidia.com/t/solving-self-intersection-artifacts-in-optix/267805 provides methods to calculate the minimum necessary offset value. Maybe give that a try.

You didn’t explain what absolute lengths your rays are and into what directions you’re shooting them, means it’s unclear what the goal of the algorithm actually is. If the goal is to avoid self-intersections with the triangle you started the ray from, that could also be done with zero ray origin or t_min offsets by filtering (with optixIgnoreIntersection) the starting triangle ID inside an anyhit program, though that is slower because the anyhit program interrupts the hardware BVH traversal.

That you start the ray from triangle vertices would then potentially hit the adjacent triangles sharing that vertex with zero offsets though. So it depends what you’re actually trying to achieve if that more robust intersection avoidance method is reasonable.

Is this for computing ambient occlusion or self-shadowing? Can you maybe cast the secondary ray in object space, and trace directly against the GAS containing only the mesh you hit, rather than tracing the secondary ray against the scene IAS? If that might work, there are minor performance considerations we should discuss.

Yes it’s true that there is precision loss when computing the hit position for a new ray’s origin. The core problem is that your precision loss is proportional to the t value of your primary ray’s hit. Even before you compute the hit position, the resolution of your hitT variable is limited, and you lose precision in t with large values. Then you lose precision again when computing a position from hitT. This is a fundamental problem that cannot be fixed, all we can do is be careful with spaces & magnitudes, and try to avoid adding any additional precision loss when offsetting the ray or when transforming between object & world space.

Sometimes you can improve intersection precision & rounding by changing your object/world space origin, for example by moving either the ray origin or the hit point to the space origin, or by putting the space origin at the ray’s midpoint so you get balanced precision at both ends.

Can you illustrate what the scene looks like, where the lights/emitters are and where the camera/sensors are, and what kind of distances are between GASes? It would help to get a better sense of magnitudes using some specific examples. The main question we need to answer first is whether your problem involves magnitudes that have any hope of being fixed, or whether the precision you’re looking for and the problem you want to solve is not available with fp32.

–
David.

Sorry I realized I asked for the same thing again, and you already gave some description of the scene. Let me clarify the ways I’m not quite understanding your current scene description, and the questions I still have.

The smallest triangle area is approximately (10^{-3}), while its bounding box spans from [225.8540, -388.3661, -605.8855] to [1155.5186, 145.3015, 991.0704].

So the smallest tri area is ~0.001, but the bounding box you mention is over the 2.5M triangles, right? You’re not talking about the bbox of a very very thin triangle, I assume?

When I generate a ray, I compute its origin by offsetting a vertex position with an epsilon. The epsilon is determined from the height of the triangle incident to that vertex. However, adding such a small epsilon to the vertex coordinates results in an inaccurate ray origin due to floating-point precision limitations.

When you say ‘offsetting a vertex position’, are you referring to one of the vertices of the triangle, or are you referring to the computed hit point? Are you computing the hit point via triangle barycentrics, or by using the ray origin & direction and the hitT value?

How far apart are your meshes, and how far away are they from your typical ray origin?

Do you have a sense of how far off you are? Like, what is the precision that you need with your offset? How big is the error you’re getting? What are you using the offset & secondary rays to do? Where is the ‘camera’ in the scene? Is this like emitting rays from the sun and rendering a room on Earth? Or is the image/output from the point of view of the Sun (for example), and rendering the entire Earth? Does that make sense? Like with a typical rendering, the precision needs are relative to the camera & size of pixels. Is that a valid analogy to what you’re doing?

–
David.

This is not a rendering scene; it is a geometric mesh used for non-graphics computation.

So the smallest tri area is ~0.001, but the bounding box you mention is over the 2.5M triangles, right? You’re not talking about the bbox of a very very thin triangle, I assume?

Yes. The smallest triangle area is approximately 0.001, while the bounding box refers to the bounding box of the entire mesh. My point is that the mesh occupies a large coordinate range, so the vertex coordinates themselves have large magnitudes.

When you say ‘offsetting a vertex position’, are you referring to one of the vertices of the triangle, or are you referring to the computed hit point? Are you computing the hit point via triangle barycentrics, or by using the ray origin & direction and the hitT value?

I am referring to one of the triangle’s vertex positions, not the computed hit point. I do not compute the hit point at all—I only launch rays.

Specifically, I compute the ray origin by adding a small epsilon (whose magnitude is determined by the size of the triangle) to one of the triangle’s vertices. Since the rays are launched directly from the mesh surface, the ray origin must be computed accurately so that the ray intersects the intended triangle.

The issue is that when the mesh coordinates are large, adding a very small offset can be lost due to FP32 precision. For example, an operation like 1000.0f + 0.0001f may not preserve the intended offset accurately enough, causing the ray origin to deviate from its expected position.

Ah, okay, understood, thanks for clarifying.

So, yes, adding 1e3 + 1e-4 is relatively inaccurate compared to the smaller number, and you can lose the smaller number completely. In that exact scenario when using fp32, 1e3 + 1e-4 == 1000.0001220703125, giving you an error of 2e-5 (or 20% of your offset). If you try to add 1e3 + 3e-5, you will get exactly 1e3, and lose the 3e-5 entirely (error of 100% of the offset).

Of course, this is always the case with floating point math, even when you don’t notice it. The result of any calculation will be rounded once the result is represented in fp32. When adding a offset to a point, the result will usually not be exact, and so in general it will move to the nearest point in the space of representable fp32 numbers. When you add any number that is smaller than half of the magnitude of the least significant bit of your 23-bit mantissa, then yes the final result will be equal to, and indistinguishable from, your larger number.

Do you know how much error in your ray origin would be acceptable?

You are not using any non-identity instance transforms? And these large-magnitude numbers are part of the original mesh data, correct? If these triangles are small and your mesh coordinates are large such that it’s difficult to compute a ray origin, then I’m wondering if the mesh data itself might be causing problems? Are any of the triangles degenerate? If the original mesh is fp64, and is being converted to fp32, for example, then you may have the same problem with your input data - vertices will be rounded, and they could easily snap to the same grid point and cause your triangle to have an area of zero. OptiX rays will automatically miss degenerate triangles.

In any case, based on what I believe from your description so far, I’m not aware of any way to fix this issue, it sounds like a fundamental mismatch of scale vs desired precision. If the precision you need for your ray origins is smaller than around 1e-7 (or around 2e-23) times the vertex coordinate, then fp32 simply can’t do that. It doesn’t even matter that the mesh values are large, it only matters how small your desired precision is compared to the mesh values. You could imagine scaling the model down, but I assume your precision needs would scale with it, so that doesn’t change anything. It is possible I still don’t understand the setup & goals correctly though.

–
David.