Invalid operation when specifying p3d_Color as vec4

When running my code on the latest v1.11 Merge branch 'release/1.10.x' · panda3d/panda3d@9517ffb · GitHub (I stayed on an older version for a few months), I now get “Invalid operation” errors. After a bit of investigation, it seems this occurs when I specify p3d_Color as a vec4, using vec3 with the appropriate type conversion is fine though.

Looking at the code and the doc this should be working though.

Here is a small example :

from panda3d.core import  CardMaker, Shader, PandaSystem, load_prc_file_data
from direct.showbase.ShowBase import ShowBase

print("Panda version: %s (%s) by %s (%s)" % (PandaSystem.getVersionString(),
                                             PandaSystem.getGitCommit(),
                                             PandaSystem.getDistributor(),
                                             PandaSystem.getBuildDate()))

load_prc_file_data("", "gl-check-errors #t")

def shader():
    return Shader.make(Shader.SL_GLSL,
                       vertex="""
#version 410

uniform mat4 p3d_ProjectionMatrix;
uniform mat4 p3d_ModelViewMatrix;

uniform vec4 p3d_Color;
//uniform vec3 p3d_Color;


in vec4 p3d_Vertex;
out vec4 color;

void main() {
    gl_Position = p3d_ProjectionMatrix * (p3d_ModelViewMatrix * p3d_Vertex);
    color = p3d_Color;
    //color = vec4(p3d_Color, 1);
}
""",
                       fragment="""
#version 410

in vec4 color;
out vec4 frag_color;

void main() {
    frag_color = color;
}
""")


base = ShowBase()
cm = CardMaker('card')
card = base.render.attach_new_node(cm.generate())
card.setPos(-0.5, 3, -0.5)
card.set_color((1, 0, 1, 1))
card.set_shader(shader())

base.run()

And the output is :

Panda version: 1.11.0 (9517ffb320fbd30f401e1550c6413a25f355e273) by cosmonium (Jan 20 2024 11:32:58)
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
:display:gsg:glgsg(error): at 2338 of panda/src/glstuff/glShaderContext_src.cxx : invalid operation

I tested both options on Windows 10.

uniform vec4 p3d_Color

Panda version: 1.10.14 (8e539bd99840da261853c08bc426e0ea43bddd24) by cmu (Jan  8 2024 13:54:48)
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)

uniform vec3 p3d_Color

Panda version: 1.10.14 (8e539bd99840da261853c08bc426e0ea43bddd24) by cmu (Jan  8 2024 13:54:48)
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
:display:gsg:glgsg(error): An error occurred while compiling GLSL vertex shader created-shader:
ERROR: created-shader:16: 'assign' :  cannot convert from ' uniform 3-component vector of float' to ' smooth out 4-component vector of float'
ERROR: created-shader:16: '' : compilation terminated
ERROR: 2 compilation errors.  No code generated.

:thinking:

It seems you posted two identical code snippets… If you uncomment the corresponding lines, then both options work.

Indeed, I’m not sure of why the code given above might have worked in the older version, if I’m understanding correctly.

Specifically, it looks like you’re attempting to assign an object of type vec3 to an object of type vec4–which I don’t think generally works in GLSL. (The object “color” having been declared as a vec4, and the object “p3d_Color” having been declared as a vec3.)

Hence changing the type of “p3d_Color” to vec4 solves the problem, as does assigning p3d_Color to be the first three components of a new vec4 and then assigning that to “color”.

Indeed, I pasted the code twice instead of the output when Panda3D throws an error, I fixed it

There are two version, one where p3d_Color is a vec4 and I directly assign it to color and one where p3d_Color is a vec3 and it is assigned to color using a type extension vec4(p3d_Color, 1.0)

Both code should work, but the vec4 version is throwing an error.

Beware that this occurs using the latest commit of the master branch, with older version, and with v1.10.14, there is no error.

Ahh, fair enough! I didn’t catch that.

Indeed, those should both work, I believe!

[edit]
In fact, I’d suggest filing this as a bug in the tracker.

That’s what I was afraid of, I wanted to be sure I didn’t goofed as it is a really weird bug.Here is the issue ticket :

1 Like