-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from deni2312/feature/animation
Feature/animation
- Loading branch information
Showing
53 changed files
with
21,167 additions
and
915 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 |
---|---|---|
|
@@ -397,6 +397,7 @@ FodyWeavers.xsd | |
*.sln.iml | ||
|
||
out/ | ||
vcpkg/ | ||
vcpkg_installed/ | ||
CMakeSettings.json | ||
Models/bread | ||
|
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,80 @@ | ||
#version 460 core | ||
layout(location = 0) in vec3 aPos; | ||
layout(location = 1) in vec3 aNormal; | ||
layout(location = 2) in vec2 aTexCoords; | ||
layout(location = 3) in vec3 aTangent; | ||
layout(location = 4) in vec2 aBitangent; | ||
layout(location = 5) in ivec4 boneIds; | ||
layout(location = 6) in vec4 weights; | ||
|
||
const int MAX_BONES = 128; | ||
const int MAX_BONE_INFLUENCE = 4; | ||
|
||
out vec3 FragPos; | ||
|
||
out vec2 TexCoords; | ||
|
||
out vec3 Normal; | ||
out vec4 shadowDirData[16]; | ||
|
||
flat out int drawId; | ||
|
||
uniform mat4 lightSpaceMatrix; | ||
|
||
layout(std140, binding = 1) uniform MeshData | ||
{ | ||
mat4 view; | ||
mat4 projection; | ||
}; | ||
|
||
layout(std430, binding = 6) buffer AnimationMatrices | ||
{ | ||
mat4 modelAnimationMatrices[]; | ||
}; | ||
|
||
struct ShadowData { | ||
mat4 shadow; | ||
}; | ||
|
||
layout(std430, binding = 4) buffer ShadowMatrices | ||
{ | ||
vec4 lenMat; | ||
ShadowData shadowMatrices[]; | ||
}; | ||
|
||
struct SSBOAnimation { | ||
mat4 animations[MAX_BONES]; | ||
}; | ||
|
||
layout(std430, binding = 8) buffer BoneMatrices | ||
{ | ||
SSBOAnimation boneMatrices[]; | ||
}; | ||
|
||
void main() | ||
{ | ||
vec4 totalPosition = vec4(0.0f); | ||
for (int i = 0; i < MAX_BONE_INFLUENCE; i++) | ||
{ | ||
if (boneIds[i] == -1) | ||
continue; | ||
if (boneIds[i] >= MAX_BONES) | ||
{ | ||
totalPosition = vec4(aPos, 1.0f); | ||
break; | ||
} | ||
vec4 localPosition = boneMatrices[gl_DrawID].animations[boneIds[i]] * vec4(aPos, 1.0f); | ||
totalPosition += localPosition * weights[i]; | ||
} | ||
|
||
drawId = gl_DrawID; | ||
FragPos = vec3(modelAnimationMatrices[gl_DrawID] * vec4(aPos, 1.0)); | ||
TexCoords = aTexCoords; | ||
mat3 normalMatrix = mat3(transpose(inverse(mat3(modelAnimationMatrices[gl_DrawID])))); | ||
Normal = normalMatrix * aNormal; | ||
for (int i = 0; i < lenMat.r; i++) { | ||
shadowDirData[i] = shadowMatrices[i].shadow * vec4(FragPos, 1.0); | ||
} | ||
|
||
gl_Position = projection * view * modelAnimationMatrices[gl_DrawID] * totalPosition; | ||
} |
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
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,28 @@ | ||
#pragma once | ||
#include <memory> | ||
#include "glm/glm.hpp" | ||
#include "../Containers/SSBO.h" | ||
#include "../GlobalData/Defines.h" | ||
#include <vector> | ||
|
||
namespace Prisma { | ||
class AnimationHandler { | ||
public: | ||
AnimationHandler(const AnimationHandler&) = delete; | ||
AnimationHandler& operator=(const AnimationHandler&) = delete; | ||
|
||
static AnimationHandler& getInstance(); | ||
|
||
void updateAnimations(); | ||
|
||
AnimationHandler(); | ||
|
||
private: | ||
std::shared_ptr<SSBO> m_ssboAnimation; | ||
struct SSBOAnimation { | ||
glm::mat4 animations[MAX_BONES]; | ||
}; | ||
void copyMatrices(SSBOAnimation& animation, std::vector<glm::mat4>& animationsData); | ||
static std::shared_ptr<AnimationHandler> instance; | ||
}; | ||
} |
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,54 @@ | ||
#pragma once | ||
#include "glm/glm.hpp" | ||
#include <iostream> | ||
#include <vector> | ||
#include <assimp/Importer.hpp> | ||
#include <assimp/postprocess.h> | ||
#include "../SceneObjects/AnimatedMesh.h" | ||
#include "../GlobalData/Defines.h" | ||
#include "Bone.h" | ||
|
||
namespace Prisma { | ||
class AnimatedMesh; | ||
} | ||
|
||
namespace Prisma { | ||
|
||
struct BoneInfo; | ||
|
||
struct AssimpNodeData | ||
{ | ||
glm::mat4 transformation; | ||
std::string name; | ||
int childrenCount; | ||
std::vector<AssimpNodeData> children; | ||
}; | ||
|
||
class Animation { | ||
public: | ||
Animation() = default; | ||
|
||
Animation(const std::string& animationPath, std::shared_ptr<Prisma::AnimatedMesh> model); | ||
|
||
~Animation(); | ||
|
||
Bone* FindBone(const std::string& name); | ||
|
||
|
||
float GetTicksPerSecond() { return m_TicksPerSecond; } | ||
float GetDuration() { return m_Duration; } | ||
const AssimpNodeData& GetRootNode() { return m_RootNode; } | ||
const std::map<std::string, Prisma::BoneInfo>& GetBoneIDMap(); | ||
|
||
private: | ||
void ReadMissingBones(const aiAnimation* animation, std::shared_ptr<Prisma::AnimatedMesh> model); | ||
glm::mat4 m_inverseTransform; | ||
void ReadHierarchyData(AssimpNodeData& dest, const aiNode* src); | ||
float m_Duration; | ||
int m_TicksPerSecond; | ||
std::vector<Bone> m_Bones; | ||
AssimpNodeData m_RootNode; | ||
std::map<std::string, Prisma::BoneInfo> m_BoneInfoMap; | ||
}; | ||
|
||
} |
Oops, something went wrong.