PDA

View Full Version : getting Texture Coordinates from view



King Fuzzy
05-30-2004, 11:35 AM
:confused: How do i get the texture coordinates of the texture at a spacific point on the screen

I need to retrieve this information so i can paint onto a bitmap that is the texture of the model

I am currently rendering am offscreen image useing the texture coords as vertex colors, then using readpixels, to read the information, however if the texture is over 256*256 there isnt enough detail to reach every pixel (if the texture is 512 i get ever second pixel)
how can i get the the texture coords :confused:

SmutMonkey
05-30-2004, 12:29 PM
Off the top of my head, I can think of 3 possibilities:

1) use a geometric solution instead. i.e. do a ray to triangle intersection, yielding barycentric coordinates. Then use the barycentric coordinates and the texture coordinates of the triangle to get the texture coordinate you're painting at. The good thing is, this will work on any hardware (because it's in software :) )

2) use a more precise format, maybe something like G16R16F (or whatever it is in OGL, sorry I'm still thinking in D3D at the moment!). Drawback: it requires a Radeon9500/GeForceFX or better.

3) use an ARGB8 surface, but double up components to get more precision, i.e. AR represents the U coordinate and GB represents the V coordinate. You're going to need a PS.1.4 part or higher for this I think (Radeon8500+)

I've not thought this through properly, hopefully those suggestions will spark a thought in your head (or someone else on the board)

[edit: attempted, and possibly failed, to fix my lame grammar]

zed
05-30-2004, 07:41 PM
yeah ive done it before with the first mrthod smutmonkey mentioned, not to difficult to do.
iirc in the math.algorithms newsgroup faq, theres a bit about barycentric coordinates that i used

King Fuzzy
05-30-2004, 10:37 PM
can you give me a url, for these calculations

SmutMonkey
05-30-2004, 11:59 PM
Google is your friend (I just plugged in "barycentric triangle ray intersection" and got a whole load of stuff)

if you're feeling lazy then here's a direct link to the 2nd Google result; plenty to chew on here:

CFXWeb - Ray Triangle Intersection (http://www.cfxweb.net/modules.php?name=News&file=article&sid=1308)

King Fuzzy
05-31-2004, 10:24 AM
Thanks, now i know what to search for,
I tryed rendering a seprate u map and a v map, however they keep getting erased when i change contexts