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 ??