Skip to content

Add support for cubemaps and skybox #72

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

Merged
merged 5 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ if(FACADE_BUILD_EXE AND FACADE_BUILD_SHADERS)
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/default.vert
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/unlit.frag
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/lit.frag
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/skybox.frag

OUTPUT
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/default_vert.spv.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/unlit_frag.spv.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/lit_frag.spv.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/skybox_frag.spv.hpp

COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/default.vert > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/default_vert.spv.hpp
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/unlit.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/unlit_frag.spv.hpp
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/lit.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/lit_frag.spv.hpp
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/skybox.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/skybox_frag.spv.hpp
)
endif()

Expand Down
2 changes: 2 additions & 0 deletions lib/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_sources(${PROJECT_NAME} PRIVATE
include/${target_prefix}/engine/editor/browse_file.hpp
include/${target_prefix}/engine/editor/common.hpp
include/${target_prefix}/engine/editor/drag_drop_id.hpp
include/${target_prefix}/engine/editor/file_browser.hpp
include/${target_prefix}/engine/editor/inspector.hpp
include/${target_prefix}/engine/editor/log.hpp
include/${target_prefix}/engine/editor/reflector.hpp
Expand All @@ -54,6 +55,7 @@ target_sources(${PROJECT_NAME} PRIVATE

src/editor/browse_file.cpp
src/editor/common.cpp
src/editor/file_browser.cpp
src/editor/inspector.cpp
src/editor/log.cpp
src/editor/reflector.cpp
Expand Down
31 changes: 31 additions & 0 deletions lib/engine/include/facade/engine/editor/file_browser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
#include <facade/engine/editor/browse_file.hpp>

namespace facade::editor {
///
/// \brief Persistent modal pop up to browse for a file given a list of extensions.
///
/// Uses Modal and BrowseFile.
///
class FileBrowser {
public:
struct Result {
std::string selected{};
std::string_view browse_path{};
bool path_changed{};
};

FileBrowser(std::string label, std::vector<std::string> extensions, std::string browse_path);

Result update(bool& out_trigger);

std::vector<std::string> extensions;

private:
std::string m_browse_path;
std::string m_label;
std::vector<std::string_view> m_extensions_view{};
env::DirEntries m_dir_entries{};
bool m_trigger{};
};
} // namespace facade::editor
4 changes: 2 additions & 2 deletions lib/engine/include/facade/engine/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class Engine {
void request_stop();

///
/// \brief Load a GLTF scene asynchronously.
/// \brief Load a GLTF scene / Skybox asynchronously.
///
/// Subsequent requests will be rejected if one is in flight
///
bool load_async(std::string gltf_json_path, UniqueTask<void()> on_loaded = {});
bool load_async(std::string json_path, UniqueTask<void()> on_loaded = {});
///
/// \brief Obtain status of in-flight async load request (if active).
///
Expand Down
11 changes: 7 additions & 4 deletions lib/engine/include/facade/engine/scene_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#include <facade/vk/buffer.hpp>

namespace facade {
class Skybox;

class SceneRenderer {
public:
explicit SceneRenderer(Gfx const& gfx);

void render(Scene const& scene, Renderer& renderer, vk::CommandBuffer cb);
void render(Scene const& scene, Ptr<Skybox const> skybox, Renderer& renderer, vk::CommandBuffer cb);

private:
void write_view(glm::vec2 const extent);
void update_view(Pipeline& out_pipeline) const;
std::span<glm::mat4x4 const> make_instances(Node const& node, glm::mat4x4 const& parent);
std::span<glm::mat4x4 const> make_instances(Node const& node, glm::mat4x4 const& parent) const;

void render(Renderer& renderer, vk::CommandBuffer cb, Node const& node, glm::mat4 const& parent = matrix_identity_v);
void render(Renderer& renderer, vk::CommandBuffer cb, Skybox const& skybox) const;
void render(Renderer& renderer, vk::CommandBuffer cb, Node const& node, glm::mat4 const& parent = matrix_identity_v) const;

Gfx m_gfx;
Sampler m_sampler;
Expand All @@ -24,7 +27,7 @@ class SceneRenderer {
Texture m_white;
Texture m_black;

std::vector<glm::mat4x4> m_instance_mats{};
mutable std::vector<glm::mat4x4> m_instance_mats{};
Scene const* m_scene{};
};
} // namespace facade
11 changes: 11 additions & 0 deletions lib/engine/src/editor/browse_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <imgui.h>
#include <facade/engine/editor/browse_file.hpp>
#include <facade/util/env.hpp>
#include <facade/util/fixed_string.hpp>
#include <filesystem>

namespace facade::editor {
Expand Down Expand Up @@ -75,6 +76,16 @@ auto BrowseFile::operator()(NotClosed<Popup> popup, std::string& out_path) -> Re
if (ImGui::Button("Downloads")) { cd(std::move(downloads)); }
}

ImGui::Separator();
auto exts = FixedString{};
if (extensions.empty()) {
exts = "*.*";
} else {
exts = FixedString{"*{}", extensions[0]};
for (auto it = std::next(extensions.begin()); it != extensions.end(); ++it) { exts += FixedString{", *{}", *it}; }
}
ImGui::Text("%s", exts.c_str());

ImGui::Separator();
if (auto window = editor::Window{popup, "File Tree"}) {
env::GetDirEntries{.extensions = extensions}(out_entries, out_path.c_str());
Expand Down
29 changes: 29 additions & 0 deletions lib/engine/src/editor/file_browser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <imgui.h>
#include <facade/engine/editor/file_browser.hpp>

namespace facade::editor {
FileBrowser::FileBrowser(std::string label, std::vector<std::string> extensions, std::string browse_path)
: extensions(std::move(extensions)), m_browse_path(std::move(browse_path)), m_label(std::move(label)) {
if (m_label.empty()) { m_label = "Browse..."; }
}

auto FileBrowser::update(bool& out_trigger) -> Result {
auto ret = Result{};
if (out_trigger && !ImGui::IsPopupOpen(m_label.c_str())) { Modal::open(m_label.c_str()); }
out_trigger = false;
if (ImGui::IsPopupOpen(m_label.c_str())) { ImGui::SetNextWindowSize({400.0f, 250.0f}, ImGuiCond_FirstUseEver); }
if (auto popup = Modal{m_label.c_str()}) {
m_extensions_view.clear();
m_extensions_view.reserve(extensions.size());
for (auto const& extension : extensions) { m_extensions_view.push_back(extension); }
auto [selected, changed] = BrowseFile{.out_entries = m_dir_entries, .extensions = m_extensions_view}(popup, m_browse_path);
ret.path_changed = changed;
ret.browse_path = m_browse_path;
if (!selected.empty()) {
popup.close_current();
ret.selected = std::move(selected);
}
}
return ret;
}
} // namespace facade::editor
1 change: 0 additions & 1 deletion lib/engine/src/editor/reflector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <imgui.h>
#include <facade/engine/editor/reflector.hpp>
#include <facade/util/enumerate.hpp>
#include <facade/util/fixed_string.hpp>
#include <optional>

Expand Down
Loading