[SOLVED] Imported GLTF model's textures are dark

In Blender 2.8 I set the material “Base Color” to a texture then export the model to .gltf.
Loading the model in Panda the texture on the model is very dark.
I wrote a shader and if I use Panda’s texture index the model is still dark:

vec4 diffuse = texture(p3d_Texture0, texcoord);

If I load the texture and pass to the shader the texture then looks normal:

vec4 diffuse = texture(image, texcoord);

Is there a setting in Blender or Panda that needs to be set to prevent the model’s texture from being dark?

Panda Code:

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

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

        base.trackball.node().set_pos(0, 30, -5)
        base.trackball.node().set_hpr(0, 40, 0)

        image = self.loader.load_texture("image/Avatar.png")
        cube = self.loader.load_model("models/cube2.gltf")
        cube.reparent_to(self.render)

        texture_shader = Shader.load(Shader.SL_GLSL, vertex="shaders/texture.vert", fragment="shaders/texture.frag")
        cube.set_shader(texture_shader)

        cube.set_shader_input('image',image)

game = Game()
game.run()

Shaders:

#version 330

uniform mat4 p3d_ModelViewProjectionMatrix;
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;

out vec2 texcoord;

void main(void){
    texcoord = p3d_MultiTexCoord0;
    gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
}
#version 330

uniform sampler2D image;
uniform sampler2D p3d_Texture0;
in vec2 texcoord;

out vec4 color;

void main (void){
    //vec4 diffuse = texture(image, texcoord); //Texture looks normal.
    vec4 diffuse = texture(p3d_Texture0, texcoord); //Texture looks dark.
    color = diffuse;
}

I’m using panda 1.10.4.1

glTF models expect a PBR render pipeline, so using a basic shader will make the model looks weird and dark. The former due to the absence of roughness and reflection, latter due to the wrong colour space used (linear instead of sRGB).

You can use panda3d-simplepbr to have a simple but correct render : https://github.com/Moguri/panda3d-simplepbr

1 Like

I figured it was because of the PBR pipeline, I hoped there might have been some option to toggle somewhere.
Thanks for the link!

Replacing the texture on the model fixes the issue so is another option:

cube.set_texture( cube.find_texture_stage('*'), image, 1)

You could also use a sRGB framebuffer and keep the current texture and shaders. This will solve (some) of the darkness problem.

Add framebuffer-srgb truein your prc data.

1 Like

Using framebuffer-srgb true does make everything brighter so the texture looks normal. Thanks!

As a heads up, panda3d-gltf is loading textures as sRGB, which is why the sRGB framebuffer is important. When you re-load the texture, it is no longer getting loaded as sRGB. You could iterate all of the textures and use Texture.set_format() to change from F_srgb/F_srgb_alpha to F_rgb/F_rgba.

1 Like

2 posts were split to a new topic: Strange issue with model texture

3 posts were merged into an existing topic: Strange issue with model texture

Please use the separate topic I created to discuss the caching issue, rather than reusing this topic. This keeps the forums organised and readable to others.