finished materials chapter
This commit is contained in:
parent
31db98c4c1
commit
14bf8435da
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "vertices.h"
|
||||
|
||||
// Continue: https://learnopengl.com/Lighting/Materials
|
||||
// Continue: https://learnopengl.com/Lighting/Lighting-maps
|
||||
// Chapter: Not yet started
|
||||
//
|
||||
// TODO: look at project->properties->VC++ Directories-> change everything to the Environment var
|
||||
|
@ -213,9 +213,22 @@ int main()
|
|||
shader->SetMatrix("modelMatrix", model);
|
||||
}
|
||||
|
||||
glm::vec3 lightColour;
|
||||
lightColour.x = sin(glfwGetTime() * 2.0f);
|
||||
lightColour.y = sin(glfwGetTime() * 0.7f);
|
||||
lightColour.z = sin(glfwGetTime() * 1.3f);
|
||||
|
||||
glm::vec3 diffuseColour = lightColour * glm::vec3(0.5f);
|
||||
glm::vec3 ambientColour = diffuseColour * glm::vec3(0.2f);
|
||||
|
||||
lighting->Use();
|
||||
lighting->SetFloat("lightColour", 1.0f, 1.0f, 1.0f);
|
||||
lighting->SetFloat("objectColour", 1.0f, 0.5f, 0.31f);
|
||||
lighting->SetFloat("material.ambientColour", 1.0f, 0.5f, 0.31f);
|
||||
lighting->SetFloat("material.diffuseColour", 1.0f, 0.5f, 0.31f);
|
||||
lighting->SetFloat("material.specularColour", 0.5f, 0.5f, 0.5f);
|
||||
lighting->SetFloat("material.shininess", 32.0f);
|
||||
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("viewPosition", cam.Position);
|
||||
|
||||
|
|
|
@ -1,28 +1,42 @@
|
|||
#version 330 core
|
||||
struct Material {
|
||||
vec3 ambientColour;
|
||||
vec3 diffuseColour;
|
||||
vec3 specularColour;
|
||||
float shininess;
|
||||
};
|
||||
struct Light {
|
||||
vec3 position;
|
||||
|
||||
vec3 ambientIntensity;
|
||||
vec3 diffuseIntensity;
|
||||
vec3 specularIntensity;
|
||||
};
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 lightColour, objectColour;
|
||||
uniform vec3 lightPosition, viewPosition;
|
||||
uniform Material material;
|
||||
uniform Light light;
|
||||
|
||||
in vec3 FragmentPos;
|
||||
in vec3 Normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
float ambientStrength = 0.1;
|
||||
vec3 ambientLight = lightColour * ambientStrength;
|
||||
|
||||
vec3 normal = normalize(Normal);
|
||||
|
||||
vec3 ambientLight = light.ambientIntensity * material.ambientColour;
|
||||
|
||||
vec3 lightDir = normalize(lightPosition - FragmentPos);
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
vec3 diffuseLight = diff * lightColour;
|
||||
vec3 diffuseLight = light.diffuseIntensity * (diff * material.diffuseColour);
|
||||
|
||||
float specularStrength = 0.5;
|
||||
vec3 viewDir = normalize(viewPosition - FragmentPos);
|
||||
vec3 reflectDir = reflect(-lightDir, normal);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32); // The exponent (here 32) is the shininess of the specular highlight
|
||||
vec3 specularLight = specularStrength * spec * lightColour;
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
vec3 specularLight = light.specularIntensity * (spec * material.specularColour);
|
||||
|
||||
vec3 result = (ambientLight + diffuseLight + specularLight) * objectColour;
|
||||
vec3 result = ambientLight + diffuseLight + specularLight;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user