🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Transforming from screen space to view space?

Started by
2 comments, last by VanillaSnake21 3 years, 5 months ago

Hello all,

Isn't that just easy as simply multiplying the pixel on the screen by the inverse of the projection matrix? It won't happen? How is it going to work?

If I transform from view to world, that's easy? just multiply by the inverse of the view matrix?

But how do I transform from screen to view space?

thanks

Jack

Advertisement

I think you can multiply by inverse, yes.

You could also store a local/world fragment position before you multiply it by the projection matrix. This is useful in a lot of cases where you have lighting/shadows that might need to be calculated too.

This might be useful: https://learnopengl.com/Getting-started/Coordinate-Systems

None

I'm still learning this myself but from what I understand this is the way the transforms work:

Model Space → World Space → View Space (camera space) →Clip Space → Screen Space

So after you apply the projection matrix you will be in the homogenous clip space, once the perspective divide happens (this is done internally by DirectX) you will have the point in normalized device coordinates which are basically in the range of -1 to 1. Once you're in NDC a viewport transform is applied (given by the viewport you set up) to move you from NDC to actual screen space coordinates.

In other words I don't think you can just multiply pixel position on screen by inverse of projection matrix. You have to first reverse the viewport transform and then reverse the projection to get to view space.

Just as a disclaimer I'm not 100% sure this is entirely correct but I think this is how it works.

If you need a very good example of the actual implementation of this you can check out the Picking demo from the DirectX sampler, it should be on github afaik.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement