I am developing a software rasterizer and want to be able to support affine (non-perspective correct) texturing but I am encountering a problem in my clipper that I can't seem to solve and I need some help.
I do my near/far plane clipping in projective space with homogenous coordinates. My view volume is defined as [-w <= x,y,z <= w]. I should also mention that my entire transformation pipeline mimicks the behaviour of Open GL 1.1.
My problem is that I cannot find a way to properly interpolate my texture/color coordinates for new vertices created by my clipper for lines & triangles that extend past the near frustum clipping plane and go behind the viewing position. When it comes to perspective-correct texture/color shading everything is fine because I just apply my linear interpolation factor calculated by my clipper to the texture and color coordinates. But for affine texture/color shading my clipper is required to do a hyperbolic interpolation and this is where my meager understanding of 3D is failing me.
I originally developed the following function to find the hyperbolic interpolation factor ftHyper based on the linear interpolation factor:
This solution works perfectly for left, right, top, bottom, and far frustum plane clipping. But when it comes to near plane clipping and objects that extend behind the viewer, the w coordinate of either the start or end vertex becomes negative and my ftHyper value is no longer correct.
So can anyone please help me with this simple issue? Part of my problem is that I have no books at all on the subject of 3D graphics. I am purely using the internet to do this project (which has gone well up to this point) and I can't find any information about this particular problem. I've also looked at the source code for Mesa and for Klimnt (another solfGL project) but both appear to just do linear interpolation which works only for perspective correct texture/color shading.
Thanks,
-Toasty
I do my near/far plane clipping in projective space with homogenous coordinates. My view volume is defined as [-w <= x,y,z <= w]. I should also mention that my entire transformation pipeline mimicks the behaviour of Open GL 1.1.
My problem is that I cannot find a way to properly interpolate my texture/color coordinates for new vertices created by my clipper for lines & triangles that extend past the near frustum clipping plane and go behind the viewing position. When it comes to perspective-correct texture/color shading everything is fine because I just apply my linear interpolation factor calculated by my clipper to the texture and color coordinates. But for affine texture/color shading my clipper is required to do a hyperbolic interpolation and this is where my meager understanding of 3D is failing me.
I originally developed the following function to find the hyperbolic interpolation factor ftHyper based on the linear interpolation factor:
Code:
float FindHyper_t (PVERTEX pDest, PVERTEX pStart, PVERTEX pEnd, float t)
{
// pDest is guaranteed to not have w coordinate of 0.0
return t * (pEnd->position.v[3] / pDest->position.v[3]);
}
This solution works perfectly for left, right, top, bottom, and far frustum plane clipping. But when it comes to near plane clipping and objects that extend behind the viewer, the w coordinate of either the start or end vertex becomes negative and my ftHyper value is no longer correct.
So can anyone please help me with this simple issue? Part of my problem is that I have no books at all on the subject of 3D graphics. I am purely using the internet to do this project (which has gone well up to this point) and I can't find any information about this particular problem. I've also looked at the source code for Mesa and for Klimnt (another solfGL project) but both appear to just do linear interpolation which works only for perspective correct texture/color shading.
Thanks,
-Toasty