p3d_Color is [1, 1, 1, 1] despite the model being purple

Hey everyone.

I am trying to make this really simple program working :

from direct.showbase.ShowBase import ShowBase
from panda3d.core import Shader
import gltf


class TestShader(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        self.loadModels()
        self.loadShader("shaders/simpleShader.vert", "shaders/simpleShader.frag")

    def loadShader(self, vertexShader, fragShader):
        self.shader = Shader.load(Shader.SL_GLSL,
                            vertex=vertexShader,
                            fragment=fragShader
                            )
        self.render.setShader(self.shader)

    def loadModels(self):
        gltf.patch_loader(self.loader)
        self.model1 = self.loader.loadModel("models/purpleCube.glb")
        self.model1.reparentTo(self.render)

app = TestShader()
app.run()

Vertex shader :

#version 120

attribute vec4 p3d_Vertex;
attribute vec4 p3d_Color;

uniform mat4 p3d_ModelViewProjectionMatrix;

varying vec4 vColor;

void main() {
    if (p3d_Color == vec4(1, 1, 1, 1)) {vColor = vec4(1, 1, 0, 1);} else {vColor = p3d_Color;};
    gl_Position = p3d_ModelViewProjectionMatrix*p3d_Vertex;
}

Fragment shader :

#version 120

varying vec4 vColor;

void main() {
    gl_FragColor = vColor;
}

So “purpleCube” is only a purple cube exported using blender and according to the panda3d-gltf viewer it’s indeed purple. However it’s appearing yellow when I run my program which means that the p3d_Color attribute is always [1, 1, 1, 1].

What am I doing wrong ? Thank you very much for your help.

Where is the colour in your model coming from? Is it in the textures? In vertex colours? Somewhere else?

It’s just a simple material made in blender so I assume it’s in the vertex colors. Isn’t it ?

p3d_Color indicates the flat colour or vertex colour assigned to the model. You need to use the p3d_Material struct to obtain the material colour.

It’s working thank you very much.

1 Like