diff --git a/src/Engine/Engine.vcxproj b/src/Engine/Engine.vcxproj
index 12ba5e3..a9b7c26 100644
--- a/src/Engine/Engine.vcxproj
+++ b/src/Engine/Engine.vcxproj
@@ -167,6 +167,7 @@
+
diff --git a/src/Engine/Engine.vcxproj.filters b/src/Engine/Engine.vcxproj.filters
index 624be92..2ee4601 100644
--- a/src/Engine/Engine.vcxproj.filters
+++ b/src/Engine/Engine.vcxproj.filters
@@ -82,6 +82,9 @@
Resource Files
+
+ Resource Files
+
diff --git a/src/Engine/images/container2.png b/src/Engine/images/container2.png
new file mode 100644
index 0000000..596e8da
Binary files /dev/null and b/src/Engine/images/container2.png differ
diff --git a/src/Engine/images/container2_specular.png b/src/Engine/images/container2_specular.png
new file mode 100644
index 0000000..681bf6e
Binary files /dev/null and b/src/Engine/images/container2_specular.png differ
diff --git a/src/Engine/main.cpp b/src/Engine/main.cpp
index bbbe8e8..78fc509 100644
--- a/src/Engine/main.cpp
+++ b/src/Engine/main.cpp
@@ -15,8 +15,8 @@
#include "vertices.h"
-// Continue: https://learnopengl.com/Lighting/Lighting-maps
-// Chapter: Not yet started
+// Continue: https://learnopengl.com/Lighting/Light-casters
+// 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
@@ -167,15 +167,16 @@ 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 verts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
- std::vector vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute() };
- Nebulix::GameObject cube(verts, vertexAttribs);
+ Texture2D diffuseMap("images/container2.png", GL_RGBA);
+ Texture2D specularMap("images/container2_specular.png", GL_RGBA);
+
+ std::vector objVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
+ std::vector lightVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
+ std::vector objVertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute(), Nebulix::VertexAttribute(2) };
+ std::vector lightVertexAttribs = { Nebulix::VertexAttribute()};
+ Nebulix::GameObject cube(objVerts, objVertexAttribs);
vec3 lightPosition = glm::vec3(1.2f, 1.0f, 2.0f);
- Nebulix::GameObject lightBulb(verts, vertexAttribs, lightPosition, glm::vec3(0.2f));
+ Nebulix::GameObject lightBulb(lightVerts, objVertexAttribs, lightPosition, glm::vec3(0.2f));
std::vector allObjects = std::vector();
allObjects.push_back(cube);
@@ -218,12 +219,12 @@ int main()
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);
+ glm::vec3 diffuseColour = glm::vec3(1.0f);//lightColour * glm::vec3(0.5f);
+ glm::vec3 ambientColour = glm::vec3(0.2f);//diffuseColour * glm::vec3(0.2f);
lighting->Use();
- lighting->SetFloat("material.ambientColour", 1.0f, 0.5f, 0.31f);
- lighting->SetFloat("material.diffuseColour", 1.0f, 0.5f, 0.31f);
+ 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);
lighting->SetFloat("light.ambientIntensity", ambientColour);
@@ -232,6 +233,9 @@ int main()
lighting->SetFloat("lightPosition", lightPosition);
lighting->SetFloat("viewPosition", cam.Position);
+ diffuseMap.BindTexture();
+ diffuseMap.BindTexture(GL_TEXTURE1);
+
for (size_t i = 0; i < allObjects.size(); i++)
{
allShaders[i]->Use();
diff --git a/src/Engine/shaders/default/default.frag b/src/Engine/shaders/default/default.frag
index a7b8f92..8b445a6 100644
--- a/src/Engine/shaders/default/default.frag
+++ b/src/Engine/shaders/default/default.frag
@@ -1,8 +1,7 @@
#version 330 core
struct Material {
- vec3 ambientColour;
- vec3 diffuseColour;
- vec3 specularColour;
+ sampler2D diffuseMap;
+ sampler2D specularMap;
float shininess;
};
struct Light {
@@ -19,6 +18,7 @@ uniform vec3 lightPosition, viewPosition;
uniform Material material;
uniform Light light;
+in vec2 TexCoords;
in vec3 FragmentPos;
in vec3 Normal;
@@ -26,16 +26,16 @@ void main()
{
vec3 normal = normalize(Normal);
- vec3 ambientLight = light.ambientIntensity * material.ambientColour;
+ vec3 ambientLight = light.ambientIntensity * vec3(texture(material.diffuseMap, TexCoords));
vec3 lightDir = normalize(lightPosition - FragmentPos);
float diff = max(dot(normal, lightDir), 0.0);
- vec3 diffuseLight = light.diffuseIntensity * (diff * material.diffuseColour);
+ vec3 diffuseLight = light.diffuseIntensity * diff * vec3(texture(material.diffuseMap, TexCoords));
vec3 viewDir = normalize(viewPosition - FragmentPos);
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
- vec3 specularLight = light.specularIntensity * (spec * material.specularColour);
+ vec3 specularLight = light.specularIntensity * spec * vec3(texture(material.specularMap, TexCoords));
vec3 result = ambientLight + diffuseLight + specularLight;
FragColor = vec4(result, 1.0);
diff --git a/src/Engine/shaders/default/default.vert b/src/Engine/shaders/default/default.vert
index 619e37c..a443705 100644
--- a/src/Engine/shaders/default/default.vert
+++ b/src/Engine/shaders/default/default.vert
@@ -1,11 +1,13 @@
#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 vec2 TexCoords;
out vec3 FragmentPos;
out vec3 Normal;
@@ -14,6 +16,7 @@ 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));
+ TexCoords = texCoords;
// note that we read the multiplication from right to left
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(aPos, 1.0);
}
diff --git a/src/Engine/textures/Texture2D.h b/src/Engine/textures/Texture2D.h
index b344fbf..e15bbea 100644
--- a/src/Engine/textures/Texture2D.h
+++ b/src/Engine/textures/Texture2D.h
@@ -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}
{
diff --git a/src/Engine/vertices.h b/src/Engine/vertices.h
index 7aa79fe..dd2a843 100644
--- a/src/Engine/vertices.h
+++ b/src/Engine/vertices.h
@@ -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.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
+ 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
+ -0.5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