Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ layout (location = 6) in vec4 bone_weights;

uniform mat4 model;
uniform mat4 bonesTransformMatrices[MAX_BONES];
uniform mat4 bonesOffsetMatrices[MAX_BONES];

out vec3 fnormal;
out vec3 ftangent;
Expand Down Expand Up @@ -46,7 +45,7 @@ void main() {
break;
}

mat4 finalBonesMatrix = bonesTransformMatrices[bone_ids[i]] * bonesOffsetMatrices[bone_ids[i]];
mat4 finalBonesMatrix = bonesTransformMatrices[bone_ids[i]];

totalPosition += finalBonesMatrix * vec4(vertex, 1.0f) * bone_weights[i];

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions Assets/Shaders/lastpass.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/lastpass.vs"
},
{
"stage": "fragment",
"source": "glsl/lastpass.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/normal.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skinning.vs"
},
{
"stage": "fragment",
"source": "glsl/normal.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/pbr.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skinning.vs"
},
{
"stage": "fragment",
"source": "glsl/pbr.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/phong.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skinning.vs"
},
{
"stage": "fragment",
"source": "glsl/phong.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/picking.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skinning.vs"
},
{
"stage": "fragment",
"source": "glsl/picking.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/skybox.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skybox.vs"
},
{
"stage": "fragment",
"source": "glsl/skybox.fs"
}
]
10 changes: 10 additions & 0 deletions Assets/Shaders/solid.shader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"stage": "vertex",
"source": "glsl/skinning.vs"
},
{
"stage": "fragment",
"source": "glsl/solid.fs"
}
]
7 changes: 6 additions & 1 deletion ICE/Assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME} PRIVATE
src/AssetBank.cpp
src/AssetPath.cpp)
src/AssetPath.cpp
src/Shader.cpp
src/Model.cpp
src/Material.cpp
src/GPURegistry.cpp
src/Texture.cpp)

target_link_libraries(${PROJECT_NAME}
PUBLIC
Expand Down
3 changes: 1 addition & 2 deletions ICE/Assets/include/AssetBank.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct AssetBankEntry {

class AssetBank {
public:
AssetBank(const std::shared_ptr<GraphicsFactory>& factory);
AssetBank();

template<typename T>
std::shared_ptr<T> getAsset(AssetUID uid) {
Expand Down Expand Up @@ -167,6 +167,5 @@ class AssetBank {
std::unordered_map<AssetPath, AssetUID> nameMapping;
std::unordered_map<AssetUID, AssetBankEntry> resources;
AssetLoader loader;
std::shared_ptr<GraphicsFactory> graphics_factory;
};
} // namespace ICE
4 changes: 2 additions & 2 deletions ICE/Assets/include/AssetLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class AssetLoader {
private:
std::unordered_map<
std::type_index,
std::variant<std::shared_ptr<IAssetLoader<Model>>, std::shared_ptr<IAssetLoader<Material>>, std::shared_ptr<IAssetLoader<Shader>>,
std::shared_ptr<IAssetLoader<Texture2D>>, std::shared_ptr<IAssetLoader<TextureCube>>>>
std::variant<std::shared_ptr<IAssetLoader<Mesh>>, std::shared_ptr<IAssetLoader<Model>>, std::shared_ptr<IAssetLoader<Material>>,
std::shared_ptr<IAssetLoader<Shader>>, std::shared_ptr<IAssetLoader<Texture2D>>, std::shared_ptr<IAssetLoader<TextureCube>>>>
loaders;
};
} // namespace ICE
42 changes: 42 additions & 0 deletions ICE/Assets/include/GPURegistry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <GPUMesh.h>
#include <GPUTexture.h>
#include <GraphicsFactory.h>
#include <ShaderProgram.h>

#include <memory>

#include "Asset.h"
#include "AssetBank.h"
#include "Mesh.h"
#include "Shader.h"
#include "Texture.h"

namespace ICE {
class GPURegistry {
public:
GPURegistry(const std::shared_ptr<GraphicsFactory> &factory, const std::shared_ptr<AssetBank> &bank);

AssetUID getUID(const AssetPath &path) const { return m_asset_bank->getUID(path); }
std::shared_ptr<Material> getMaterial(const AssetPath &path) { return m_asset_bank->getAsset<Material>(getUID(path)); }
std::shared_ptr<Material> getMaterial(AssetUID id) { return m_asset_bank->getAsset<Material>(id); }
std::shared_ptr<ShaderProgram> getShader(AssetUID id);
std::shared_ptr<ShaderProgram> getShader(const AssetPath &path) { return getShader(getUID(path)); }
AABB getMeshAABB(AssetUID id) { return m_asset_bank->getAsset<Mesh>(id)->getBoundingBox(); }
std::shared_ptr<GPUMesh> getMesh(AssetUID id);
std::shared_ptr<GPUMesh> getMesh(const AssetPath &path) { return getMesh(getUID(path)); }
std::shared_ptr<GPUTexture> getTexture2D(AssetUID id);
std::shared_ptr<GPUTexture> getTexture2D(const AssetPath &path) { return getTexture2D(getUID(path)); }
std::shared_ptr<GPUTexture> getCubemap(AssetUID id);

private:
std::unordered_map<AssetUID, std::shared_ptr<ShaderProgram>> m_shader_programs;
std::unordered_map<AssetUID, std::shared_ptr<GPUMesh>> m_gpu_meshes;
std::unordered_map<AssetUID, std::shared_ptr<GPUTexture>> m_gpu_tex2d;
std::unordered_map<AssetUID, std::shared_ptr<GPUTexture>> m_gpu_cubemaps;

std::shared_ptr<GraphicsFactory> m_graphics_factory;
std::shared_ptr<AssetBank> m_asset_bank;
};
} // namespace ICE
File renamed without changes.
124 changes: 55 additions & 69 deletions ICE/Graphics/include/Mesh.h → ICE/Assets/include/Mesh.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,56 @@
//
// Created by Thomas Ibanez on 16.11.20.
//

#pragma once

#include <AABB.h>
#include <Asset.h>

#include <Eigen/Dense>
#include <vector>

#include "VertexArray.h"

namespace ICE {

constexpr int MAX_BONES_PER_VERTEX = 4;
constexpr int MAX_BONES = 100;
constexpr int INVALID_BONE_ID = -1;

struct MeshData {
std::vector<Eigen::Vector3f> vertices;
std::vector<Eigen::Vector3f> normals;
std::vector<Eigen::Vector2f> uvCoords;
std::vector<Eigen::Vector3f> tangents;
std::vector<Eigen::Vector3f> bitangents;
std::vector<Eigen::Vector4i> boneIDs;
std::vector<Eigen::Vector4f> boneWeights;
std::vector<Eigen::Vector3i> indices;
};

struct SkinningData {
std::unordered_map<int, Eigen::Matrix4f> boneOffsetMatrices;
};

class Mesh : public Asset {
public:
Mesh(const MeshData &data);
Mesh(MeshData &&data);

const std::vector<Eigen::Vector3f> &getVertices() const;

const std::vector<Eigen::Vector3f> &getNormals() const;

const std::vector<Eigen::Vector2f> &getUVCoords() const;

const std::vector<Eigen::Vector3i> &getIndices() const;

const std::shared_ptr<VertexArray> getVertexArray() const;
void setVertexArray(const std::shared_ptr<VertexArray> &vao);

const AABB &getBoundingBox() const;

std::string getTypeName() const override;
AssetType getType() const override;
bool usesBones() const { return m_has_bones; }
void setSkinningData(const SkinningData &skinningData) {
m_skinningData = skinningData;
m_has_bones = true;
}

SkinningData getSkinningData() const { return m_skinningData; }
private:
MeshData m_data;
SkinningData m_skinningData;
bool m_has_bones = false;
std::shared_ptr<VertexArray> vertexArray;
AABB boundingBox;
};
//
// Created by Thomas Ibanez on 16.11.20.
//

#pragma once

#include <AABB.h>
#include <Asset.h>

#include <Eigen/Dense>
#include <vector>

#include "VertexArray.h"

namespace ICE {

constexpr int MAX_BONES_PER_VERTEX = 4;
constexpr int MAX_BONES = 100;
constexpr int INVALID_BONE_ID = -1;

struct MeshData {
std::vector<Eigen::Vector3f> vertices;
std::vector<Eigen::Vector3f> normals;
std::vector<Eigen::Vector2f> uvCoords;
std::vector<Eigen::Vector3f> tangents;
std::vector<Eigen::Vector3f> bitangents;
std::vector<Eigen::Vector4i> boneIDs;
std::vector<Eigen::Vector4f> boneWeights;
std::vector<Eigen::Vector3i> indices;
};

class Mesh : public Asset {
public:
Mesh(const MeshData &data);
Mesh(MeshData &&data);

const MeshData &getMeshData() const { return m_data; }

const std::vector<Eigen::Vector3f> &getVertices() const;

const std::vector<Eigen::Vector3f> &getNormals() const;

const std::vector<Eigen::Vector2f> &getUVCoords() const;

const std::vector<Eigen::Vector3i> &getIndices() const;

const AABB &getBoundingBox() const;

std::string getTypeName() const override;
AssetType getType() const override;

private:
MeshData m_data;
AABB boundingBox;
};
} // namespace ICE
15 changes: 8 additions & 7 deletions ICE/Graphics/include/Model.h → ICE/Assets/include/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@ class Model : public Asset {
};

struct BoneInfo {
Eigen::Matrix4f finalTransformation;
Eigen::Matrix4f finalTransform;
};

struct Skeleton {
std::unordered_map<std::string, int> boneMapping;
std::vector<BoneInfo> bones;
Eigen::Matrix4f globalInverseTransform;
std::vector<Eigen::Matrix4f> inverseBindMatrices;
};

Model(const std::vector<Node> &nodes, const std::vector<std::shared_ptr<ICE::Mesh>> &meshes, const std::vector<ICE::AssetUID> &materials);
Model(const std::vector<Node> &nodes, const std::vector<AssetUID> &meshes, const std::vector<ICE::AssetUID> &materials);

std::vector<Node> getNodes() const { return m_nodes; }
std::vector<Node> &getNodes() { return m_nodes; }
std::vector<std::shared_ptr<ICE::Mesh>> getMeshes() const { return m_meshes; }
std::vector<ICE::AssetUID> getMaterialsIDs() const { return m_materials; }
std::vector<AssetUID> getMeshes() const { return m_meshes; }
std::vector<AssetUID> getMaterialsIDs() const { return m_materials; }
AABB getBoundingBox() const { return m_boundingbox; }
std::unordered_map<std::string, Animation> getAnimations() const { return m_animations; }
Skeleton &getSkeleton() { return m_skeleton; }
void setSkeleton(const Skeleton &skeleton) { m_skeleton = skeleton; }
void setAnimations(const std::unordered_map<std::string, Animation> &animations) { m_animations = animations; }

void traverse(std::vector<std::shared_ptr<Mesh>> &meshes, std::vector<AssetUID> &materials, std::vector<Eigen::Matrix4f> &transforms,
void traverse(std::vector<AssetUID> &meshes, std::vector<AssetUID> &materials, std::vector<Eigen::Matrix4f> &transforms,
const Eigen::Matrix4f &base_transform = Eigen::Matrix4f::Identity());

AssetType getType() const override { return AssetType::EModel; }
std::string getTypeName() const override { return "Model"; }

private:
std::vector<Node> m_nodes;
std::vector<std::shared_ptr<ICE::Mesh>> m_meshes;
std::vector<ICE::AssetUID> m_materials;
std::vector<AssetUID> m_meshes;
std::vector<AssetUID> m_materials;
std::unordered_map<std::string, Animation> m_animations;
Skeleton m_skeleton;
AABB m_boundingbox{{0, 0, 0}, {0, 0, 0}};
Expand Down
31 changes: 31 additions & 0 deletions ICE/Assets/include/Shader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by Thomas Ibanez on 20.11.20.
//

#pragma once

#include <Asset.h>

#include <unordered_map>

namespace ICE {
enum ShaderStage { Vertex, Fragment, Geometry, TessControl, TessEval, Compute };

// Map of shader stages to their source code {filename, source}
using ShaderSource = std::unordered_map<ShaderStage, std::pair<std::string, std::string>>;

class Shader : public Asset {
public:
Shader() = default;
Shader(const ShaderSource& sources) : m_sources(sources) {}

ShaderSource getSources() const { return m_sources; }

std::string getTypeName() const override;

AssetType getType() const override;

private:
ShaderSource m_sources;
};
} // namespace ICE
Loading