Re: [Algorithms] 2D in a 3D world
Brought to you by:
vexxed72
From: Colin B. <bar...@gm...> - 2010-08-08 12:16:53
|
On 8 August 2010 04:21, Jason Hughes <jh...@st...> 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 :-) ). |