perspective to world space inverse projection

隐身守侯 提交于 2019-12-25 05:12:08

问题


i am extending shadow feature to my already existing 3d renderer that i have created as my class homework. I am trying to implement 2 pass z buffer algorithm. I have already done the first pass and created the depth map. However, the issue is that i rasterize my lines in screen space and so i have to bring my coordinates back to image space, as the comparison between z value of depth map and that of the fragment coordinates takes place in image space.

I use a stack implementation which stores the space transformation matrices in the following form :

[Xsp] * [Xpi] * [Xiw ] * (x,y,z) coordinates in world space = x,y,z in screen space where Xsp - perspective to screen Xpi - image to perspective Xiw - world to image

Here, the bottom of the stack contains Xsp, second to bottom contains, Xsp multiplied with the Xpi, third to bottom contains the result of Xsp * Xpi multiplied by Xiw .....

now, i only want x,y,z in image space , that is (Xiw * x,y,z in world space), so getting x,y,z in world space will work for me... Is it possible to achieve if i multiply the inverse of each matrix and then multiply the result with x,y,z in screen space ???

I mean, i want to do

[Xsp]inverse * [Xpi]inverse * [Xiw]inverse , and multiply this with x,y,z of screen space will it get me back to world space ??


回答1:


Let me guess. USC CS580?

Anyway I'll help.

How you got your vertex originally:

Xsp * Xpi * Xiw * Xwm * v = vf //Concat * model-space vertex = raster-space vertex

vf' = (vf.x / vf.w, vf.y / vf.w, vf.z / vf.w); //Perspective

How you get it back with vf':

Xwm * vf = Xiw^-1 * Xpi^-1 * Xsp^-1 * vf' //Inverted partial concat * raster-space vertex = world-space vertex

v = (vf.x / vf.w,  vf.y / vf.w, vf.z / vf.w); //Perspective again

Normal is the same idea except you only need an inverted Xiw to go back to world space since normals only go to image space. There is also no perspective involved.



来源:https://stackoverflow.com/questions/10192886/perspective-to-world-space-inverse-projection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!