-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
356 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Blender 3.4.1 MTL File: 'None' | ||
# www.blender.org | ||
|
||
newmtl Bark | ||
Ns 256.000031 | ||
Ka 1.000000 1.000000 1.000000 | ||
Kd 0.207595 0.138513 0.055181 | ||
Ks 0.000000 0.000000 0.000000 | ||
Ke 0.000000 0.000000 0.000000 | ||
Ni 1.450000 | ||
d 1.000000 | ||
illum 1 | ||
|
||
newmtl Tree | ||
Ns 256.000031 | ||
Ka 1.000000 1.000000 1.000000 | ||
Kd 0.256861 0.440506 0.110769 | ||
Ks 0.000000 0.000000 0.000000 | ||
Ke 0.000000 0.000000 0.000000 | ||
Ni 1.450000 | ||
d 1.000000 | ||
illum 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#version 330 core | ||
|
||
out vec4 FragColor; | ||
|
||
in vec3 FragmentNormal; | ||
in vec3 FragPos; | ||
|
||
uniform vec3 lightPos = vec3(3, 3, 3); | ||
uniform vec3 cameraPosition; | ||
uniform vec3 lightColor = vec3(1,1,1); | ||
uniform vec3 objectColor = vec3(0.3,0.3,0.3); | ||
|
||
void main() | ||
{ | ||
// ambient | ||
float ambientStrength = 0.1; | ||
vec3 ambient = ambientStrength * lightColor; | ||
|
||
// diffuse | ||
vec3 norm = normalize(FragmentNormal); | ||
vec3 lightDir = normalize(lightPos - FragPos); | ||
float diff = max(dot(norm, lightDir), 0.0); | ||
vec3 diffuse = diff * lightColor; | ||
|
||
// specular | ||
float specularStrength = 0.5; | ||
vec3 viewDir = normalize(cameraPosition - FragPos); | ||
vec3 reflectDir = reflect(-lightDir, norm); | ||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32); | ||
vec3 specular = specularStrength * spec * lightColor; | ||
|
||
vec3 result = (ambient + diffuse + specular) * objectColor; | ||
FragColor = vec4(result, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#version 330 core | ||
|
||
layout(location = 0) in vec3 position; // Vertex position | ||
layout(location = 1) in vec3 normal; // Norm | ||
layout(location = 2) in vec2 texCoords; // Texture coordinates | ||
|
||
out vec3 FragmentNormal; | ||
out vec3 FragPos; | ||
|
||
uniform mat4 model = mat4(1.0); | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
void main() | ||
{ | ||
mat4 mvp = projection * view * model; | ||
FragPos = vec3(model * vec4(normal, 1.0)); | ||
FragmentNormal = mat3(transpose(inverse(model))) * normal; | ||
|
||
gl_Position = mvp * vec4(position, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#version 330 core | ||
|
||
out vec4 FragColor; | ||
|
||
uniform vec3 lightPos = vec3(3, 3, 3); | ||
uniform vec3 cameraPosition; | ||
uniform vec3 lightColor = vec3(1,1,1); | ||
uniform vec3 objectColor = vec3(0.3,0.3,0.3); | ||
|
||
void main() | ||
{ | ||
FragColor = vec4(0.5,0.5,0.5, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#version 330 core | ||
|
||
layout(location = 0) in vec3 position; // Vertex position | ||
layout(location = 1) in vec3 normal; // Norm | ||
layout(location = 2) in vec2 texCoords; // Texture coordinates | ||
|
||
uniform mat4 model = mat4(1.0); | ||
uniform mat4 view; | ||
uniform mat4 projection; | ||
|
||
void main() | ||
{ | ||
mat4 mvp = projection * view * model; | ||
gl_Position = mvp * vec4(position, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "Mesh.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include "Renderer/Graphics/3D/Core/Vertex.h" | ||
|
||
#include <Renderer/Renderer.h> | ||
#include <Renderer/Core/Shader.h> | ||
#include <Renderer/Core/VertexArray.h> | ||
#include <Renderer/Core/Buffers/BufferLayout.h> | ||
#include <Renderer/Core/Buffers/IndexBuffer.h> | ||
#include <Renderer/Graphics/Texture.h> | ||
|
||
class Mesh | ||
{ | ||
public: | ||
Mesh(const std::vector<Vertex>& vertices, const std::vector<unsigned>& indices, | ||
const std::vector<Texture>& textures) | ||
: vertices(vertices), | ||
indices(indices), | ||
textures(textures) | ||
{ | ||
mVBO.setBuffer(vertices.data(), vertices.size()); | ||
mEBO.setBuffer(indices.data(), indices.size()); | ||
|
||
mVAO.bind(); | ||
mVBO.bind(); | ||
mBufferLayout.push<float>(3); | ||
mBufferLayout.push<float>(3); | ||
mBufferLayout.push<float>(2); | ||
mVAO.setBuffer(mVBO, mBufferLayout); | ||
mVAO.unbind(); | ||
} | ||
|
||
void draw(const Renderer& target, const Camera& camera, const Shader& shader) const | ||
{ | ||
target.draw3D(mVAO, mEBO, shader, camera); | ||
} | ||
|
||
private: | ||
std::vector<Vertex> vertices; | ||
std::vector<unsigned int> indices; | ||
std::vector<Texture> textures; // TODO: resource manager should be used there | ||
|
||
VertexArray mVAO; | ||
VertexBuffer mVBO; | ||
IndexBuffer mEBO; | ||
BufferLayout mBufferLayout; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
struct Vertex | ||
{ | ||
glm::vec3 position; | ||
glm::vec3 normal; | ||
glm::vec2 textureCoordinates; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "Model.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "Core/Mesh.h" | ||
|
||
#include <Renderer/Renderer.h> | ||
#include <Resources/ObjLoader.h> | ||
|
||
class Model | ||
{ | ||
public: | ||
explicit Model(const std::string objFilePath) | ||
: mShader{{ShaderType::VertexShader, "resources/Shaders/veryBasic3d.vs"}, | ||
{ShaderType::FragmentShader, "resources/Shaders/veryBasic3d.fs"}} | ||
, mObjLoader(objFilePath) | ||
, mMesh(mObjLoader.vertices(), mObjLoader.indices(), std::vector<Texture>{}) | ||
{ | ||
} | ||
|
||
void draw(const Renderer& target, const Camera& camera) const | ||
{ | ||
mMesh.draw(target, camera, mShader); | ||
} | ||
|
||
private: | ||
Shader mShader; | ||
ObjLoader mObjLoader; | ||
Mesh mMesh; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#include "ObjLoader.h" | ||
#include "pch.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#pragma once | ||
#include <fstream> | ||
#include <Renderer/Graphics/3D/Core/Vertex.h> | ||
|
||
|
||
class ObjLoader | ||
{ | ||
public: | ||
ObjLoader(const std::string& objFilePath) | ||
{ | ||
loadObject(objFilePath); | ||
} | ||
|
||
[[nodiscard]] const std::vector<Vertex>& vertices() const | ||
{ | ||
return mVertices; | ||
} | ||
[[nodiscard]] const std::vector<unsigned int>& indices() const | ||
{ | ||
return mIndices; | ||
} | ||
|
||
private: | ||
std::vector<Vertex> mVertices; | ||
std::vector<glm::vec3> mPositions; | ||
std::vector<glm::vec3> mNormals; | ||
std::vector<glm::vec2> mTextureCoordinates; | ||
std::vector<unsigned int> mIndices; | ||
|
||
void loadObject(const std::string& objFilePath) | ||
{ | ||
std::ifstream file(objFilePath); | ||
std::string line; | ||
while (std::getline(file, line)) | ||
{ | ||
parseLine(line); | ||
} | ||
|
||
/* | ||
assert(mPositions.size() == mNormals.size() == mTextureCoordinates.size()); | ||
for (auto i = 0; i < mPositions.size(); ++i) | ||
{ | ||
mVertices.push_back(Vertex(mPositions[i], mNormals[i], mTextureCoordinates[i])); | ||
} | ||
mPositions.clear(); | ||
mNormals.clear(); | ||
mTextureCoordinates.clear(); | ||
*/ | ||
} | ||
|
||
void parseVertex(std::istringstream& ss) | ||
{ | ||
glm::vec3 position; | ||
ss >> position.x >> position.y >> position.z; | ||
mPositions.push_back(position); | ||
} | ||
|
||
void parseNormal(std::istringstream& ss) | ||
{ | ||
glm::vec3 normal; | ||
ss >> normal.x >> normal.y >> normal.z; | ||
mNormals.push_back(normal); | ||
} | ||
|
||
void parseTextureCoordinate(std::istringstream& ss) | ||
{ | ||
glm::vec2 textureCoordinate; | ||
ss >> textureCoordinate.x >> textureCoordinate.y; | ||
mTextureCoordinates.push_back(textureCoordinate); | ||
} | ||
|
||
std::tuple<int, int, int> parseIndices(const std::string& vertex) | ||
{ | ||
std::istringstream vertexStream(vertex); | ||
std::string index; | ||
std::vector<int> indices; | ||
|
||
while (std::getline(vertexStream, index, '/')) | ||
{ | ||
if (!index.empty()) | ||
{ | ||
indices.push_back(std::stoi(index) - 1); | ||
} | ||
} | ||
|
||
return {indices[0], indices[1], indices[2]}; | ||
} | ||
|
||
void parseFace(std::istringstream& ss) | ||
{ | ||
std::string vertex; | ||
while (ss >> vertex) | ||
{ | ||
auto [positionIndex, textureIndex, normalIndex] = parseIndices(vertex); | ||
Vertex v{mPositions[positionIndex], | ||
mNormals[normalIndex], mTextureCoordinates[textureIndex]}; | ||
mVertices.push_back(v); | ||
mIndices.push_back(mIndices.size()); | ||
} | ||
} | ||
|
||
void parseLine(const std::string& line) | ||
{ | ||
std::istringstream ss(line); | ||
std::string prefix; | ||
ss >> prefix; | ||
|
||
if (prefix == "v") | ||
{ | ||
parseVertex(ss); | ||
} | ||
else if (prefix == "vn") | ||
{ | ||
parseNormal(ss); | ||
} | ||
else if (prefix == "vt") | ||
{ | ||
parseTextureCoordinate(ss); | ||
} | ||
else if (prefix == "f") | ||
{ | ||
parseFace(ss); | ||
} | ||
} | ||
}; |
Oops, something went wrong.