I tried my best to make the Shader as self explanatory as possible without the use of comments. My colors are definitely showing up because when I add 0.8 to the final result color you can see them just barely. I have yet to do grade ten math but I will once I get there so please understand I do not know how most of this math works with trigonometry and linear algebra. I have not done any code for lighting in main other than a uniform vec3 called Light_Position and enabling lighting, is there code required in main to grab surface normals and other stuff?? if so please let me know what I need to do
in main for lighting:
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glm::vec3 Light_Position(0.2f, 0.1f, 0.2f);
int lightpos = glGetUniformLocation(shader, “light_position”);
glUniformMatrix4fv(lightpos, 1, GL_FALSE, glm::value_ptr(Light_Position));
#shader vertex
#version 330 core
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
uniform mat4 model_matrix;
uniform mat4 perspective;
uniform mat4 just_translations;
uniform vec3 light_position;
out vec3 fragment_position;
out vec3 Normals;
void main()
{
gl_Position = model_matrix * vec4(position.x, position.y, position.z, 1.0);
fragment_position = vec3(just_translations * vec4(position.x, position.y, position.z, 1.0));
Normals = mat3(transpose(inverse(just_translations))) * normal;
};
#shader fragment
#version 330 core
layout(location = 0) out vec4 color;
uniform vec4 Color_u;
uniform vec3 light_position;
in vec3 fragment_position;
in vec3 Normals;
void main()
{
float ambient_strength = 0.1f;
vec4 ambient_light = ambient_stength * Color_u;
vec3 norm = normalize(Normals);
vec3 light_direction = normalize(light_position - fragment_position);
float diffuse = max(dot(norm, light_direction), 0.0);
color = ambient_light * diffuse;
};