# 3D [SOLVED] artifacts in Ray-OBB intersection test

## Recommended Posts

SOLUTION: The problem seemed to be due to the different epsilon values (comparison value with dot-product) not being consistent throughout all tests. I realized this when I replaced them all with EPSILON being #defined. It still confuses me how that could generate those artifacts, though.

Hi, i wasnt sure where to post this but i suppose this is good enough

I'm implementing a bunch of Ray collision tests for a ray-tracer assignment for school.  All tests (plane, sphere, triangle) have worked fine but the OBB one gives weird results.

To test the ray in order to get the distance from the ray origin to the intersection I'm using the algorithm presented in Real-time Rendering, third edition (Three slabs method)

The actual intersection test seems to work fine, however when I'm calculating the normal for the intersection (in order to shade it), a lot of pixels seem to fail the tests and thus aren't shaded properly.

Here's the code where I calculate this normal:

pointOnSurface = camPos + lastT*ray_dir.xyz; //world space position of intersection

obb_type o = obb_data[objIndex]; //Contains centre of box, basis vectors and half widths
vec4 arr[3] = {o.u_hu, o.v_hv, o.w_hw}; //xyz = basis, w = half width
vec3 normal;

for (int i = 0; i < 3; i++) //for every basis vector
{
//vector from pointOnSurface to middle of plane
//If pointOnSurface is on the same plane we are testing, the dot product calculated
//later will be close to 0
vec3 planeVector = (o.centre.xyz + (arr[i].xyz * arr[i].w)) - pointOnSurface;

float dotProduct = dot(planeVector, arr[i].xyz);

if ( (dotProduct > -0.00001) && (dotProduct < 0.00001) )
{
normal = normalize(arr[i].xyz);
}
else //check other plane in slab (arr.xyz * -1.0)
{
vec3 planeVector = (o.centre.xyz - (arr[i].xyz * arr[i].w)) - pointOnSurface;
dotProduct = dot(planeVector, arr[i].xyz);

if ( (dotProduct > -0.000001) && (dotProduct < 0.000001) )
{
normal = normalize(arr[i].xyz * -1.0);
}
}
}
return shade(pointOnSurface, normal, obb_data[objIndex].colour.xyz);

As you can see, if the dot product is never close to 0, the normal is never changed with means shade() gets the wrong normal, creating the artifacts.
So, why does this test fail for so many pixels? I've tried changing the tolerance both up and down without success. There is always some significant error.

Worth noting is that for three of the planes on the box, the artifacts show up only when I zoom out very far. For the other three, they disappear when I get very close.

I'm really at a loss here...

Here's a snapshot of the box:

Edited by GreenGodDiary
solved

## Create an account

Register a new account

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633294
• Total Posts
3011242
• ### Who's Online (See full list)

There are no registered users currently online

×