Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gltf] Add glTF2 loader and pbr renderer #270

Draft
wants to merge 127 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
4d6bed9
[conan] Update tinygltf to version 2.5.0
IAmNotHanni May 10, 2021
e4862b0
[gltf-file] Added small wrapper class for tinygltf library
IAmNotHanni May 10, 2021
e155e97
[gltf2-file] Fix clang-tidy warnings (squash me)
IAmNotHanni May 10, 2021
b49661f
[gltf2-file] Fix clang-tidy warnings (squash me)
IAmNotHanni May 10, 2021
fe404c8
[gltf-model|gltf-file] Add basic glTF2 model file loader
IAmNotHanni May 10, 2021
91da276
[gltf-model] Fix clang build
IAmNotHanni May 10, 2021
549d8b8
[gltf-model|gltf-file] Fix clang-tidy
IAmNotHanni May 10, 2021
61cb447
[*] Small fixes
IAmNotHanni May 10, 2021
64448e0
[*] Small fixes
IAmNotHanni May 10, 2021
4a00a08
[gltf-model] Improve conversion of rgb data to rgba (thanks to user a…
IAmNotHanni May 11, 2021
6b7b644
[gltf-model] Add default destructor
IAmNotHanni May 11, 2021
6299883
[gltf] Add nolints for pointer arithmetics
IAmNotHanni May 23, 2021
d5c2945
[gltf] Refactoring
IAmNotHanni Jul 24, 2021
b52ff56
[gltf-model] Fix scene loop, add get methods, and prefer emplace_back…
IAmNotHanni Jul 24, 2021
a61651e
[gltf] Set up loading of gltf sample file
IAmNotHanni Jul 25, 2021
224e574
[gltf] Fix model loading
IAmNotHanni Jul 25, 2021
65cc6c2
[gltf] Small improvements
IAmNotHanni Jul 26, 2021
9883100
[gltf-model] Change spdlog messages from debug to trace
IAmNotHanni Jul 26, 2021
4ae6fb1
[gltf] Rework
IAmNotHanni Jul 28, 2021
5ebe47b
[gltf] Trying to get glTF rendering working
IAmNotHanni Jul 28, 2021
806c929
[gltf|render-graph] Fix gltf rendering setup in rendergraph
yeetari Jul 29, 2021
5a76282
[gltf] Fix clang-tidy warnings about namespaces
IAmNotHanni Jul 30, 2021
d442719
[gltf] Fix clang-tidy
IAmNotHanni Jul 30, 2021
5bba8c7
[gltf] WIP
IAmNotHanni Jul 30, 2021
96300e9
[shaders] Backup
IAmNotHanni Jul 31, 2021
4b8ae3f
[gltf] WIP
IAmNotHanni Jul 31, 2021
fb2aa66
[gltf] WIP
IAmNotHanni Jul 31, 2021
f32409b
[gltf] WIP
IAmNotHanni Jul 31, 2021
e2b5f21
[gltf] WIP
IAmNotHanni Jul 31, 2021
94f81f3
[gltf] Fix build
IAmNotHanni Jul 31, 2021
7287190
[gltf] WIP
IAmNotHanni Aug 1, 2021
9a52f36
[gltf] WIP
IAmNotHanni Aug 4, 2021
4b77d2d
[gltf] WIP broken
IAmNotHanni Aug 4, 2021
f8964cf
[gltf] WIP
IAmNotHanni Aug 6, 2021
601693c
[gltf] WIP
IAmNotHanni Aug 6, 2021
e865f7d
[gltf] WIP
IAmNotHanni Aug 6, 2021
3180590
[gltf] WIP
IAmNotHanni Aug 6, 2021
44ab701
[gltf] WIP broken
IAmNotHanni Aug 7, 2021
4fac42d
[gltf] WIP
IAmNotHanni Aug 7, 2021
9a6af5b
[gltf] Fix build
IAmNotHanni Aug 7, 2021
ab0950a
[gltf] WIP
IAmNotHanni Aug 8, 2021
457dbe0
[gltf] Fix build
IAmNotHanni Aug 8, 2021
81bd6b4
[gltf] WIP
IAmNotHanni Aug 8, 2021
eebe8ff
[gltf] Fix some clang-tidy warnings
IAmNotHanni Aug 8, 2021
1eb4652
[gltf] Refactor material loading
IAmNotHanni Aug 8, 2021
8f34a45
[gltf] Print list of unsupported glTF material features
IAmNotHanni Aug 8, 2021
69e04e9
[gltf] Use one vertex and index buffer per model, not per scene
IAmNotHanni Aug 8, 2021
ba5f9ce
[gltf] Fix some clang-tidy warnings
IAmNotHanni Aug 8, 2021
2c0648f
[gltf] Load model skins
IAmNotHanni Aug 8, 2021
d8e7d63
[*] Do not worry I will split that up into atomic commits
IAmNotHanni Aug 9, 2021
769221d
[gltf] WIP
IAmNotHanni Aug 10, 2021
ef26e6d
[gltf] Fix build
IAmNotHanni Aug 10, 2021
e1047da
[*] Ah shit, here we go again
IAmNotHanni Sep 24, 2021
f04fa1e
[uniform-buffer] Fix Linux build
IAmNotHanni Sep 26, 2021
3c6405a
[assets] Remove big glTF file
IAmNotHanni Sep 26, 2021
76812fd
[*] backup of WIP
IAmNotHanni Sep 28, 2021
7108e4b
[*] Backup of progress
IAmNotHanni Oct 1, 2021
2d2239b
[*] Fix Linux build
IAmNotHanni Oct 1, 2021
2aba578
[cubemap] Attempt to fix build in Windows
IAmNotHanni Oct 1, 2021
0676881
[*] Backup of image wrapper refactoring
IAmNotHanni Oct 2, 2021
851ad37
[*] Backup of cubemap WIP
IAmNotHanni Oct 3, 2021
d0b610c
[*] Backup of work
IAmNotHanni Oct 11, 2021
33a7f97
[*] Backup of work despite validation layer errors
IAmNotHanni Oct 30, 2021
738223f
[*] Fix validation layer errors
IAmNotHanni Oct 31, 2021
e2008cb
[*] Backup and trying to fix build
IAmNotHanni Nov 1, 2021
2fc9020
[*] Fix build
IAmNotHanni Nov 1, 2021
5adad75
[*] Backup of work
IAmNotHanni Nov 3, 2021
7c81db2
[*] Backup of work. Refactoring shader loading
IAmNotHanni Nov 4, 2021
450829c
[*] Further reduce console log messages to reduce spam
IAmNotHanni Nov 4, 2021
c63a6b1
[*] Fix octree and ImGui rendering and disable glTF rendering
IAmNotHanni Nov 4, 2021
ee28232
[conan] Add ktx dependency
IAmNotHanni Nov 4, 2021
f7cb070
[assets] Add new assets
IAmNotHanni Nov 7, 2021
2bacd20
[*] Backup of work (broken)
IAmNotHanni Nov 7, 2021
bfd7aa7
[ci] Update Vulkan SDK version
IAmNotHanni Nov 6, 2021
2fe2fc7
[byte-stream|cube] Fix clang-tidy warnings
IAmNotHanni Nov 6, 2021
32afeec
[clang-tidy] Ignore portability-simd-intrinsics
IAmNotHanni Nov 6, 2021
394e901
[*] Backup of work
IAmNotHanni Nov 7, 2021
a24b4c1
[*] Backup of work
IAmNotHanni Nov 8, 2021
0a61cbb
[*] Fix cubemap code
IAmNotHanni Nov 8, 2021
8fc49d1
[*] Backup of work
IAmNotHanni Nov 9, 2021
ed8c85b
[*] Fix some clang warnings
IAmNotHanni Nov 9, 2021
30f4996
[*] Backup of work
IAmNotHanni Nov 9, 2021
c1bbfed
[*] Make UniformBuffer a full template class
IAmNotHanni Nov 9, 2021
d57c295
[*] Backup of work
IAmNotHanni Nov 10, 2021
841451f
[*] Backup of work
IAmNotHanni Nov 11, 2021
d8596d1
[*] Backup of work
IAmNotHanni Nov 11, 2021
303548d
[application] Fix octree regeneration code
IAmNotHanni Nov 11, 2021
8468349
[*] Backup of work
IAmNotHanni Nov 12, 2021
8324f10
[*] Backup of work
IAmNotHanni Nov 13, 2021
35c753f
[*] Backup of work
IAmNotHanni Nov 14, 2021
a0e5b94
[*] Backup of work
IAmNotHanni Jan 1, 2022
2632b22
[*] Backup of work
IAmNotHanni Jan 3, 2022
b05bd62
[*] Backup of work
IAmNotHanni Jan 5, 2022
39c3169
[*] Backup of work
IAmNotHanni Jan 8, 2022
b6aa5ed
[*] Backup of work
IAmNotHanni Jan 9, 2022
c676d4c
[*] Backup of work
IAmNotHanni Jan 9, 2022
3280f45
[*] Backup of work
IAmNotHanni Jan 9, 2022
4ba175d
[*] Backup of work
IAmNotHanni Jan 10, 2022
6ccf738
[*] Backup of work
IAmNotHanni Jan 10, 2022
f70dc48
[*] Backup of work
IAmNotHanni Jan 10, 2022
1ca05ee
[*] Backup of work, skybox renderer working
IAmNotHanni Jan 25, 2022
2935ee2
[*] Backup of work, skybox is rendering
IAmNotHanni Jan 28, 2022
42ae246
[*] Backup of work
IAmNotHanni Jan 29, 2022
9087acd
[*] Backup of work
IAmNotHanni Jan 30, 2022
6b97f17
[*] Backup of work
IAmNotHanni Jan 30, 2022
77328af
[*] Backup of work
IAmNotHanni Jan 30, 2022
e6af513
[*] Backup of work
IAmNotHanni Jan 30, 2022
31e503b
[*] Backup of work, model vertices are being loaded and rendered
IAmNotHanni Mar 12, 2022
0b86863
[*] Backup of work
IAmNotHanni Mar 12, 2022
19cd038
[gltf-gpu-data-base] Minor fixes
IAmNotHanni Mar 14, 2022
d897109
[*] Backup of work
IAmNotHanni Mar 18, 2022
64cb3fc
[*] Add RAII wrapper for pipeline layouts
IAmNotHanni Mar 19, 2022
52f92a1
[*] Backup of work
IAmNotHanni Mar 19, 2022
8ceab57
[*] Backup of work (broken)
IAmNotHanni Mar 20, 2022
67994c6
[*] Backup of work
IAmNotHanni Mar 23, 2022
75fc79b
[*] Backup of work
IAmNotHanni Mar 24, 2022
67d1302
[*] Update of work
IAmNotHanni Mar 29, 2022
0d46616
[*] Backup of work
IAmNotHanni Apr 2, 2022
67e61eb
[*] Fix build
IAmNotHanni Apr 2, 2022
958be42
[*] Backup of work
IAmNotHanni Apr 3, 2022
3672d9a
[*] Backup of work
IAmNotHanni Apr 3, 2022
1b8cd84
[*] Backup of work
IAmNotHanni Apr 9, 2022
bbf9fcf
[*] Backup of work
IAmNotHanni Apr 10, 2022
72a2237
[*] Backup of work
IAmNotHanni Apr 11, 2022
f00740e
[*] Backup of work
IAmNotHanni Apr 18, 2022
ec6cff7
[*] Backup of work
IAmNotHanni Apr 18, 2022
bf7ca5e
[*] Backup of work
IAmNotHanni Apr 24, 2022
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
Prev Previous commit
Next Next commit
[gltf] WIP
  • Loading branch information
IAmNotHanni committed Sep 26, 2021
commit 769221d81be4968bbbc171fb20f3686d979611bc
6 changes: 3 additions & 3 deletions include/inexor/vulkan-renderer/gltf/model_gpu_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ class ModelGpuData {

void load_materials(const tinygltf::Model &model);
void load_animations(const tinygltf::Model &model);
void load_textures(RenderGraph *render_graph, const tinygltf::Model &model);
void load_textures(const wrapper::Device &device_wrapper, const tinygltf::Model &model);
void load_skins(const tinygltf::Model &model);
void load_nodes(const tinygltf::Model &model);

void setup_rendering_resources(RenderGraph *render_graph);
void setup_rendering_resources(const wrapper::Device &device_wrapper, RenderGraph *render_graph);

public:
///
///
///
ModelGpuData(RenderGraph *render_graph, const ModelFile &model_file);
ModelGpuData(const wrapper::Device &device_wrapper, RenderGraph *render_graph, const ModelFile &model_file);
ModelGpuData(const ModelGpuData &) = delete;
ModelGpuData(ModelGpuData &&) noexcept;
~ModelGpuData() = default;
Expand Down
5 changes: 0 additions & 5 deletions include/inexor/vulkan-renderer/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,6 @@ class RenderGraph {
return m_device.device();
}

/// It's useful to have a get method for the device in the rendergraph itself.
[[nodiscard]] const wrapper::Device &device_wrapper() const {
return m_device;
}

/// @brief Compiles the render graph resources/stages into physical vulkan objects.
/// @param target The target resource of the render graph (usually the back buffer)
void compile(const RenderResource *target);
Expand Down
45 changes: 19 additions & 26 deletions src/vulkan-renderer/gltf/model_gpu_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@

namespace inexor::vulkan_renderer::gltf {

ModelGpuData::ModelGpuData(RenderGraph *render_graph, const ModelFile &model_file) : m_name(model_file.model_name()) {
ModelGpuData::ModelGpuData(const wrapper::Device &device_wrapper, RenderGraph *render_graph,
const ModelFile &model_file)
: m_name(model_file.model_name()) {

assert(render_graph);

const auto &model = model_file.model();
load_textures(render_graph, model);
load_textures(device_wrapper, model);
load_materials(model);
load_nodes(model);
load_animations(model);
load_skins(model);
setup_rendering_resources(render_graph);
setup_rendering_resources(device_wrapper, render_graph);
}

ModelGpuData::ModelGpuData(ModelGpuData &&other) noexcept
Expand All @@ -44,7 +46,7 @@ ModelGpuData::ModelGpuData(ModelGpuData &&other) noexcept
m_unsupported_attributes = std::move(other.m_unsupported_attributes);
}

void ModelGpuData::load_textures(RenderGraph *render_graph, const tinygltf::Model &model) {
void ModelGpuData::load_textures(const wrapper::Device &device_wrapper, const tinygltf::Model &model) {
spdlog::trace("Loading {} glTF2 model texture indices", model.textures.size());

// Preallocate memory for the texture indices.
Expand All @@ -71,14 +73,8 @@ void ModelGpuData::load_textures(RenderGraph *render_graph, const tinygltf::Mode
for (const auto &texture : model.textures) {
const auto &texture_image = model.images[texture.source];

TextureSampler new_sampler{};

if (texture.sampler == -1) {
// No sampler specified, use a default one.
new_sampler = m_default_texture_sampler;
} else {
new_sampler = m_texture_samplers.at(texture.sampler);
}
const auto &new_sampler =
(texture.sampler == -1) ? m_default_texture_sampler : m_texture_samplers.at(texture.sampler);

// The size of the texture if it had 4 channels (rgba).
const std::size_t texture_size =
Expand All @@ -97,25 +93,24 @@ void ModelGpuData::load_textures(RenderGraph *render_graph, const tinygltf::Mode
rgba_target.reserve(texture_size);

std::transform(rgb_source.begin(), rgb_source.end(), rgba_target.begin(),
[](const std::array<std::uint32_t, 3> a) {
[](const std::array<std::uint32_t, 3> rgb_values) {
// convert RGB-only to RGBA.
return std::array<std::uint32_t, 4>{a[0], a[1], a[2], 1};
return std::array<std::uint32_t, 4>{rgb_values[0], rgb_values[1], rgb_values[2], 1};
});

std::string texture_name = texture.name.empty() ? "glTF2 model texture" : texture.name;

// Create a texture using the data which was converted to RGBA.
m_textures.emplace_back(render_graph->device_wrapper(), new_sampler, rgba_target.data(), texture_size,
texture_image.width, texture_image.height, texture_image.component, 1,
texture_name);
m_textures.emplace_back(device_wrapper, new_sampler, rgba_target.data(), texture_size, texture_image.width,
texture_image.height, texture_image.component, 1, texture_name);
break;
}
case 4: {
std::string texture_name = texture.name.empty() ? "glTF2 model texture" : texture.name;

// Create a texture using RGBA data.
m_textures.emplace_back(render_graph->device_wrapper(), new_sampler, texture_image.image.data(),
texture_size, texture_image.width, texture_image.height, texture_image.component, 1,
m_textures.emplace_back(device_wrapper, new_sampler, &texture_image.image[0], texture_size,
texture_image.width, texture_image.height, texture_image.component, 1,
texture_name);
break;
}
Expand All @@ -124,8 +119,7 @@ void ModelGpuData::load_textures(RenderGraph *render_graph, const tinygltf::Mode
spdlog::warn("Generating error texture as a replacement.");

// Generate an error texture.
// m_textures.emplace_back(render_graph->device_wrapper(), m_default_texture_sampler,
// wrapper::CpuTexture());
m_textures.emplace_back(device_wrapper, m_default_texture_sampler, wrapper::CpuTexture());
break;
}
}
Expand Down Expand Up @@ -736,7 +730,7 @@ void ModelGpuData::load_animations(const tinygltf::Model &model) {
}
}

void ModelGpuData::setup_rendering_resources(RenderGraph *render_graph) {
void ModelGpuData::setup_rendering_resources(const wrapper::Device &device_wrapper, RenderGraph *render_graph) {

m_vertex_buffer = render_graph->add<BufferResource>("gltf vertex buffer", BufferUsage::VERTEX_BUFFER);

Expand All @@ -752,12 +746,11 @@ void ModelGpuData::setup_rendering_resources(RenderGraph *render_graph) {
// TODO: Update for glTF2 PBR rendering!
const std::vector<VkDescriptorPoolSize> pool_sizes{{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}};

m_descriptor_pool = std::make_unique<wrapper::DescriptorPool>(render_graph->device_wrapper(), pool_sizes, "gltf");
m_descriptor_pool = std::make_unique<wrapper::DescriptorPool>(device_wrapper, pool_sizes, "gltf");

wrapper::DescriptorBuilder builder(render_graph->device_wrapper(), m_descriptor_pool->descriptor_pool());
wrapper::DescriptorBuilder builder(device_wrapper, m_descriptor_pool->descriptor_pool());

m_uniform_buffer =
std::make_unique<wrapper::UniformBuffer>(render_graph->device_wrapper(), "octree", sizeof(UniformBufferObject));
m_uniform_buffer = std::make_unique<wrapper::UniformBuffer>(device_wrapper, "octree", sizeof(UniformBufferObject));

m_descriptor = builder.add_uniform_buffer<UniformBufferObject>(m_uniform_buffer->buffer()).build("octree");
}
Expand Down
13 changes: 6 additions & 7 deletions src/vulkan-renderer/wrapper/gpu_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ GpuTexture::GpuTexture(const Device &device, const gltf::TextureSampler &sampler
create_texture_sampler(sampler);
}

GpuTexture::GpuTexture(const Device &device, void *data, const std::size_t data_size, const std::uint32_t texture_width,
const std::uint32_t texture_height, const std::uint32_t texture_channels,
const std::uint32_t mip_levels, std::string name)
GpuTexture::GpuTexture(const Device &device, void *data, std::size_t data_size, std::uint32_t texture_width,
std::uint32_t texture_height, std::uint32_t texture_channels, std::uint32_t mip_levels,
std::string name)
: m_device(device), m_texture_width(texture_width), m_texture_height(texture_height),
m_texture_channels(texture_channels), m_mip_levels(mip_levels), m_name(std::move(name)),
m_copy_command_buffer(device, device.graphics_queue(), device.graphics_queue_family_index()) {
create_texture(data, data_size);
create_texture_sampler();
}

GpuTexture::GpuTexture(const Device &device, const gltf::TextureSampler &sampler, void *data,
const std::size_t data_size, const std::uint32_t texture_width,
const std::uint32_t texture_height, const std::uint32_t texture_channels,
const std::uint32_t mip_levels, std::string name)
GpuTexture::GpuTexture(const Device &device, const gltf::TextureSampler &sampler, void *data, std::size_t data_size,
std::uint32_t texture_width, std::uint32_t texture_height, std::uint32_t texture_channels,
std::uint32_t mip_levels, std::string name)
: m_device(device), m_texture_width(texture_width), m_texture_height(texture_height),
m_texture_channels(texture_channels), m_mip_levels(mip_levels), m_name(std::move(name)),
m_copy_command_buffer(device, device.graphics_queue(), device.graphics_queue_family_index()) {
Expand Down