Skip to content

Commit bf3847f

Browse files
committed
Vulkan_Helpers: Reduce MyVertex struct
Cannot be reduced as much as the SDL3_GPU experiment's MyVertex struct, though. Due to alignment issues. I find this odd. I'm supposed to have MORE control here, but I can't seem to get it out. Oh well...
1 parent 16aee93 commit bf3847f

File tree

8 files changed

+12
-35
lines changed

8 files changed

+12
-35
lines changed
-640 Bytes
Binary file not shown.
572 Bytes
Binary file not shown.
-524 Bytes
Binary file not shown.

Vulkan_Helpers/assets/shaders/tex_image.frag.glsl renamed to Vulkan_Helpers/assets/shaders/triangle.frag.glsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#version 450
22

33
//shader input
4-
layout (location = 0) in vec4 inColor;
5-
layout (location = 1) in vec2 inUV;
4+
layout (location = 0) in vec2 inUV;
65

76
//output write
87
layout (location = 0) out vec4 outFragColor;

Vulkan_Helpers/assets/shaders/triangle.vert.glsl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
#extension GL_EXT_buffer_reference : require
44

5-
layout (location = 0) out vec4 outColor;
6-
layout (location = 1) out vec2 outUV;
5+
layout (location = 0) out vec2 outUV;
76

87
struct Vertex {
9-
vec3 position;
10-
float uv_x;
11-
vec3 normal;
12-
float uv_y;
13-
vec4 color;
8+
vec4 position;
9+
vec2 uv;
1410
};
1511

1612
layout(buffer_reference, std430) readonly buffer VertexBuffer{
@@ -32,7 +28,6 @@ void main()
3228
Vertex v = PushConstants.vertexBuffer.vertices[gl_VertexIndex];
3329

3430
//output data
35-
gl_Position = PushConstants.projectionMatrix * PushConstants.viewMatrix * PushConstants.modelMatrix * vec4(v.position, 1.0);
36-
outColor = v.color;
37-
outUV = vec2(v.uv_x, v.uv_y);
31+
gl_Position = PushConstants.projectionMatrix * PushConstants.viewMatrix * PushConstants.modelMatrix * v.position;
32+
outUV = v.uv;
3833
}

Vulkan_Helpers/src/vk_custom_types.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ struct AllocatedBuffer {
3434
};
3535

3636
struct MyVertex {
37-
math::float3 pos;
38-
float uvX; //spread out to keep the struct small
39-
math::float3 normal;
40-
float uvY; //spread out to keep the struct small
41-
math::float4 colour;
37+
math::float4 pos;
38+
math::float2 uv;
4239
};
4340

4441
struct GPUMeshBuffers {

Vulkan_Helpers/src/vk_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ SDL_AppResult VulkanEngine::InitPipelines() {
383383
SDL_AppResult VulkanEngine::InitMeshPipeline() {
384384
VkShaderModule meshFragShader;
385385
{
386-
const std::filesystem::path fullPath = GetAssetsDir() / "shaders/compiled/" / "tex_image.frag.spv";
386+
const std::filesystem::path fullPath = GetAssetsDir() / "shaders/compiled/" / "triangle.frag.spv";
387387
if (const std::optional<VkShaderModule> meshFragShaderResult = vk_util::LoadShaderModule(fullPath.string().c_str(), device); !meshFragShaderResult.has_value()) {
388388
SDL_Log("Couldn't load mesh fragment shader module");
389389
return SDL_APP_FAILURE;

Vulkan_Helpers/src/vk_loader.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,10 @@ std::optional<std::vector<std::shared_ptr<MeshAsset>>> ImportMesh(VulkanEngine*
3939
for (int i = 0; i < mesh->mNumVertices; i++) {
4040
const aiVector3D& pos = mesh->mVertices[i];
4141
const aiVector3D& tex = mesh->mTextureCoords[0][i];
42-
const aiVector3D& nor = mesh->HasNormals() ? mesh->mNormals[i] : aiVector3D{0.0f, 0.0f, 1.0f}; // Default normal if no normals are present
43-
aiColor4D col;
44-
if (mesh->HasVertexColors(i)) {
45-
col = mesh->mColors[0][i];
46-
} else {
47-
// If no vertex colours, we choose a "random" colour
48-
float r = 0.5f + 0.5f * sinf(static_cast<float>(i) * 0.1f);
49-
float g = 0.5f + 0.5f * sinf(static_cast<float>(i) * 0.2f);
50-
float b = 0.5f + 0.5f * sinf(static_cast<float>(i) * 0.3f);
51-
col = aiColor4D{r, g, b, 1.0f};
52-
}
53-
SDL_Log("Assimp: Vertex %d: pos{x: %f, y: %f, z: %f} tex{x: %f, y: %f, z: %f} col{r: %f, g: %f, b: %f, a: %f}", i, pos.x, pos.y, pos.z, tex.x, tex.y, tex.z, col.r, col.g, col.b, col.a);
42+
SDL_Log("Assimp: Vertex %d: pos{x: %f, y: %f, z: %f} tex{x: %f, y: %f, z: %f}", i, pos.x, pos.y, pos.z, tex.x, tex.y, tex.z);
5443
vertices[i] = MyVertex{
55-
.pos = math::float3(pos.x, pos.y, pos.z),
56-
.uvX = tex.x,
57-
.normal = math::float3(nor.x, nor.y, nor.z),
58-
.uvY = tex.y,
59-
.colour = math::float4(col.r, col.g, col.b, col.a),
44+
.pos = math::float4(pos.x, pos.y, pos.z, 1.0f),
45+
.uv = math::float2(tex.x, tex.y),
6046
};
6147
}
6248
// > Indices

0 commit comments

Comments
 (0)