# RayTracer: Texture coordinates for intersectionpoint

This topic is 4984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I am creating a raytracer. I am using a texture atlas. Can i calculate the texture coordinates of the intersectionpoint P as follow: vec3 Triangle::barycentric(vec3 P) { float F_abc, F_pbc, F_apc; vec3 bary(0,0,0); F_abc = tri_area(_A,_B,_C); F_pbc = tri_area(P,_B,_C); F_apc = tri_area(_A,P,_C); if (F_abc == 0.0f) return bary; bary.x = F_pbc/F_abc; bary.y = F_apc/F_abc; bary.z = 1.0f- bary.x-bary.y; return bary; } // Texturecoordinates for point P void Triangle::uv(vec3 P, float &u, float &v) { vec3 Pb = barycentric(P); u = _A.texcoord.x * Pb.x + _B.texcoord.x * Pb.y + _C.texcoord.x * Pb.z; v = _A.texcoord.y * Pb.x + _B.texcoord.y * Pb.y + _C.texcoord.y * Pb.z; }

##### Share on other sites
yep. not sure if its the fastest way for your specific siituation, but it will work.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 12
• 15
• 11
• 12
• ### Forum Statistics

• Total Topics
634153
• Total Posts
3015846
×