diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c52be43..f17d412 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_DEBUG_POSTFIX "-d") -set(${target_prefix}_version 0.1.0) +set(${target_prefix}_version 0.2.0) project(${target_prefix}-lib VERSION ${${target_prefix}_version}) diff --git a/lib/engine/src/editor/reflector.cpp b/lib/engine/src/editor/reflector.cpp index daf6d67..310d230 100644 --- a/lib/engine/src/editor/reflector.cpp +++ b/lib/engine/src/editor/reflector.cpp @@ -65,14 +65,20 @@ bool Reflector::operator()(char const* label, glm::quat& out_quat) const { auto euler = to_degree(glm::eulerAngles(out_quat)); float deg[3] = {euler.x, euler.y, euler.z}; auto const org = euler; + bool ret = false; if (drag_float(label, deg, 0.5f, -180.0f, 180.0f, ImGuiSliderFlags_NoInput)) { euler = {deg[0], deg[1], deg[2]}; if (auto const diff = org.x - euler.x; std::abs(diff) > 0.0f) { out_quat = glm::rotate(out_quat, glm::radians(diff), right_v); } if (auto const diff = org.y - euler.y; std::abs(diff) > 0.0f) { out_quat = glm::rotate(out_quat, glm::radians(diff), up_v); } if (auto const diff = org.z - euler.z; std::abs(diff) > 0.0f) { out_quat = glm::rotate(out_quat, glm::radians(diff), front_v); } - return true; + ret = true; } - return false; + ImGui::SameLine(); + if (ImGui::SmallButton("Reset")) { + out_quat = quat_identity_v; + ret = true; + } + return ret; } bool Reflector::operator()(char const* label, AsRgb out_rgb) const { @@ -101,8 +107,6 @@ bool Reflector::operator()(Transform& out_transform, Bool& out_unified_scaling, if (ret((*this)("Position", vec3, 0.01f))) { out_transform.set_position(vec3); } auto quat = out_transform.orientation(); if (ret((*this)("Orientation", quat))) { out_transform.set_orientation(quat); } - ImGui::SameLine(); - if (ImGui::SmallButton("Reset")) { out_transform.set_orientation(quat_identity_v); } vec3 = out_transform.scale(); if (out_unified_scaling) { if (ret(ImGui::DragFloat("Scale", &vec3.x, 0.01f))) { out_transform.set_scale({vec3.x, vec3.x, vec3.x}); } diff --git a/lib/engine/src/engine.cpp b/lib/engine/src/engine.cpp index d4f3134..f9c36bb 100644 --- a/lib/engine/src/engine.cpp +++ b/lib/engine/src/engine.cpp @@ -193,13 +193,13 @@ std::optional load_skybox_data(char const* path, AtomicLoadStatus& for (auto [face, image] : zip_ranges(faces_v, images)) { image = load_image(json[face].as_string()); } - if (!std::all_of(std::begin(images), std::end(images), [](MaybeFuture const& i) { return i.active(); })) { + if (!std::all_of(std::begin(images), std::end(images), [](StoredFuture const& i) { return i.active(); })) { // TODO: error return {}; } auto ret = Skybox::Data{}; - for (auto [in, out] : zip_ranges(images, ret.images)) { out = in.get(); } + for (auto [in, out] : zip_ranges(images, ret.images)) { out = std::move(in.get()); } return ret; } diff --git a/lib/engine/src/scene_renderer.cpp b/lib/engine/src/scene_renderer.cpp index c0cc88c..5a2e702 100644 --- a/lib/engine/src/scene_renderer.cpp +++ b/lib/engine/src/scene_renderer.cpp @@ -14,7 +14,7 @@ struct DirLightSSBO { static DirLightSSBO make(DirLight const& light) { return { - .direction = light.direction.value(), + .direction = glm::normalize(light.direction * front_v), .diffuse = light.rgb.to_vec4(), }; } @@ -147,8 +147,8 @@ void SceneRenderer::render(Renderer& renderer, vk::CommandBuffer cb, Node const& update_view(pipeline); material.write_sets(pipeline, store); - if (mesh_primitive.has_joints()) { - auto& set3 = pipeline.next_set(3); + if (auto const joints_set = mesh_primitive.joints_set()) { + auto& set3 = pipeline.next_set(*joints_set); set3.update(0, make_joint_mats(resources.skins[*node.find()], parent)); pipeline.bind(set3); draw(cb, mesh_primitive, {}); diff --git a/lib/ext/src.zip b/lib/ext/src.zip index a7ac3d3..43c88fe 100644 Binary files a/lib/ext/src.zip and b/lib/ext/src.zip differ diff --git a/lib/scene/include/facade/scene/gltf_loader.hpp b/lib/scene/include/facade/scene/gltf_loader.hpp index 435168e..0e7865c 100644 --- a/lib/scene/include/facade/scene/gltf_loader.hpp +++ b/lib/scene/include/facade/scene/gltf_loader.hpp @@ -21,19 +21,19 @@ struct AtomicLoadStatus { }; template -struct LoadFuture : MaybeFuture { +struct LoadFuture : StoredFuture { LoadFuture() = default; template LoadFuture(ThreadPool& pool, std::atomic& post_increment, F func) - : MaybeFuture(pool, [&post_increment, f = std::move(func)] { + : StoredFuture(pool, [&post_increment, f = std::move(func)] { auto ret = f(); ++post_increment; return ret; }) {} template - LoadFuture(std::atomic& post_increment, F func) : MaybeFuture(std::move(func)) { + LoadFuture(std::atomic& post_increment, F func) : StoredFuture(std::move(func)) { ++post_increment; } }; diff --git a/lib/scene/include/facade/scene/lights.hpp b/lib/scene/include/facade/scene/lights.hpp index a5092a9..69d9744 100644 --- a/lib/scene/include/facade/scene/lights.hpp +++ b/lib/scene/include/facade/scene/lights.hpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace facade { /// @@ -11,7 +12,7 @@ struct DirLight { /// /// \brief Direction. /// - nvec3 direction{-front_v}; + glm::quat direction{glm::angleAxis(glm::radians(180.0f), up_v)}; /// /// \brief Colour and intensity. /// diff --git a/lib/scene/include/facade/scene/scene.hpp b/lib/scene/include/facade/scene/scene.hpp index aed4325..a02a61a 100644 --- a/lib/scene/include/facade/scene/scene.hpp +++ b/lib/scene/include/facade/scene/scene.hpp @@ -190,6 +190,12 @@ class Scene { /// Texture make_texture(Image::View image) const; + /// + /// \brief Update animations and corresponding nodes. + /// \param dt Duration to advance simulation by (time since last call to tick) + /// + void tick(float dt); + /// /// \brief Obtain a mutable reference to the scene's resources. /// \returns Mutable reference to SceneResources @@ -211,12 +217,6 @@ class Scene { /// RenderMode render_mode{}; - /// - /// \brief Update animations and corresponding nodes. - /// \param dt Duration to advance simulation by (time since last call to tick) - /// - void tick(float dt); - private: struct TreeBuilder; @@ -241,6 +241,8 @@ class Scene { Node make_camera_node(Id id) const; void add_default_camera(); + void add_default_camera(TreeImpl& out, Id id); + void add_default_light(); bool load_tree(Id id); Id add_unchecked(Mesh mesh); diff --git a/lib/scene/src/gltf_loader.cpp b/lib/scene/src/gltf_loader.cpp index 0de5029..470d203 100644 --- a/lib/scene/src/gltf_loader.cpp +++ b/lib/scene/src/gltf_loader.cpp @@ -313,10 +313,10 @@ auto make_load_future(ThreadPool* pool, std::atomic& out_done, F fu } template -std::vector from_maybe_futures(std::vector>&& futures) { +std::vector from_stored(std::vector>&& futures) { auto ret = std::vector{}; ret.reserve(futures.size()); - for (auto& future : futures) { ret.push_back(future.get()); } + for (auto& future : futures) { ret.push_back(std::move(future.get())); } return ret; } } // namespace @@ -328,9 +328,17 @@ bool Scene::GltfLoader::operator()(dj::Json const& json, DataProvider const& pro m_status.total = 1 + meta.images + meta.textures + meta.primitives + 1; m_status.stage = LoadStage::eParsingJson; - auto get_bytes = [&provider](std::string_view uri) { + auto loaded_bytes = std::unordered_map{}; + auto loaded_mutex = std::mutex{}; + auto get_bytes = [&](std::string_view uri) { + auto str = std::string{uri}; + auto lock = std::unique_lock{loaded_mutex}; + if (auto it = loaded_bytes.find(str); it != loaded_bytes.end()) { return it->second.span(); } + lock.unlock(); auto ret = provider.load(uri); - return gltf2cpp::ByteArray{std::move(ret.bytes), ret.size}; + lock.lock(); + auto [it, _] = loaded_bytes.insert_or_assign(str, std::move(ret)); + return it->second.span(); }; auto root = parser.parse(get_bytes); @@ -341,11 +349,11 @@ bool Scene::GltfLoader::operator()(dj::Json const& json, DataProvider const& pro m_status.stage = LoadStage::eUploadingResources; m_scene.m_storage = {}; - auto image_futures = std::vector>{}; - image_futures.reserve(root.images.size()); + auto images = std::vector>{}; + images.reserve(root.images.size()); for (auto& image : root.images) { assert(!image.bytes.empty()); - image_futures.push_back(make_load_future(thread_pool, m_status.done, [i = std::move(image)] { return Image{i.bytes.span(), std::move(i.name)}; })); + images.push_back(make_load_future(thread_pool, m_status.done, [i = std::move(image)] { return Image{i.bytes.span(), std::move(i.name)}; })); } for (auto const& sampler : root.samplers) { m_scene.add(to_sampler_info(sampler)); } @@ -354,19 +362,18 @@ bool Scene::GltfLoader::operator()(dj::Json const& json, DataProvider const& pro return m_scene.m_storage.resources.samplers[*sampler_id].sampler(); }; - auto textures = std::vector>{}; + auto textures = std::vector>{}; textures.reserve(root.textures.size()); - auto const images = from_maybe_futures(std::move(image_futures)); for (auto& texture : root.textures) { textures.push_back(make_load_future(thread_pool, m_status.done, [texture = std::move(texture), &images, &get_sampler, this] { bool const mip_mapped = !texture.linear; auto const colour_space = texture.linear ? ColourSpace::eLinear : ColourSpace::eSrgb; auto const tci = Texture::CreateInfo{.name = std::move(texture.name), .mip_mapped = mip_mapped, .colour_space = colour_space}; - return Texture{m_scene.m_gfx, get_sampler(texture.sampler), images[texture.source], tci}; + return Texture{m_scene.m_gfx, get_sampler(texture.sampler), images[texture.source].get(), tci}; })); } - auto mesh_primitives = std::vector>{}; + auto mesh_primitives = std::vector>{}; auto mesh_layout = to_mesh_layout(root); mesh_primitives.reserve(mesh_layout.primitives.size()); for (auto& data : mesh_layout.data) { @@ -384,8 +391,8 @@ bool Scene::GltfLoader::operator()(dj::Json const& json, DataProvider const& pro m_scene.m_storage.resources.nodes.m_array = to_nodes(root.nodes); - m_scene.replace(from_maybe_futures(std::move(textures))); - m_scene.replace(from_maybe_futures(std::move(mesh_primitives))); + m_scene.replace(from_stored(std::move(textures))); + m_scene.replace(from_stored(std::move(mesh_primitives))); m_status.stage = LoadStage::eBuildingScenes; if (root.cameras.empty()) { diff --git a/lib/scene/src/scene.cpp b/lib/scene/src/scene.cpp index d441c85..689540c 100644 --- a/lib/scene/src/scene.cpp +++ b/lib/scene/src/scene.cpp @@ -34,29 +34,20 @@ struct Img1x1 { struct Scene::TreeBuilder { Scene& out_scene; - bool set_camera(TreeImpl& out_tree, Id id, std::span nodes) const { + void add_cameras(TreeImpl& out_tree, Id id, std::span nodes) const { auto& node = nodes[id]; - if (auto cam = node.find()) { - out_tree.camera = id; - return true; - } - for (auto const child : node.children) { - if (set_camera(out_tree, child, nodes)) { return true; } - } - return false; + if (auto cam = node.find()) { out_tree.cameras.push_back(id); } + for (auto const child : node.children) { add_cameras(out_tree, child, nodes); } } void set_camera(TreeImpl& out_tree, std::span nodes) const { - for (auto const& id : out_tree.roots) { - if (set_camera(out_tree, id, nodes)) { return; } + for (auto const& id : out_tree.roots) { add_cameras(out_tree, id, nodes); } + if (!out_tree.cameras.empty()) { + out_tree.camera = out_tree.cameras.front(); + return; } - auto node = Node{.name = "camera"}; - node.attach(0); - auto const id = out_scene.m_storage.resources.nodes.size(); - out_scene.m_storage.resources.nodes.m_array.push_back(std::move(node)); - out_tree.roots.push_back(id); - out_tree.cameras.push_back(id); - out_tree.camera = out_tree.cameras.front(); + assert(!out_scene.m_storage.resources.cameras.empty()); + out_scene.add_default_camera(out_tree, 0); } TreeImpl operator()(Id id) { @@ -67,7 +58,10 @@ struct Scene::TreeBuilder { } }; -Scene::Scene(Gfx const& gfx) : m_gfx(gfx), m_sampler(gfx) { add_default_camera(); } +Scene::Scene(Gfx const& gfx) : m_gfx(gfx), m_sampler(gfx) { + add_default_camera(); + add_default_light(); +} Id Scene::add(Camera camera) { auto const id = m_storage.resources.cameras.size(); @@ -183,11 +177,18 @@ Node Scene::make_camera_node(Id id) const { return node; } -void Scene::add_default_camera() { - m_tree.cameras.push_back(m_storage.resources.nodes.size()); - m_tree.roots.push_back(m_storage.resources.nodes.size()); - m_storage.resources.nodes.m_array.push_back(make_camera_node(add(Camera{.name = "default"}))); - m_tree.camera = m_tree.cameras.front(); +void Scene::add_default_camera(TreeImpl& out, Id id) { + auto const node = add(make_camera_node(id)); + out.roots.push_back(node); + out.cameras.push_back(node); + out.camera = out.cameras.front(); +} + +void Scene::add_default_camera() { add_default_camera(m_tree, add(Camera{.name = "default"})); } + +void Scene::add_default_light() { + static auto const dir_light_orn = [] { return glm::angleAxis(glm::radians(180.0f + 45.0f), up_v) * glm::angleAxis(glm::radians(45.0f), right_v); }(); + lights.dir_lights.insert(DirLight{.direction = dir_light_orn, .rgb = {.intensity = 5.0f}}); } bool Scene::load_tree(Id id) { diff --git a/lib/util/include/facade/util/rgb.hpp b/lib/util/include/facade/util/rgb.hpp index 10052e6..f25a744 100644 --- a/lib/util/include/facade/util/rgb.hpp +++ b/lib/util/include/facade/util/rgb.hpp @@ -54,15 +54,19 @@ struct Rgb { }; } + /// + /// \brief Obtain only the normalzed tint (no HDR). + /// + constexpr glm::vec4 to_tint(float alpha) const { return glm::vec4{to_f32(channels.x), to_f32(channels.y), to_f32(channels.z), alpha}; } /// /// \brief Convert instance to 3 channel normalized output. /// \returns 3 normalized floats /// - constexpr glm::vec3 to_vec3() const { return intensity * glm::vec3{to_f32(channels.x), to_f32(channels.y), to_f32(channels.z)}; } + constexpr glm::vec3 to_vec3() const { return to_vec4(1.0f); } /// /// \brief Convert instance to 4 channel normalized output. /// \returns 4 normalized floats /// - constexpr glm::vec4 to_vec4(float alpha = 1.0f) const { return {to_vec3(), alpha}; } + constexpr glm::vec4 to_vec4(float alpha = 1.0f) const { return intensity * to_tint(alpha); } }; } // namespace facade diff --git a/lib/util/include/facade/util/thread_pool.hpp b/lib/util/include/facade/util/thread_pool.hpp index d2c9a4c..1add70c 100644 --- a/lib/util/include/facade/util/thread_pool.hpp +++ b/lib/util/include/facade/util/thread_pool.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace facade { @@ -63,26 +64,28 @@ class ThreadPool { }; template -struct MaybeFuture { - std::future future{}; +struct StoredFuture { + std::shared_future future{}; std::optional t{}; - MaybeFuture() = default; + StoredFuture() = default; template requires(std::same_as, T>) - MaybeFuture(ThreadPool& pool, F func) : future(pool.enqueue([f = std::move(func)] { return f(); })) {} + StoredFuture(ThreadPool& pool, F func) : future(pool.enqueue([f = std::move(func)] { return f(); }).share()) {} template requires(std::same_as, T>) - explicit MaybeFuture(F func) : t(func()) {} + explicit StoredFuture(F func) : t(func()) {} bool active() const { return future.valid() || t.has_value(); } - T get() { + T const& get() const { assert(active()); if (future.valid()) { return future.get(); } - return std::move(*t); + return *t; } + + T& get() { return const_cast(std::as_const(*this).get()); } }; } // namespace facade diff --git a/lib/vk/include/facade/vk/mesh_primitive.hpp b/lib/vk/include/facade/vk/mesh_primitive.hpp index c0dc375..a7f2e54 100644 --- a/lib/vk/include/facade/vk/mesh_primitive.hpp +++ b/lib/vk/include/facade/vk/mesh_primitive.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace facade { struct MeshJoints { @@ -27,6 +28,7 @@ class MeshPrimitive { Info info() const; VertexLayout const& vertex_layout() const { return m_vlayout; } bool has_joints() const { return m_jwbo.get().get().size > 0; } + std::optional joints_set() const { return m_jwbo.get().get().size > 0 ? std::optional{3} : std::nullopt; } std::uint32_t instance_binding() const { return m_instance_binding; } void draw(vk::CommandBuffer cb, std::uint32_t instances = 1u) const; diff --git a/lib/vk/include/facade/vk/pipes.hpp b/lib/vk/include/facade/vk/pipes.hpp index 3274434..94fbd9c 100644 --- a/lib/vk/include/facade/vk/pipes.hpp +++ b/lib/vk/include/facade/vk/pipes.hpp @@ -10,9 +10,6 @@ #include namespace facade { -struct DrawInstance; -class StaticMesh; - class Pipes { public: using State = Pipeline::State; diff --git a/lib/vk/src/geometry.cpp b/lib/vk/src/geometry.cpp index 599d3aa..c850127 100644 --- a/lib/vk/src/geometry.cpp +++ b/lib/vk/src/geometry.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/lib/vk/src/skybox.cpp b/lib/vk/src/skybox.cpp index e84199d..9056c73 100644 --- a/lib/vk/src/skybox.cpp +++ b/lib/vk/src/skybox.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,18 +6,35 @@ namespace facade { namespace { -std::array make_blank_cubemap_images() { - static constexpr std::byte black_v[] = {0x0_B, 0x0_B, 0x0_B, 0xff_B}; +template +constexpr void set_rgbs(std::span vertices, glm::vec3 rgb, T... indices) { + ((vertices[static_cast(indices)].rgb = rgb), ...); +} + +constexpr glm::vec4 gradient_v[2] = { + {0.9254f, 0.9215f, 0.8942f, 1.0f}, + {0.7254f, 0.7215f, 0.6942f, 1.0f}, +}; + +Geometry make_gradient_cubemap_cube() { + auto ret = make_cube(glm::vec3{1.0f}); + set_rgbs(ret.vertices, Rgb::to_linear(gradient_v[0]), 0, 1, 4, 5, 8, 9, 12, 13, 16, 17, 18, 19); + set_rgbs(ret.vertices, Rgb::to_linear(gradient_v[1]), 2, 3, 6, 7, 10, 11, 14, 15, 20, 21, 22, 23); + return ret; +} + +std::array make_cubemap_images() { + static constexpr std::byte black_v[] = {0xff_B, 0xff_B, 0xff_B, 0xff_B}; static constexpr auto image_v = Image::View{.bytes = black_v, .extent = {1, 1}}; return {image_v, image_v, image_v, image_v, image_v, image_v}; } } // namespace Skybox::Skybox(Gfx const& gfx) - : m_sampler(gfx), m_cube(gfx, make_cube(glm::vec3{1.0f}), {}, "skybox"), m_cubemap(gfx, m_sampler.sampler(), make_blank_cubemap_images(), "skybox"), + : m_sampler(gfx), m_cube(gfx, make_gradient_cubemap_cube(), {}, "skybox"), m_cubemap(gfx, m_sampler.sampler(), make_cubemap_images(), "skybox"), m_gfx(gfx) {} void Skybox::set(std::span images) { m_cubemap = {m_gfx, m_sampler.sampler(), images, "skybox"}; } -void Skybox::reset() { m_cubemap = {m_gfx, m_sampler.sampler(), make_blank_cubemap_images()}; } +void Skybox::reset() { m_cubemap = {m_gfx, m_sampler.sampler(), make_cubemap_images()}; } } // namespace facade diff --git a/src/bin/skybox_frag.spv.hpp b/src/bin/skybox_frag.spv.hpp index 3213811..6100465 100644 --- a/src/bin/skybox_frag.spv.hpp +++ b/src/bin/skybox_frag.spv.hpp @@ -2,48 +2,54 @@ namespace facade { inline constexpr unsigned char skybox_frag_v[] = { - 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0d, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, + 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x0d, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x04, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc2, 0x01, 0x00, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x47, 0x4c, 0x5f, 0x47, 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0x5f, 0x63, 0x70, 0x70, 0x5f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x5f, 0x6c, 0x69, 0x6e, 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x47, 0x4c, 0x5f, 0x47, 0x4f, 0x4f, 0x47, 0x4c, 0x45, 0x5f, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x5f, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x76, 0x65, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00, 0x6f, 0x75, - 0x74, 0x5f, 0x72, 0x67, 0x62, 0x61, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x63, 0x75, 0x62, 0x65, 0x6d, - 0x61, 0x70, 0x00, 0x05, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x66, 0x70, 0x6f, 0x73, 0x00, 0x05, 0x00, 0x07, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x76, 0x70, 0x6f, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x6f, 0x73, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, - 0x00, 0x05, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x72, 0x67, 0x62, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x1c, 0x00, - 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x75, 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x6e, 0x6f, + 0x74, 0x5f, 0x72, 0x67, 0x62, 0x61, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x72, 0x67, + 0x62, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x63, 0x75, 0x62, 0x65, 0x6d, 0x61, 0x70, 0x00, 0x05, 0x00, 0x04, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x66, 0x70, 0x6f, 0x73, 0x00, 0x05, 0x00, 0x07, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, + 0x76, 0x70, 0x6f, 0x73, 0x5f, 0x65, 0x78, 0x70, 0x6f, 0x73, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x23, 0x00, + 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x75, 0x76, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x24, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, - 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, - 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x19, - 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, + 0x47, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, + 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x16, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1b, + 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, - 0x03, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, - 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, - 0x0f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, - 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x14, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x17, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0f, 0x00, 0x00, - 0x00, 0x12, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x14, 0x00, - 0x00, 0x00, 0x4f, 0x00, 0x08, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x83, 0x00, 0x05, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, - 0x00, 0x17, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, - 0x01, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0b, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x3f, 0x19, 0x00, 0x09, 0x00, 0x13, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x14, 0x00, 0x00, + 0x00, 0x13, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x3b, 0x00, + 0x04, 0x00, 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x18, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x3b, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x21, 0x00, + 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0a, 0x00, 0x00, + 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x0d, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, + 0x00, 0x0e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x3d, 0x00, + 0x04, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1c, + 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x83, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x00, + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1f, 0x00, + 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x12, + 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, + 0x38, 0x00, 0x01, 0x00, }; } // namespace facade diff --git a/src/main.cpp b/src/main.cpp index c9206de..595aedb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,40 +54,17 @@ void run(AppOpts const& opts) { engine_info.desired_msaa = config.config.window.msaa; engine_info.force_thread_count = opts.force_threads; - auto node_id = Id{}; - auto post_scene_load = [&engine, &node_id]() { - auto& scene = engine->scene(); - scene.lights.dir_lights.insert(DirLight{.direction = glm::normalize(glm::vec3{-1.0f, -1.0f, -1.0f}), .rgb = {.intensity = 5.0f}}); - scene.camera().transform.set_position({0.0f, 0.0f, 5.0f}); - - auto material = LitMaterial{}; - material.albedo = {1.0f, 0.0f, 0.0f}; - auto material_id = scene.add(Material{std::move(material), "custom"}); - auto primitive_id = scene.add(Geometry::Packed::from(make_cubed_sphere(1.0f, 32))); - auto mesh_id = scene.add(Mesh{.primitives = {Mesh::Primitive{.primitive = primitive_id, .material = material_id}}}); - - auto node = Node{}; - node.attach(mesh_id); - node.instances.emplace_back().set_position({1.0f, -5.0f, -20.0f}); - node.instances.emplace_back().set_position({-1.0f, 1.0f, 0.0f}); - node_id = scene.add(std::move(node)); - }; - auto init = [&] { engine.emplace(engine_info); if (config.config.window.position) { glfwSetWindowPos(engine->window(), config.config.window.position->x, config.config.window.position->y); } log_prologue(); engine->add_shaders(vert::default_(), vert::skinned(), frag::unlit(), frag::lit(), frag::skybox()); - - post_scene_load(); engine->show(true); }; init(); - float const drot_z[] = {100.0f, -150.0f}; - auto file_menu = FileMenu{}; auto window_menu = WindowMenu{}; @@ -98,8 +75,8 @@ void run(AppOpts const& opts) { std::string title{}; } loading{}; - auto load_async = [&engine, &file_menu, &loading, &post_scene_load, &config](fs::path const& path) { - if (engine->load_async(path.generic_string(), post_scene_load)) { + auto load_async = [&engine, &file_menu, &loading, &config](fs::path const& path) { + if (engine->load_async(path.generic_string())) { loading.title = fmt::format("Loading {}...", path.filename().generic_string()); file_menu.add_recent(path.generic_string()); config.config.file_menu.recents = {file_menu.recents().begin(), file_menu.recents().end()}; @@ -156,21 +133,6 @@ void run(AppOpts const& opts) { if (auto path = path_sources.update(); !path.empty()) { load_async(std::move(path)); } config.update(*engine); - - // TEMP CODE - if (!ImGui::GetIO().WantTextInput && input.keyboard.pressed(GLFW_KEY_R)) { - logger::info("Reloading..."); - engine.reset(); - init(); - continue; - } - - if (auto* node = engine->scene().resources().nodes.find(node_id); node && node->instances.size() > 1) { - node->instances[0].rotate(glm::radians(drot_z[0]) * dt, {0.0f, 1.0f, 0.0f}); - node->instances[1].rotate(glm::radians(drot_z[1]) * dt, {1.0f, 0.0f, 0.0f}); - } - // TEMP CODE - engine->render(); } } diff --git a/src/shaders/skybox.frag b/src/shaders/skybox.frag index c795ecb..1d6a911 100644 --- a/src/shaders/skybox.frag +++ b/src/shaders/skybox.frag @@ -2,16 +2,16 @@ layout (set = 1, binding = 0) uniform samplerCube cubemap; +layout (location = 0) in vec3 in_rgb; layout (location = 3) in vec3 in_fpos; layout (location = 4) in vec4 in_vpos_exposure; layout (location = 0) out vec4 out_rgba; // unused -layout (location = 0) in vec3 in_rgb; layout (location = 1) in vec2 in_uv; layout (location = 2) in vec3 in_normal; void main() { - out_rgba = texture(cubemap, in_fpos - in_vpos_exposure.xyz); + out_rgba = vec4(in_rgb, 1.0) * texture(cubemap, in_fpos - in_vpos_exposure.xyz); }