diff options
author | Frederico Linhares <fred@linhares.blue> | 2022-08-16 16:25:02 -0300 |
---|---|---|
committer | Frederico Linhares <fred@linhares.blue> | 2022-08-17 11:24:10 -0300 |
commit | 67b78f24a9ec8c823bbb8ff091ccd6bb4144a435 (patch) | |
tree | c7c2fa49c1752a85625ef054905d4302a9c66d4a | |
parent | eb6fc926be7f29d6d92f238146180d510d69c79e (diff) |
feat Simplify the 3d model structure
-rw-r--r-- | glsl/shader.vert | 6 | ||||
-rw-r--r-- | src/vk/graphics_pipeline.cpp | 13 | ||||
-rw-r--r-- | src/vk/model.cpp | 46 | ||||
-rw-r--r-- | src/vk/vertex.hpp | 1 | ||||
-rw-r--r-- | test/models/cube.cgmodel | bin | 952 -> 920 bytes |
5 files changed, 12 insertions, 54 deletions
diff --git a/glsl/shader.vert b/glsl/shader.vert index bc89a8c..50dcec5 100644 --- a/glsl/shader.vert +++ b/glsl/shader.vert @@ -3,8 +3,7 @@ layout(location = 0) in vec3 in_position; layout(location = 1) in vec3 in_normal; -layout(location = 2) in vec3 in_color; -layout(location = 3) in vec2 in_texture_coord; +layout(location = 2) in vec2 in_texture_coord; layout(location = 0) out DataTransferObject @@ -32,8 +31,7 @@ main() gl_Position = ubo_view_projection.proj * ubo_view_projection.view * ubo_model_instance.model[gl_InstanceIndex] * vec4(in_position, 1.0); - out_dto.frag_color = vec4(in_color.r, in_color.g, in_color.b, 1.0) * - ubo_view_projection.ambient_color; + out_dto.frag_color = ubo_view_projection.ambient_color; out_dto.frag_texture_coord = in_texture_coord; out_dto.normal = mat3(ubo_model_instance.model[gl_InstanceIndex]) * in_normal; diff --git a/src/vk/graphics_pipeline.cpp b/src/vk/graphics_pipeline.cpp index bd0406c..de08945 100644 --- a/src/vk/graphics_pipeline.cpp +++ b/src/vk/graphics_pipeline.cpp @@ -533,7 +533,7 @@ load_pipeline(void *obj) vertex_input_binding.stride = sizeof(VK::Vertex); vertex_input_binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - std::array<VkVertexInputAttributeDescription, 4> vertex_attribute{}; + std::array<VkVertexInputAttributeDescription, 3> vertex_attribute{}; // Position. vertex_attribute[0].location = 0; vertex_attribute[0].binding = 0; @@ -544,16 +544,11 @@ load_pipeline(void *obj) vertex_attribute[1].binding = 0; vertex_attribute[1].format = VK_FORMAT_R32G32B32_SFLOAT; vertex_attribute[1].offset = offsetof(VK::Vertex, normal); - // Color. + // Texture coordinate. vertex_attribute[2].location = 2; vertex_attribute[2].binding = 0; - vertex_attribute[2].format = VK_FORMAT_R32G32B32_SFLOAT; - vertex_attribute[2].offset = offsetof(VK::Vertex, color); - // Texture coordinate. - vertex_attribute[3].location = 3; - vertex_attribute[3].binding = 0; - vertex_attribute[3].format = VK_FORMAT_R32G32_SFLOAT; - vertex_attribute[3].offset = offsetof(VK::Vertex, texture_coord); + vertex_attribute[2].format = VK_FORMAT_R32G32_SFLOAT; + vertex_attribute[2].offset = offsetof(VK::Vertex, texture_coord); VkPipelineVertexInputStateCreateInfo vertex_input_info = {}; vertex_input_info.sType = diff --git a/src/vk/model.cpp b/src/vk/model.cpp index d47db8a..5cf96b6 100644 --- a/src/vk/model.cpp +++ b/src/vk/model.cpp @@ -48,16 +48,6 @@ ModelBuilder::ModelBuilder(VK::Model *m, const char *mp): { } -struct MeshData -{ - glm::vec3 color; - - uint32_t vertex_base; - uint32_t vertex_count; - uint32_t index_base; - uint32_t index_count; -}; - uint32_t read_uint32_from_file(std::ifstream &input_file) { uint32_t data{}; @@ -90,42 +80,20 @@ load_mesh(void *obj) std::ifstream input_file{self->model_path}; if(!input_file.is_open()) throw CommandError{"Failed to open file."}; - std::vector<MeshData> meshes{}; - self->model->queue_family = cg_core.vk_device_with_swapchain->get_queue_family_with_graphics(); VK::Queue transfer_queue{self->model->queue_family->get_queue()}; - // Load meshes. - { - uint32_t meshes_count{read_uint32_from_file(input_file)}; - meshes.resize(meshes_count); - - for(uint32_t i{0}; i < meshes_count; i++) - { - meshes[i].color = read_vec3_from_file(input_file); - - meshes[i].vertex_base = read_uint32_from_file(input_file); - meshes[i].vertex_count = read_uint32_from_file(input_file); - meshes[i].index_base = read_uint32_from_file(input_file); - meshes[i].index_count = read_uint32_from_file(input_file); - } - } - // Load vertexes. { - uint32_t vertex_count{read_uint32_from_file(input_file)}; + auto vertex_count{read_uint32_from_file(input_file)}; std::vector<VK::Vertex> vertexes{vertex_count}; - for(auto mesh: meshes) + for(auto i{0}; i < vertex_count; i++) { - for(uint32_t i{mesh.vertex_base}; i < mesh.vertex_count; i++) - { - vertexes[i].position = read_vec3_from_file(input_file); - vertexes[i].normal = read_vec3_from_file(input_file); - vertexes[i].texture_coord = read_vec2_from_file(input_file); - vertexes[i].color = mesh.color; - } + vertexes[i].position = read_vec3_from_file(input_file); + vertexes[i].normal = read_vec3_from_file(input_file); + vertexes[i].texture_coord = read_vec2_from_file(input_file); } void *vertexes_data{vertexes.data()}; @@ -142,10 +110,8 @@ load_mesh(void *obj) self->model->index_count = read_uint32_from_file(input_file); std::vector<uint32_t> indexes(self->model->index_count); - for(uint32_t i{0}; i < self->model->index_count; i++) - { + for(auto i{0}; i < self->model->index_count; i++) indexes[i] = read_uint32_from_file(input_file); - } void *indexes_data{indexes.data()}; size_t indexes_size{sizeof(indexes[0]) * indexes.size()}; diff --git a/src/vk/vertex.hpp b/src/vk/vertex.hpp index 735d0a7..07332a8 100644 --- a/src/vk/vertex.hpp +++ b/src/vk/vertex.hpp @@ -26,7 +26,6 @@ struct Vertex { glm::vec3 position; glm::vec3 normal; - glm::vec3 color; glm::vec2 texture_coord; }; diff --git a/test/models/cube.cgmodel b/test/models/cube.cgmodel Binary files differindex 1cb35a0..5b0103e 100644 --- a/test/models/cube.cgmodel +++ b/test/models/cube.cgmodel |