added directional light
This commit is contained in:
parent
88c08edfef
commit
35085524d3
|
@ -199,13 +199,8 @@ int main()
|
||||||
for (size_t i = 0; i < allShaders.size(); i++)
|
for (size_t i = 0; i < allShaders.size(); i++)
|
||||||
{
|
{
|
||||||
auto shader = allShaders[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->Use();
|
||||||
shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
|
shader->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
|
||||||
|
@ -220,7 +215,7 @@ int main()
|
||||||
lightColour.z = sin(glfwGetTime() * 1.3f);
|
lightColour.z = sin(glfwGetTime() * 1.3f);
|
||||||
|
|
||||||
glm::vec3 diffuseColour = glm::vec3(1.0f);//lightColour * glm::vec3(0.5f);
|
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->Use();
|
||||||
lighting->SetInt("material.diffuseMap", 0);
|
lighting->SetInt("material.diffuseMap", 0);
|
||||||
|
@ -230,7 +225,7 @@ int main()
|
||||||
lighting->SetFloat("light.ambientIntensity", ambientColour);
|
lighting->SetFloat("light.ambientIntensity", ambientColour);
|
||||||
lighting->SetFloat("light.diffuseIntensity", diffuseColour);
|
lighting->SetFloat("light.diffuseIntensity", diffuseColour);
|
||||||
lighting->SetFloat("light.specularIntensity", 1.0f, 1.0f, 1.0f);
|
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);
|
lighting->SetFloat("viewPosition", cam.Position);
|
||||||
|
|
||||||
diffuseMap.BindTexture();
|
diffuseMap.BindTexture();
|
||||||
|
@ -239,8 +234,21 @@ int main()
|
||||||
for (size_t i = 0; i < allObjects.size(); i++)
|
for (size_t i = 0; i < allObjects.size(); i++)
|
||||||
{
|
{
|
||||||
allShaders[i]->Use();
|
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();
|
allObjects[i].Draw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
|
@ -5,7 +5,8 @@ struct Material {
|
||||||
float shininess;
|
float shininess;
|
||||||
};
|
};
|
||||||
struct Light {
|
struct Light {
|
||||||
vec3 position;
|
// vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
|
||||||
vec3 ambientIntensity;
|
vec3 ambientIntensity;
|
||||||
vec3 diffuseIntensity;
|
vec3 diffuseIntensity;
|
||||||
|
@ -28,7 +29,7 @@ void main()
|
||||||
|
|
||||||
vec3 ambientLight = light.ambientIntensity * vec3(texture(material.diffuseMap, TexCoords));
|
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);
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 diffuseLight = light.diffuseIntensity * diff * vec3(texture(material.diffuseMap, TexCoords));
|
vec3 diffuseLight = light.diffuseIntensity * diff * vec3(texture(material.diffuseMap, TexCoords));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user