# ray tracer: calculating shading normal and texture coordinates

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

## Recommended Posts

ello, i am using the function of Tomas Moller and ben Trumbore to calculate the intersection with a triangle:
    intersect_triangle(float orig[3], float dir[3], float vert0[3],
float vert1[3], float vert2[3],
float *t, float *u, float *v);

It returns also the barycentric coordinates u and v. Can i use them to calculate the texturecoordinates of the intersection point? How can i use them to calculate the texturecoordinates? I got the texturecoordinates of the vertices of the triangle. If i could use u and v, i dont have to calculate again the barycentric coordinates. I compute the shading normal as follow with u and v from the function intersect_triangle:
float* Hit::getShadingNormal(void)
{
if (!triangle->surface->vnorm)   // no per-vertex normals
return triangle->normal;
else {
const R3* n = triangle->getNormals();
PINT(n[0], n[1], n[2], s, t, normal);
R3NORMALIZE(normal);
return &normal[0];
}
}

/* Point IN Triangle: barycentric parametrisation */
#define PINT(v0, v1, v2, u, v, p)     {						        double _u = (u), _v = (v); 							(p)[0] = (v0)[0] + _u * ((v1)[0] - (v0)[0]) + _v * ((v2)[0] - (v0)[0]);		(p)[1] = (v0)[1] + _u * ((v1)[1] - (v0)[1]) + _v * ((v2)[1] - (v0)[1]);		(p)[2] = (v0)[2] + _u * ((v1)[2] - (v0)[2]) + _v * ((v2)[2] - (v0)[2]);	

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013231
×