-->

分類

2016年4月18日 星期一

NDC to world coordinates

here is the original link
link

We transform it to clip space by multiplying it with our projection/modelview matrix.

clip = Matrix\text{ }world
Then move on to device coordinates by dividing with w.

device = clip_{xyz} / clip_w
So the problem we face is: given clip = Matrix\text{ }worlddevice = clip_{xyz} / clip_wworld_w = 1,
and given device as an input and Matrix as a constant, calculate world.
Let’s walk through it. Invert the first step:

Matrix^{-1}\text{ }clip = Matrix^{-1}\text{ }Matrix\text{ }world

Matrix^{-1}\text{ }clip = world
Now let’s see what we can do with the second equation.

device = clip_{xyz} / clip_w

clip_w\text{ }device = clip_{xyz}
Let’s use this syntax to indicate a 4-vector formed by combining a 3-vector and a fourth number:

clip = clip_{xyzw} = (clip_{xyz}, clip_w)
substitute clip_{xyz}

clip = (clip_w\text{ }device, clip_w)
insert into our earlier equation

Matrix^{-1}\text{ }clip = world

Matrix^{-1}\text{ }(clip_w\text{ }device, clip_w) = world

Matrix^{-1}\text{ }clip_w\text{ }(device, 1) = world
And note that since matrices are linear transforms, we can pull that clip_w in front of the matrix multiply:

clip_w\text{ }Matrix^{-1}\text{ }(device, 1) = world
So it seems we run into a wall. clip_w is lost, right? Don’t give up hope: we haven’t used the third of our initial givens yet.

world_w = 1
So let’s look at just the w component of that last equation there:

clip_w\text{ }\left(Matrix^{-1}\text{ }(device, 1)\right)_w = world_w = 1
Divide:

clip_w = \frac 1 {\left(Matrix^{-1}\text{ }(device, 1)\right)_w}
And insert into the equation that previously gave us trouble:

\frac{Matrix^{-1}\text{ }(device, 1)}{\left(Matrix^{-1}\text{ }(device, 1)\right)_w} = world
Or in other words:

\left(Matrix^{-1}\text{ }(device, 1)\right)_{xyz/w} = world\text{ ... and done.}

沒有留言:

張貼留言