Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
66 Views

Barycentric coordinates u, v

Hi,

After intersecting a ray with a scene, what is the proper way to use the u, v  coordinates to calculate the world coordinates (x, y, z) of the hit? I believe from the geomID and primID, I can identify the triangle which is hit and its corresponding v0, v1, v2. But now what do I do?

0 Kudos
9 Replies
Highlighted
Moderator
66 Views

Just calculate ray.org + ray.tfar * ray.dir to get the hit point in world coordinates.

0 Kudos
Highlighted
Beginner
66 Views

sidenote: calculating it from uv coordinates is MUCH more precise and will drastically reduce amount of selfintersections from subsequent secondary rays.

0 Kudos
Highlighted
Moderator
66 Views

I agree, the accuracy can be much higher when you use the u/v coordinates to calculate the hit point.You can do this the following way: Ph = (1.0f-ray.u-ray.v)*p0 + ray.u*p1 + ray.v*p2

0 Kudos
Highlighted
Beginner
66 Views

Hi Sven,

In your example p0, p1 and p2 are 3 vertices of the triangle right?

Another question: I am trying to iteratively shoot a ray until it escapes the triangle mesh. So basically what I am doing is, I will shoot a ray and if it hits a geometry I will shoot another ray from the hit in the same direction and I will keep doing this untill the ray does not hit anything. In this case, I am constructing a ray only once and at every iteration I am just changing the ray.tnear to the previous value of ray.tfar. Is this a good way to do this? or should I calculate the exact coordinates of the hit and then shoot the next ray?

Thanks

0 Kudos
Highlighted
Moderator
66 Views

Yes, these are the triangle vertices.

What you describe is one way of finding all hits along the ray. However, depending on your application, a more efficient way of doing this is to use the intersection filter feature of the newer Embree versions.

0 Kudos
Highlighted
Beginner
66 Views

But even using intersection filter functions, I would still have to update the ray after every hit inside the filter function right? In that case should I use u,v coordinates or just update ray.tnear for the new ray? Which is a better way of doing it?

0 Kudos
Highlighted
Moderator
66 Views

Inside the filter function you would only reject the hit by setting ray.geomID to -1. You would further put the hit into some list. However, you will gather the hits in some unspecified order.

0 Kudos
Highlighted
Beginner
66 Views

So that means I call rtcIntersect() only once and as long as I keep rejecting the hit, the ray keeps going through?

Also, once I call rtcSetIntersectionFilterFunction(), the filter function is set, after that how do I revert back to normal behaviour, i.e. how to I detach the callback filter function?

0 Kudos
Highlighted
Moderator
66 Views

Yes, you call rtcIntersect only once and get all hits reported.

Setting back the filter function can be done in two ways:

1) reset the filter function by using the rtcSetIntersectionFilterFunction call with NULL as filter function

2) or register one global wrapper filter function, which reads a function pointer out of the ray (you can extend the ray at the end with your own data) and call this function pointer if it is not NULL. This way the feature can essentially be enabled per ray.

0 Kudos