Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
16 changes: 15 additions & 1 deletion Resources/Editor/Shaders/OutlineFallback.ovfx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#pass OUTLINE_PASS
#engine_feature SKINNING

#shader vertex
#version 450 core

layout(location = 0) in vec3 geo_Pos;
#if defined(SKINNING)
layout(location = 5) in uvec4 geo_BoneIDs;
layout(location = 6) in vec4 geo_BoneWeights;
#endif

#include ":Shaders/Common/Skinning.ovfxh"

layout(std140) uniform EngineUBO
{
Expand All @@ -14,7 +23,12 @@ layout(std140) uniform EngineUBO

void main()
{
gl_Position = ubo_Projection * ubo_View * ubo_Model * vec4(geo_Pos, 1.0);
mat4 skinningMatrix = mat4(1.0);
#if defined(SKINNING)
skinningMatrix = ComputeSkinningMatrix(geo_BoneIDs, geo_BoneWeights);
#endif

gl_Position = ubo_Projection * ubo_View * ubo_Model * skinningMatrix * vec4(geo_Pos, 1.0);
}

#shader fragment
Expand Down
16 changes: 15 additions & 1 deletion Resources/Editor/Shaders/PickingFallback.ovfx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#pass PICKING_PASS
#engine_feature SKINNING

#shader vertex
#version 450 core

layout (location = 0) in vec3 geo_Pos;
#if defined(SKINNING)
layout (location = 5) in uvec4 geo_BoneIDs;
layout (location = 6) in vec4 geo_BoneWeights;
#endif

layout (std140) uniform EngineUBO
{
Expand All @@ -12,9 +19,16 @@ layout (std140) uniform EngineUBO
float ubo_Time;
};

#include ":Shaders/Common/Skinning.ovfxh"

void main()
{
gl_Position = ubo_Projection * ubo_View * ubo_Model * vec4(geo_Pos, 1.0);
mat4 skinningMatrix = mat4(1.0);
#if defined(SKINNING)
skinningMatrix = ComputeSkinningMatrix(geo_BoneIDs, geo_BoneWeights);
#endif

gl_Position = ubo_Projection * ubo_View * ubo_Model * skinningMatrix * vec4(geo_Pos, 1.0);
}

#shader fragment
Expand Down
4 changes: 4 additions & 0 deletions Resources/Engine/Shaders/Common/Buffers/SkinningSSBO.ovfxh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
layout(std430, binding = 1) buffer SkinningSSBO
{
mat4 ssbo_Bones[];
};
23 changes: 23 additions & 0 deletions Resources/Engine/Shaders/Common/Skinning.ovfxh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include ":Shaders/Common/Buffers/SkinningSSBO.ovfxh"

mat4 ComputeSkinningMatrix(uvec4 p_boneIDs, vec4 p_boneWeights)
{
const int boneCount = ssbo_Bones.length();
mat4 skinning = mat4(0.0);
float totalWeight = 0.0;

for (int i = 0; i < 4; ++i)
{
float w = p_boneWeights[i];
if (w > 0.0 && int(p_boneIDs[i]) < boneCount)
{
skinning += ssbo_Bones[p_boneIDs[i]] * w;
totalWeight += w;
}
}

if (totalWeight <= 0.0) return mat4(1.0);

return skinning / totalWeight;
}

15 changes: 14 additions & 1 deletion Resources/Engine/Shaders/ShadowFallback.ovfx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
#pass SHADOW_PASS
#engine_feature SKINNING

#shader vertex
#version 450 core

layout (location = 0) in vec3 geo_Pos;
#if defined(SKINNING)
layout (location = 5) in uvec4 geo_BoneIDs;
layout (location = 6) in vec4 geo_BoneWeights;
#endif

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Skinning.ovfxh"

void main()
{
gl_Position = ubo_Projection * ubo_View * ubo_Model * vec4(geo_Pos, 1.0);
mat4 skinningMatrix = mat4(1.0);
#if defined(SKINNING)
skinningMatrix = ComputeSkinningMatrix(geo_BoneIDs, geo_BoneWeights);
#endif

gl_Position = ubo_Projection * ubo_View * ubo_Model * skinningMatrix * vec4(geo_Pos, 1.0);
}

#shader fragment
Expand Down
19 changes: 16 additions & 3 deletions Resources/Engine/Shaders/Standard.ovfx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
#feature NORMAL_MAPPING
#feature DISTANCE_FADE
#feature SPECULAR_WORKFLOW
#engine_feature SKINNING

#shader vertex
#version 450 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Skinning.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

layout (location = 0) in vec3 geo_Pos;
layout (location = 1) in vec2 geo_TexCoords;
layout (location = 2) in vec3 geo_Normal;
layout (location = 3) in vec3 geo_Tangent;
layout (location = 4) in vec3 geo_Bitangent;
#if defined(SKINNING)
layout (location = 5) in uvec4 geo_BoneIDs;
layout (location = 6) in vec4 geo_BoneWeights;
#endif

out VS_OUT
{
Expand All @@ -32,10 +38,17 @@ out VS_OUT

void main()
{
vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
mat4 skinningMatrix = mat4(1.0);
#if defined(SKINNING)
skinningMatrix = ComputeSkinningMatrix(geo_BoneIDs, geo_BoneWeights);
#endif

const mat4 modelMatrix = ubo_Model * skinningMatrix;

vs_out.FragPos = vec3(modelMatrix * vec4(geo_Pos, 1.0));
vs_out.TexCoords = geo_TexCoords;
vs_out.Normal = normalize(mat3(transpose(inverse(ubo_Model))) * geo_Normal);
vs_out.TBN = ConstructTBN(ubo_Model, geo_Normal, geo_Tangent, geo_Bitangent);
vs_out.Normal = normalize(mat3(transpose(inverse(modelMatrix))) * geo_Normal);
vs_out.TBN = ConstructTBN(modelMatrix, geo_Normal, geo_Tangent, geo_Bitangent);

#if defined(PARALLAX_MAPPING)
const mat3 TBNi = transpose(vs_out.TBN);
Expand Down
15 changes: 14 additions & 1 deletion Resources/Engine/Shaders/Unlit.ovfx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#pass SHADOW_PASS

#feature ALPHA_CLIPPING
#engine_feature SKINNING

#shader vertex
#version 450 core

#include ":Shaders/Common/Buffers/EngineUBO.ovfxh"
#include ":Shaders/Common/Skinning.ovfxh"
#include ":Shaders/Common/Utils.ovfxh"

layout (location = 0) in vec3 geo_Pos;
layout (location = 1) in vec2 geo_TexCoords;
#if defined(SKINNING)
layout (location = 5) in uvec4 geo_BoneIDs;
layout (location = 6) in vec4 geo_BoneWeights;
#endif

out VS_OUT
{
Expand All @@ -19,7 +25,14 @@ out VS_OUT

void main()
{
vs_out.FragPos = vec3(ubo_Model * vec4(geo_Pos, 1.0));
mat4 skinningMatrix = mat4(1.0);
#if defined(SKINNING)
skinningMatrix = ComputeSkinningMatrix(geo_BoneIDs, geo_BoneWeights);
#endif

const mat4 modelMatrix = ubo_Model * skinningMatrix;

vs_out.FragPos = vec3(modelMatrix * vec4(geo_Pos, 1.0));
vs_out.TexCoords = geo_TexCoords;

gl_Position = ubo_Projection * ubo_View * vec4(vs_out.FragPos, 1.0);
Expand Down
Loading
Loading