Getting pixel color from Texture

Started by
9 comments, last by Muhammad Haggag 18 years, 9 months ago
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
Advertisement
LPDIRECT3DSURFACE9 surf;
texture->GetSurfaceLevel ( 0, &surf );
D3DLOCKED_RECT rect;
surf->LockRect ( &rect, NULL, D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY );
// pixel color is rect.pBits <br>surf-&gt;Release ();
If you plan on doing this frequently, consider using dynamic textures. Not all hardware supports it but if they are available, use them.

See Using Dynamic Textures
....[size="1"]Brent Gunning
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?
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
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.
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.
....[size="1"]Brent Gunning
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?
it turns that the UVs i have r the barycentric UV's.

can these help me in getting the pixel color? :(
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.
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
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.

This topic is closed to new replies.

Advertisement