Erratic behaviour with setShaderInput and GLSL

Hi all,

i’m interested in GLSL shader scripting and read about the new support for GLSL in Panda. I made a quick test for passing values from the application to the shader and found erratic behaviour.

In my code below I pass a uniform float variable “test” with value 1.0 to the fragment shader that should lead to a yellow colored sphere object. Sometimes I see yellow, but other times the sphere is red, as if “test” is 0.0.

You might have to start the script several times to see the behaviour. What am I doing wrong?

I’m using a self compiled Panda from cvs from September 21st on Linux 64Bit.

Thanks,
Sanne

glsltest.py:

import direct.directbase.DirectStart
from panda3d.core import *

vertshader = "simple.vert"
fragshader = "simple.frag"

testobject = loader.loadModel("smiley")
testobject.reparentTo(render)

shader = Shader.load(Shader.SLGLSL, vertshader, fragshader)
testobject.setShader(shader)
testobject.setShaderInput("test", 1.0)

camera.setPos(0,-10,0)
base.disableMouse()

base.accept("escape", exit)
base.run()

simple.vert:

void main() {
  gl_Position = ftransform();
}

simple.frag:

uniform float test;

void main() {
  gl_FragColor = vec4(1.0, test, 0.0, 1.0);
}

Hmm… I remember I’ve seen this happen before. What happens if you pass a Vec4 (and reference it as float4 in the shader) instead?

rdb, thanks for replying. I did:

Relevant line in script:

testobject.setShaderInput("test", Vec4(1.0, 1.0, 0.0, 1.0))

And the fragment shader:

uniform float4 test;

void main() {
  gl_FragColor = test;
}

It’s the same behaviour. I see the expected yellow sphere several times, but from time to time the sphere is black. I also tried with vec4 instead of float4 in the shader (didn’t know GLSL had float4, can’t find it in the spec), with also the same behaviour.