I realised that models can be loaded in many different ways. Some might have no textures and just use vertex colours, while others have materials with textures. Now, I have one shader that is used to draw 3d models with lighting but how would I go about loading models that are required to be rendered differently and have them rendered correctly in the scene.
One method I thought of is having hard defined attribute pointers in the vertex shader and that if the model doesn't require binding an attribute, it doesn't have to. I would imagine that if an attribute isn't binded to and is used in calculations, it won't contribute or offset any values (especially if you do the calculations separately and sum them in the end (for example, calculating the colour of the pixel for the vertex colour at that fragment and summing that for the colour of the pixel for the texture)
You can imagine the vertex shader looking like:
#version 330 core
layout (location = 0) in vec3 aPos; // Vertex positions
layout (location = 1) in vec3 aNormal; // Normals
layout (location = 2) in vec2 aTexCoords; // Optional Texture coordinates
layout (location = 3) in vec3 aColors; // Optional vertex colours
out vec3 FragPos;
out vec3 Normal;
out vec2 TexCoords;
out vec3 Colors;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.0));
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoords = aTexCoords;
Colors = aColors;
gl_Position = projection * view * vec4(FragPos, 1.0);
}
An issue I can see with this is I'm not sure how I could tell whether to use texCoords or colours or both. Perhaps using a uniform as a flag and keeping that data in the model object?
Another method would be by defining shaders for different types of lighting techniques and then determining which shader is called for which model. This is my least favourite as it doesn't allow for dynamic approaches (i.e both vertex colours and textures at the same time)
What would be the approach done in a professional setting so that any model can be loaded and drawn into a scene with lighting in the same vain as game engines manage? (Using forward rendering right now so don't need any deffered shading concepts as that's above my paygrade at the moment). I'm not seeking specific solutions, more of an experts knowledge of how this issue is approached.
Also, I'm using OpenGL 3.3
What would be the approach done in a professional setting so that any model can be loaded and drawn into a scene with lighting in the same vain as game engines manage?
Either this:
defining shaders for different types of lighting techniques and then determining which shader is called for which model
or this:
having hard defined attribute pointers in the vertex shader and that if the model doesn't require binding an attribute, it doesn't have to
Pick one. In the second approach, you don't need flags - you can just bind dummy values, like a plain white texture if the model has no texture, and a white vertex colour if the model has no vertex colours.