Skip to content
Snippets Groups Projects
Commit d726a260 authored by Martin Štourač's avatar Martin Štourač
Browse files

added specular lighting

parent 453b1ef5
No related branches found
No related tags found
No related merge requests found
......@@ -7,17 +7,27 @@ in vec3 Normal;
uniform vec3 objectColor;
uniform vec3 lightColor;
uniform vec3 lightPos;
uniform vec3 viewPos;
void main()
{
//ambient
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * lightColor;
// diffuse
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = diff * lightColor;
FragColor = vec4((ambient + diffuse) * objectColor, 1.0f);
// specular
float specularStrength = 0.5; // TO DO: Object shine
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = specularStrength * spec * lightColor;
FragColor = vec4((ambient + diffuse + specular) * objectColor, 1.0f);
}
......@@ -18,8 +18,8 @@ protected:
float step = 0;
// FTO DO: shared ptr
//Frame &bound_frame;
Frame* bound_frame;
//std::shared_ptr<Frame> bound_frame;
public:
Controller(Frame* frame)
......
......@@ -69,7 +69,7 @@ void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view
ASSUMPTION(glGetError() == GL_NO_ERROR);
}
void draw_objects(std::map<std::string, shader_ptr> &myShaders,
void draw_objects(std::map<std::string, shader_ptr> &myShaders, Frame &cam_frame,
std::vector<object_ptr> &objects,std::vector<frame_ptr> &obj_frames,
glm::mat4 &view, glm::mat4 &projection)
{
......@@ -84,6 +84,7 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders,
// Hardcoded light index
myShaders[shader_used]->setVec3("lightColor", objects[1]->getColor());
myShaders[shader_used]->setVec3("lightPos", obj_frames[1]->getPosition());
myShaders[shader_used]->setVec3("viewPos", cam_frame.getPosition());
}
glm::mat4 model = obj_frames[i]->getModelMat();
......@@ -158,7 +159,7 @@ void gfx_draw(std::map<std::string, shader_ptr> &myShaders,
ASSUMPTION(glGetError() == GL_NO_ERROR);
// DRAW OBJECTS
draw_objects(myShaders, objects, obj_frames, view, projection);
draw_objects(myShaders, cam_frame, objects, obj_frames, view, projection);
// DRAW GRID
draw_grid(myShaders, grid, grid_frame, view, projection);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment