In Qt I would imagine they are using "materials" as an abstraction of their predefined shaders. You create a material such as QPhongMaterial that you want to render an entity with and set things for that material which will be passed in as arguments to the shader (uniforms) like the ambient, specular and diffuse lighting color.
So you need a shader that will support vertex colors for your model. So each vertex of your model will have a color associated with it and these values get passed in to the vertex shader and forwarded to the fragment shader. It's fairly straightforward to do this with OpenGL but you're using Qt3D so it might be easier to use the infrastructure that's already there.
Qt3D already has some material classes that you can use to create some of these shaders to apply to your entity. You could try using the QPerVertexColorMaterial instead.
https://doc.qt.io/qt-5/qt3dextras-qpervertexcolormaterial.html
Qt3DExtras::QPerVertexColorMaterial Default implementation for
rendering the color properties set for each vertex
Obviously you will need to provide the list of vertex colors in order to color parts of the model differently. In addition to this, you will need to provide vertex colors for each vertex, even if you want to color each vertex of the triangle all the same color (face colors).
Alternatively you could create your own shader and give it to Qt3D to bind to the pipeline:
(from the forum)
Qt3D does not generate shaders at runtime. For its default pipeline it comes with predefined default shaders. But you are free to change the pipeline as you wish (in C++ and also in QML) and you can use your own shaders.
For custom materials the following example look promising:
https://doc.qt.io/qt-5/qt3d-simplecustommaterial-example.html
And for information on Qt3D shaders:
https://doc.qt.io/qt-5/qml-qt3d-render-shaderprogram.html
ShaderProgram class encapsulates a shader program. A shader program consists of several different shaders, such as vertex and fragment shaders.
Qt3D will automatically populate a set of default uniforms if they are encountered during the shader instrospection phase.
If you've never written a shader in GLSL and compiled it in an OpenGL program you might want to first get up to speed on how that is done as you need to understand the parts that the vertex, geometry and fragment shaders all play as well as the role of attributes and uniforms. I suppose you could still get the job done without doing that but I would imagine it would be significantly harder.
There is pages and pages out there on shaders but just briefly...
A shader generally comprises of three parts; the vertex shader, the geometry shader and the fragment shader, these are written using GLSL and usually saved as three files. At a minimum to compile a shader you need the vertex shader source and the fragment shader source.
Generally people like to save these files with the respective extension such as .frag, .vert or .vs/ .fs but ultimately they are just text files.
To compile a shader and bind it to the render pipeline you need to load the source from the respective files and link them to create your shader program which you can then use by binding it to the render pipeline and rendering your geometry. Lazy Foo has an awesome tutorial on how that is done in OpenGL: http://lazyfoo.net/tutorials/SDL/51_SDL_and_modern_opengl/index.php
If you were just using OpenGL, you would first write a vertex shader then a fragment shader with the correct inputs/outputs for rendering geometry with vertex colors, then you would go through that process to create your shader program.
As for the shader implementation itself, here is a quick implementation of what your vertex and fragment shader would look like:
Vertex Shader (Color.vs)
#version 330
in vec3 position;
in vec4 vertexColor;
uniform mat4 WORLD_VIEW_PROJECTION_MATRIX;
out vec4 fragColor;
void main()
{
fragColor.x = vertexColor.x;
fragColor.y = vertexColor.y;
fragColor.z = vertexColor.z;
fragColor.w = vertexColor.w; //alpha
gl_Position = WORLD_VIEW_PROJECTION_MATRIX * vec4( position, 1 );
}
Fragment Shader (Color.fs)
#version 330
out vec4 LFragment;
in vec4 fragColor;
void main()
{
LFragment = fragColor;
}