Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Texture coloring
- vec2_t tex1, tex2, tex3;
- vec2_copy_dest(&tex1, &rt->shape->vertices[0]->texCoord);
- vec2_copy_dest(&tex2, &rt->shape->vertices[1]->texCoord);
- vec2_copy_dest(&tex3, &rt->shape->vertices[2]->texCoord);
- vec2_mul(&tex1, 1.f/rt->pRaster[0]->coords.z);
- vec2_mul(&tex2, 1.f/rt->pRaster[1]->coords.z);
- vec2_mul(&tex3, 1.f/rt->pRaster[2]->coords.z);
- //rt->bc is a vec3_t with barycentric coordinates saved
- float texx = rt->bc.coords.x*tex1.coords.x +
- rt->bc.coords.y*tex2.coords.x +
- rt->bc.coords.z*tex3.coords.x;
- float texy = rt->bc.coords.x*tex1.coords.y +
- rt->bc.coords.y*tex2.coords.y +
- rt->bc.coords.z*tex3.coords.y;
- //this cuts texture in perspective...may be right should tested
- texx = (texx / rt->z)/rt->z;
- texy = (texy / rt->z)/rt->z;
- //can cause number over 1.08f seems a magic number otherwise we must iterate twice for interpolation
- texx = interpolate_lin(texx, 0.f, 0.f, 1.08f, 512.f);
- texy = interpolate_lin(texy, 0.f, 0.f, 1.08f, 512.f);
- int texIndex = floor(texy) * rt->renderer->imgWidth + floor(texx);
- crgb_crgb_copy(&curCol1, &rt->renderer->texture[texIndex]);
Advertisement
Add Comment
Please, Sign In to add comment