I have been trying to understand ssao, and since it is a post-processing effect I need to construct a position from depth and texture position. My results is wrong and I cant understand why. Here is my function for the reconstruction
Thx Ignatz, but I don’t think that is the problem. If I try to explain:
I store the depth for every pixel in an image. Same as a shadowmap.
InvVP becomes the matrix that will unproject the depth and its texturecoordinates from Screenspace to worldspace. I want the position of the depth.
In the fragment part of the ssao-shader I transform the depth and the texturecoordinates into NDC (Normalized Device Coordinates). I multiply with the invVP (unprojecting my textureposition) and divide by w.
Now I should have its worldposition!
To check if this is right I use the same formula to calculate the depth of this pixel (if the unprojected position is correct the following should be the same as the depth image from 1.) and write it to gl_FragColor.
Are you sure? Whats the difference in 6*4*2 or 6*2*4 or whatever. the result is the same: 48. Its not cross product or anything, just plain multiplication …
@se24vad Matrix multiplication is not associative. Order matters very much. Matrices represent transformations and in 2D and above, it matters which way round you do things. For example, rotating by 90 degrees followed by a reflection in the x-axis is very different to reflecting in the x-axis followed by rotating 90 degrees.