Cubemap within an egg (no generation from within Panda)

OK, so the ultimate goal here is to create a cubemap for a water shader without having to use any python code to do so (no creating a TexGenAttrib etc). I was wondering considering the Egg sytax can specify a cubemap texture…if I could somehow create my water plane, set it’s normal map (for waves) and somehow include the cubemap texture in that same egg. It’d be nice to simply call setShader( and have the CubeMap already in there without having to generate it somehow from a .dds file or something within Panda itself. Any suggestions?

What exactly do you mean by CubeMaps?

A textured cube? A 3D texture? A cube with a special TexGenAttrib? Or a texture which represents a roundview? (There are probably even more definitions)

Basically, I just want something that can get passed to a shader as samplerCUBE. It’s technically a 3D texture I guess, but it has 6 maps for each side of the cube. Normally used as an environment for reflective objects.

That’s not a 3-D texture; it’s a cube map, which is similar to a 3-D texture but is its own very specific thing. The egg syntax certainly supports it, as described in the eggSyntax document:

<Texture> cube {
  <Scalar> type { cube_map }

This gets turned into a Texture object whose TextureType is TT_cube_map.


Hrm, did that part…do I actually have to apply that texture to a cube somewhere in the egg to get it as a shader input? I figured since it was the second Tref in the file it would come in as tex1 (since the normal map for the waves is in tex0). The shader doesn’t die or crash the world when I try to access it, but I’m not getting any actual reflection result on the surface so my hunch is it’s not there or I’m grabbing it incorrectly. I’ll keep digging, if you think of anything let me know. Thanks


No, you actually need to apply it. The egg loader ignores any entries that aren’t applied to any geometry.


ok, got that all working nicely. second question…is there a way to generate a cubemap from six image files that aren’t set up to work in a sequence? ex

I’m trying to get cubemaps as shader inputs working in the editor and we realized there’s an edge case where the use could try and use a bunch of random images to build this cubemap…ideally they’d just use one .dds file if they could, or a sequence/pattern.

You can copy the six images to a series of numbered images, and load them that way. Or, you can read them individually into six PNMImages, then apply them to the texture six times with code something like this:

tex = Texture('cubemap')
for i in range(6):
  image = PNMImage()
  if not[i]):
     raise StandardError, 'Invalid filename'
  if not tex.load(image, i, 0):
     raise StandardError, 'Inconsistent properties'


Does the copying to PNImage cause any penalty? In case it doesn’t I’d prefer to name my 6 textures top, bottom, left etc. instead of giving them numbers that have to be explained in a text file.

It’s just a clumsier way to load them, but there’s no performance penalty to speak of.