I have created a mesh in Blender (just a sphere with a texture over it; it's supposed to look like mars) and I've exported it as OBJ. I've tried it both with exporting with normals in Blender's export settings and also with the aiProcess_GenNormals flag. But for some reason I'm still getting this lighting issue.
There's a lot of C++ code but I'm not sure if any of it is relevant to this issue, so I'll just include the shaders.
The vertex shader:
#version 330 core
layout(location = 0) in vec3 vertexpos_modelspace;
layout(location = 1) in vec2 texcoord_vertex;
layout(location = 2) in vec3 normal_vertex;
uniform mat4 world;
uniform mat4 view;
uniform mat4 projection;
out vec2 texcoord_fragment;
out vec3 normal_fragment;
void main()
{
texcoord_fragment = texcoord_vertex;
vec4 transformed_normal;
transformed_normal = vec4(normal_vertex, 1);
transformed_normal = world * transformed_normal;
normal_fragment = transformed_normal.xyz;
gl_Position.xyzw = projection * view * world * vec4(vertexpos_modelspace, 1);
}
The fragment shader:
#version 330 core
uniform sampler2D texsampler;
uniform vec3 light_direction;
in vec2 texcoord_fragment;
in vec3 normal_fragment;
out vec4 color;
void main()
{
float lighting = 0;
lighting = dot(normalize(normal_fragment), normalize(light_direction));
lighting = clamp(lighting, 0, 1);
vec4 sample = texture(texsampler, texcoord_fragment).rgba;
color = sample * lighting;
}
And the result looks like this:
I can't figure out why this is happening. It doesn't appear this way in Blender, just in my application.