-
Junior Member
Regular Contributor
ray/triangle intersection + uv calculation
Hello,
What is the most direct way to intersect a ray with a triangle and compute the associated uv coordinates at this point ?
(something less consuming than matrix operations if possible)
-
Re: ray/triangle intersection + uv calculation
Google a little about barycentric coordinate and I think that you can find all you want about this.
-
Re: ray/triangle intersection + uv calculation
Or more simple (but not really more speed) if you have already your proper algorithm for to find the point of intersection (say P) of a triangle ABC and a line from P0 to P1 ...
First, you compute distances from P to A, B and C:
dA = distance from A to P
dB = distance from B to P
dC = distance from C to B
sum = dA + dB + dC
coefA = dA / sum
coefB = dB / sum
coefC = dC / sum
So, the texture coordinate at point P is :
uP = uA * coefA + uB * coefB + uC * coefC
vP = vA * coefA + vB * coefB + vC * coefC
Note too that you can apply this to alls points P into the triangle ABC and to be applied to another style of coordinates such as color componants for example ...
-
Junior Member
Regular Contributor
Re: ray/triangle intersection + uv calculation
Thanks !
I first calculated my own barycentric formulas, however it requires far more operations than yours. But yours involve square roots operation, so.. Well I have to give it a try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules