Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Determining whether a cube obscures another cube

Author
Message
Michael P
20
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 30th Dec 2010 18:35 Edited at: 30th Dec 2010 18:36
I'm attempting a basic form of occlusion culling and have some constraints on the universe which should simplify the problem significantly.

My universe is made entirely of cubes which are all the same size and are opaque. How can I work out if a cube is completely obscuring another cube, and thus can be hidden, baring in mind that the camera can be at any orientation?

Here is a diagram of this:


C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 30th Dec 2010 19:08
I don't know the best way to do it but I'd recommend not doing a load of raycasts from the camera out the way hoping to hit things and testing it that way round, but I'd do it from the cubes to the camera seeing what is in the way.

I don't have any more specific ways of doing it than that to make it faster or anything though.



On a side note: I'm surprised you're asking all these questions Michael P - you made DarkNet xD - You seem like you should be able to do all this better than the rest of us.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2010 20:17
Quote: "but I'd do it from the cubes to the camera seeing what is in the way"


Me too.

Are the cubes all oriented the same way? If so then I think you only need to check the corners.

The question is: is such culling any faster than automatic DBPro culling?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Dec 2010 20:18
If the cubes are in a grid, you can precalculate which cubes will be hidden if a certain cube relative to the camera exists. You'd only do this for cubes close to the camera.

Basically you'd have a 3d grid in memory for each grid cell near the camera. You fill these grids before-hand with either 0 or 1 depending on whether they are hidden if the grid cell is solid. In the actual game, you take the grid for each solid cell and cull all the grid cells set to 1 in the grid.

[b]
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 30th Dec 2010 20:27 Edited at: 30th Dec 2010 20:30
Well, first of all you'd need to project those points on the camera viewport. Afterwards you check using those coordinates whether or not a point of the back cube is visible through any of the plains facing forward of the front cube using 3D math (projection on each plain normal).
Afterwards you have to check whether or not all points are within the projected convex 2D hull.

For each step I just described, there are numerous solutions. I will see in which way this goes before giving any lengthy explanation (which I started at first ).

[edit] Apart from the pure mathematical version which I was describing here, I have to agree with the raycasting thing... It's probably the easiest to implement.

Cheers!
Sven B

Michael P
20
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 2nd Jan 2011 14:53 Edited at: 2nd Jan 2011 14:53
Quote: "If the cubes are in a grid, you can precalculate which cubes will be hidden if a certain cube relative to the camera exists. You'd only do this for cubes close to the camera.

Basically you'd have a 3d grid in memory for each grid cell near the camera. You fill these grids before-hand with either 0 or 1 depending on whether they are hidden if the grid cell is solid. In the actual game, you take the grid for each solid cell and cull all the grid cells set to 1 in the grid."

This is really specific to what I'm doing.

So to bring in some additional information: All cubes are the same size and orientation. They are in a 3D grid as Diggsey describes where some may be filled and some may be unfilled (and thus transparent). This doesn't need to be precise, so it doesn't matter if less than 100% of the cubes that are obscured are culled.

@ Diggsey
So are you saying that we can do most of the work just by looking at the player's position. I'll prototype this at a 2D level first; if we look for blocks that are filled around us then we can instantly cull large sections like this:


Above the green square is the camera, the grey squares are filled spaces (the one non grey square surrounding the camera is unfilled), the blue squares are squares that might be visible to the camera and so should not be culled, the red squares are squares that can be culled.



Quote: "On a side note: I'm surprised you're asking all these questions Michael P - you made DarkNet xD - You seem like you should be able to do all this better than the rest of us"

DarkNet is a different ball game, there's no mathematics or 3D stuff in there. I'm very inexperienced with both these things hence the questions.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Jan 2011 16:48
There's lots of theory and non-DB code on the rogue-like site.

Login to post a reply

Server time is: 2026-07-19 19:14:35
Your offset time is: 2026-07-19 19:14:35