Compare commits
No commits in common. "f5469d85e187c04f8eb22c443ce8b26c06af21b5" and "31db98c4c11d2d9a19daf0c1b5b89bd8eea5cf6a" have entirely different histories.
f5469d85e1
...
31db98c4c1
|
@ -71,8 +71,8 @@
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<IncludePath>$(OPENGL_LIBS)\assimp;$(OPENGL_LIBS)\glad\include;$(OPENGL_LIBS)\glfw\include;$(OPENGL_LIBS)\glm;$(IncludePath)</IncludePath>
|
<IncludePath>T:\Privat\Daniel\Selfmade\libraries\glad\include;T:\Privat\Daniel\Selfmade\libraries\glfw\include;$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(OPENGL_LIBS)\glfw\lib;$(LibraryPath)</LibraryPath>
|
<LibraryPath>T:\Privat\Daniel\Selfmade\libraries\glfw\lib;$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<IncludePath>$(OPENGL_LIBS)\glm;C:\Users\Daniel\Documents\SelfmadeProgramme\libraries\glad\include;C:\Users\Daniel\Documents\SelfmadeProgramme\libraries\glfw\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(OPENGL_LIBS)\glm;C:\Users\Daniel\Documents\SelfmadeProgramme\libraries\glad\include;C:\Users\Daniel\Documents\SelfmadeProgramme\libraries\glfw\include;$(IncludePath)</IncludePath>
|
||||||
|
@ -151,8 +151,6 @@
|
||||||
</CopyFileToFolders>
|
</CopyFileToFolders>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="lights\directionalLight.h" />
|
|
||||||
<ClInclude Include="lights\pointLight.h" />
|
|
||||||
<ClInclude Include="object\game_object.h" />
|
<ClInclude Include="object\game_object.h" />
|
||||||
<ClInclude Include="util\camera\camera.h" />
|
<ClInclude Include="util\camera\camera.h" />
|
||||||
<ClInclude Include="Exceptions\IOException.h" />
|
<ClInclude Include="Exceptions\IOException.h" />
|
||||||
|
@ -169,8 +167,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="images\awesomeface.png" />
|
<Image Include="images\awesomeface.png" />
|
||||||
<Image Include="images\container.jpg" />
|
<Image Include="images\container.jpg" />
|
||||||
<Image Include="images\container2.png" />
|
|
||||||
<Image Include="images\container2_specular.png" />
|
|
||||||
<Image Include="images\wall.jpg" />
|
<Image Include="images\wall.jpg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -65,12 +65,6 @@
|
||||||
<ClInclude Include="vertices.h">
|
<ClInclude Include="vertices.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="lights\directionalLight.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="lights\pointLight.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CopyFileToFolders Include="Shaders\default\default.frag" />
|
<CopyFileToFolders Include="Shaders\default\default.frag" />
|
||||||
|
@ -88,12 +82,6 @@
|
||||||
<Image Include="images\awesomeface.png">
|
<Image Include="images\awesomeface.png">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
<Image Include="images\container2.png">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Image>
|
|
||||||
<Image Include="images\container2_specular.png">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Image>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="shaders\default\simple.vert" />
|
<None Include="shaders\default\simple.vert" />
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 457 KiB |
Binary file not shown.
Before Width: | Height: | Size: 141 KiB |
|
@ -1,37 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "../shaders/Shader.h"
|
|
||||||
|
|
||||||
namespace Nebulix
|
|
||||||
{
|
|
||||||
|
|
||||||
struct DirectionalLight
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DirectionalLight(glm::vec3 direction, glm::vec3 ambient, glm::vec3 diffuse, glm::vec3 specular)
|
|
||||||
: direction{ direction }, ambient{ambient}, diffuse{diffuse}, specular{specular}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Sets the values of a directional light in the shader
|
|
||||||
name: The name of the variable in the shader. Needs to be a struct with the same components as this struct
|
|
||||||
shader: The shader to set the values of
|
|
||||||
*/
|
|
||||||
void SetLight(std::string name, Shader& shader)
|
|
||||||
{
|
|
||||||
shader.SetFloat(name + ".direction", direction);
|
|
||||||
|
|
||||||
shader.SetFloat(name + ".ambient", ambient);
|
|
||||||
shader.SetFloat(name + ".diffuse", diffuse);
|
|
||||||
shader.SetFloat(name + ".specular", specular);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 direction;
|
|
||||||
|
|
||||||
glm::vec3 ambient;
|
|
||||||
glm::vec3 diffuse;
|
|
||||||
glm::vec3 specular;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include "../shaders/Shader.h"
|
|
||||||
|
|
||||||
namespace Nebulix
|
|
||||||
{
|
|
||||||
|
|
||||||
struct PointLight
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PointLight(glm::vec3 &position, glm::vec3 &ambient, glm::vec3 &diffuse, glm::vec3 specular, float linear = 0.09f, float quadratic = 0.032f, float constant = 1.0f)
|
|
||||||
: position{position}, ambient{ambient}, diffuse{diffuse}, specular{specular}, linear{linear}, quadratic{quadratic}, constant{constant}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
Sets the values of a spot light in the shader
|
|
||||||
name: The name of the variable in the shader. Needs to be a struct with the same components as this struct
|
|
||||||
shader: The shader to set the values of
|
|
||||||
*/
|
|
||||||
void SetLight(std::string name, Shader &shader)
|
|
||||||
{
|
|
||||||
shader.SetFloat(name + ".position", position);
|
|
||||||
|
|
||||||
shader.SetFloat(name + ".constant", constant);
|
|
||||||
shader.SetFloat(name + ".linear", linear);
|
|
||||||
shader.SetFloat(name + ".quadratic", quadratic);
|
|
||||||
|
|
||||||
shader.SetFloat(name + ".ambient", ambient);
|
|
||||||
shader.SetFloat(name + ".diffuse", diffuse);
|
|
||||||
shader.SetFloat(name + ".specular", specular);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 position;
|
|
||||||
|
|
||||||
float constant;
|
|
||||||
float linear;
|
|
||||||
float quadratic;
|
|
||||||
|
|
||||||
glm::vec3 ambient;
|
|
||||||
glm::vec3 diffuse;
|
|
||||||
glm::vec3 specular;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
|
@ -12,14 +12,13 @@
|
||||||
#include "util/stb_image.h"
|
#include "util/stb_image.h"
|
||||||
#include "util/camera/camera.h"
|
#include "util/camera/camera.h"
|
||||||
#include "object/game_object.h"
|
#include "object/game_object.h"
|
||||||
#include "lights/directionalLight.h"
|
|
||||||
#include "lights/pointLight.h"
|
|
||||||
|
|
||||||
#include "vertices.h"
|
#include "vertices.h"
|
||||||
|
|
||||||
// Continue: https://learnopengl.com/Model-Loading/Mesh
|
// Continue: https://learnopengl.com/Lighting/Materials
|
||||||
// Chapter: Not yet started
|
// Chapter: Not yet started
|
||||||
//
|
//
|
||||||
|
// 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
|
||||||
// (so basically having an "external" folder which has open gl, GLAD, GLM, stb_image etc. in it or something like this)
|
// (so basically having an "external" folder which has open gl, GLAD, GLM, stb_image etc. in it or something like this)
|
||||||
|
|
||||||
|
@ -147,12 +146,6 @@ int main()
|
||||||
vec3(1.5f, 0.2f, -1.5f),
|
vec3(1.5f, 0.2f, -1.5f),
|
||||||
vec3(-1.3f, 1.0f, -1.5f)
|
vec3(-1.3f, 1.0f, -1.5f)
|
||||||
};
|
};
|
||||||
std::vector<vec3> pointLightPositions = {
|
|
||||||
vec3(0.7f, 0.2f, 2.0f),
|
|
||||||
vec3(2.3f, -3.3f, -4.0f),
|
|
||||||
vec3(-4.0f, 2.0f, -12.0f),
|
|
||||||
vec3(0.0f, 0.0f, -3.0f)
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
std::string lightingVertexPath = "shaders/default/default.vert", lampVertexPath = "shaders/default/simple.vert";
|
std::string lightingVertexPath = "shaders/default/default.vert", lampVertexPath = "shaders/default/simple.vert";
|
||||||
|
@ -174,35 +167,20 @@ int main()
|
||||||
}
|
}
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
Texture2D diffuseMap("images/container2.png", GL_RGBA);
|
// TEXTURES
|
||||||
Texture2D specularMap("images/container2_specular.png", GL_RGBA);
|
//Texture2D containerImage("images/container.jpg");
|
||||||
|
//Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA);
|
||||||
std::vector<float> objVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
|
||||||
std::vector<float> lightVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
std::vector<float> verts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
||||||
std::vector<Nebulix::VertexAttribute> objVertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(), Nebulix::VertexAttribute(2) };
|
std::vector<Nebulix::VertexAttribute> vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute() };
|
||||||
std::vector<Nebulix::VertexAttribute> lightVertexAttribs = { Nebulix::VertexAttribute()};
|
Nebulix::GameObject cube(verts, vertexAttribs);
|
||||||
Nebulix::GameObject cube(objVerts, objVertexAttribs);
|
|
||||||
vec3 lightPosition = glm::vec3(1.2f, 1.0f, 2.0f);
|
vec3 lightPosition = glm::vec3(1.2f, 1.0f, 2.0f);
|
||||||
Nebulix::GameObject lightBulb(lightVerts, objVertexAttribs, lightPosition, glm::vec3(0.2f));
|
Nebulix::GameObject lightBulb(verts, vertexAttribs, lightPosition, glm::vec3(0.2f));
|
||||||
|
|
||||||
auto allObjects = std::vector<Nebulix::GameObject>();
|
std::vector<Nebulix::GameObject> allObjects = std::vector<Nebulix::GameObject>();
|
||||||
allObjects.push_back(cube);
|
allObjects.push_back(cube);
|
||||||
allObjects.push_back(lightBulb);
|
allObjects.push_back(lightBulb);
|
||||||
|
|
||||||
vec3 diffuseColour = vec3(1.0f);
|
|
||||||
vec3 ambientColour = diffuseColour * vec3(0.1f);
|
|
||||||
|
|
||||||
Nebulix::DirectionalLight dirLight(vec3(-0.2f, -1.0f, -0.3f), ambientColour, vec3(0.4f), vec3(0.5f));
|
|
||||||
auto pointLights = std::vector<Nebulix::PointLight>();
|
|
||||||
Nebulix::PointLight pLight1(pointLightPositions[0], ambientColour, diffuseColour, vec3(1.0f));
|
|
||||||
Nebulix::PointLight pLight2(pointLightPositions[1], ambientColour, diffuseColour, vec3(1.0f));
|
|
||||||
Nebulix::PointLight pLight3(pointLightPositions[2], ambientColour, diffuseColour, vec3(1.0f));
|
|
||||||
Nebulix::PointLight pLight4(pointLightPositions[3], ambientColour, diffuseColour, vec3(1.0f));
|
|
||||||
pointLights.push_back(pLight1);
|
|
||||||
pointLights.push_back(pLight2);
|
|
||||||
pointLights.push_back(pLight3);
|
|
||||||
pointLights.push_back(pLight4);
|
|
||||||
|
|
||||||
// main loop
|
// main loop
|
||||||
while(!glfwWindowShouldClose(window))
|
while(!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
|
@ -220,70 +198,31 @@ 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];
|
||||||
glm::mat4 model = allObjects[i].GetModelMatrix();
|
auto 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
|
||||||
shader->SetMatrix("projectionMatrix", projectionMatrix);
|
shader->SetMatrix("projectionMatrix", projectionMatrix);
|
||||||
|
//shader->SetMatrix("modelMatrix", allObjects[i].GetModelMatrix());
|
||||||
shader->SetMatrix("modelMatrix", model);
|
shader->SetMatrix("modelMatrix", model);
|
||||||
}
|
}
|
||||||
|
|
||||||
lighting->Use();
|
lighting->Use();
|
||||||
lighting->SetInt("material.diffuseMap", 0);
|
lighting->SetFloat("lightColour", 1.0f, 1.0f, 1.0f);
|
||||||
lighting->SetInt("material.specularMap", 1);
|
lighting->SetFloat("objectColour", 1.0f, 0.5f, 0.31f);
|
||||||
lighting->SetFloat("material.specularColour", 0.5f, 0.5f, 0.5f);
|
lighting->SetFloat("lightPosition", lightPosition);
|
||||||
lighting->SetFloat("material.shininess", 32.0f);
|
|
||||||
|
|
||||||
dirLight.SetLight("dirLight", *lighting.get());
|
|
||||||
for (size_t i = 0; i < pointLights.size(); i++)
|
|
||||||
{
|
|
||||||
pointLights[i].SetLight("pointLights[" + std::to_string(i) + "]", *lighting.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
//lighting->SetFloat("spotLight.ambientIntensity", ambientColour);
|
|
||||||
//lighting->SetFloat("spotLight.diffuseIntensity", diffuseColour);
|
|
||||||
//lighting->SetFloat("spotLight.specularIntensity", 1.0f, 1.0f, 1.0f);
|
|
||||||
//lighting->SetFloat("spotLight.position", cam.Position);
|
|
||||||
//lighting->SetFloat("spotLight.direction", cam.Front);
|
|
||||||
//lighting->SetFloat("spotLight.cutOffAngle", glm::cos(glm::radians(12.5f)));
|
|
||||||
//lighting->SetFloat("spotLight.outerCutOffAngle", glm::cos(glm::radians(20.0f)));
|
|
||||||
lighting->SetFloat("viewPosition", cam.Position);
|
lighting->SetFloat("viewPosition", cam.Position);
|
||||||
//lighting->SetFloat("spotLight.constant", 1.0f);
|
|
||||||
//lighting->SetFloat("spotLight.linear", 0.09f);
|
|
||||||
//lighting->SetFloat("spotLight.quadratic", 0.032f);
|
|
||||||
|
|
||||||
diffuseMap.BindTexture();
|
|
||||||
specularMap.BindTexture(GL_TEXTURE1);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < allObjects.size(); i++)
|
for (size_t i = 0; i < allObjects.size(); i++)
|
||||||
{
|
{
|
||||||
allShaders[i]->Use();
|
allShaders[i]->Use();
|
||||||
|
allObjects[i].Draw();
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
for (size_t j = 0; j < 10; j++)
|
|
||||||
{
|
|
||||||
allObjects[i].Position = cubePositions[j];
|
|
||||||
glm::mat4 model = allObjects[i].GetModelMatrix();
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (size_t j = 0; j < 4; j++)
|
|
||||||
{
|
|
||||||
allObjects[i].Position = pointLightPositions[j];
|
|
||||||
glm::mat4 model = allObjects[i].GetModelMatrix();
|
|
||||||
|
|
||||||
allShaders[i]->SetMatrix("modelMatrix", model);
|
|
||||||
allObjects[i].Draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace Nebulix
|
||||||
glDeleteBuffers(1, &vertexBuffer);
|
glDeleteBuffers(1, &vertexBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: This method will not call "Shader.Use()" and will not set any properties.
|
// NOTE: This method will not call "Shader.Use()" but will not set any properties.
|
||||||
// This is because I do not know the names and values of the properties. Most likely this will be possible after learning about materials
|
// This is because I do not know the names and values of the properties. Most likely this will be possible after learning about materials
|
||||||
void Draw()
|
void Draw()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,128 +1,28 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
|
|
||||||
#define NR_POINT_LIGHTS 4
|
|
||||||
|
|
||||||
struct Material {
|
|
||||||
sampler2D diffuseMap;
|
|
||||||
sampler2D specularMap;
|
|
||||||
float shininess;
|
|
||||||
};
|
|
||||||
struct SpotLight {
|
|
||||||
vec3 position;
|
|
||||||
vec3 direction;
|
|
||||||
float cutOffAngle;
|
|
||||||
float outerCutOffAngle;
|
|
||||||
|
|
||||||
vec3 ambient;
|
|
||||||
vec3 diffuse;
|
|
||||||
vec3 specular;
|
|
||||||
|
|
||||||
float constant;
|
|
||||||
float linear;
|
|
||||||
float quadratic;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DirectionalLight {
|
|
||||||
vec3 direction;
|
|
||||||
|
|
||||||
vec3 ambient;
|
|
||||||
vec3 diffuse;
|
|
||||||
vec3 specular;
|
|
||||||
};
|
|
||||||
struct PointLight {
|
|
||||||
vec3 position;
|
|
||||||
|
|
||||||
float constant;
|
|
||||||
float linear;
|
|
||||||
float quadratic;
|
|
||||||
|
|
||||||
vec3 ambient;
|
|
||||||
vec3 diffuse;
|
|
||||||
vec3 specular;
|
|
||||||
};
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec3 viewPosition;
|
uniform vec3 lightColour, objectColour;
|
||||||
uniform Material material;
|
uniform vec3 lightPosition, viewPosition;
|
||||||
uniform DirectionalLight dirLight;
|
|
||||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
|
||||||
uniform SpotLight spotLight;
|
|
||||||
|
|
||||||
in vec2 TexCoords;
|
in vec3 FragmentPos;
|
||||||
in vec3 FragPos;
|
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
|
|
||||||
vec3 CalculateDirectionalLight(DirectionalLight light, vec3 normal, vec3 viewDir)
|
|
||||||
{
|
|
||||||
vec3 lightDir = normalize(-light.direction);
|
|
||||||
|
|
||||||
float diff = max(dot(normal, lightDir), 0.0);
|
|
||||||
|
|
||||||
vec3 reflectionDir = reflect(-lightDir, normal);
|
|
||||||
float spec = pow(max(dot(viewDir, reflectionDir), 0.0), material.shininess);
|
|
||||||
|
|
||||||
vec3 ambient = light.ambient * vec3(texture(material.diffuseMap, TexCoords));
|
|
||||||
vec3 diffuse = light.diffuse * diff * vec3(texture(material.diffuseMap, TexCoords));
|
|
||||||
vec3 specular = light.specular * spec * vec3(texture(material.specularMap, TexCoords));
|
|
||||||
|
|
||||||
return ambient + diffuse + specular;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 CalculatePointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
|
||||||
{
|
|
||||||
vec3 lightDir = normalize(light.position - fragPos);
|
|
||||||
|
|
||||||
float diff = max(dot(normal, lightDir), 0.0);
|
|
||||||
|
|
||||||
vec3 reflectionDir = reflect(-lightDir, normal);
|
|
||||||
float spec = pow(max(dot(viewDir, reflectionDir), 0.0), material.shininess);
|
|
||||||
|
|
||||||
float distance = length(light.position - fragPos);
|
|
||||||
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
|
||||||
|
|
||||||
vec3 ambientLight = light.ambient * texture(material.diffuseMap, TexCoords).rgb * attenuation;
|
|
||||||
vec3 diffuseLight = light.diffuse * diff * texture(material.diffuseMap, TexCoords).rgb * attenuation;
|
|
||||||
vec3 specularLight = light.specular * spec * texture(material.specularMap, TexCoords).rgb * attenuation;
|
|
||||||
|
|
||||||
return ambientLight + diffuseLight + specularLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 CalculateSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
|
|
||||||
{
|
|
||||||
vec3 lightDir = normalize(light.position - fragPos);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
vec3 reflectDir = reflect(-lightDir, normal);
|
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
|
||||||
|
|
||||||
float distance = length(light.position - fragPos);
|
|
||||||
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
|
|
||||||
|
|
||||||
vec3 ambientLight = light.ambient * texture(material.diffuseMap, TexCoords).rgb * attenuation;
|
|
||||||
vec3 diffuseLight = light.diffuse * diff * texture(material.diffuseMap, TexCoords).rgb * attenuation * intensity;
|
|
||||||
vec3 specularLight = light.specular * spec * texture(material.specularMap, TexCoords).rgb * attenuation * intensity;
|
|
||||||
|
|
||||||
return ambientLight + diffuseLight + specularLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
float ambientStrength = 0.1;
|
||||||
|
vec3 ambientLight = lightColour * ambientStrength;
|
||||||
|
|
||||||
vec3 normal = normalize(Normal);
|
vec3 normal = normalize(Normal);
|
||||||
vec3 viewDir = normalize(viewPosition - FragPos);
|
vec3 lightDir = normalize(lightPosition - FragmentPos);
|
||||||
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 diffuseLight = diff * lightColour;
|
||||||
|
|
||||||
vec3 result = CalculateDirectionalLight(dirLight, normal, viewDir);
|
float specularStrength = 0.5;
|
||||||
|
vec3 viewDir = normalize(viewPosition - FragmentPos);
|
||||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
result += CalculatePointLight(pointLights[i], normal, FragPos, viewDir);
|
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;
|
||||||
//result += CalculateSpotLight(spotLight, normal, FragPos, viewDir);
|
|
||||||
|
|
||||||
|
vec3 result = (ambientLight + diffuseLight + specularLight) * objectColour;
|
||||||
FragColor = vec4(result, 1.0);
|
FragColor = vec4(result, 1.0);
|
||||||
}
|
}
|
|
@ -1,22 +1,19 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
layout (location = 1) in vec3 normalVector;
|
layout (location = 1) in vec3 normalVector;
|
||||||
layout (location = 2) in vec2 texCoords;
|
|
||||||
|
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
|
|
||||||
out vec2 TexCoords;
|
out vec3 FragmentPos;
|
||||||
out vec3 FragPos;
|
|
||||||
out vec3 Normal;
|
out vec3 Normal;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// NOTE: inverse() is very costly to calculate, so the normal matrix should be calculated on the CPU and sent over (just like we do with the model matrix)
|
// NOTE: inverse() is very costly to calculate, so the normal matrix should be calculated on the CPU and sent over (just like we do with the model matrix)
|
||||||
Normal = mat3(transpose(inverse(modelMatrix))) * normalVector;
|
Normal = mat3(transpose(inverse(modelMatrix))) * normalVector;
|
||||||
FragPos = vec3((modelMatrix) * vec4(aPos, 1.0));
|
FragmentPos = vec3((modelMatrix) * vec4(aPos, 1.0));
|
||||||
TexCoords = texCoords;
|
|
||||||
// note that we read the multiplication from right to left
|
// note that we read the multiplication from right to left
|
||||||
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// maybe add a parameter for configuring mipmapping
|
// maybe add a parameter for configuring mipmapping
|
||||||
Texture2D(std::string pathToTexture, GLenum fileFormat = GL_RGB, int desiredColourChannels = 0)
|
Texture2D(std::string pathToTexture, int desiredColourChannels = 0, GLenum fileFormat = GL_RGB)
|
||||||
: TextureWrapMode{GL_REPEAT}, MinifyingInterpolation{GL_LINEAR}, MagnifyingInterpolation{GL_LINEAR}
|
: TextureWrapMode{GL_REPEAT}, MinifyingInterpolation{GL_LINEAR}, MagnifyingInterpolation{GL_LINEAR}
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -45,49 +45,48 @@ float vertices_cube[] = {
|
||||||
-0.5f, 0.5f, -0.5f
|
-0.5f, 0.5f, -0.5f
|
||||||
};
|
};
|
||||||
|
|
||||||
float vertices_cube_normals[] = {
|
float vertices_cube_normals[] = { // object coordinates; normal vector
|
||||||
// positions // normals // texture coords
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
|
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 0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.0f,
|
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f
|
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
float vertices_container[] = { // object coordinates, uv-coordinates
|
float vertices_container[] = { // object coordinates, uv-coordinates
|
||||||
|
|
Loading…
Reference in New Issue
Block a user