Advertisement

Texture Pixel

Started by March 01, 2003 10:44 AM
4 comments, last by IceWizard 22 years ago
Hi, How can I detemine the pixel color of a point on a 3D polygon based only on the texture coordinates and the polygon vertices?
Guy
1. You have a 3D point... (I hope Im right)
2. Render the polygon
3. Use glReadPixels to obtain the pixel data
4. Use gluUnProject (or gluProject??? I dont know) to get the position of your point on the screen
5. Get the color from the array returned by glReadPixels...

Hope this helps...



PM



Times change.


Excuse my poor english!
PM Times change... Excuse my poor english!
Advertisement
Opps...

I forgot to mention the reason why I need the pixel color. In essence, I am creating an intersection routine that will allow me to detect the intersection between a line segment and any polygon on my scene. If a hit is detected, I need to determine if the segment actually intersected with a transparent area of the polygon.

For example, assume I have a bush (or tree) in my scene composed of either 1 quad or two triangle. The polygon has a bush texture mapped on it with an alpha channel. There will be areas on the polygon that are transparent. If I hit those areas, I should ignore the intersection.

I need a way to get the alpha component of the texture associated with my 3D intersection point.

I have the following information:

1) The 3D intersection point.
2) The polygon vertices.
3) The texture coordinate associated with each vertices.
4) The polygon normal.
5) The texture size, raster, etc.

I don''t want to render the polygon to get the color. Also, doing it that way would also cause me to loose the alpha channel that I am looking for.

Later, I will use a scoring texture as opposed to a visual texture. The scoring texture will have the same size of the visual texture but it will only be used for intersection. That way I can define solid or hard areas of the object. For example, A ''tree'' can be associated with a single texture although it contain hard and soft surfaces.

I hope this provides for information on what I need.


Guy
Opps...

I forgot to mention the reason why I need the pixel color. In essence, I am creating an intersection routine that will allow me to detect the intersection between a line segment and any polygon on my scene. If a hit is detected, I need to determine if the segment actually intersected with a transparent area of the polygon.

For example, assume I have a bush (or tree) in my scene composed of either 1 quad or two triangle. The polygon has a bush texture mapped on it with an alpha channel. There will be areas on the polygon that are transparent. If I hit those areas, I should ignore the intersection.

I need a way to get the alpha component of the texture associated with my 3D intersection point.

I have the following information:

1) The 3D intersection point.
2) The polygon vertices.
3) The texture coordinate associated with each vertices.
4) The polygon normal.
5) The texture size, raster, etc.

I don''t want to render the polygon to get the color. Also, doing it that way would also cause me to loose the alpha channel that I am looking for.

Later, I will use a scoring texture as opposed to a visual texture. The scoring texture will have the same size of the visual texture but it will only be used for intersection. That way I can define solid or hard areas of the object. For example, A ''tree'' can be associated with a single texture although it contain hard and soft surfaces.

I hope this provides for information on what I need.


Guy
Interpolation.

You have your hit location of the polygon. Calculate the distance from each vertex, and store it as a percent. Then, use that percent on the texture itself (in memory) and it will give you that current pixel.
Psuedo time:

  char RetPixelColor()  Get location of line/poly intersection  calculated distances from all verts of this triange, turn  into a percent.  convert that percent, using the TexCoords for the polygon  verts and get the XY of the texture spot you hit  return poly.texture[x][y]  


tada
~Main

==
Colt "MainRoach" McAnlis
Programmer
www.badheat.com/sinewave
==Colt "MainRoach" McAnlisGraphics Engineer - http://mainroach.blogspot.com
Thanks,
Guy

This topic is closed to new replies.

Advertisement