Occlusion, Portals etc...

Ok, here’s a subject we’ve all touched on in the past here on the Panda3d forums.

I’m getting to the point where my models are not small rooms (huge) and now need to figure out how to get occlusion working in the engine.

Josh mentioned that occlusion is possible with the Panda3d engine but there is no documentation yet for this. He said you need to portalize the scene (room) and that the room is inside a cell.

Well, I’m sure you guessed what I’m going to ask. Any hints on where we might find this so we can try and figure it out for ourselves? I should probably add that I’ve looked through the Documentation for Classes, Functions and Methods and didn’t really see anything that obviously related to what I’m looking for.

Thanks,

Steve

The portal-visibility code is in place in Panda, but it hasn’t really been exercised yet; you should consider it alpha code.

See PortalNode in the API docs for some of the interface. Some of the interface is a little confused and some of it is completely irrelevant; the programmer who originally implemented this was new to Panda, and copied a lot of the interface from CollisionNode and renamed it, without fully understanding its purpose.

The basic idea is that you divide your scene up into “cells”, which are just toplevel nodes under render. Everything that is in cell A should be grouped together under node A. Then you parent all cell nodes to render, and hide them all.

Then you create a bunch of PortalNodes. Each PortalNode is a window from one cell to another. The PortalNode itself contains the geometry of the window. Parent the PortalNode within the cell that you are looking from, and call node.setCellIn() and node.setCellOut() to tell it the NodePaths of the “in” cell (the current cell) and the “out” cell (the cell you are looking at), respectively.

I think you will also need to define:


allow-portal-cull 1

in your Config.prc to enable this code.

You can define PortalNodes in your egg file by putting the syntax:


<Scalar> portal { 1 }

within a entry that contains just a single rectangular polygon. You will, however, then have to find the PortalNodes in Python code to associate them with the appropriate cells by hand.

Good luck! :slight_smile:

David

Oh yeah, you have to have some application-level code that decides what cell your camera should be in, and calls show() on the appropriate cell node (and hide() on the other ones). One way to do this is to have a CollisionRay that detects which floor polygon your avatar is standing on; another way is explicitly, as your avatar opens and walks through doors. It’s very application-specific, though, so Panda can’t do this part automatically.

David

Wow, thanks David. Just the information I needed.

Incidently, I didn’t see anything in the API docs about PortalNode. Maybe it just hasn’t been updated in the online documentation yet or maybe I’m just missing it somehow.

Steve

The PortalNode is documented in the API reference here: http://panda3d.org/apiref.php?page=PortalNode

It might be a little hard to find at first, because the names are sorted with the uppercase letters before all of the lowercase letters, a bit counter-intuitive. So you have POD, PSphereLens, PStatClient, and it looks like there’s no PortalNode–but PortalNode is actually much further down the list, between Pool and PosHprInterval.

David

Huh, that is really strange. I did realize that an entry with a capital letter wouldn’t be in the same place as a lower case and I looked at the P’s several times… oh well. Thanks for taking the time to point it out David.

Steve

While we’re on the subject, I’ve been thinking about how nice it would be if panda supported some sort of hierarchical Z-buffer algorithm. I don’t know how ambitious you’re feeling… but I think I’d rather implement hierarchical Z than portalize an entire game.

Well, your probably right. After digesting what David said about hand editing my egg files. I’m not sure its really worth it! :slight_smile:

Maybe in the mean time I can just break up the scene into smaller chunks that load when needed or some figure out some other trick.

Steve

It has been one of my longer-term goals for Panda to add support for this kind of algorithm for a while. Of course, it’s not the solution to every problem, and it would require a certain amount of hardware support. But it would be an easy boost for a lot of common kinds of scenes, and it would be a fairly painless way to optimize most indoor-type scenes.

A lot of times, simple application-specific visibility algorithms like this can be at least as effective as (and much cheaper than) engine-implemented general algorithms like cell-portal visibility and hierarchical Z-buffers. :slight_smile:

David