I recently learned how to load a model to openGL using assimp, but I am having trouble figuring out how to do lighting calculations on this model. Previously with my own created objects I would set the normals manually and pass them to the shader as attributes. Then I would use one diffuse and one specular texture passed as uniforms for lighting.
I'm trying to do the same with a model, but I can't seem to get it to behave correctly. When I use my own objects everything works normally, but when I try to draw the model some weird lighting occurs.
Here's how the model should look:
But mine looks like this:
What confuses me in particular is that assimp loads both normal vertices and normal textures. I'm not sure what the difference between them is or if there is more about model loading that I've yet to learn, which is entirely possible since I don't know much about heightmaps and other things yet.
Anyway, here's what I'm doing for calculations:
void main()
{
vec3 normal = normalize(Normal);
vec3 viewDir = normalize(viewPos - fragPos);
vec3 result;
for (int j = 0; j < sizeModels; j++)
result += CalcDirLight(DirLights, normal, viewDir, models[j]);
FragColor = vec4(result, 1.0);
}
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, Material textures)
{
vec3 lightDir = normalize(-light.direction);
// diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), textures.shininess);
// combine results
vec3 ambient = light.ambient * vec3(texture(textures.diffuse, Tex));
vec3 diffuse = light.diffuse * diff * vec3(texture(textures.diffuse, Tex));
vec3 specular = light.specular * spec * vec3(texture(textures.specular, Tex));
return (ambient + diffuse + specular);
}
Notice that I'm providing my own diffuse values to the DirLight struct. The Material struct is what contains the diffuse and specular textures, as well as a shininess float.
For reference I am following guides from this site: https://learnopengl.com/
Any help would be appreciated!