How to use assimp to load vertex color material

Any assimp user here? I need help (beginner)

How to use assimp to load solid color material (kd value in .mtl) instead of loading image textures, im using learnopengl code to load the model https://github.com/JoeyDeVries/LearnOpenGL/tree/master/src/3.model_loading/1.model_loading, I’m trying to modify the shader program, but I don’t know how to implement it, I searched the web and most of the implementations are using image textures.

I think the process is to retrieve the kd diffuse value from mtl file and pass it into shader program, but when using assimp, it only works when image texture is provided…

#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{    
    FragColor = texture(texture_diffuse1, TexCoords);
}

The outcome if no image texture is provided…


Thanks in advance!

windmill.mtl source : https://github.com/liho98/gp-practical-3/blob/master/model/windmill/untitled.mtl

Assimp itself can read OBJ materials, but the loader in the git repo (includes/learnopengl/model.h) ignores them, and only processes textures. If you want to modify the loader, use e.g.

aiMaterial* mat = ...
aiColor3D color(0.f,0.f,0.f);
mat->Get(AI_MATKEY_COLOR_DIFFUSE, color);

to retrieve colours. For rendering, you can then pass the per-mesh colours in as uniforms.

A post was split to a new topic: How to pass mesh colors?