Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to create camera view/projection matrices based on a screen rect?

Started by Waaayoff Aug 18, 2019 at 9:02 AM 3 replies 2.7k views
Original Post
Waaayoff
Waaayoff

I am trying to do GPU box selection (by using imageStore in the fragment shader as suggested to me in an earlier question). Basically I would like to call imageStore only on pixels that lie inside a user-defined screen rectangle. How do I setup my camera for the selection render pass such that everything outside the selection rectangle is clipped?

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
JohnnyCode
JohnnyCode

Do you want it to be an orthogonal perspective camera ?

Waaayoff
Waaayoff

Perspective I think. The user is creating the screen rectangle when looking through a perspective camera.


"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
JohnnyCode
JohnnyCode

You've got a little design flaw there, be more specific about the feature, since for example user can pick a small rectangle in upper left corner, and there is no perspective observation to that corner without rotating the camera view and zooming, thus changing entire observation.

If you want to achieve that, find center-of-rectangle ray, rotate the view to align with it (just world space "at" position), and zoom. The amount of zoom is simply lessening the FOV. You can compute the FOV as rectangle world space size dividing near plane world space size.



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.