Re: 2D in a 3D world
Colin Barrett <[email protected]> Sun, 8 Aug 2010 13:16:46 +0100
| Newsgroups | gmane.games.devel.algorithms |
|---|---|
| Message-ID | <[email protected]> |
On 8 August 2010 04:21, Jason Hughes <[email protected]> wrote: > - @Colin: I did read that previously, which is why I attempted a half-pixel > offset with the projection and/or view matrices. This did not seem to have > the desired effect of correcting a solid gray to black and white. I was a > bit surprised at that. No value I could put in there seemed to do more than > 25% correction, at best, which leads me to believe it's a texture issue. > I see where you said that now: I was a little bit too anxious to stick my oar in. Apologies! > I guess the real question I had was, how is the best way to correct for > pixel/texel mismatches? Do most people adjust the view matrix or the > projection matrix, or do you modify the vertices on the quads you generate, > or do you trick it with texture matrix modifications or generate the UVs > differently? Lots of options. The easiest seemed to me to be the view > matrix, but when it didn't work, I started looking for other things that > could affect the calculation, but didn't find any culprits. > I like to think of it not so much as an adjustment of those matrices, but as another transform applied after the model/view/projection. If you consider just the x-coordinate, the post-projection value of the sides of your fullscreen quad are -1 and 1. The viewport transform is: x * 0.5 * vpw + (vpx + 0.5 * vpw) Which (assuming vpx is 0) gives you: -1: -0.5 * vpw + 0.5 * vpw = 0 1: 0.5 * vpw + 0.5 * vpw = vpw Where you actually want to be, accounting for the position offset, is -0.5 and vpw - 0.5. So you solve for x and you get (leaving out vpx for simplicity): x * 0.5 * vpw + 0.5 * vpw = -0.5 -> x = -(1 + vpw) / vpw x * 0.5 * vpw + 0.5 * vpw = vpw - 0.5 -> x = (-1 + vpw) / vpw Subtract -1 and 1 respectively and you get a constant offset of -1/vpw. This is essentially the same thing that Jon said already, except I'm working in post projection space so my offset is double his ( at least, I hope that's why :-) ). ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ GDAlgorithms-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list