Added point light
This commit is contained in:
parent
35085524d3
commit
f7ba23fb17
|
@ -16,7 +16,7 @@
|
||||||
#include "vertices.h"
|
#include "vertices.h"
|
||||||
|
|
||||||
// Continue: https://learnopengl.com/Lighting/Light-casters
|
// Continue: https://learnopengl.com/Lighting/Light-casters
|
||||||
// Chapter: not yet started
|
// Chapter: Spot light
|
||||||
//
|
//
|
||||||
// TODO: look at project->properties->VC++ Directories-> change everything to the Environment var
|
// TODO: look at project->properties->VC++ Directories-> change everything to the Environment var
|
||||||
// For the "real" Nebulix Engine setup everything so it can be compiled/used with VSCode/CLion and not just VS
|
// For the "real" Nebulix Engine setup everything so it can be compiled/used with VSCode/CLion and not just VS
|
||||||
|
@ -225,8 +225,11 @@ 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("light.direction", -0.2f, -1.0f, -0.3f);
|
lighting->SetFloat("light.position", lightPosition);
|
||||||
lighting->SetFloat("viewPosition", cam.Position);
|
lighting->SetFloat("viewPosition", cam.Position);
|
||||||
|
lighting->SetFloat("light.constant", 1.0f);
|
||||||
|
lighting->SetFloat("light.linear", 0.09f);
|
||||||
|
lighting->SetFloat("light.quadratic", 0.032f);
|
||||||
|
|
||||||
diffuseMap.BindTexture();
|
diffuseMap.BindTexture();
|
||||||
diffuseMap.BindTexture(GL_TEXTURE1);
|
diffuseMap.BindTexture(GL_TEXTURE1);
|
||||||
|
@ -235,17 +238,21 @@ int main()
|
||||||
{
|
{
|
||||||
allShaders[i]->Use();
|
allShaders[i]->Use();
|
||||||
|
|
||||||
for (size_t j = 0; j < 10; j++)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
allObjects[i].Position = cubePositions[j];
|
for (size_t j = 0; j < 10; j++)
|
||||||
glm::mat4 model = allObjects[i].GetModelMatrix();
|
|
||||||
if (i == 0)
|
|
||||||
{
|
{
|
||||||
|
allObjects[i].Position = cubePositions[j];
|
||||||
|
glm::mat4 model = allObjects[i].GetModelMatrix();
|
||||||
float angle = 20.0f * j;// * currentFrameTime;
|
float angle = 20.0f * j;// * currentFrameTime;
|
||||||
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
|
model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.3f, 0.5f));
|
||||||
}
|
|
||||||
|
|
||||||
allShaders[i]->SetMatrix("modelMatrix", model);
|
allShaders[i]->SetMatrix("modelMatrix", model);
|
||||||
|
allObjects[i].Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
allObjects[i].Draw();
|
allObjects[i].Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
struct Material {
|
struct Material {
|
||||||
sampler2D diffuseMap;
|
sampler2D diffuseMap;
|
||||||
sampler2D specularMap;
|
sampler2D specularMap;
|
||||||
float shininess;
|
float shininess;
|
||||||
};
|
};
|
||||||
struct Light {
|
struct Light {
|
||||||
// vec3 position;
|
vec3 position;
|
||||||
vec3 direction;
|
|
||||||
|
|
||||||
vec3 ambientIntensity;
|
vec3 ambientIntensity;
|
||||||
vec3 diffuseIntensity;
|
vec3 diffuseIntensity;
|
||||||
vec3 specularIntensity;
|
vec3 specularIntensity;
|
||||||
|
|
||||||
|
float constant;
|
||||||
|
float linear;
|
||||||
|
float quadratic;
|
||||||
};
|
};
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec3 lightPosition, viewPosition;
|
uniform vec3 viewPosition;
|
||||||
uniform Material material;
|
uniform Material material;
|
||||||
uniform Light light;
|
uniform Light light;
|
||||||
|
|
||||||
|
@ -27,16 +30,23 @@ void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(Normal);
|
vec3 normal = normalize(Normal);
|
||||||
|
|
||||||
vec3 ambientLight = light.ambientIntensity * vec3(texture(material.diffuseMap, TexCoords));
|
vec3 ambientLight = light.ambientIntensity * texture(material.diffuseMap, TexCoords).rgb;
|
||||||
|
|
||||||
vec3 lightDir = normalize(-light.direction); //normalize(lightPosition - FragmentPos);
|
vec3 lightDir = normalize(light.position - 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 * texture(material.diffuseMap, TexCoords).rgb;
|
||||||
|
|
||||||
vec3 viewDir = normalize(viewPosition - FragmentPos);
|
vec3 viewDir = normalize(viewPosition - FragmentPos);
|
||||||
vec3 reflectDir = reflect(-lightDir, normal);
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||||
vec3 specularLight = light.specularIntensity * spec * vec3(texture(material.specularMap, TexCoords));
|
vec3 specularLight = light.specularIntensity * spec * texture(material.specularMap, TexCoords).rgb;
|
||||||
|
|
||||||
|
float distance = length(light.position - FragmentPos);
|
||||||
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
|
||||||
|
ambientLight *= attenuation;
|
||||||
|
diffuseLight *= attenuation;
|
||||||
|
specularLight *= attenuation;
|
||||||
|
|
||||||
vec3 result = ambientLight + diffuseLight + specularLight;
|
vec3 result = ambientLight + diffuseLight + specularLight;
|
||||||
FragColor = vec4(result, 1.0);
|
FragColor = vec4(result, 1.0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user