added spotlight and finished light casters chapter
This commit is contained in:
parent
f7ba23fb17
commit
5cc00590f7
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
#include "vertices.h"
|
#include "vertices.h"
|
||||||
|
|
||||||
// Continue: https://learnopengl.com/Lighting/Light-casters
|
// Continue: https://learnopengl.com/Lighting/Multiple-lights
|
||||||
// Chapter: Spot light
|
// Chapter: Not yet started
|
||||||
//
|
//
|
||||||
// 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
|
||||||
|
@ -215,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 = diffuseColour * glm::vec3(0.05f);
|
glm::vec3 ambientColour = diffuseColour * glm::vec3(0.1f);
|
||||||
|
|
||||||
lighting->Use();
|
lighting->Use();
|
||||||
lighting->SetInt("material.diffuseMap", 0);
|
lighting->SetInt("material.diffuseMap", 0);
|
||||||
|
@ -225,7 +225,10 @@ 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.position", lightPosition);
|
lighting->SetFloat("light.position", cam.Position);
|
||||||
|
lighting->SetFloat("light.direction", cam.Front);
|
||||||
|
lighting->SetFloat("light.cutOffAngle", glm::cos(glm::radians(12.5f)));
|
||||||
|
lighting->SetFloat("light.outerCutOffAngle", glm::cos(glm::radians(20.0f)));
|
||||||
lighting->SetFloat("viewPosition", cam.Position);
|
lighting->SetFloat("viewPosition", cam.Position);
|
||||||
lighting->SetFloat("light.constant", 1.0f);
|
lighting->SetFloat("light.constant", 1.0f);
|
||||||
lighting->SetFloat("light.linear", 0.09f);
|
lighting->SetFloat("light.linear", 0.09f);
|
||||||
|
|
|
@ -6,6 +6,9 @@ struct Material {
|
||||||
};
|
};
|
||||||
struct Light {
|
struct Light {
|
||||||
vec3 position;
|
vec3 position;
|
||||||
|
vec3 direction;
|
||||||
|
float cutOffAngle;
|
||||||
|
float outerCutOffAngle;
|
||||||
|
|
||||||
vec3 ambientIntensity;
|
vec3 ambientIntensity;
|
||||||
vec3 diffuseIntensity;
|
vec3 diffuseIntensity;
|
||||||
|
@ -28,11 +31,15 @@ in vec3 Normal;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(Normal);
|
|
||||||
|
|
||||||
vec3 ambientLight = light.ambientIntensity * texture(material.diffuseMap, TexCoords).rgb;
|
vec3 ambientLight = light.ambientIntensity * texture(material.diffuseMap, TexCoords).rgb;
|
||||||
|
|
||||||
|
vec3 normal = normalize(Normal);
|
||||||
vec3 lightDir = normalize(light.position - FragmentPos);
|
vec3 lightDir = normalize(light.position - FragmentPos);
|
||||||
|
|
||||||
|
float theta = dot(lightDir, normalize(-light.direction));
|
||||||
|
float epsilon = light.cutOffAngle - light.outerCutOffAngle;
|
||||||
|
float intensity = clamp((theta - light.outerCutOffAngle) / epsilon, 0.0, 1.0);
|
||||||
|
|
||||||
float diff = max(dot(normal, lightDir), 0.0);
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
vec3 diffuseLight = light.diffuseIntensity * diff * texture(material.diffuseMap, TexCoords).rgb;
|
vec3 diffuseLight = light.diffuseIntensity * diff * texture(material.diffuseMap, TexCoords).rgb;
|
||||||
|
|
||||||
|
@ -45,8 +52,8 @@ void main()
|
||||||
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
||||||
|
|
||||||
ambientLight *= attenuation;
|
ambientLight *= attenuation;
|
||||||
diffuseLight *= attenuation;
|
diffuseLight *= attenuation * intensity;
|
||||||
specularLight *= attenuation;
|
specularLight *= attenuation * intensity;
|
||||||
|
|
||||||
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