Simple Environment Mapping and `"gl-version 3 2"`

First of all, I would like to point out that perhaps my problem is related to another, probably similar, which I also reported today:

I’m having trouble combining simple environment mapping and "gl-version 3 2".

I am trying to follow this tutorial:
https://docs.panda3d.org/1.10/python/programming/texturing/simple-environment-mapping

When I don’t enable newer versions of GLSL (i.e. I don’t set "gl-version 3 2" in the configuration), everything is OK. A simple environment mapping texture is generated and they can set it on the teapot.

Code:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextureStage, TexGenAttrib, loadPrcFileData

# loadPrcFileData("", "gl-version 3 2")
base = ShowBase()
base.cam.setPos(0, -16, 2)
scene = base.loader.loadModel('environment')
scene.reparentTo(base.render)
scene_bounds = scene.getTightBounds()
base.saveSphereMap('scene_env.jpg', size=256)
teapot = base.loader.loadModel('teapot')
teapot.reparentTo(base.render)
tex = base.loader.loadTexture('scene_env.jpg')
ts = TextureStage('ts')
teapot.setTexGen(ts.getDefault(), TexGenAttrib.MEyeSphereMap)
teapot.setTexture(tex)
base.run()

Effect:

Now let’s assume I enable newer versions of GLSL (that is, I set "gl-version 3 2" in the configuration). Note that for now, I don’t even set any custom shaders, just enabled the newer GLSL. Let’s also assume that this time I’m not generating a new version of a simple environment mapping texture, I’m using a previously generated one. Unfortunately, the teapot is a uniform dark green (I’m assuming it’s one of the colors of the old texture that has now spread across the entire teapot).

Code:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextureStage, TexGenAttrib, loadPrcFileData

loadPrcFileData("", "gl-version 3 2")
base = ShowBase()
base.cam.setPos(0, -16, 2)
scene = base.loader.loadModel('environment')
scene.reparentTo(base.render)
scene_bounds = scene.getTightBounds()
# base.saveSphereMap('scene_env.jpg', size=256)
teapot = base.loader.loadModel('teapot')
teapot.reparentTo(base.render)
tex = base.loader.loadTexture('scene_env.jpg')
ts = TextureStage('ts')
teapot.setTexGen(ts.getDefault(), TexGenAttrib.MEyeSphereMap)
teapot.setTexture(tex)
base.run()

Effect:

And when I try to generate a new simple environment mapping texture with "gl-version 3 2" set in the configuration, the process throws the following error message to the console:

:display:gsg:glgsg(error): Sampler type of GLSL shader input p3d_Texture0 does not match type of texture scene_env.jpg.
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable
:display:gsg:glgsg(error): Sampler type of GLSL shader input p3d_Texture0 does not match type of texture scene_env.jpg.

The texture generates all black and of course all black also makes the teapot.

Code:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextureStage, TexGenAttrib, loadPrcFileData

loadPrcFileData("", "gl-version 3 2")
base = ShowBase()
base.cam.setPos(0, -16, 2)
scene = base.loader.loadModel('environment')
scene.reparentTo(base.render)
scene_bounds = scene.getTightBounds()
base.saveSphereMap('scene_env.jpg', size=256)
teapot = base.loader.loadModel('teapot')
teapot.reparentTo(base.render)
tex = base.loader.loadTexture('scene_env.jpg')
ts = TextureStage('ts')
teapot.setTexGen(ts.getDefault(), TexGenAttrib.MEyeSphereMap)
teapot.setTexture(tex)
base.run()

Effect:

I can’t say that I know why the gl-version 3 2 string causes such failures.

However, if you’re curious about whether or not it’s currently possible to do an env map reflection on newer GL versions and with .gltf or .bam files in panda3d, I can say that it is possible and I can provide sample code for such a GL 330 workflow. I’m not sure about the status of GL 330 support with panda3d on Mac.

Thank you for your comment. Can you post a snippet that works for you?
I have OpenGL support up to version 410 on my Mac.

You must use custom shaders when you enable gl-version 3 2. That is because forcing a 3.2+ context disables the fixed-function pipeline in OpenGL. For your convenience (and for rendering GUI and such), Panda applies a very simple shader that just maps a 2D texture onto the first set of UV coordinates on the model. This shader will break when you do anything fancy, like apply a cube map.

If you need help with the math to do the reflection mapping, let me know.

Here is some old, dirty, not-cleaned-up code I experimented with a long time ago to do PBL+IBL (not verified to be correct) that you may be able to extract the cube map equation from.

https://rdb.name/pbr-ibl0.zip

1 Like

Thank you very much, I will test it too!