View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Portal visibility culling

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1lukesmith123  Members

Posted 16 July 2012 - 03:07 PM

I have a couple of questions about portal systems for visibility determination that I couldnt find any info on and I hope somebody here could answer.

How do you keep track of which cell the player is currently in? Do you contain each cell in a bounding box? if so, what about cells that aren't box shaped?

Also I have read that a good method is to project the portal into screen space and check which objects in the connecting cell are within the 2d bounds of the portal. Could anybody explain how to do this I dont really understand how to project the portal from world to screen space and test collisions with objects this way.

thanks,

### #2Hodgman  Moderators

Posted 16 July 2012 - 07:12 PM

How do you keep track of which cell the player is currently in? Do you contain each cell in a bounding box? if so, what about cells that aren't box shaped?

If your cells aren't box shaped, they should probably be convex polytopes., which can be described as an array of planes (if a point is on the 'inside' of every plane in the array, then it's inside the polytope). You can start by checking against each cell's bounding box first (which might give more than 1 result), and then do the more expensive plane test for every cell that passed the first test.

Also I have read that a good method is to project the portal into screen space and check which objects in the connecting cell are within the 2d bounds of the portal. Could anybody explain how to do this I dont really understand how to project the portal from world to screen space and test collisions with objects this way.

To project a point from world to screen, you multiply it with the view-projection matrix.

### #3lukesmith123  Members

Posted 17 July 2012 - 02:19 AM

Ok, so would you check the players bounds against all of the cell bounding boxes each frame? or would you need to keep track of the players movement through portals to speed this up?

So when you project the corners of the portal into screen space and build a 2D bounding box from them how do you project the objects to screen space and get a 2D box from those? Would you take the corners of the objects bounding box and project them to screen space and then create the smallest 2D box from the 8 corners?

Thanks so much for the tips!

### #4Hodgman  Moderators

Posted 17 July 2012 - 05:18 AM

Ok, so would you check the players bounds against all of the cell bounding boxes each frame? or would you need to keep track of the players movement through portals to speed this up?

In theory, the latter is optimal. However, it's probably complicated to implement, wheras the former option is simple (if somewhat brute force). I'd probably default to the first option, and only worry with the complexity of actually tracking the player if it turned out to be prohibitively slow.

So when you project the corners of the portal into screen space and build a 2D bounding box from them how do you project the objects to screen space and get a 2D box from those? Would you take the corners of the objects bounding box and project them to screen space and then create the smallest 2D box from the 8 corners?

Yes, you could project all 8 points and take the min/max to get their 2D bounds.

Also, I forgot to mention before that projection requires a few more steps than just "multiply with the view-projection matrix". After that multiply, you've got a vec4 result -- to convert that to a 2D position you've then got to perform perspective division, which means divide the result by it's own w/[3]/4th component. That then gives you a 2D point from (-1,-1)to(1,1), so you've then got to remap it if you want a (0,0)to(1,1) value, e.g. final = result * 0.5 + 0.5

Alternatively, you can turn this around and transform your portal's 2D bound into a 3D frustum. If you take the 4 corners of that bounding rectangle, and unproject them (mul with inverse viewproj matrix) with z=0 and z=1, then you get 8 3D points that are the bounding frustum of the portal. This frustum (bounding volume of the 8 points) is equivalent to 6 planes -- instead of the above 2D test, you could test each object's 3D bounds against this 3D frustum.

### #5lukesmith123  Members

Posted 17 July 2012 - 06:25 AM

Fantastic thanks so much!

### #6lukesmith123  Members

Posted 17 July 2012 - 02:07 PM

One thing, with the last point you made, would that not be a much slower method than just creating a frustum from the 4 corners in the first place?

Also do you have any opinion on whether projecting to screen space vs creating frustums from the portals is faster?

### #7Hodgman  Moderators

Posted 17 July 2012 - 08:43 PM

Yes the screen space idea is probably simple and fast. I mentioned the 3D case just to get you thinking about other possibilities.

e.g. A more advanced 3D version would take the 2D outline of each portal (could be more than 4 sides -- e.g. an octagonal window portal) and create a plane from the observer's position and each of those lines, so the 3D 'frustum' for testing is an extruded octagon instead of an extruded rectangle.

### #8lukesmith123  Members

Posted 18 July 2012 - 01:43 AM

Ah I see. Great answers thanks!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.