finished lighting maps chapter
This commit is contained in:
parent
14bf8435da
commit
88c08edfef
|
@ -167,6 +167,7 @@
|
||||||
<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\wall.jpg" />
|
<Image Include="images\wall.jpg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -82,6 +82,9 @@
|
||||||
<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>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="shaders\default\simple.vert" />
|
<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 |
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
#include "vertices.h"
|
#include "vertices.h"
|
||||||
|
|
||||||
// Continue: https://learnopengl.com/Lighting/Lighting-maps
|
// Continue: https://learnopengl.com/Lighting/Light-casters
|
||||||
// Chapter: Not yet started
|
// 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
|
||||||
|
@ -167,15 +167,16 @@ int main()
|
||||||
}
|
}
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
||||||
// TEXTURES
|
Texture2D diffuseMap("images/container2.png", GL_RGBA);
|
||||||
//Texture2D containerImage("images/container.jpg");
|
Texture2D specularMap("images/container2_specular.png", GL_RGBA);
|
||||||
//Texture2D faceImage("images/awesomeface.png", 0, GL_RGBA);
|
|
||||||
|
|
||||||
std::vector<float> verts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
std::vector<float> objVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
||||||
std::vector<Nebulix::VertexAttribute> vertexAttribs = { Nebulix::VertexAttribute(), Nebulix::VertexAttribute() };
|
std::vector<float> lightVerts(std::begin(vertices_cube_normals), std::end(vertices_cube_normals));
|
||||||
Nebulix::GameObject cube(verts, vertexAttribs);
|
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);
|
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<Nebulix::GameObject> allObjects = std::vector<Nebulix::GameObject>();
|
std::vector<Nebulix::GameObject> allObjects = std::vector<Nebulix::GameObject>();
|
||||||
allObjects.push_back(cube);
|
allObjects.push_back(cube);
|
||||||
|
@ -218,12 +219,12 @@ int main()
|
||||||
lightColour.y = sin(glfwGetTime() * 0.7f);
|
lightColour.y = sin(glfwGetTime() * 0.7f);
|
||||||
lightColour.z = sin(glfwGetTime() * 1.3f);
|
lightColour.z = sin(glfwGetTime() * 1.3f);
|
||||||
|
|
||||||
glm::vec3 diffuseColour = lightColour * glm::vec3(0.5f);
|
glm::vec3 diffuseColour = glm::vec3(1.0f);//lightColour * glm::vec3(0.5f);
|
||||||
glm::vec3 ambientColour = diffuseColour * glm::vec3(0.2f);
|
glm::vec3 ambientColour = glm::vec3(0.2f);//diffuseColour * glm::vec3(0.2f);
|
||||||
|
|
||||||
lighting->Use();
|
lighting->Use();
|
||||||
lighting->SetFloat("material.ambientColour", 1.0f, 0.5f, 0.31f);
|
lighting->SetInt("material.diffuseMap", 0);
|
||||||
lighting->SetFloat("material.diffuseColour", 1.0f, 0.5f, 0.31f);
|
lighting->SetInt("material.specularMap", 1);
|
||||||
lighting->SetFloat("material.specularColour", 0.5f, 0.5f, 0.5f);
|
lighting->SetFloat("material.specularColour", 0.5f, 0.5f, 0.5f);
|
||||||
lighting->SetFloat("material.shininess", 32.0f);
|
lighting->SetFloat("material.shininess", 32.0f);
|
||||||
lighting->SetFloat("light.ambientIntensity", ambientColour);
|
lighting->SetFloat("light.ambientIntensity", ambientColour);
|
||||||
|
@ -232,6 +233,9 @@ int main()
|
||||||
lighting->SetFloat("lightPosition", lightPosition);
|
lighting->SetFloat("lightPosition", lightPosition);
|
||||||
lighting->SetFloat("viewPosition", cam.Position);
|
lighting->SetFloat("viewPosition", cam.Position);
|
||||||
|
|
||||||
|
diffuseMap.BindTexture();
|
||||||
|
diffuseMap.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();
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
struct Material {
|
struct Material {
|
||||||
vec3 ambientColour;
|
sampler2D diffuseMap;
|
||||||
vec3 diffuseColour;
|
sampler2D specularMap;
|
||||||
vec3 specularColour;
|
|
||||||
float shininess;
|
float shininess;
|
||||||
};
|
};
|
||||||
struct Light {
|
struct Light {
|
||||||
|
@ -19,6 +18,7 @@ uniform vec3 lightPosition, viewPosition;
|
||||||
uniform Material material;
|
uniform Material material;
|
||||||
uniform Light light;
|
uniform Light light;
|
||||||
|
|
||||||
|
in vec2 TexCoords;
|
||||||
in vec3 FragmentPos;
|
in vec3 FragmentPos;
|
||||||
in vec3 Normal;
|
in vec3 Normal;
|
||||||
|
|
||||||
|
@ -26,16 +26,16 @@ void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(Normal);
|
vec3 normal = normalize(Normal);
|
||||||
|
|
||||||
vec3 ambientLight = light.ambientIntensity * material.ambientColour;
|
vec3 ambientLight = light.ambientIntensity * vec3(texture(material.diffuseMap, TexCoords));
|
||||||
|
|
||||||
vec3 lightDir = normalize(lightPosition - FragmentPos);
|
vec3 lightDir = normalize(lightPosition - FragmentPos);
|
||||||
float diff = max(dot(normal, lightDir), 0.0);
|
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 viewDir = normalize(viewPosition - FragmentPos);
|
||||||
vec3 reflectDir = reflect(-lightDir, normal);
|
vec3 reflectDir = reflect(-lightDir, normal);
|
||||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
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;
|
vec3 result = ambientLight + diffuseLight + specularLight;
|
||||||
FragColor = vec4(result, 1.0);
|
FragColor = vec4(result, 1.0);
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#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 FragmentPos;
|
||||||
out vec3 Normal;
|
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)
|
// 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;
|
||||||
FragmentPos = 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, 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}
|
: TextureWrapMode{GL_REPEAT}, MinifyingInterpolation{GL_LINEAR}, MagnifyingInterpolation{GL_LINEAR}
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -45,48 +45,49 @@ float vertices_cube[] = {
|
||||||
-0.5f, 0.5f, -0.5f
|
-0.5f, 0.5f, -0.5f
|
||||||
};
|
};
|
||||||
|
|
||||||
float vertices_cube_normals[] = { // object coordinates; normal vector
|
float vertices_cube_normals[] = {
|
||||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
// 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.0f, 0.0f,
|
||||||
|
|
||||||
-0.5f, -0.5f, 0.5f, 0.0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.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,
|
-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,
|
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.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
|
||||||
};
|
};
|
||||||
|
|
||||||
float vertices_container[] = { // object coordinates, uv-coordinates
|
float vertices_container[] = { // object coordinates, uv-coordinates
|
||||||
|
|
Loading…
Reference in New Issue
Block a user