Projected Textures 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 projected textures and "gl-version 3 2".

I am trying to follow this tutorial:
https://docs.panda3d.org/1.10/python/programming/texturing/projected-textures

When I don’t enable newer versions of GLSL (i.e. I don’t set "gl-version 3 2" in the configuration), everything is fine.

Code:

from direct.actor import Actor
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *

# loadPrcFileData("", "gl-version 3 2")

base = ShowBase()

base.setBackgroundColor(1, 1, 1, 1)

ripple = Actor.Actor('ripple.egg')
ripple.reparentTo(base.render)
ripple.setScale(10)
ripple.pose('animation', 17)

dl = DirectionalLight('dl')
dlnp = base.camera.attachNewNode(dl)
ripple.setLight(dlnp)

proj = base.render.attachNewNode(LensNode('proj'))
lens = PerspectiveLens()
proj.node().setLens(lens)
proj.node().showFrustum()
proj.find('frustum').setColor(1, 0, 0, 1)
camModel = base.loader.loadModel('camera.egg')
camModel.reparentTo(proj)
proj.reparentTo(base.render)
proj.setPos(1.5, -7.3, 2.9)
proj.setHpr(22, -15, 0)

tex = base.loader.loadTexture('maps/envir-reeds.png')
tex.setWrapU(SamplerState.WMBorderColor)
tex.setWrapV(SamplerState.WMBorderColor)
tex.setBorderColor((1, 1, 1, 0))
ts = TextureStage('ts')
ts.setSort(1)
ts.setMode(TextureStage.MDecal)
ripple.projectTexture(ts, tex, proj)

base.disableMouse()
base.camera.setPos(-7.8, -22.4, 0)
base.camera.setHpr(-21, 0, 0)

base.graphicsEngine.renderFrame()
base.screenshot('projected_bamboo.jpg', defaultFilename=0)

Effect:

Now let’s assume that 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, I just enabled the newer GLSL. Unfortunately, texture projecting doesn’t work this time.

Code:

from direct.actor import Actor
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *

loadPrcFileData("", "gl-version 3 2")

base = ShowBase()

base.setBackgroundColor(1, 1, 1, 1)

ripple = Actor.Actor('ripple.egg')
ripple.reparentTo(base.render)
ripple.setScale(10)
ripple.pose('animation', 17)

dl = DirectionalLight('dl')
dlnp = base.camera.attachNewNode(dl)
ripple.setLight(dlnp)

proj = base.render.attachNewNode(LensNode('proj'))
lens = PerspectiveLens()
proj.node().setLens(lens)
proj.node().showFrustum()
proj.find('frustum').setColor(1, 0, 0, 1)
camModel = base.loader.loadModel('camera.egg')
camModel.reparentTo(proj)
proj.reparentTo(base.render)
proj.setPos(1.5, -7.3, 2.9)
proj.setHpr(22, -15, 0)

tex = base.loader.loadTexture('maps/envir-reeds.png')
tex.setWrapU(SamplerState.WMBorderColor)
tex.setWrapV(SamplerState.WMBorderColor)
tex.setBorderColor((1, 1, 1, 0))
ts = TextureStage('ts')
ts.setSort(1)
ts.setMode(TextureStage.MDecal)
ripple.projectTexture(ts, tex, proj)

base.disableMouse()
base.camera.setPos(-7.8, -22.4, 0)
base.camera.setHpr(-21, 0, 0)

base.graphicsEngine.renderFrame()
base.screenshot('projected_bamboo.jpg', defaultFilename=0)

Effect:

I have no error messages on the console.

This problem is fixed in Panda3D 1.11 on the master branch. For now, you must use a custom shader.

1 Like

Thank you, I understand.
At the same time, as I understand it, Panda3D 1.11 will not be available soon (Panda 1.10.14 is still on the way), and currently there is no stable alpha/beta version.

For what it’s worth, bugfix (1.10.x) releases are developed concurrently with the next feature release (1.11.0). We are currently actively working on 1.11.0, but bugfixes are backported to the 1.10 branch when they come in and when enough bugfixes have accumulated, we kick off an 1.10.x release. In theory (though unlikely), 1.11.0 could even be released before 1.10.14.

If you need to use 1.11.0 features, you could consider using development builds.

But in this case, I think you probably want to use a custom shader anyway. Or, pull in a package like panda3d-simplepbr that provides shaders for you.

Here is a simple shader that implements texture matrices (which are required to use the texture projector):

// shader.vert

#version 330

in vec4 p3d_Vertex;
in vec4 p3d_Color;
in vec4 p3d_MultiTexCoord0;
out vec3 texcoord;
out vec4 color;

uniform mat4 p3d_ModelViewProjectionMatrix;
uniform mat4 p3d_TextureMatrix;
uniform vec4 p3d_ColorScale;

void main(void) {
  gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
  texcoord = (p3d_TextureMatrix * p3d_MultiTexCoord0).xyw;
  color = p3d_Color * p3d_ColorScale;
}
// shader.frag

#version 330

in vec3 texcoord;
in vec4 color;
out vec4 p3d_FragColor;

uniform sampler2D p3d_Texture0;
uniform vec4 p3d_TexAlphaOnly;

void main(void) {
  p3d_FragColor = textureProj(p3d_Texture0, texcoord);
  p3d_FragColor += p3d_TexAlphaOnly;
  p3d_FragColor *= color;
}
1 Like

Thank you very much, I will test it!