Panda3D Manual: Dynamic Cube Maps
Since the six faces of a cube map are really just six different views of a scene from the same point, it's possible to generate a cube map automatically by rendering these six different views at runtime. This is really just a form of offscreen rendering to a texture. Instead of rendering just one 2-D texture image, though, rendering a dynamic cube map means rendering six different 2-D images, one for each face of a cube map texture. Panda3D makes this easy for you. To start rendering a dynamic cube map, simply call: rig = NodePath('rig') This will return an offscreen
There are also additional, optional parameters to
Note that we passed a new The actual cube map itself be retrieved with the call: tex = buffer.getTexture() You can apply the texture to geometry as in the previous example. You should use the When you are done with the cube map, you should remove its buffer (and stop the cube map from continuing to render) by calling: base.graphicsEngine.removeWindow(buffer) As a complete example, here is how we might load up a dynamic cube map environment on our teapot and move the teapot down the street to show off the dynamic reflections: scene = loader.loadModel('bvw-f2004--streetscene/street-scene.egg') A word of cautionWhen you render a dynamic cube map, don't forget that you are re-rendering your scene six times every frame in addition to the main frame render. If you are not careful, and if you have a complex scene, then you could easily end up reducing your frame rate by a factor of seven. It is a good idea to limit the amount of geometry that you render in the cube map. One simple way to do this is to ensure that the far plane on the cube map cameras is set relatively close in. Since all of the cube map cameras share the same lens, you can adjust the near and far plane of all of the cameras at once like this: lens = rig.find('**/+Camera').node().getLens() It is especially important when you are using cube maps that you structure your scene graph hierarchically and divide it up spatially so that Panda3D's view-frustum culling can do an effective job of eliminating the parts of the scene that are behind each of the six cameras. (Unfortunately, the street-scene model used in the above example is not at all well-structured, so the example performs very poorly on all but the highest-end hardware.) It's also usually a good idea to keep the cube map size (the You can also take advantage of the Finally, you can temporarily disable the cube map rendering from time to time if you know the environment won't be changing for a little while. The cube map will retain its last-rendered image. You can do this with
© Carnegie Mellon University 2010 |