added directional light

This commit is contained in:
Daniel 2023-08-10 10:54:30 +02:00
parent 88c08edfef
commit 35085524d3
2 changed files with 20 additions and 11 deletions

View File

@ -199,13 +199,8 @@ int main()
for (size_t i = 0; i < allShaders.size(); i++)
{
auto shader = allShaders[i];
auto model = allObjects[i].GetModelMatrix();
glm::mat4 model = allObjects[i].GetModelMatrix();
if(i == 0)
{
float angle = 20.0f * currentFrameTime;
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
}
shader->Use();
shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
@ -220,7 +215,7 @@ int main()
lightColour.z = sin(glfwGetTime() * 1.3f);
glm::vec3 diffuseColour = glm::vec3(1.0f);//lightColour * glm::vec3(0.5f);
glm::vec3 ambientColour = glm::vec3(0.2f);//diffuseColour * glm::vec3(0.2f);
glm::vec3 ambientColour = diffuseColour * glm::vec3(0.05f);
lighting->Use();
lighting->SetInt("material.diffuseMap", 0);
@ -230,7 +225,7 @@ int main()
lighting->SetFloat("light.ambientIntensity", ambientColour);
lighting->SetFloat("light.diffuseIntensity", diffuseColour);
lighting->SetFloat("light.specularIntensity", 1.0f, 1.0f, 1.0f);
lighting->SetFloat("lightPosition", lightPosition);
lighting->SetFloat("light.direction", -0.2f, -1.0f, -0.3f);
lighting->SetFloat("viewPosition", cam.Position);
diffuseMap.BindTexture();
@ -239,8 +234,21 @@ int main()
for (size_t i = 0; i < allObjects.size(); i++)
{
allShaders[i]->Use();
for (size_t j = 0; j < 10; j++)
{
allObjects[i].Position = cubePositions[j];
glm::mat4 model = allObjects[i].GetModelMatrix();
if (i == 0)
{
float angle = 20.0f * j;// * currentFrameTime;
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
}
allShaders[i]->SetMatrix("modelMatrix", model);
allObjects[i].Draw();
}
}
glfwSwapBuffers(window);
glfwPollEvents();

View File

@ -5,7 +5,8 @@ struct Material {
float shininess;
};
struct Light {
vec3 position;
// vec3 position;
vec3 direction;
vec3 ambientIntensity;
vec3 diffuseIntensity;
@ -28,7 +29,7 @@ void main()
vec3 ambientLight = light.ambientIntensity * vec3(texture(material.diffuseMap, TexCoords));
vec3 lightDir = normalize(lightPosition - FragmentPos);
vec3 lightDir = normalize(-light.direction); //normalize(lightPosition - FragmentPos);
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuseLight = light.diffuseIntensity * diff * vec3(texture(material.diffuseMap, TexCoords));