Compare commits
10 Commits
31db98c4c1
...
f5469d85e1
Author | SHA1 | Date | |
---|---|---|---|
f5469d85e1 | |||
da0815ac8b | |||
725c8d8fa3 | |||
b6477b6617 | |||
97a20a02b2 | |||
5cc00590f7 | |||
f7ba23fb17 | |||
35085524d3 | |||
88c08edfef | |||
14bf8435da |
|
@ -71,8 +71,8 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>T:\Privat\Daniel\Selfmade\libraries\glad\include;T:\Privat\Daniel\Selfmade\libraries\glfw\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>T:\Privat\Daniel\Selfmade\libraries\glfw\lib;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(OPENGL_LIBS)\assimp;$(OPENGL_LIBS)\glad\include;$(OPENGL_LIBS)\glfw\include;$(OPENGL_LIBS)\glm;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(OPENGL_LIBS)\glfw\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<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>
|
||||
|
@ -151,6 +151,8 @@
|
|||
</CopyFileToFolders>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="lights\directionalLight.h" />
|
||||
<ClInclude Include="lights\pointLight.h" />
|
||||
<ClInclude Include="object\game_object.h" />
|
||||
<ClInclude Include="util\camera\camera.h" />
|
||||
<ClInclude Include="Exceptions\IOException.h" />
|
||||
|
@ -167,6 +169,8 @@
|
|||
<ItemGroup>
|
||||
<Image Include="images\awesomeface.png" />
|
||||
<Image Include="images\container.jpg" />
|
||||
<Image Include="images\container2.png" />
|
||||
<Image Include="images\container2_specular.png" />
|
||||
<Image Include="images\wall.jpg" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -65,6 +65,12 @@
|
|||
<ClInclude Include="vertices.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lights\directionalLight.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lights\pointLight.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="Shaders\default\default.frag" />
|
||||
|
@ -82,6 +88,12 @@
|
|||
<Image Include="images\awesomeface.png">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
<Image Include="images\container2.png">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
<Image Include="images\container2_specular.png">
|
||||
<Filter>Resource Files</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\default\simple.vert" />
|
||||
|
|
BIN
src/Engine/images/container2.png
Normal file
BIN
src/Engine/images/container2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 457 KiB |
BIN
src/Engine/images/container2_specular.png
Normal file
BIN
src/Engine/images/container2_specular.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 KiB |
37
src/Engine/lights/directionalLight.h
Normal file
37
src/Engine/lights/directionalLight.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#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;
|
||||
};
|
||||
|
||||
}
|
45
src/Engine/lights/pointLight.h
Normal file
45
src/Engine/lights/pointLight.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
#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,13 +12,14 @@
|
|||
#include "util/stb_image.h"
|
||||
#include "util/camera/camera.h"
|
||||
#include "object/game_object.h"
|
||||
#include "lights/directionalLight.h"
|
||||
#include "lights/pointLight.h"
|
||||
|
||||
#include "vertices.h"
|
||||
|
||||
// Continue: https://learnopengl.com/Lighting/Materials
|
||||
// Continue: https://learnopengl.com/Model-Loading/Mesh
|
||||
// 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
|
||||
// (so basically having an "external" folder which has open gl, GLAD, GLM, stb_image etc. in it or something like this)
|
||||
|
||||
|
@ -146,6 +147,12 @@ int main()
|
|||
vec3(1.5f, 0.2f, -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";
|
||||
|
@ -167,20 +174,35 @@ int main()
|
|||
}
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
// TEXTURES
|
||||
//Texture2D containerImage("images/container.jpg");
|
||||
//Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA);
|
||||
|
||||
std::vector<float> verts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
||||
std::vector<Nebulix::VertexAttribute> vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute() };
|
||||
Nebulix::GameObject cube(verts, vertexAttribs);
|
||||
vec3 lightPosition = glm::vec3(1.2f, 1.0f, 2.0f);
|
||||
Nebulix::GameObject lightBulb(verts, vertexAttribs, lightPosition, glm::vec3(0.2f));
|
||||
Texture2D diffuseMap("images/container2.png", GL_RGBA);
|
||||
Texture2D specularMap("images/container2_specular.png", GL_RGBA);
|
||||
|
||||
std::vector<Nebulix::GameObject> allObjects = std::vector<Nebulix::GameObject>();
|
||||
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<Nebulix::VertexAttribute> objVertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(), Nebulix::VertexAttribute(2) };
|
||||
std::vector<Nebulix::VertexAttribute> lightVertexAttribs = { Nebulix::VertexAttribute()};
|
||||
Nebulix::GameObject cube(objVerts, objVertexAttribs);
|
||||
vec3 lightPosition = glm::vec3(1.2f, 1.0f, 2.0f);
|
||||
Nebulix::GameObject lightBulb(lightVerts, objVertexAttribs, lightPosition, glm::vec3(0.2f));
|
||||
|
||||
auto allObjects = std::vector<Nebulix::GameObject>();
|
||||
allObjects.push_back(cube);
|
||||
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
|
||||
while(!glfwWindowShouldClose(window))
|
||||
{
|
||||
|
@ -198,31 +220,70 @@ int main()
|
|||
for (size_t i = 0; i < allShaders.size(); 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->SetMatrix("viewMatrix", cam.GetViewMatrix()); // more or less the camera
|
||||
shader->SetMatrix("projectionMatrix", projectionMatrix);
|
||||
//shader->SetMatrix("modelMatrix", allObjects[i].GetModelMatrix());
|
||||
shader->SetMatrix("modelMatrix", model);
|
||||
}
|
||||
|
||||
lighting->Use();
|
||||
lighting->SetFloat("lightColour", 1.0f, 1.0f, 1.0f);
|
||||
lighting->SetFloat("objectColour", 1.0f, 0.5f, 0.31f);
|
||||
lighting->SetFloat("lightPosition", lightPosition);
|
||||
lighting->SetInt("material.diffuseMap", 0);
|
||||
lighting->SetInt("material.specularMap", 1);
|
||||
lighting->SetFloat("material.specularColour", 0.5f, 0.5f, 0.5f);
|
||||
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("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++)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace Nebulix
|
|||
glDeleteBuffers(1, &vertexBuffer);
|
||||
}
|
||||
|
||||
// NOTE: This method will not call "Shader.Use()" but will not set any properties.
|
||||
// NOTE: This method will not call "Shader.Use()" and 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
|
||||
void Draw()
|
||||
{
|
||||
|
|
|
@ -1,28 +1,128 @@
|
|||
#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;
|
||||
|
||||
uniform vec3 lightColour, objectColour;
|
||||
uniform vec3 lightPosition, viewPosition;
|
||||
uniform vec3 viewPosition;
|
||||
uniform Material material;
|
||||
uniform DirectionalLight dirLight;
|
||||
uniform PointLight pointLights[NR_POINT_LIGHTS];
|
||||
uniform SpotLight spotLight;
|
||||
|
||||
in vec3 FragmentPos;
|
||||
in vec2 TexCoords;
|
||||
in vec3 FragPos;
|
||||
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()
|
||||
{
|
||||
float ambientStrength = 0.1;
|
||||
vec3 ambientLight = lightColour * ambientStrength;
|
||||
|
||||
vec3 normal = normalize(Normal);
|
||||
vec3 lightDir = normalize(lightPosition - FragmentPos);
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
vec3 diffuseLight = diff * lightColour;
|
||||
vec3 viewDir = normalize(viewPosition - FragPos);
|
||||
|
||||
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;
|
||||
vec3 result = CalculateDirectionalLight(dirLight, normal, viewDir);
|
||||
|
||||
for(int i = 0; i < NR_POINT_LIGHTS; i++)
|
||||
result += CalculatePointLight(pointLights[i], normal, FragPos, viewDir);
|
||||
|
||||
//result += CalculateSpotLight(spotLight, normal, FragPos, viewDir);
|
||||
|
||||
vec3 result = (ambientLight + diffuseLight + specularLight) * objectColour;
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
|
@ -1,19 +1,22 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec3 normalVector;
|
||||
layout (location = 2) in vec2 texCoords;
|
||||
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
out vec3 FragmentPos;
|
||||
out vec2 TexCoords;
|
||||
out vec3 FragPos;
|
||||
out vec3 Normal;
|
||||
|
||||
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)
|
||||
Normal = mat3(transpose(inverse(modelMatrix))) * normalVector;
|
||||
FragmentPos = vec3((modelMatrix) * vec4(aPos, 1.0));
|
||||
FragPos = vec3((modelMatrix) * vec4(aPos, 1.0));
|
||||
TexCoords = texCoords;
|
||||
// note that we read the multiplication from right to left
|
||||
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
|
||||
// maybe add a parameter for configuring mipmapping
|
||||
Texture2D(std::string pathToTexture, int desiredColourChannels = 0, GLenum fileFormat = GL_RGB)
|
||||
Texture2D(std::string pathToTexture, GLenum fileFormat = GL_RGB, int desiredColourChannels = 0)
|
||||
: TextureWrapMode{GL_REPEAT}, MinifyingInterpolation{GL_LINEAR}, MagnifyingInterpolation{GL_LINEAR}
|
||||
{
|
||||
|
||||
|
|
|
@ -45,48 +45,49 @@ float vertices_cube[] = {
|
|||
-0.5f, 0.5f, -0.5f
|
||||
};
|
||||
|
||||
float vertices_cube_normals[] = { // object coordinates; normal vector
|
||||
-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.5f, 0.5f, -0.5f, 0.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.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
float vertices_cube_normals[] = {
|
||||
// positions // normals // texture coords
|
||||
-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, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0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||
};
|
||||
|
||||
float vertices_container[] = { // object coordinates, uv-coordinates
|
||||
|
|
Loading…
Reference in New Issue
Block a user