Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / Mesh.Intersect and Texture Color Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

May 04, 2005, 07:31 AM


Is it possible to know the texture color at the point of intersection of a ray and a mesh (with texture on it)?

The reason we need the above functionality is to exclude those textures that are totally transparent at the point of intersection. The mesh.Intersect does not care what the texture that is currently mapped (transparency is not considered during intersect test).



May 04, 2005, 08:02 AM

The best thing to do here is to give up on the restrictive sphere and plane primitives commonly used in raytracing, and to go ahead and start using polygonal (preferably triangular) meshes. After all, spheres and planes can be represented with triangular meshes.

When you determine what polygon of the mesh the ray intersects with, you check the texture coordinates of that triangle's vertices, then you interpolate them to find out the exact texture coordinates at the point of intersection.


May 05, 2005, 06:53 PM


I assume you are talking about mesh.Intersect in managed directX.
Some overloads of that function will return you one or several IntersectInformation structures.

this structure contains the index of the intersected face and the barycentric coordinates of your ray intersection (U,V).

first fetch the 3 vertices of the triangle of the given inndex : V1, V2, V3
as you said you use texture mapping, your vertices must define texture coordinates.

The texture coordinates of your intersection are :

V1.TexCoords + U(V2.TexCoords-V1.TexCoords) + V(V3.TexCoords-V1.TexCoords)

With this in hands you can fetch the color you need from your texture. Et voila!

I hope this helps



May 05, 2005, 06:57 PM


I don't think you really get the topic in here but anyway using primitives and quadratic surfaces (spheres etc..) for ray tracing has a lot of advantages. For exemple a ray intersection test against a perfect sphere is a trivial operation, actually, it is even simpler than a ray/triangle intersection test. to represent an almost perfect sphere you would need a huge amount of triangles... this is just a waste. To access that huge polygon dataset efficiently you have to precompute some rather complex accelerating structures that makes it impossible (or hard) to move objects dynamically in your scene. So if you want to render a fully detailed boat (like some nicely do in here ;) ) polygons are the thing but as long as you intend to render a bunch of reflective spheres on a checker moving around platonic solids in a Cornell box... primitives will rule the world.

(though I like triangles too ;) )



May 06, 2005, 09:23 AM

This notation is confusing to me. What does U() and V() parenthesis notation mean?
Function? Multiplication?

Maybe someone give a real example with numbers?

SDK Docs:
The Intersect method provides a way to understand points in and around a triangle,
independent of where the triangle is actually located. This method returns the
resulting point by using the following equation:

V1 + U(V2-V1) + V(V3-V1)

Any point in the plane (V1,V2,V3) can be represented by the barycentric coordinate (U,V).
The U parameter controls how much V2 gets weighted into the result, and the V parameter
controls how much V3 gets weighted into the result. Lastly, 1-U-V controls how much
V1 gets weighted into the result.


May 06, 2005, 03:12 PM

That's multiplication. The scalar values U and V, as the docs say, are the barycentric coordinates of the intersection point within the triangle. You can use these values to linearly interpolate any scalar or vector quantity across the surface of the triangle. The doc you posted shows them being used to interpolate position, using the three vertex locations V1,V2,V3. In order to determine the texture color, you can use the same formula, but replacing the vertex locations with their corresponding texture coordinates. That gives you the texture coordinates of the intersection point, and you have to do the texture lookup yourself.


May 06, 2005, 06:03 PM

Yeah, that's indeed multiplication of scalar with a vecor. Thank's Reedbeta for making it clear.

V1.TexCoords + U*(V2.TexCoords-V1.TexCoords) + V*(V3.TexCoords-V1.TexCoords)

with U and V : scalars
and Foo.TexCoords : 2D vectors


This thread contains 7 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.