Skip to content

Commit ceaee7c

Browse files
committed
Expanded morph targets up to 8
1 parent da2f39f commit ceaee7c

23 files changed

Lines changed: 118 additions & 48 deletions

VesperEngine/Assets/Shaders/fullscreen.vert

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ layout(location = 8) in vec3 inMorphPos2;
1313
layout(location = 9) in vec3 inMorphNorm2;
1414
layout(location = 10) in vec3 inMorphPos3;
1515
layout(location = 11) in vec3 inMorphNorm3;
16+
layout(location = 12) in vec3 inMorphPos4;
17+
layout(location = 13) in vec3 inMorphNorm4;
18+
layout(location = 14) in vec3 inMorphPos5;
19+
layout(location = 15) in vec3 inMorphNorm5;
20+
layout(location = 16) in vec3 inMorphPos6;
21+
layout(location = 17) in vec3 inMorphNorm6;
22+
layout(location = 18) in vec3 inMorphPos7;
23+
layout(location = 19) in vec3 inMorphNorm7;
1624

1725
layout (location = 0) out vec2 outUV;
1826

464 Bytes
Binary file not shown.

VesperEngine/Assets/Shaders/pbr_shader.vert

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ layout(location = 8) in vec3 inMorphPos2;
1616
layout(location = 9) in vec3 inMorphNorm2;
1717
layout(location = 10) in vec3 inMorphPos3;
1818
layout(location = 11) in vec3 inMorphNorm3;
19+
layout(location = 12) in vec3 inMorphPos4;
20+
layout(location = 13) in vec3 inMorphNorm4;
21+
layout(location = 14) in vec3 inMorphPos5;
22+
layout(location = 15) in vec3 inMorphNorm5;
23+
layout(location = 16) in vec3 inMorphPos6;
24+
layout(location = 17) in vec3 inMorphNorm6;
25+
layout(location = 18) in vec3 inMorphPos7;
26+
layout(location = 19) in vec3 inMorphNorm7;
1927

2028
layout(location = 0) out vec3 fragColor;
2129
layout(location = 1) out vec3 fragPositionWorld;
@@ -34,30 +42,39 @@ layout(std140, set = 0, binding = 0) uniform SceneUBO
3442
layout(std140, set = 2, binding = 0) uniform EntityUBO
3543
{
3644
mat4 ModelMatrix;
37-
vec4 MorphWeights;
45+
vec4 MorphWeights0;
46+
vec4 MorphWeights1;
3847
int MorphTargetCount;
3948
} entityUBO;
4049
#else
4150
layout(std140, set = 1, binding = 0) uniform EntityUBO
4251
{
4352
mat4 ModelMatrix;
44-
vec4 MorphWeights;
53+
vec4 MorphWeights0;
54+
vec4 MorphWeights1;
4555
int MorphTargetCount;
4656
} entityUBO;
4757
#endif
4858

4959
void main()
5060
{
51-
vec3 morphPos[4] = vec3[](inMorphPos0, inMorphPos1, inMorphPos2, inMorphPos3);
52-
vec3 morphNorm[4] = vec3[](inMorphNorm0, inMorphNorm1, inMorphNorm2, inMorphNorm3);
61+
vec3 morphPos[8] = vec3[](inMorphPos0, inMorphPos1, inMorphPos2, inMorphPos3,
62+
inMorphPos4, inMorphPos5, inMorphPos6, inMorphPos7);
63+
vec3 morphNorm[8] = vec3[](inMorphNorm0, inMorphNorm1, inMorphNorm2, inMorphNorm3,
64+
inMorphNorm4, inMorphNorm5, inMorphNorm6, inMorphNorm7);
5365

5466
vec3 finalPos = inPosition;
5567
vec3 finalNorm = inNormal;
56-
int morphCount = clamp(entityUBO.MorphTargetCount, 0, 4);
68+
69+
vec4 weights0 = entityUBO.MorphWeights0;
70+
vec4 weights1 = entityUBO.MorphWeights1;
71+
int morphCount = clamp(entityUBO.MorphTargetCount, 0, 8);
72+
5773
for (int i = 0; i < morphCount; ++i)
5874
{
59-
finalPos += morphPos[i] * entityUBO.MorphWeights[i];
60-
finalNorm += morphNorm[i] * entityUBO.MorphWeights[i];
75+
float w = (i < 4) ? weights0[i] : weights1[i - 4];
76+
finalPos += morphPos[i] * w;
77+
finalNorm += morphNorm[i] * w;
6178
}
6279

6380
vec4 positionWorld = entityUBO.ModelMatrix * vec4(finalPos, 1.0);
1.11 KB
Binary file not shown.
1.11 KB
Binary file not shown.

VesperEngine/Assets/Shaders/phong_shader.vert

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ layout(location = 8) in vec3 inMorphPos2;
1616
layout(location = 9) in vec3 inMorphNorm2;
1717
layout(location = 10) in vec3 inMorphPos3;
1818
layout(location = 11) in vec3 inMorphNorm3;
19+
layout(location = 12) in vec3 inMorphPos4;
20+
layout(location = 13) in vec3 inMorphNorm4;
21+
layout(location = 14) in vec3 inMorphPos5;
22+
layout(location = 15) in vec3 inMorphNorm5;
23+
layout(location = 16) in vec3 inMorphPos6;
24+
layout(location = 17) in vec3 inMorphNorm6;
25+
layout(location = 18) in vec3 inMorphPos7;
26+
layout(location = 19) in vec3 inMorphNorm7;
1927

2028
layout(location = 0) out vec3 fragColor;
2129
layout(location = 1) out vec3 fragPositionWorld;
@@ -35,31 +43,40 @@ layout(std140, set = 0, binding = 0) uniform SceneUBO
3543
layout(std140, set = 2, binding = 0) uniform EntityUBO
3644
{
3745
mat4 ModelMatrix;
38-
vec4 MorphWeights;
46+
vec4 MorphWeights0;
47+
vec4 MorphWeights1;
3948
int MorphTargetCount;
4049
} entityUBO;
4150
#else
4251
layout(std140, set = 1, binding = 0) uniform EntityUBO
4352
{
4453
mat4 ModelMatrix;
45-
vec4 MorphWeights;
54+
vec4 MorphWeights0;
55+
vec4 MorphWeights1;
4656
int MorphTargetCount;
4757
} entityUBO;
4858
#endif
4959

5060

5161
void main()
5262
{
53-
vec3 morphPos[4] = vec3[](inMorphPos0, inMorphPos1, inMorphPos2, inMorphPos3);
54-
vec3 morphNorm[4] = vec3[](inMorphNorm0, inMorphNorm1, inMorphNorm2, inMorphNorm3);
63+
vec3 morphPos[8] = vec3[](inMorphPos0, inMorphPos1, inMorphPos2, inMorphPos3,
64+
inMorphPos4, inMorphPos5, inMorphPos6, inMorphPos7);
65+
vec3 morphNorm[8] = vec3[](inMorphNorm0, inMorphNorm1, inMorphNorm2, inMorphNorm3,
66+
inMorphNorm4, inMorphNorm5, inMorphNorm6, inMorphNorm7);
5567

5668
vec3 finalPos = inPosition;
5769
vec3 finalNorm = inNormal;
58-
int morphCount = clamp(entityUBO.MorphTargetCount, 0, 4);
70+
71+
vec4 weights0 = entityUBO.MorphWeights0;
72+
vec4 weights1 = entityUBO.MorphWeights1;
73+
int morphCount = clamp(entityUBO.MorphTargetCount, 0, 8);
74+
5975
for (int i = 0; i < morphCount; ++i)
6076
{
61-
finalPos += morphPos[i] * entityUBO.MorphWeights[i];
62-
finalNorm += morphNorm[i] * entityUBO.MorphWeights[i];
77+
float w = (i < 4) ? weights0[i] : weights1[i - 4];
78+
finalPos += morphPos[i] * w;
79+
finalNorm += morphNorm[i] * w;
6380
}
6481

6582
vec4 positionWorld = entityUBO.ModelMatrix * vec4(finalPos, 1.0);
1.11 KB
Binary file not shown.
1.11 KB
Binary file not shown.

VesperEngine/Backend/model_data.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ std::vector<VkVertexInputAttributeDescription> Vertex::GetAttributeDescriptions(
2525
attributeDescriptions.push_back({ 1, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, Color) });
2626
attributeDescriptions.push_back({ 2, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, Normal) });
2727
attributeDescriptions.push_back({ 3, 0, VK_FORMAT_R32G32_SFLOAT , offsetof(Vertex, UV) });
28-
attributeDescriptions.push_back({ 4, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphPos[0]) });
29-
attributeDescriptions.push_back({ 5, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphNorm[0]) });
30-
attributeDescriptions.push_back({ 6, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphPos[1]) });
31-
attributeDescriptions.push_back({ 7, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphNorm[1]) });
32-
attributeDescriptions.push_back({ 8, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphPos[2]) });
33-
attributeDescriptions.push_back({ 9, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphNorm[2]) });
34-
attributeDescriptions.push_back({ 10, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphPos[3]) });
35-
attributeDescriptions.push_back({ 11, 0, VK_FORMAT_R32G32B32_SFLOAT , offsetof(Vertex, MorphNorm[3]) });
28+
size_t morphPosOffset = offsetof(Vertex, MorphPos);
29+
size_t morphNormOffset = offsetof(Vertex, MorphNorm);
30+
for (uint32 i = 0; i < kMaxMorphTargets; ++i)
31+
{
32+
attributeDescriptions.push_back({ static_cast<uint32>(4 + i * 2), 0, VK_FORMAT_R32G32B32_SFLOAT , static_cast<uint32>(morphPosOffset + sizeof(glm::vec3) * i) });
33+
attributeDescriptions.push_back({ static_cast<uint32>(5 + i * 2), 0, VK_FORMAT_R32G32B32_SFLOAT , static_cast<uint32>(morphNormOffset + sizeof(glm::vec3) * i) });
34+
}
3635

3736

3837
return attributeDescriptions;

VesperEngine/Backend/model_data.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "Components/graphics_components.h"
1111

12+
#include "Systems/uniform_buffer.h"
13+
1214
#include "vma/vk_mem_alloc.h"
1315

1416
#include <vector>
@@ -17,22 +19,23 @@
1719

1820
VESPERENGINE_NAMESPACE_BEGIN
1921

22+
2023
struct Vertex
2124
{
2225
glm::vec3 Position{};
2326
glm::vec3 Color{};
2427
glm::vec3 Normal{};
2528
glm::vec2 UV{};
26-
glm::vec3 MorphPos[4]{};
27-
glm::vec3 MorphNorm[4]{};
29+
glm::vec3 MorphPos[kMaxMorphTargets]{};
30+
glm::vec3 MorphNorm[kMaxMorphTargets]{};
2831

2932
static std::vector<VkVertexInputBindingDescription> GetBindingDescriptions();
3033
static std::vector<VkVertexInputAttributeDescription> GetAttributeDescriptions();
3134

3235
bool operator==(const Vertex& _other) const
3336
{
3437
bool equal = Position == _other.Position && Color == _other.Color && Normal == _other.Normal && UV == _other.UV;
35-
for (int i = 0;i < 4 && equal;++i)
38+
for (int i = 0; i < static_cast<int>(kMaxMorphTargets) && equal; ++i)
3639
{
3740
equal = equal && MorphPos[i] == _other.MorphPos[i] && MorphNorm[i] == _other.MorphNorm[i];
3841
}
@@ -73,7 +76,7 @@ struct ModelData
7376
std::vector<uint32> Indices{};
7477
std::shared_ptr<MaterialData> Material;
7578
bool IsStatic{ false };
76-
glm::vec4 MorphWeights{ 0.0f };
79+
glm::vec4 MorphWeights[2]{ glm::vec4(0.0f), glm::vec4(0.0f) };
7780
uint32 MorphTargetCount{ 0 };
7881
};
7982

0 commit comments

Comments
 (0)