If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
![]() |
|
|
#1 |
|
Junior Member
Join Date: Jul 2002
Posts: 50
|
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: 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]);
}
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 |
|
|
|
|
|
#2 |
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
|
I don't understand your problem. You say you want to do linear texturing so why not just set your texture W component to a constant 1.0?
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2002
Posts: 50
|
I need the hyperbolic interpolation because my clipper operates in projective space but for affine mapping I must interpolate texture/color values as if I were in screen space. I can't really explain it any better, so to help clarify things here's some pseudocode about how I perform interpolations in my clipper.
Code:
if (PerspectiveCorrectionHint() == GL_NICEST) {
InterpolatePosition(pNew, pV1, pV2, t);
InterpolateNormal(pNew, pV1, pV2, t);
InterpolateColor(pNew, pV1, pV2, t);
InterpolateTexcoords(pNew, pV1, pV2, t);
}
else { // GL_FASTEST , GL_DONT_CARE
InterpolatePosition(pNew, pV1, pV2, t);
InterpolateNormal(pNew, pV1, pV2, t);
float ftHyper = FindHyper_t(pNew, pV1, pV2, t);
InterpolateColor(pNew, pV1, pV2, ftHyper);
InterpolateTexcoords(pNew, pV1, pV2, ftHyper);
}
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
|
There is no 'correct' way to clip texture coordinates if you're using them for affine interpolation. I think the best you can do is just plain linear interpolation. Flat polygons (coplanar to the screen) have to look ok, that's the most important.
Have you checked whether the OpenGL specifications say anything about this? |
|
|
|
|
|
#5 | |
|
Junior Member
Join Date: Jul 2002
Posts: 50
|
Quote:
I checked the OGL 1.3 spec and it only describes linear interpolation for texture and color coordinates while clipping. It doesn't even contain mention of affine texture and color shading so it is certainly possible to just do away with it. But I'm so close.... I've got interpolation for 5 frustum planes working perfectly. The only thing left to do is figure out how to hyperbolically interpolate the texture/color values for triangles that extend behind the viewer (ie. they contain a vertex or 2 vertices with a -w coordinate). What's annoying is that my Radeon 9800 Windows OGL driver does not react to a perspective hint of GL_FASTEST - I always get perspective-correct texture and color shading. Does anyone know if there exists an OpenGL implementation (software or hardware) that actually performs affine texture or color shading when requested via PERSPECTIVE_CORRECTION_HINT? Also if someone knows of an old PC game that used affine texturing and whose source code is available please let me know. Thanks. |
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
|
So you manage to fix the seam problem by using hyperbolic interpolation? That's cool, I never realized that could work. Although...
The problem is that w becomes negative... I'm afraid it's unsolvable. Your interpolation value, t, has to remain between 0 and 1. The way you defined your hyperbolic t, this isn't guaranteed. So even for other clipping planes I think things can go wrong. Could you check that? Besides, why do you really want to do affine texture mapping? It's ok to speed up rendering of small and distant polygons, but it starts to show serious artifacts for big and closeby polygons. So in situations where in my opinion it is useful, it doesn't clip the near plane anyway... Tomb Raider 1 used a software renderer where perspective correction could be switched on and off. I think I remember seeing seems. But of course there's not such thing as a 'referece' game for affine texture mapping... |
|
|
|
|
|
#7 | |
|
Junior Member
Join Date: Jul 2002
Posts: 50
|
Quote:
1. Perspective-correct mapping: http://www.izabel.info/uploads/p_linear.JPG 2. Affine mapping: http://www.izabel.info/uploads/p_rational_linear.JPG 3. Affine mapping with near and far planes pushed closer together: http://www.izabel.info/uploads/p_rational_linear_2.JPG I'll spend some more time considering solutions to this problem; I don't want to let it go just yet. And I do realize that the result for texturing will look pretty ugly but this technique is still feasible for affine gouraud shading which probably won't look nearly as bad. |
|
|
|
|
|
|
#8 | ||
|
Senior Member
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
|
Quote:
Quote:
Anyway, good luck with your project! |
||
|
|
|
|
|
#9 | |
|
Moderator
Join Date: Feb 2002
Location: Redmond, WA
Posts: 3,177
|
Quote:
|
|
|
|
|
|
|
#10 | ||||
|
Junior Member
Join Date: Jul 2002
Posts: 50
|
Quote:
The texture seam in the second and third images is produced because the scene is composed of two triangle primitives arranged to look like a square and the texture seam is the expected result for affine texturing. EDIT -- addendum : Quote:
Here is a completely unclipped scene (ie. no hyperbolic interpolation taking place): http://www.izabel.info/uploads/unclipped_affine.JPG And here is the exact same scene but with left and right frustum clip planes collapsed so as to produce clipping. http://www.izabel.info/uploads/clipped_affine.JPG If you flip between them you can see that the hyperbolic interpolation does not alter the texture mapping in any distinct way (there are very slight differences but that may just be jpeg artifacts or caused by slight imprecisions in the calculated clipped vertices). Overall I do think this solution is sound, I just need to devise a special case to work with clipping against a -w coordinate. |
||||
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Jan 2003
Location: Ottawa, Ontario
Posts: 1,783
|
Thanks for the explanation! Sorry I misunderstood some of it.
Unfortunately, I'm still of the opinion that it doesn't really solve anything. Ok, there are no new seams, but that's not something to care much about anyway. For gouraud shading, you're not going to see the seams, and it's actually more correct to use the linearly interpolated clipping points. Even if it causes more seams, they will be less noticable. Quote:
It's something weird you're doing here. You attempt to fix a wrong interpolation with another wrong interpolation. The common way is to use hyperbolic interpolation in screen space and linear interpolation in clip space. What you do is linear interpolation in screen space and hyperbolic interpolation in clip space. Unfortunately, two wrongs almost never make a right. But it's a cool attempt. 8) |
|
|
|
|
|
|
#12 |
|
Naughty Boy!
|
Useless tidbit of info: at work I have a PC with a Matrox G450... In OpenGL it screws up lighting when a polygon is clipped against the viewing frustum.
I suppose it's because it does linear gouraud shading, and the clipper is also bugged. |
|
|
|
|
|
#13 | ||
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
|
Quote:
If you have your points in eye/camera space AKA cannonical clipping coordinates, then you are still in homogenous space, i.e. you have [X,Y,Z,W] positions, and all clipping is linear.
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|