I'm working on a project that requires two lights in opengl. These should be directional lights. I'm 99% sure I have taken a route that is more complicated than it needed to be, but I'm not understanding the project well as is, so whatever I could get to work was the route I took. I have a pyramid object with a texture on it. I also have two separate lights, a fill light and a key light. The fill light is more for the ambient lighting, and the key light is the primary "lightbulb" per se. For all 3 objects, I have a vertex shader and fragment shader (although I don't know if I actually needed to / should have done that). I have a list of verticies that draw the shapes, contain normals, and texture coordinates. The primary pyramid object uses all 3 of these attributes, but the lights only use the verticies so they have the same shape.
My main problem is that the lights aren't working correctly. The pyramid is only lit via the ambient lighting of the key light. It doesn't properly incorporate the diffuse or specular lighting components. The fill light also seems to be largely ignored, but it seems to be because the key light is overriding all other light data.
Here is what my shaders look like for the primary pyramid:
/* Pyramid Vertex Shader Source Code */
const GLchar * = GLSL(330,
layout (location = 0) in vec3 position; // Vertex data from Vertex Attrib Pointer 0
layout (location = 1) in vec3 normal; // VAP position 1 for normals
layout (location = 2) in vec2 textureCoordinate; // Color data from Vertex Attrib Pointer 1
out vec3 Normal; // For outgoing normals to fragment shader
out vec3 FragmentPos; // For outgoing color / pixels to fragment shader
out vec2 mobileTextureCoordinate; // variable to transfer Texture data to the fragment shader
// Global variables for the transform matrices
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main(){
gl_Position = projection * view * model * vec4(position, 1.0f); // transforms vertices to clip coordinates
FragmentPos = vec3(model * vec4(position, 1.0f)); // Gets fragment / pixel position in world space only (exclude view and projection)
mobileTextureCoordinate = vec2(textureCoordinate.x, 1.0f - textureCoordinate.y); // flips the texture horizontal
Normal = mat3(transpose(inverse(model))) * normal; // get normal vectors in world space only and exclude normal translation properties
}
);
/* Pyramid Fragment Shader Source Code */
const GLchar * = GLSL(330,
in vec2 mobileTextureCoordinate; // Variable to hold incoming color data from vertex shader
in vec3 Normal; // For incoming normals
in vec3 FragmentPos; // For incoming fragment position
out vec4 pyramidColor; // For outgoing pyramid color
// Uniform variables for object color, light color, light position, and camera/view position
uniform vec3 fillLightColor;
uniform vec3 fillLightPos;
uniform vec3 keyLightColor;
uniform vec3 keyLightPos;
uniform vec3 viewPosition;
uniform sampler2D uTexture; // Useful when working with multiple textures
void main() {
/* Phong lighting model calculations to generate ambient, diffuse, and specular components */
// Calculate Ambient lighting
float ambientStrength = 0.3f; // Set ambient or global lighting strength
vec3 ambient = ambientStrength * fillLightColor; // Generate ambient light color
// Calculate Diffuse lighting for fill lamp
vec3 norm = normalize(Normal); // Normalize vectors to 1 unit
vec3 lightDirection