Sign in to follow this  
ramy

Getting pixel color from Texture

Recommended Posts

ramy    148
Hey guys, Is there a way to get a pixel color of a texture at a specific U and V coord.? i mean, i have a specific UV coordinate for a texture. and i want to find out wat pixel color is that UV pixel. is that feasible? thx

Share this post


Link to post
Share on other sites
ReaVeR-Andrey    199
LPDIRECT3DSURFACE9 surf;
texture->GetSurfaceLevel ( 0, &surf );
D3DLOCKED_RECT rect;
surf->LockRect ( &rect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY );
// pixel color is rect.pBits [ u * bytes_per_pixel + rect.Pitch * v ]
surf->Release ();

Share this post


Link to post
Share on other sites
deadimp    310
I've heard quite a bit about Dynamic Textures, but haven't quite understood what they are... Are they stored in the RAM? Is that what makes them dynamic?

Share this post


Link to post
Share on other sites
ramy    148
i wil be doing it for quite a few times, like 10 to 15 times MAX.

thx for the help, i will be trying thatReaVeR-Andrey.

Share this post


Link to post
Share on other sites
gunning    749
Quote:
Original post by deadimp
I've heard quite a bit about Dynamic Textures, but haven't quite understood what they are... Are they stored in the RAM? Is that what makes them dynamic?


It is really up to Direct3D and the card to determine where they will be stored, but in general they will end up in either device memory or in AGP memory. IIRC, AGP is the better of the two for these types of operations.

When you lock the surface, Direct3D makes a local copy in system memory for you and lets you play with it. When you are done, it uploads the data back into where it was stored. Unless you create managed or scratch textures, Direct3D will not keep a local copy of your texture in system memory.

Share this post


Link to post
Share on other sites
ramy    148
hey ReaVeR-Andrey,

i am on MDX, so i need change things abit.

i have to lock it, and that brings the GraphicStream.

and from then i get the Array of bytes.

now, when i get the array of bytes of the entire texture, i use ur equation to reach the first byte of the first color component of the pixel?

Share this post


Link to post
Share on other sites
ramy    148
doesnt anybody know how to convert the barycentric UV coordinates to normal texture float UV coordinates?

cause i recieve from the IntersectInformation a U and V floats. these r the barycentric coordinates.

and i want to know the real float UV coordinates for the texture, to be able to get its pixel color???


plz, thx in advanced.

Share this post


Link to post
Share on other sites
Cambo_frog    855
Quote:
Original post by ramy
doesnt anybody know how to convert the barycentric UV coordinates to normal texture float UV coordinates?

cause i recieve from the IntersectInformation a U and V floats. these r the barycentric coordinates.

and i want to know the real float UV coordinates for the texture, to be able to get its pixel color???


plz, thx in advanced.

Hi Ramy,
The u, v barycentric coordinates refer to a point within a triangle your ray intesects (your "IntersectInformation").

Call your triangle vertices v0, v1 and V2.
Call the texture coordinates in your vertex structure, tu and tv.

You can derive a third barycentric coordinate w as:
float w = 1.0f - (u + v);

Your tu, tv values at the intersection point is:
float intersectionTu = v0.tu * u + v1.tu * v + v2.tu * w;
float intersectionTv = v0.tv * u + v1.tv * v + v2.tv * w;

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this