Jump to content
  • Advertisement
Sign in to follow this  
takis

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.

If you intended to correct an error in the post then please contact us.

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]);	

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!