Ok, so as I get a bit more into the worderful(ly horrifying) world of global illumination and ray tracing, I'm starting to see that the D3DXIntersect function is probably of great use.
One return value caught my interest; the U and V outputs. I about had a heart attack (in a good way) when I thought to myself that these could possibly be a direct link to outputting texture coordinates, although upon reflection that was quite dumb of me (no of course it wouldn't be that easy *rolls eyes* ).
However, I still think that these are key elements in extracting the location on a given texture mapped to the mesh. So is there a specific way that this can be done? If my thinking is correct, the UV coordinates will simply give a value between 0 and 1 that will represent the position on the given triangle face. So my thought is that that can be in turn used in some way with the TEXCOORDS stored in the verticies to extract this data.
Thanks in advance. I honestly have no clue how complex an answer this question might require.
Barycentric coordinates and ray tracing?
Started by starstutter, Mar 22 2008 02:01 AM
3 replies to this topic
#1
Posted 22 March 2008 - 02:01 AM
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!
#2
Posted 22 March 2008 - 02:07 AM
It's quite simple. If the texture coordinates at the vertices of the triangle are t0, t1, t2, then the texture coordinates at the hit point are:
(1 - u - v) * t0 + u * t1 + v * t2.
(1 - u - v) * t0 + u * t1 + v * t2.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 22 March 2008 - 02:13 AM
wow... that's really it? *faints*
I seriously wish my mind was more math based.
Out of sheer curiosity, did you make that equasion or get it from somewhere else (or older source code from one of your previous projects)?
Either way, thanks a lot
I seriously wish my mind was more math based.
Out of sheer curiosity, did you make that equasion or get it from somewhere else (or older source code from one of your previous projects)?
Either way, thanks a lot
(\__/)
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!
(='.'=) This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!
#4
Posted 22 March 2008 - 02:26 AM
I guessed it based on my previous experience with barycentric coordinates, and confirmed by looking at the D3DXIntersect help page (which has the same equation but with vertex positions instead of texcoords).
Anyway, it's easy to remember how barycentrics work. You start at vertex 0, and U is how far you move toward vertex 1, while V is how far you move toward vertex 2. Therefore if you interpolate some quantity (position, normal, texcoords, anything) across the triangle, you have to multiply the quantity's value at vertex 1 by U, and its value at vertex 2 by V. Then you must also include something times the quantity's value at vertex 0. The three weights have to add up to 1, so the weight for vertex 0 must be 1 - U - V.
Anyway, it's easy to remember how barycentrics work. You start at vertex 0, and U is how far you move toward vertex 1, while V is how far you move toward vertex 2. Therefore if you interpolate some quantity (position, normal, texcoords, anything) across the triangle, you have to multiply the quantity's value at vertex 1 by U, and its value at vertex 2 by V. Then you must also include something times the quantity's value at vertex 0. The three weights have to add up to 1, so the weight for vertex 0 must be 1 - U - V.
reedbeta.com - developer blog, OpenGL demos, and other projects
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












