diff --git a/CMakeLists.txt b/CMakeLists.txt index 41dcc93..e8ec3c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ option (USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) +set(BUILD_SHARED_LIBS OFF) set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine) set(EXTERNAL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/external) @@ -56,8 +57,7 @@ if(CMAKE_DEBUG_POSTFIX) add_compile_definitions(SEELE_DEBUG) endif() -add_library(Engine SHARED "") -add_executable(Editor "") +add_library(Engine STATIC "") target_compile_definitions(Engine PUBLIC GLFW_WINDOWS) target_include_directories(Engine PUBLIC src/Engine) target_link_libraries(Engine PUBLIC Vulkan::Vulkan) @@ -75,8 +75,8 @@ target_link_libraries(Engine PUBLIC stb) target_link_libraries(Engine PUBLIC nlohmann_json::nlohmann_json) target_link_libraries(Engine PUBLIC dp::thread-pool) if(UNIX) - target_link_libraries(Engine Threads::Threads) - target_link_libraries(Engine dl) + target_link_libraries(Engine PUBLIC Threads::Threads) + target_link_libraries(Engine PUBLIC dl) endif() target_precompile_headers(Engine PUBLIC @@ -97,11 +97,15 @@ target_precompile_headers(Engine if(MSVC) set(_CRT_SECURE_NO_WARNINGS) - target_compile_options(Engine PUBLIC /Zi /MP /W4 /DEBUG "/WX-") + target_compile_options(Engine PUBLIC /Zi /MP15 /W4 /DEBUG "/WX-") else() target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) endif() +add_executable(Editor "") + +target_include_directories(Editor PRIVATE src/Editor) + target_link_libraries(Editor PUBLIC Engine) add_subdirectory(src/) @@ -110,12 +114,12 @@ add_executable(Seele_unit_tests "") add_subdirectory(test/) add_custom_target(SeeleEngine ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ - COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ + COMMAND ${CMAKE_COMMAND} -E copy $ $ COMMAND_EXPAND_LISTS DEPENDS Editor slang-build) diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake index b3e102a..f674783 100644 --- a/cmake/SuperBuild.cmake +++ b/cmake/SuperBuild.cmake @@ -1,11 +1,14 @@ include (ExternalProject) +#--------------FreeType------------------------------ +set(FT_DISABLE_ZLIB ON) + +add_subdirectory(${FREETYPE_ROOT}) + #------------ASSIMP--------------- set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "") set(ASSIMP_BUILD_SAMPLES OFF CACHE INTERNAL "") set(ASSIMP_BUILD_OVERALLS OFF CACHE INTERNAL "") -set(BUILD_SHARED_LIBS ON CACHE INTERNAL "") - add_subdirectory(${ASSIMP_ROOT}) target_compile_definitions(assimp PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) if(WIN32) @@ -31,7 +34,7 @@ add_subdirectory(${JSON_ROOT}) #--------------GLM------------------------------ add_subdirectory(${GLM_ROOT}) -target_compile_options(glm_shared INTERFACE /W0) +target_compile_options(glm INTERFACE /W0) #--------------GLFW------------------------------ set(ENKITS_BUILD_EXAMPLES OFF CACHE BOOL "Build basic example applications" ) @@ -46,9 +49,6 @@ add_subdirectory(${GLFW_ROOT}) #--------------EnTT------------------------------ add_subdirectory(${ENTT_ROOT}) -#--------------FreeType------------------------------ -add_subdirectory(${FREETYPE_ROOT}) - #--------------STB----------------------------------- add_library(stb INTERFACE) @@ -92,3 +92,4 @@ target_include_directories(slang INTERFACE ${SLANG_ROOT}) target_link_libraries(slang INTERFACE ${SLANG_BINARY_DIR}/*.lib) set_target_properties(slang PROPERTIES SLANG_BINARY ${SLANG_BINARY_DIR}/slang.dll) set_target_properties(slang PROPERTIES GLSLANG_BINARY ${SLANG_BINARY_DIR}/slang-glslang.dll) + diff --git a/res/shaders/ComputeFrustums.slang b/res/shaders/ComputeFrustums.slang index 108210a..3e77098 100644 --- a/res/shaders/ComputeFrustums.slang +++ b/res/shaders/ComputeFrustums.slang @@ -38,7 +38,7 @@ void computeFrustums(ComputeShaderInput in) for(int i = 0; i < 4; i++) { - viewSpace[i] = screenToView(screenSpace[i]).xyz; + viewSpace[i] = screenToClip(screenSpace[i]).xyz; } //Compute frustum diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index f63c116..a5b1eb4 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -105,9 +105,9 @@ void cullLights(ComputeShaderInput in) float fMinDepth = asfloat(uMinDepth); float fMaxDepth = asfloat(uMaxDepth); - float minDepthVS = clipToView(float4(0, 0, fMinDepth, 1)).z; - float maxDepthVS = clipToView(float4(0, 0, fMaxDepth, 1)).z; - float nearClipVS = clipToView(float4(0, 0, 0, 1.0f)).z; + float minDepthVS = fMinDepth; + float maxDepthVS = fMaxDepth; + float nearClipVS = 0.1f; Plane minPlane = {float3(0, 0, -1), -minDepthVS}; diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 4f7244e..728af98 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -6,34 +6,21 @@ struct ViewParameter { float4x4 viewMatrix; float4x4 projectionMatrix; - float4x4 inverseProjection; float4 cameraPos_WS; float2 screenDimensions; } layout(set = INDEX_VIEW_PARAMS, binding = 0, std430) ConstantBuffer gViewParams; -// Convert clip space coordinates to view space -float4 clipToView( float4 clip ) -{ - // View space position. - float4 view = mul( gViewParams.inverseProjection, clip ); - // Perspective projection. - view = view / view.w; - - return view; -} // Convert screen space coordinates to view space. -float4 screenToView( float4 screen ) +float4 screenToClip( float4 screen ) { // Convert to normalized texture coordinates float2 texCoord = screen.xy / gViewParams.screenDimensions; - // Convert to clip space - float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); - - return clipToView( clip ); + // Convert to clip space + return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); } struct Plane diff --git a/src/Editor/CMakeLists.txt b/src/Editor/CMakeLists.txt index a36935f..19b1540 100644 --- a/src/Editor/CMakeLists.txt +++ b/src/Editor/CMakeLists.txt @@ -1,3 +1,6 @@ +add_subdirectory(System/) +add_subdirectory(Window/) + target_sources(Editor PRIVATE main.cpp) \ No newline at end of file diff --git a/src/Editor/Component/CMakeLists.txt b/src/Editor/Component/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/Editor/System/CMakeLists.txt b/src/Editor/System/CMakeLists.txt new file mode 100644 index 0000000..7e54b38 --- /dev/null +++ b/src/Editor/System/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(Editor + PRIVATE) \ No newline at end of file diff --git a/src/Editor/Window/CMakeLists.txt b/src/Editor/Window/CMakeLists.txt new file mode 100644 index 0000000..5e99fb0 --- /dev/null +++ b/src/Editor/Window/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(Editor + PRIVATE + InspectorView.h + InspectorView.cpp + SceneView.h + SceneView.cpp + ViewportControl.h + ViewportControl.cpp) \ No newline at end of file diff --git a/src/Engine/Window/InspectorView.cpp b/src/Editor/Window/InspectorView.cpp similarity index 57% rename from src/Engine/Window/InspectorView.cpp rename to src/Editor/Window/InspectorView.cpp index 724b7c5..be771e6 100644 --- a/src/Engine/Window/InspectorView.cpp +++ b/src/Editor/Window/InspectorView.cpp @@ -1,7 +1,7 @@ #include "InspectorView.h" #include "Graphics/Graphics.h" -#include "Scene/Actor/Actor.h" -#include "Window.h" +#include "Actor/Actor.h" +#include "Window/Window.h" #include "Asset/AssetRegistry.h" #include "UI/System.h" @@ -9,18 +9,15 @@ using namespace Seele; InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo) : View(graphics, window, createInfo, "InspectorView") - , uiPass(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle()))) - , textPass(TextPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle()))) + , renderGraph(RenderGraphBuilder::build( + UIPass(graphics), + TextPass(graphics) + )) , uiSystem(new UI::System()) { AssetRegistry::importFile("./fonts/Calibri.ttf"); - PRenderGraphResources resources = new RenderGraphResources(); - uiPass.setResources(resources); - textPass.setResources(resources); - uiPass.publishOutputs(); - textPass.publishOutputs(); - uiPass.createRenderPass(); - textPass.createRenderPass(); + renderGraph.updateViewport(viewport); + uiSystem->updateViewport(viewport); } InspectorView::~InspectorView() @@ -43,18 +40,15 @@ void InspectorView::commitUpdate() void InspectorView::prepareRender() { - uiPass.updateViewFrame(uiSystem->getUIPassData()); - textPass.updateViewFrame(uiSystem->getTextPassData()); + renderGraph.updatePassData( + uiSystem->getUIPassData(), + uiSystem->getTextPassData() + ); } void InspectorView::render() { - uiPass.beginFrame(); - textPass.beginFrame(); - uiPass.render(); - textPass.render(); - uiPass.endFrame(); - textPass.endFrame(); + renderGraph.render(uiSystem->getVirtualCamera()); } void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) diff --git a/src/Engine/Window/InspectorView.h b/src/Editor/Window/InspectorView.h similarity index 93% rename from src/Engine/Window/InspectorView.h rename to src/Editor/Window/InspectorView.h index 31a5b9f..9b16af9 100644 --- a/src/Engine/Window/InspectorView.h +++ b/src/Editor/Window/InspectorView.h @@ -1,5 +1,5 @@ #pragma once -#include "View.h" +#include "Window/View.h" #include "Graphics/RenderPass/RenderGraph.h" #include "Graphics/RenderPass/UIPass.h" #include "Graphics/RenderPass/TextPass.h" @@ -22,8 +22,9 @@ public: virtual void render() override; void selectActor(); protected: - UIPass uiPass; - TextPass textPass; + RenderGraph< + UIPass, + TextPass> renderGraph; UIPassData uiPassData; TextPassData textPassData; diff --git a/src/Editor/Window/SceneView.cpp b/src/Editor/Window/SceneView.cpp new file mode 100644 index 0000000..eaf6b02 --- /dev/null +++ b/src/Editor/Window/SceneView.cpp @@ -0,0 +1,108 @@ +#include "SceneView.h" +#include "Scene/Scene.h" +#include "Window/Window.h" +#include "Graphics/Mesh.h" +#include "Graphics/Graphics.h" +#include "Asset/MeshAsset.h" +#include "Asset/AssetRegistry.h" +#include "Actor/CameraActor.h" +#include "Component/Camera.h" +#include "Component/StaticMesh.h" + +using namespace Seele; +using namespace Seele::Editor; + +SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo) + : View(graphics, owner, createInfo, "SceneView") + , scene(new Scene(graphics)) + , renderGraph(RenderGraphBuilder::build( + DepthPrepass(graphics), + LightCullingPass(graphics), + BasePass(graphics) + )) + , cameraSystem(createInfo.dimensions, Math::Vector(0, 0, 10)) +{ + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png"); + AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Ayaka.fbx"); + auto meshAsset = AssetRegistry::findMesh("Ayaka"); + for(auto mesh : meshAsset->getMeshes()) + { + PActor actor = new Actor(scene); + actor->attachComponent(mesh->vertexInput, mesh->indexBuffer, mesh->referencedMaterial); + } + + //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx"); + //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj"); + AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx"); + + cameraSystem.update(viewportCamera, static_cast(Gfx::currentFrameDelta)); + + renderGraph.updateViewport(viewport); +} + +SceneView::~SceneView() +{ +} + +void SceneView::beginUpdate() +{ + scene->beginUpdate(Gfx::currentFrameDelta); + //co_return; +} + +void SceneView::update() +{ + cameraSystem.update(viewportCamera, static_cast(Gfx::currentFrameDelta)); + scene->commitUpdate(); + //co_return; +} + +void SceneView::commitUpdate() +{ + depthPrepassData.staticDrawList = scene->getStaticMeshes(); + lightCullingPassData.lightEnv = scene->getLightBuffer(); + basePassData.staticDrawList = scene->getStaticMeshes(); +} + +void SceneView::prepareRender() +{ + renderGraph.updatePassData(depthPrepassData, lightCullingPassData, basePassData); +} + +void SceneView::render() +{ + renderGraph.render(viewportCamera); +} + +static float cameraSpeed = 1; + +void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier) +{ + cameraSystem.keyCallback(code, action); +} + +static bool mouseDown = false; + +void SceneView::mouseMoveCallback(double xPos, double yPos) +{ + cameraSystem.mouseMoveCallback(xPos, yPos); +} + +void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier) +{ + cameraSystem.mouseButtonCallback(button, action); +} + +void SceneView::scrollCallback(double, double) +{ +} + +void SceneView::fileCallback(int, const char**) +{ + +} diff --git a/src/Engine/Window/SceneView.h b/src/Editor/Window/SceneView.h similarity index 83% rename from src/Engine/Window/SceneView.h rename to src/Editor/Window/SceneView.h index acd4380..7f49d83 100644 --- a/src/Engine/Window/SceneView.h +++ b/src/Editor/Window/SceneView.h @@ -1,20 +1,23 @@ #pragma once #include -#include "View.h" +#include "Window/View.h" #include "Graphics/RenderPass/DepthPrepass.h" #include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/BasePass.h" -#include "Scene/System/CameraSystem.h" +#include "ViewportControl.h" + namespace Seele { DECLARE_REF(Scene) -DECLARE_REF(CameraActor) +namespace Editor +{ class SceneView : public View { public: SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo); ~SceneView(); + virtual void beginUpdate() override; virtual void update() override; virtual void commitUpdate() override; @@ -25,18 +28,19 @@ public: PScene getScene() const { return scene; } private: PScene scene; - PCameraActor activeCamera; + Component::Camera viewportCamera; - DepthPrepass depthPrepass; - LightCullingPass lightCullingPass; - BasePass basePass; + RenderGraph< + DepthPrepass, + LightCullingPass, + BasePass> renderGraph; DepthPrepassData depthPrepassData; LightCullingPassData lightCullingPassData; BasePassData basePassData; dp::thread_pool<> pool; - System::CameraSystem cameraSystem; + ViewportControl cameraSystem; virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override; virtual void mouseMoveCallback(double xPos, double yPos) override; @@ -45,4 +49,5 @@ private: virtual void fileCallback(int count, const char** paths) override; }; DEFINE_REF(SceneView) +} // namespace Editor } // namespace Seele \ No newline at end of file diff --git a/src/Editor/Window/ViewportControl.cpp b/src/Editor/Window/ViewportControl.cpp new file mode 100644 index 0000000..a64582c --- /dev/null +++ b/src/Editor/Window/ViewportControl.cpp @@ -0,0 +1,102 @@ +#include "ViewportControl.h" +#include "Component/Camera.h" + +using namespace Seele; + +ViewportControl::ViewportControl(const Math::URect& viewportDimensions, Math::Vector initialPos) + : position(initialPos) + , fieldOfView(glm::radians(70.f)) + , aspectRatio(static_cast(viewportDimensions.size.x) / viewportDimensions.size.y) + , yaw(glm::pi()/-2.0f) + , pitch(0) +{ + std::cout << yaw << " " << pitch << std::endl; +} + +ViewportControl::~ViewportControl() +{ + +} + +void ViewportControl::update(Component::Camera& camera, float deltaTime) +{ + float cameraMove = deltaTime * 20; + if(keys[KeyCode::KEY_LEFT_SHIFT]) + { + cameraMove *= 4; + } + Math::Vector moveVector = Math::Vector(); + Math::Vector forward = glm::normalize(springArm); + Math::Vector side = glm::cross(Math::Vector(0, 1, 0), forward); + if(keys[KeyCode::KEY_W]) + { + moveVector += forward * cameraMove; + } + if(keys[KeyCode::KEY_S]) + { + moveVector += forward * -cameraMove; + } + if(keys[KeyCode::KEY_A]) + { + moveVector += side * cameraMove; + } + if(keys[KeyCode::KEY_D]) + { + moveVector += side * -cameraMove; + } + if(keys[KeyCode::KEY_E]) + { + moveVector += glm::vec3(0, cameraMove, 0); + } + if(keys[KeyCode::KEY_Q]) + { + moveVector += glm::vec3(0, -cameraMove, 0); + } + position += moveVector; + static float lastX, lastY; + if(mouse2) + { + float deltaX = mouseX - lastX; + float deltaY = mouseY - lastY; + yaw += deltaX / 500.f; + pitch -= deltaY / 500.f; + } + lastX = mouseX; + lastY = mouseY; + springArm = glm::normalize( + Math::Vector( + cos(yaw) * cos(pitch), + sin(pitch), + sin(yaw) * cos(pitch))); + camera.viewMatrix = glm::lookAt(position, position + springArm, Math::Vector(0, 1, 0)); + camera.projectionMatrix = glm::perspective(fieldOfView, aspectRatio, 0.1f, 1000.0f); + std::cout << yaw << " " << pitch << std::endl; +} + +void ViewportControl::keyCallback(KeyCode key, InputAction action) +{ + keys[static_cast(key)] = action != InputAction::RELEASE; +} + +void ViewportControl::mouseMoveCallback(double xPos, double yPos) +{ + mouseX = static_cast(xPos); + mouseY = static_cast(yPos); +} + +void ViewportControl::mouseButtonCallback(MouseButton button, InputAction action) +{ + if(button == MouseButton::MOUSE_BUTTON_1) + { + mouse1 = action != InputAction::RELEASE; + } + if(button == MouseButton::MOUSE_BUTTON_2) + { + mouse2 = action != InputAction::RELEASE; + } +} + +void ViewportControl::viewportResize(Math::URect dimensions) +{ + aspectRatio = static_cast(dimensions.size.x) / dimensions.size.y; +} diff --git a/src/Editor/Window/ViewportControl.h b/src/Editor/Window/ViewportControl.h new file mode 100644 index 0000000..248dc33 --- /dev/null +++ b/src/Editor/Window/ViewportControl.h @@ -0,0 +1,31 @@ +#pragma once +#include "MinimalEngine.h" +#include "Math/Vector.h" +#include "Component/Camera.h" + +namespace Seele +{ +class ViewportControl +{ +public: + ViewportControl(const Math::URect& viewportDimensions, Math::Vector initialPos /*TODO: configurable initial rotations*/); + ~ViewportControl(); + void update(Component::Camera& camera, float deltaTime); + void keyCallback(KeyCode key, InputAction action); + void mouseMoveCallback(double xPos, double yPos); + void mouseButtonCallback(MouseButton button, InputAction action); + void viewportResize(Math::URect dimensions); +private: + Math::Vector position; + Math::Vector springArm; + float fieldOfView; + float aspectRatio; + StaticArray(KeyCode::KEY_LAST)> keys; + bool mouse1 = false; + bool mouse2 = false; + float mouseX; + float mouseY; + float pitch; + float yaw; +}; +} // namespace Seele diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 089732e..f9fcfd5 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -4,6 +4,7 @@ #include "Asset/AssetRegistry.h" using namespace Seele; +using namespace Seele::Editor; int main() { @@ -18,20 +19,20 @@ int main() mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM; auto window = windowManager->addWindow(mainWindowInfo); ViewportCreateInfo sceneViewInfo; - sceneViewInfo.sizeX = 640; - sceneViewInfo.sizeY = 720; - sceneViewInfo.offsetX = 0; - sceneViewInfo.offsetY = 0; + sceneViewInfo.dimensions.size.x = 1280; + sceneViewInfo.dimensions.size.y = 720; + sceneViewInfo.dimensions.offset.x = 0; + sceneViewInfo.dimensions.offset.y = 0; PSceneView sceneView = new SceneView(windowManager->getGraphics(), window, sceneViewInfo); window->addView(sceneView); ViewportCreateInfo inspectorViewInfo; - inspectorViewInfo.sizeX = 640; - inspectorViewInfo.sizeY = 720; - inspectorViewInfo.offsetX = 640; - inspectorViewInfo.offsetY = 0; + inspectorViewInfo.dimensions.size.x = 640; + inspectorViewInfo.dimensions.size.y = 720; + inspectorViewInfo.dimensions.offset.x = 640; + inspectorViewInfo.dimensions.offset.y = 0; PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo); - window->addView(inspectorView); + //window->addView(inspectorView); sceneView->setFocused(); window->render(); diff --git a/src/Engine/Scene/Actor/Actor.cpp b/src/Engine/Actor/Actor.cpp similarity index 100% rename from src/Engine/Scene/Actor/Actor.cpp rename to src/Engine/Actor/Actor.cpp diff --git a/src/Engine/Scene/Actor/Actor.h b/src/Engine/Actor/Actor.h similarity index 94% rename from src/Engine/Scene/Actor/Actor.h rename to src/Engine/Actor/Actor.h index cb18bf0..47ef8c0 100644 --- a/src/Engine/Scene/Actor/Actor.h +++ b/src/Engine/Actor/Actor.h @@ -1,6 +1,6 @@ #pragma once #include "Entity.h" -#include "Scene/Component/Transform.h" +#include "Component/Transform.h" namespace Seele { diff --git a/src/Engine/Scene/Actor/CMakeLists.txt b/src/Engine/Actor/CMakeLists.txt similarity index 92% rename from src/Engine/Scene/Actor/CMakeLists.txt rename to src/Engine/Actor/CMakeLists.txt index 6946cd4..9a82d7c 100644 --- a/src/Engine/Scene/Actor/CMakeLists.txt +++ b/src/Engine/Actor/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Actor.cpp Actor.h CameraActor.cpp diff --git a/src/Engine/Scene/Actor/CameraActor.cpp b/src/Engine/Actor/CameraActor.cpp similarity index 100% rename from src/Engine/Scene/Actor/CameraActor.cpp rename to src/Engine/Actor/CameraActor.cpp diff --git a/src/Engine/Scene/Actor/CameraActor.h b/src/Engine/Actor/CameraActor.h similarity index 89% rename from src/Engine/Scene/Actor/CameraActor.h rename to src/Engine/Actor/CameraActor.h index 7cd1e9a..fa51458 100644 --- a/src/Engine/Scene/Actor/CameraActor.h +++ b/src/Engine/Actor/CameraActor.h @@ -1,6 +1,6 @@ #pragma once #include "Actor.h" -#include "Scene/Component/Camera.h" +#include "Component/Camera.h" namespace Seele { diff --git a/src/Engine/Scene/Actor/Entity.cpp b/src/Engine/Actor/Entity.cpp similarity index 100% rename from src/Engine/Scene/Actor/Entity.cpp rename to src/Engine/Actor/Entity.cpp diff --git a/src/Engine/Scene/Actor/Entity.h b/src/Engine/Actor/Entity.h similarity index 100% rename from src/Engine/Scene/Actor/Entity.h rename to src/Engine/Actor/Entity.h diff --git a/src/Engine/Asset/CMakeLists.txt b/src/Engine/Asset/CMakeLists.txt index 8587ce2..2e3e90a 100644 --- a/src/Engine/Asset/CMakeLists.txt +++ b/src/Engine/Asset/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Asset.h Asset.cpp AssetRegistry.h diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index 123e9e7..a92b50b 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -1,14 +1,17 @@ target_sources(Engine - PUBLIC + PRIVATE EngineTypes.h MinimalEngine.h MinimalEngine.cpp) +add_subdirectory(Actor/) add_subdirectory(Asset/) +add_subdirectory(Component/) add_subdirectory(Containers/) add_subdirectory(Graphics/) add_subdirectory(Material/) add_subdirectory(Math/) add_subdirectory(Scene/) +add_subdirectory(System/) add_subdirectory(UI/) add_subdirectory(Window/) diff --git a/src/Engine/Scene/Component/CMakeLists.txt b/src/Engine/Component/CMakeLists.txt similarity index 91% rename from src/Engine/Scene/Component/CMakeLists.txt rename to src/Engine/Component/CMakeLists.txt index 0d183a6..cc1f3e0 100644 --- a/src/Engine/Scene/Component/CMakeLists.txt +++ b/src/Engine/Component/CMakeLists.txt @@ -1,8 +1,8 @@ target_sources(Engine - PUBLIC - Component.h + PRIVATE Camera.h Camera.cpp + Component.h StaticMesh.h Transform.h Transform.cpp) \ No newline at end of file diff --git a/src/Engine/Scene/Component/Camera.cpp b/src/Engine/Component/Camera.cpp similarity index 91% rename from src/Engine/Scene/Component/Camera.cpp rename to src/Engine/Component/Camera.cpp index a70b60f..79b2c73 100644 --- a/src/Engine/Scene/Component/Camera.cpp +++ b/src/Engine/Component/Camera.cpp @@ -1,5 +1,5 @@ #include "Camera.h" -#include "Scene/Actor/Actor.h" +#include "Actor/Actor.h" #include #include @@ -10,8 +10,8 @@ using namespace Seele::Math; Camera::Camera() : aspectRatio(0) , fieldOfView(glm::radians(70.f)) - , bNeedsViewBuild(true) - , bNeedsProjectionBuild(true) + , bNeedsViewBuild(false) + , bNeedsProjectionBuild(false) , viewMatrix(Matrix4()) , projectionMatrix(Matrix4()) { @@ -65,7 +65,7 @@ void Camera::setViewport(Gfx::PViewport newViewport) void Camera::buildViewMatrix() { Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition(); - Vector lookAt = Vector(0, 0, 0);//eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch))); + Vector lookAt = eyePos + glm::normalize(Vector(cos(yaw) * cos(pitch), sin(pitch), sin(yaw) * cos(pitch))); //std::cout << "Eye: " << eyePos << " lookAt: " << lookAt << std::endl; viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0)); diff --git a/src/Engine/Scene/Component/Camera.h b/src/Engine/Component/Camera.h similarity index 85% rename from src/Engine/Scene/Component/Camera.h rename to src/Engine/Component/Camera.h index d139dc6..12bad72 100644 --- a/src/Engine/Scene/Component/Camera.h +++ b/src/Engine/Component/Camera.h @@ -15,19 +15,19 @@ struct Camera Camera(); ~Camera(); - Math::Matrix4 getViewMatrix() + Math::Matrix4 getViewMatrix() const { assert (!bNeedsViewBuild); return viewMatrix; } - Math::Matrix4 getProjectionMatrix() + Math::Matrix4 getProjectionMatrix() const { assert (!bNeedsProjectionBuild); return projectionMatrix; } - Math::Vector getCameraPosition() + Math::Vector getCameraPosition() const { - return getTransform().getPosition(); + return Math::Vector(viewMatrix[3]); } void setViewport(Gfx::PViewport viewport); void mouseMove(float deltaX, float deltaY); @@ -38,6 +38,8 @@ struct Camera float fieldOfView; void buildViewMatrix(); void buildProjectionMatrix(); + Math::Matrix4 viewMatrix; + Math::Matrix4 projectionMatrix; private: bool bNeedsViewBuild; bool bNeedsProjectionBuild; @@ -45,8 +47,6 @@ private: Gfx::PViewport viewport; //Transforms relative to actor - Math::Matrix4 viewMatrix; - Math::Matrix4 projectionMatrix; float yaw; float pitch; }; diff --git a/src/Engine/Scene/Component/Component.h b/src/Engine/Component/Component.h similarity index 100% rename from src/Engine/Scene/Component/Component.h rename to src/Engine/Component/Component.h diff --git a/src/Engine/Scene/Component/StaticMesh.h b/src/Engine/Component/StaticMesh.h similarity index 100% rename from src/Engine/Scene/Component/StaticMesh.h rename to src/Engine/Component/StaticMesh.h diff --git a/src/Engine/Scene/Component/Transform.cpp b/src/Engine/Component/Transform.cpp similarity index 100% rename from src/Engine/Scene/Component/Transform.cpp rename to src/Engine/Component/Transform.cpp diff --git a/src/Engine/Scene/Component/Transform.h b/src/Engine/Component/Transform.h similarity index 100% rename from src/Engine/Scene/Component/Transform.h rename to src/Engine/Component/Transform.h diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 38488b5..730299b 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -705,6 +705,16 @@ public: { return _data; } + template + constexpr reference operator[](I index) noexcept + { + return operator[](static_cast(index)); + } + template + constexpr const_reference operator[](I index) const noexcept + { + return operator[](static_cast(index)); + } constexpr reference operator[](size_type index) noexcept { assert(index < N); diff --git a/src/Engine/Containers/CMakeLists.txt b/src/Engine/Containers/CMakeLists.txt index 8c79012..9e81f08 100644 --- a/src/Engine/Containers/CMakeLists.txt +++ b/src/Engine/Containers/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Array.h Map.h List.h) \ No newline at end of file diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index 3f896c4..608fc3b 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE GraphicsResources.h GraphicsResources.cpp GraphicsInitializer.h diff --git a/src/Engine/Graphics/GraphicsEnums.h b/src/Engine/Graphics/GraphicsEnums.h index 89f1c88..77ecf02 100644 --- a/src/Engine/Graphics/GraphicsEnums.h +++ b/src/Engine/Graphics/GraphicsEnums.h @@ -3,7 +3,7 @@ namespace Seele { -enum class KeyCode +enum class KeyCode : size_t { /* Printable keys */ KEY_SPACE = 32, @@ -127,6 +127,7 @@ enum class KeyCode KEY_RIGHT_ALT = 346, KEY_RIGHT_SUPER = 347, KEY_MENU = 348, + KEY_LAST = KEY_MENU }; enum class MouseButton diff --git a/src/Engine/Graphics/GraphicsInitializer.h b/src/Engine/Graphics/GraphicsInitializer.h index 859fab7..0c41c5a 100644 --- a/src/Engine/Graphics/GraphicsInitializer.h +++ b/src/Engine/Graphics/GraphicsInitializer.h @@ -42,10 +42,7 @@ struct WindowCreateInfo }; struct ViewportCreateInfo { - uint32 sizeX; - uint32 sizeY; - uint32 offsetX; - uint32 offsetY; + Math::URect dimensions; }; // doesnt own the data, only proxy it struct BulkResourceData @@ -235,6 +232,11 @@ struct GraphicsPipelineCreateInfo colorBlend.blendConstants[1] = 1.0f; colorBlend.blendConstants[2] = 1.0f; colorBlend.blendConstants[3] = 1.0f; + colorBlend.blendAttachments[0].colorWriteMask = + Gfx::SE_COLOR_COMPONENT_R_BIT | + Gfx::SE_COLOR_COMPONENT_G_BIT | + Gfx::SE_COLOR_COMPONENT_B_BIT | + Gfx::SE_COLOR_COMPONENT_A_BIT; } }; struct ComputePipelineCreateInfo diff --git a/src/Engine/Graphics/GraphicsResources.cpp b/src/Engine/Graphics/GraphicsResources.cpp index e63a7c0..e26d96f 100644 --- a/src/Engine/Graphics/GraphicsResources.cpp +++ b/src/Engine/Graphics/GraphicsResources.cpp @@ -504,10 +504,10 @@ Window::~Window() } Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo) - : sizeX(viewportInfo.sizeX) - , sizeY(viewportInfo.sizeY) - , offsetX(viewportInfo.offsetX) - , offsetY(viewportInfo.offsetY) + : sizeX(viewportInfo.dimensions.size.x) + , sizeY(viewportInfo.dimensions.size.y) + , offsetX(viewportInfo.dimensions.offset.x) + , offsetY(viewportInfo.dimensions.offset.y) , owner(owner) { } diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 3d5b5c4..b86494c 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -1,17 +1,16 @@ #include "BasePass.h" #include "Graphics/Graphics.h" #include "Window/Window.h" -#include "Scene/Component/Camera.h" -#include "Scene/Actor/CameraActor.h" +#include "Component/Camera.h" +#include "Actor/CameraActor.h" #include "Math/Vector.h" #include "RenderGraph.h" #include "Material/MaterialAsset.h" using namespace Seele; -BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass) +BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass) : MeshProcessor(graphics) - , target(viewport) , translucentBasePass(translucentBasePass) //, cachedPrimitiveIndex(0) { @@ -23,8 +22,8 @@ BasePassMeshProcessor::~BasePassMeshProcessor() void BasePassMeshProcessor::processMeshBatch( const MeshBatch& batch, -// const PPrimitiveComponent primitiveComponent, - const Gfx::PRenderPass& renderPass, + Gfx::PViewport target, + Gfx::PRenderPass renderPass, Gfx::PPipelineLayout baseLayout, Gfx::PDescriptorLayout primitiveLayout, Array descriptorSets, @@ -70,11 +69,10 @@ void BasePassMeshProcessor::processMeshBatch( //co_return; } -BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) - : RenderPass(graphics, viewport) - , processor(new BasePassMeshProcessor(viewport, graphics, false)) +BasePass::BasePass(Gfx::PGraphics graphics) + : RenderPass(graphics) + , processor(new BasePassMeshProcessor(graphics, false)) , descriptorSets(4) - , source(source) { UniformBufferCreateInfo uniformInitializer; basePassLayout = graphics->createPipelineLayout(); @@ -115,16 +113,15 @@ BasePass::~BasePass() { } -void BasePass::beginFrame() +void BasePass::beginFrame(const Component::Camera& cam) { processor->clearCommands(); primitiveLayout->reset(); BulkResourceData uniformUpdate; - viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); - viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); - viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); - viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix); + viewParams.viewMatrix = cam.getViewMatrix(); + viewParams.projectionMatrix = cam.getProjectionMatrix(); + viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0); viewParams.screenDimensions = Math::Vector2(static_cast(viewport->getSizeX()), static_cast(viewport->getSizeY())); uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.data = (uint8*)&viewParams; @@ -158,7 +155,7 @@ void BasePass::render() graphics->beginRenderPass(renderPass); for (auto &&meshBatch : passData.staticDrawList) { - processor->processMeshBatch(meshBatch, renderPass, basePassLayout, primitiveLayout, descriptorSets); + processor->processMeshBatch(meshBatch, viewport, renderPass, basePassLayout, primitiveLayout, descriptorSets); } graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); @@ -186,6 +183,8 @@ void BasePass::createRenderPass() numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS"); Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; + colorAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR; + colorAttachment->storeOp = Gfx::SE_ATTACHMENT_STORE_OP_STORE; Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment); renderPass = graphics->createRenderPass(layout, viewport); oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST"); diff --git a/src/Engine/Graphics/RenderPass/BasePass.h b/src/Engine/Graphics/RenderPass/BasePass.h index bd185c5..3e55441 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.h +++ b/src/Engine/Graphics/RenderPass/BasePass.h @@ -8,13 +8,13 @@ namespace Seele class BasePassMeshProcessor : public MeshProcessor { public: - BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass); + BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass); virtual ~BasePassMeshProcessor(); virtual void processMeshBatch( const MeshBatch& batch, -// const PPrimitiveComponent primitiveComponent, - const Gfx::PRenderPass& renderPass, + Gfx::PViewport target, + Gfx::PRenderPass renderPass, Gfx::PPipelineLayout pipelineLayout, Gfx::PDescriptorLayout primitiveLayout, Array descriptorSets, @@ -34,9 +34,11 @@ struct BasePassData class BasePass : public RenderPass { public: - BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); + BasePass(Gfx::PGraphics graphics); + BasePass(BasePass&& other) = default; virtual ~BasePass(); - virtual void beginFrame() override; + BasePass& operator=(BasePass&& other) = default; + virtual void beginFrame(const Component::Camera& cam) override; virtual void render() override; virtual void endFrame() override; virtual void publishOutputs() override; diff --git a/src/Engine/Graphics/RenderPass/CMakeLists.txt b/src/Engine/Graphics/RenderPass/CMakeLists.txt index c6172d9..e1d4094 100644 --- a/src/Engine/Graphics/RenderPass/CMakeLists.txt +++ b/src/Engine/Graphics/RenderPass/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE BasePass.h BasePass.cpp DepthPrepass.h @@ -9,7 +9,8 @@ target_sources(Engine MeshProcessor.h MeshProcessor.cpp RenderGraph.h - RenderGraph.cpp + RenderGraphResources.h + RenderGraphResources.cpp RenderPass.h TextPass.h TextPass.cpp diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index c8a42fb..06bb5ef 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -1,17 +1,16 @@ #include "DepthPrepass.h" #include "Graphics/Graphics.h" #include "Window/Window.h" -#include "Scene/Component/Camera.h" -#include "Scene/Actor/CameraActor.h" +#include "Component/Camera.h" +#include "Actor/CameraActor.h" #include "Math/Vector.h" #include "RenderGraph.h" #include "Material/MaterialAsset.h" using namespace Seele; -DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics) +DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PGraphics graphics) : MeshProcessor(graphics) - , target(viewport) { } @@ -21,8 +20,8 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor() void DepthPrepassMeshProcessor::processMeshBatch( const MeshBatch& batch, -// const PPrimitiveComponent primitiveComponent, - const Gfx::PRenderPass& renderPass, + Gfx::PViewport target, + Gfx::PRenderPass renderPass, Gfx::PPipelineLayout baseLayout, Gfx::PDescriptorLayout primitiveLayout, Array descriptorSets, @@ -69,11 +68,10 @@ void DepthPrepassMeshProcessor::processMeshBatch( //co_return; } -DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) - : RenderPass(graphics, viewport) - , processor(new DepthPrepassMeshProcessor(viewport, graphics)) +DepthPrepass::DepthPrepass(Gfx::PGraphics graphics) + : RenderPass(graphics) + , processor(new DepthPrepassMeshProcessor(graphics)) , descriptorSets(3) - , source(source) { UniformBufferCreateInfo uniformInitializer; @@ -98,16 +96,15 @@ DepthPrepass::~DepthPrepass() { } -void DepthPrepass::beginFrame() +void DepthPrepass::beginFrame(const Component::Camera& cam) { processor->clearCommands(); primitiveLayout->reset(); BulkResourceData uniformUpdate; - viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); - viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); - viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); - viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix); + viewParams.viewMatrix = cam.getViewMatrix(); + viewParams.projectionMatrix = cam.getProjectionMatrix(); + viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0); viewParams.screenDimensions = Math::Vector2(static_cast(viewport->getSizeX()), static_cast(viewport->getSizeY())); uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.data = (uint8*)&viewParams; @@ -129,7 +126,7 @@ void DepthPrepass::render() graphics->beginRenderPass(renderPass); for (auto &&meshBatch : passData.staticDrawList) { - processor->processMeshBatch(meshBatch, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets); + processor->processMeshBatch(meshBatch, viewport, renderPass, depthPrepassLayout, primitiveLayout, descriptorSets); } graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.h b/src/Engine/Graphics/RenderPass/DepthPrepass.h index 76b9a7f..d597a69 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.h +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.h @@ -8,22 +8,21 @@ namespace Seele class DepthPrepassMeshProcessor : public MeshProcessor { public: - DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics); + DepthPrepassMeshProcessor(Gfx::PGraphics graphics); virtual ~DepthPrepassMeshProcessor(); virtual void processMeshBatch( const MeshBatch& batch, - const Gfx::PRenderPass& renderPass, + Gfx::PViewport target, + Gfx::PRenderPass renderPass, Gfx::PPipelineLayout pipelineLayout, Gfx::PDescriptorLayout primitiveLayout, Array descriptorSets, int32 staticMeshId = -1) override; private: - Gfx::PViewport target; }; DEFINE_REF(DepthPrepassMeshProcessor) -DECLARE_REF(CameraActor) struct DepthPrepassData { Array staticDrawList; @@ -31,9 +30,11 @@ struct DepthPrepassData class DepthPrepass : public RenderPass { public: - DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); + DepthPrepass(Gfx::PGraphics graphics); + DepthPrepass(DepthPrepass&& other) = default; ~DepthPrepass(); - virtual void beginFrame() override; + DepthPrepass& operator=(DepthPrepass& other) = default; + virtual void beginFrame(const Component::Camera& cam) override; virtual void render() override; virtual void endFrame() override; virtual void publishOutputs() override; @@ -45,7 +46,6 @@ private: UPDepthPrepassMeshProcessor processor; Array descriptorSets; - PCameraActor source; Gfx::PPipelineLayout depthPrepassLayout; // Set 0: viewParameter static constexpr uint32 INDEX_VIEW_PARAMS = 0; diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index 510418f..275bdd2 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -1,15 +1,14 @@ #include "LightCullingPass.h" #include "Graphics/Graphics.h" #include "Scene/Scene.h" -#include "Scene/Actor/CameraActor.h" -#include "Scene/Component/Camera.h" +#include "Actor/CameraActor.h" +#include "Component/Camera.h" #include "RenderGraph.h" using namespace Seele; -LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera) - : RenderPass(graphics, viewport) - , source(camera) +LightCullingPass::LightCullingPass(Gfx::PGraphics graphics) + : RenderPass(graphics) { } @@ -18,16 +17,15 @@ LightCullingPass::~LightCullingPass() } -void LightCullingPass::beginFrame() +void LightCullingPass::beginFrame(const Component::Camera& cam) { uint32_t viewportWidth = viewport->getSizeX(); uint32_t viewportHeight = viewport->getSizeY(); BulkResourceData uniformUpdate; - viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); - viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); - viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); - viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix); + viewParams.viewMatrix = cam.getViewMatrix(); + viewParams.projectionMatrix = cam.getProjectionMatrix(); + viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0); viewParams.screenDimensions = Math::Vector2(static_cast(viewportWidth), static_cast(viewportHeight)); uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.data = (uint8*)&viewParams; @@ -263,10 +261,9 @@ void LightCullingPass::setupFrustums() glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1)); viewParams = { - .viewMatrix = source->getCameraComponent().getViewMatrix(), - .projectionMatrix = source->getCameraComponent().getProjectionMatrix(), - .inverseProjectionMatrix = glm::inverse(source->getCameraComponent().getProjectionMatrix()), - .cameraPosition = Math::Vector4(source->getTransform().getPosition(), 0), + .viewMatrix = Math::Matrix4(), + .projectionMatrix = Math::Matrix4(), + .cameraPosition = Math::Vector4(), .screenDimensions = glm::vec2(viewportWidth, viewportHeight), }; dispatchParams.numThreads = numThreads; diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index 0295f9b..03801ab 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -15,9 +15,9 @@ struct LightCullingPassData class LightCullingPass : public RenderPass { public: - LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera); + LightCullingPass(Gfx::PGraphics graphics); virtual ~LightCullingPass(); - virtual void beginFrame() override; + virtual void beginFrame(const Component::Camera& cam) override; virtual void render() override; virtual void endFrame() override; virtual void publishOutputs() override; @@ -71,7 +71,6 @@ private: Gfx::PComputeShader cullingShader; Gfx::PPipelineLayout cullingLayout; Gfx::PComputePipeline cullingPipeline; - PCameraActor source; }; DEFINE_REF(LightCullingPass) } // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/MeshProcessor.h b/src/Engine/Graphics/RenderPass/MeshProcessor.h index 2dd18f4..041b76c 100644 --- a/src/Engine/Graphics/RenderPass/MeshProcessor.h +++ b/src/Engine/Graphics/RenderPass/MeshProcessor.h @@ -18,8 +18,8 @@ protected: Gfx::PGraphics graphics; virtual void processMeshBatch( const MeshBatch& batch, -// const PPrimitiveComponent primitiveComponent, - const Gfx::PRenderPass& renderPass, + Gfx::PViewport target, + Gfx::PRenderPass renderPass, Gfx::PPipelineLayout pipelineLayout, Gfx::PDescriptorLayout primitiveLayout, Array descriptorSets, diff --git a/src/Engine/Graphics/RenderPass/RenderGraph.h b/src/Engine/Graphics/RenderPass/RenderGraph.h index 2d0c60b..172ab52 100644 --- a/src/Engine/Graphics/RenderPass/RenderGraph.h +++ b/src/Engine/Graphics/RenderPass/RenderGraph.h @@ -1,29 +1,95 @@ #pragma once -#include "MinimalEngine.h" -#include "Graphics/GraphicsResources.h" +#include "RenderPass.h" namespace Seele { -DECLARE_REF(ViewFrame) +template +class RenderGraph; -class RenderGraphResources +template<> +class RenderGraph<> { public: - RenderGraphResources(); - ~RenderGraphResources(); - Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName); - Gfx::PTexture requestTexture(const std::string& outputName); - Gfx::PStructuredBuffer requestBuffer(const std::string& outputName); - Gfx::PUniformBuffer requestUniform(const std::string& outputName); - void registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment); - void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer); - void registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer); - void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer); + RenderGraph(PRenderGraphResources) {} + void updatePassData() {} protected: - Map registeredAttachments; - Map registeredTextures; - Map registeredBuffers; - Map registeredUniforms; + void setViewport(Gfx::PViewport) {} + void createRenderPass() {} + void beginFrame(const Component::Camera&) {} + void render() {} + void endFrame() {} }; -DEFINE_REF(RenderGraphResources) + +template +class RenderGraph : private RenderGraph +{ +public: + RenderGraph(PRenderGraphResources resources, This&& pass, Rest&&... rest) + : RenderGraph(resources, std::move(rest)...) + , resources(resources) + , rp(std::move(pass)) + { + rp.setResources(resources); + } + template + void updatePassData(PassData passData, OtherData... otherData) + { + rp.updateViewFrame(std::move(passData)); + RenderGraph::updatePassData(otherData...); + } + void updateViewport(Gfx::PViewport viewport) + { + setViewport(viewport); + createRenderPass(); + } + void render(const Component::Camera& cam) + { + beginFrame(cam); + render(); + endFrame(); + } +protected: + void setViewport(Gfx::PViewport viewport) + { + rp.setViewport(viewport); + RenderGraph::setViewport(viewport); + } + void createRenderPass() + { + rp.createRenderPass(); + RenderGraph::createRenderPass(); + } + void beginFrame(const Component::Camera& cam) + { + rp.beginFrame(cam); + RenderGraph::beginFrame(cam); + } + void render() + { + rp.render(); + RenderGraph::render(); + } + void endFrame() + { + rp.endFrame(); + RenderGraph::endFrame(); + } +private: + PRenderGraphResources resources; + This rp; +}; + +class RenderGraphBuilder +{ +public: + template + static RenderGraph build(RenderPasses&&... renderPasses) + { + PRenderGraphResources resources = new RenderGraphResources(); + return RenderGraph(resources, std::move(renderPasses)...); + } +private: + RenderGraphBuilder() = delete; +}; + } // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/RenderGraph.cpp b/src/Engine/Graphics/RenderPass/RenderGraphResources.cpp similarity index 98% rename from src/Engine/Graphics/RenderPass/RenderGraph.cpp rename to src/Engine/Graphics/RenderPass/RenderGraphResources.cpp index 294edab..019c864 100644 --- a/src/Engine/Graphics/RenderPass/RenderGraph.cpp +++ b/src/Engine/Graphics/RenderPass/RenderGraphResources.cpp @@ -1,4 +1,4 @@ -#include "RenderGraph.h" +#include "RenderGraphResources.h" using namespace Seele; diff --git a/src/Engine/Graphics/RenderPass/RenderGraphResources.h b/src/Engine/Graphics/RenderPass/RenderGraphResources.h new file mode 100644 index 0000000..2d0c60b --- /dev/null +++ b/src/Engine/Graphics/RenderPass/RenderGraphResources.h @@ -0,0 +1,29 @@ +#pragma once +#include "MinimalEngine.h" +#include "Graphics/GraphicsResources.h" + +namespace Seele +{ +DECLARE_REF(ViewFrame) + +class RenderGraphResources +{ +public: + RenderGraphResources(); + ~RenderGraphResources(); + Gfx::PRenderTargetAttachment requestRenderTarget(const std::string& outputName); + Gfx::PTexture requestTexture(const std::string& outputName); + Gfx::PStructuredBuffer requestBuffer(const std::string& outputName); + Gfx::PUniformBuffer requestUniform(const std::string& outputName); + void registerRenderPassOutput(const std::string& outputName, Gfx::PRenderTargetAttachment attachment); + void registerTextureOutput(const std::string& outputName, Gfx::PTexture buffer); + void registerBufferOutput(const std::string& outputName, Gfx::PStructuredBuffer buffer); + void registerUniformOutput(const std::string& outputName, Gfx::PUniformBuffer buffer); +protected: + Map registeredAttachments; + Map registeredTextures; + Map registeredBuffers; + Map registeredUniforms; +}; +DEFINE_REF(RenderGraphResources) +} // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/RenderPass.h b/src/Engine/Graphics/RenderPass/RenderPass.h index 8b45134..811e568 100644 --- a/src/Engine/Graphics/RenderPass/RenderPass.h +++ b/src/Engine/Graphics/RenderPass/RenderPass.h @@ -1,7 +1,8 @@ #pragma once #include "MinimalEngine.h" #include "Math/Math.h" -#include "RenderGraph.h" +#include "RenderGraphResources.h" +#include "Component/Camera.h" namespace Seele { @@ -12,27 +13,30 @@ template class RenderPass { public: - RenderPass(Gfx::PGraphics graphics, Gfx::PViewport viewport) + RenderPass(Gfx::PGraphics graphics) : graphics(graphics) - , viewport(viewport) {} virtual ~RenderPass() {} void updateViewFrame(RenderPassDataType viewFrame) { passData = std::move(viewFrame); } - virtual void beginFrame() = 0; + virtual void beginFrame(const Component::Camera& cam) = 0; virtual void render() = 0; virtual void endFrame() = 0; virtual void publishOutputs() = 0; virtual void createRenderPass() = 0; void setResources(PRenderGraphResources _resources) { resources = _resources; } + void setViewport(Gfx::PViewport _viewport) + { + viewport = _viewport; + publishOutputs(); + } protected: struct ViewParameter { Math::Matrix4 viewMatrix; Math::Matrix4 projectionMatrix; - Math::Matrix4 inverseProjectionMatrix; Math::Vector4 cameraPosition; Math::Vector2 screenDimensions; Math::Vector2 pad0; @@ -43,7 +47,7 @@ protected: Gfx::PGraphics graphics; Gfx::PViewport viewport; }; -template -concept RenderPassType = true; +template +concept RenderPassType = std::derived_from>; } // namespace Seele diff --git a/src/Engine/Graphics/RenderPass/TextPass.cpp b/src/Engine/Graphics/RenderPass/TextPass.cpp index 7d83d8f..941c052 100644 --- a/src/Engine/Graphics/RenderPass/TextPass.cpp +++ b/src/Engine/Graphics/RenderPass/TextPass.cpp @@ -5,9 +5,8 @@ using namespace Seele; -TextPass::TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment) - : RenderPass(graphics, viewport) - , renderTarget(attachment) +TextPass::TextPass(Gfx::PGraphics graphics) + : RenderPass(graphics) { } @@ -16,7 +15,7 @@ TextPass::~TextPass() } -void TextPass::beginFrame() +void TextPass::beginFrame(const Component::Camera& cam) { for(TextRender& render : passData.texts) { @@ -60,6 +59,13 @@ void TextPass::beginFrame() .scale = render.scale, }; } + BulkResourceData projectionUpdate = { + .size = sizeof(Math::Matrix4), + .data = (uint8*)&cam.projectionMatrix, + }; + projectionBuffer->updateContents(projectionUpdate); + generalSet->updateBuffer(1, projectionBuffer); + generalSet->writeChanges(); //co_return; } @@ -99,7 +105,9 @@ void TextPass::publishOutputs() void TextPass::createRenderPass() { + renderTarget = resources->requestRenderTarget("UIPASS_COLOR"); depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH"); + ShaderCreateInfo createInfo; createInfo.mainModule = "TextPass"; createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; @@ -146,13 +154,12 @@ void TextPass::createRenderPass() textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT); textureArrayLayout->create(); - Math::Matrix4 projectionMatrix = glm::ortho(0.f, (float)viewport->getSizeX(), 0.f, (float)viewport->getSizeY()); projectionBuffer = graphics->createUniformBuffer({ .resourceData = { .size = sizeof(Math::Matrix4), - .data = (uint8*)&projectionMatrix, + .data = nullptr, }, - .bDynamic = false, + .bDynamic = true, }); glyphSampler = graphics->createSamplerState({ diff --git a/src/Engine/Graphics/RenderPass/TextPass.h b/src/Engine/Graphics/RenderPass/TextPass.h index 25460b8..1bdf590 100644 --- a/src/Engine/Graphics/RenderPass/TextPass.h +++ b/src/Engine/Graphics/RenderPass/TextPass.h @@ -25,9 +25,9 @@ struct TextPassData class TextPass : public RenderPass { public: - TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); + TextPass(Gfx::PGraphics graphics); virtual ~TextPass(); - virtual void beginFrame() override; + virtual void beginFrame(const Component::Camera& cam) override; virtual void render() override; virtual void endFrame() override; virtual void publishOutputs() override; @@ -69,7 +69,6 @@ private: Gfx::PRenderTargetAttachment renderTarget; Gfx::PRenderTargetAttachment depthAttachment; - Gfx::PTexture2D depthBuffer; Gfx::PDescriptorLayout generalLayout; Gfx::PDescriptorLayout textureArrayLayout; diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index 3fa0914..7e0d9a0 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -4,9 +4,8 @@ using namespace Seele; -UIPass::UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment) - : RenderPass(graphics, viewport) - , renderTarget(attachment) +UIPass::UIPass(Gfx::PGraphics graphics) + : RenderPass(graphics) { } @@ -15,7 +14,7 @@ UIPass::~UIPass() } -void UIPass::beginFrame() +void UIPass::beginFrame(const Component::Camera&) { VertexBufferCreateInfo info = { .resourceData = { @@ -58,20 +57,30 @@ void UIPass::endFrame() void UIPass::publishOutputs() { - TextureCreateInfo depthBufferInfo; - // Even if we only render to part of an image, we need to make sure - // that the depthbuffer is the same size or they can't be used in the same - // framebuffer - depthBufferInfo.width = viewport->getOwner()->getSizeX(); - depthBufferInfo.height = viewport->getOwner()->getSizeY(); - depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT; - depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; + TextureCreateInfo depthBufferInfo = { + .width = viewport->getSizeX(), + .height = viewport->getSizeY(), + .format = Gfx::SE_FORMAT_D32_SFLOAT, + .usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, + }; depthBuffer = graphics->createTexture2D(depthBufferInfo); depthAttachment = new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); - depthAttachment->clear.depthStencil.depth = 1.0f; + depthAttachment->clear.depthStencil.depth = 1.0f; resources->registerRenderPassOutput("UIPASS_DEPTH", depthAttachment); + + TextureCreateInfo colorBufferInfo = { + .width = viewport->getSizeX(), + .height = viewport->getSizeY(), + .format = Gfx::SE_FORMAT_R16G16B16A16_SFLOAT, + .usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + }; + colorBuffer = graphics->createTexture2D(colorBufferInfo); + renderTarget = + new Gfx::RenderTargetAttachment(colorBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + renderTarget->clear.color = { 0.0f, 0.0f, 0.0f, 1.0f }; + resources->registerRenderPassOutput("UIPASS_COLOR", renderTarget); } void UIPass::createRenderPass() diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h index 84692c8..7c6fc82 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.h +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -15,15 +15,16 @@ struct UIPassData class UIPass : public RenderPass { public: - UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); + UIPass(Gfx::PGraphics graphics); virtual ~UIPass(); - virtual void beginFrame() override; + virtual void beginFrame(const Component::Camera& cam) override; virtual void render() override; virtual void endFrame() override; virtual void publishOutputs() override; virtual void createRenderPass() override; private: Gfx::PRenderTargetAttachment renderTarget; + Gfx::PTexture2D colorBuffer; Gfx::PRenderTargetAttachment depthAttachment; Gfx::PTexture2D depthBuffer; diff --git a/src/Engine/Graphics/Vulkan/CMakeLists.txt b/src/Engine/Graphics/Vulkan/CMakeLists.txt index f9c5e22..bf2f494 100644 --- a/src/Engine/Graphics/Vulkan/CMakeLists.txt +++ b/src/Engine/Graphics/Vulkan/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE NsightAftermathGpuCrashTracker.h NsightAftermathGpuCrashTracker.cpp NsightAftermathHelpers.h diff --git a/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp b/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp index de59b04..2ac61ba 100644 --- a/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp @@ -283,7 +283,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp; blendAttachment.blendEnable = attachment.blendEnable; blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp; - blendAttachment.colorWriteMask = colorAttachments[i]->componentFlags; + blendAttachment.colorWriteMask = attachment.colorWriteMask; blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor; blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor; blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor; diff --git a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp index 6ab54b7..6a75320 100644 --- a/src/Engine/Graphics/Vulkan/VulkanViewport.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanViewport.cpp @@ -355,10 +355,10 @@ void Window::choosePresentMode(const Array &modes) Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo) : Gfx::Viewport(owner, viewportInfo), graphics(graphics) { - handle.width = static_cast(viewportInfo.sizeX); - handle.height = static_cast(viewportInfo.sizeY); - handle.x = static_cast(viewportInfo.offsetX); - handle.y = static_cast(viewportInfo.offsetY) + handle.height; + handle.width = static_cast(viewportInfo.dimensions.size.x); + handle.height = static_cast(viewportInfo.dimensions.size.y); + handle.x = static_cast(viewportInfo.dimensions.offset.x); + handle.y = static_cast(viewportInfo.dimensions.offset.y) + handle.height; handle.height = -handle.height; handle.minDepth = 0.f; handle.maxDepth = 1.f; diff --git a/src/Engine/Material/CMakeLists.txt b/src/Engine/Material/CMakeLists.txt index 8c1eff2..34244ca 100644 --- a/src/Engine/Material/CMakeLists.txt +++ b/src/Engine/Material/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE BRDF.h BRDF.cpp MaterialAsset.h diff --git a/src/Engine/Math/CMakeLists.txt b/src/Engine/Math/CMakeLists.txt index eb76468..41125a6 100644 --- a/src/Engine/Math/CMakeLists.txt +++ b/src/Engine/Math/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Math.h Matrix.h Transform.h diff --git a/src/Engine/Math/Vector.h b/src/Engine/Math/Vector.h index 6233e49..f0f0af5 100644 --- a/src/Engine/Math/Vector.h +++ b/src/Engine/Math/Vector.h @@ -27,10 +27,6 @@ typedef glm::quat Quaternion; Vector parseVector(const char*); -std::ostream& operator<<(std::ostream& stream, const Vector2& vector); -std::ostream& operator<<(std::ostream& stream, const Vector& vector); -std::ostream& operator<<(std::ostream& stream, const Vector4& vector); - static inline float square(float x) { return x * x; @@ -101,4 +97,9 @@ static inline Vector toRotator(const Quaternion &other) return rotatorFromQuat; } } // namespace Math -} // namespace Seele \ No newline at end of file +} // namespace Seele + + +std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector2& vector); +std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector& vector); +std::ostream& operator<<(std::ostream& stream, const Seele::Math::Vector4& vector); \ No newline at end of file diff --git a/src/Engine/Scene/CMakeLists.txt b/src/Engine/Scene/CMakeLists.txt index fa7ee3b..81fdb35 100644 --- a/src/Engine/Scene/CMakeLists.txt +++ b/src/Engine/Scene/CMakeLists.txt @@ -1,9 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Util.h Scene.cpp Scene.h) - -add_subdirectory(Actor/) -add_subdirectory(Component/) -add_subdirectory(System/) \ No newline at end of file diff --git a/src/Engine/Scene/System/CameraSystem.cpp b/src/Engine/Scene/System/CameraSystem.cpp deleted file mode 100644 index 1612115..0000000 --- a/src/Engine/Scene/System/CameraSystem.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "CameraSystem.h" -#include "Scene/Component/Camera.h" - -using namespace Seele; -using namespace Seele::System; - -void CameraSystem::update(Component::Camera& camera) -{ - camera.buildViewMatrix(); - camera.buildProjectionMatrix(); -} \ No newline at end of file diff --git a/src/Engine/Scene/System/CameraSystem.h b/src/Engine/Scene/System/CameraSystem.h deleted file mode 100644 index e3b7c1d..0000000 --- a/src/Engine/Scene/System/CameraSystem.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "SystemBase.h" -#include "Scene/Component/Camera.h" - -namespace Seele -{ -namespace System -{ -class CameraSystem : public SystemBase -{ -public: - CameraSystem(entt::registry& registry) : SystemBase(registry) {} - virtual ~CameraSystem() {} - virtual void update(Component::Camera& component); -private: -}; -} // namespace System -} // namespace Seele diff --git a/src/Engine/Scene/System/CMakeLists.txt b/src/Engine/System/CMakeLists.txt similarity index 58% rename from src/Engine/Scene/System/CMakeLists.txt rename to src/Engine/System/CMakeLists.txt index 1028496..a81e825 100644 --- a/src/Engine/Scene/System/CMakeLists.txt +++ b/src/Engine/System/CMakeLists.txt @@ -1,7 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Executor.h Executor.cpp - CameraSystem.h - CameraSystem.cpp SystemBase.h) \ No newline at end of file diff --git a/src/Engine/Scene/System/Executor.cpp b/src/Engine/System/Executor.cpp similarity index 100% rename from src/Engine/Scene/System/Executor.cpp rename to src/Engine/System/Executor.cpp diff --git a/src/Engine/Scene/System/Executor.h b/src/Engine/System/Executor.h similarity index 100% rename from src/Engine/Scene/System/Executor.h rename to src/Engine/System/Executor.h diff --git a/src/Engine/Scene/System/SystemBase.h b/src/Engine/System/SystemBase.h similarity index 96% rename from src/Engine/Scene/System/SystemBase.h rename to src/Engine/System/SystemBase.h index 8b73f74..e4dbf14 100644 --- a/src/Engine/Scene/System/SystemBase.h +++ b/src/Engine/System/SystemBase.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include "Scene/Component/Component.h" +#include "Component/Component.h" namespace Seele { diff --git a/src/Engine/UI/CMakeLists.txt b/src/Engine/UI/CMakeLists.txt index 899bde4..c1bb37c 100644 --- a/src/Engine/UI/CMakeLists.txt +++ b/src/Engine/UI/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE HorizontalLayout.h HorizontalLayout.cpp Layout.h diff --git a/src/Engine/UI/Elements/CMakeLists.txt b/src/Engine/UI/Elements/CMakeLists.txt index ab68032..005c939 100644 --- a/src/Engine/UI/Elements/CMakeLists.txt +++ b/src/Engine/UI/Elements/CMakeLists.txt @@ -1,5 +1,5 @@ target_sources(Engine - PUBLIC + PRIVATE Button.h Button.cpp Element.h diff --git a/src/Engine/UI/System.cpp b/src/Engine/UI/System.cpp index 1adaaf6..f909e83 100644 --- a/src/Engine/UI/System.cpp +++ b/src/Engine/UI/System.cpp @@ -22,6 +22,11 @@ void System::update() } +void System::updateViewport(Gfx::PViewport viewport) +{ + virtualCamera.projectionMatrix = glm::ortho(0.0f, static_cast(viewport->getSizeX()), 0.0f, static_cast(viewport->getSizeY())); +} + UIPassData System::getUIPassData() { UIPassData uiPassData; @@ -46,3 +51,8 @@ TextPassData System::getTextPassData() render.textColor = Math::Vector4(1, 0, 0, 1); return textPassData; } + +Component::Camera System::getVirtualCamera() const +{ + return virtualCamera; +} diff --git a/src/Engine/UI/System.h b/src/Engine/UI/System.h index 6381cec..1eacf3a 100644 --- a/src/Engine/UI/System.h +++ b/src/Engine/UI/System.h @@ -15,9 +15,12 @@ public: System(); virtual ~System(); void update(); + void updateViewport(Gfx::PViewport viewport); UIPassData getUIPassData(); TextPassData getTextPassData(); + Component::Camera getVirtualCamera() const; private: + Component::Camera virtualCamera; PPanel rootPanel; RenderHierarchy hierarchy; }; diff --git a/src/Engine/Window/CMakeLists.txt b/src/Engine/Window/CMakeLists.txt index 96631bf..597edbf 100644 --- a/src/Engine/Window/CMakeLists.txt +++ b/src/Engine/Window/CMakeLists.txt @@ -1,9 +1,5 @@ target_sources(Engine - PUBLIC - InspectorView.h - InspectorView.cpp - SceneView.h - SceneView.cpp + PRIVATE View.h View.cpp Window.cpp diff --git a/src/Engine/Window/SceneView.cpp b/src/Engine/Window/SceneView.cpp deleted file mode 100644 index 3f5c548..0000000 --- a/src/Engine/Window/SceneView.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "SceneView.h" -#include "Scene/Scene.h" -#include "Window.h" -#include "Graphics/Mesh.h" -#include "Graphics/Graphics.h" -#include "Asset/MeshAsset.h" -#include "Asset/AssetRegistry.h" -#include "Scene/Actor/CameraActor.h" -#include "Scene/Component/Camera.h" -#include "Scene/Component/StaticMesh.h" - -using namespace Seele; - -Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo) - : View(graphics, owner, createInfo, "SceneView") - , scene(new Scene(graphics)) - , activeCamera(new CameraActor(scene)) - , depthPrepass(DepthPrepass(graphics, viewport, activeCamera)) - , lightCullingPass(LightCullingPass(graphics, viewport, activeCamera)) - , basePass(BasePass(graphics, viewport, activeCamera)) - , cameraSystem(scene->registry) -{ - activeCamera->getCameraComponent().setViewport(viewport); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png"); - AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Ayaka.fbx"); - auto meshAsset = AssetRegistry::findMesh("Ayaka"); - for(auto mesh : meshAsset->getMeshes()) - { - PActor actor = new Actor(scene); - actor->attachComponent(mesh->vertexInput, mesh->indexBuffer, mesh->referencedMaterial); - } - - //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx"); - //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj"); - AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx"); - - cameraSystem.run(pool); - - PRenderGraphResources resources = new RenderGraphResources(); - depthPrepass.setResources(resources); - lightCullingPass.setResources(resources); - basePass.setResources(resources); - - depthPrepass.publishOutputs(); - lightCullingPass.publishOutputs(); - basePass.publishOutputs(); - - depthPrepass.createRenderPass(); - lightCullingPass.createRenderPass(); - basePass.createRenderPass(); -} - -Seele::SceneView::~SceneView() -{ -} - -void SceneView::beginUpdate() -{ - scene->beginUpdate(Gfx::currentFrameDelta); - //co_return; -} - -void SceneView::update() -{ - scene->commitUpdate(); - //co_return; -} - -void SceneView::commitUpdate() -{ - depthPrepassData.staticDrawList = scene->getStaticMeshes(); - lightCullingPassData.lightEnv = scene->getLightBuffer(); - basePassData.staticDrawList = scene->getStaticMeshes(); -} - -void SceneView::prepareRender() -{ - depthPrepass.updateViewFrame(depthPrepassData); - lightCullingPass.updateViewFrame(lightCullingPassData); - basePass.updateViewFrame(basePassData); -} - -void SceneView::render() -{ - cameraSystem.run(pool); - depthPrepass.beginFrame(); - lightCullingPass.beginFrame(); - basePass.beginFrame(); - depthPrepass.render(); - lightCullingPass.render(); - basePass.render(); - depthPrepass.endFrame(); - lightCullingPass.endFrame(); - basePass.endFrame(); -} - -static float cameraSpeed = 1; - -void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier mod) -{ - if((KeyModifierFlags)mod & (KeyModifierFlags)KeyModifier::MOD_SHIFT) - { - cameraSpeed = 5; - } - else - { - cameraSpeed = 1; - } - if(action != InputAction::RELEASE) - { - if(code == KeyCode::KEY_W) - { - activeCamera->getCameraComponent().moveX(1); - } - if(code == KeyCode::KEY_S) - { - activeCamera->getCameraComponent().moveX(-1); - } - if(code == KeyCode::KEY_A) - { - activeCamera->getCameraComponent().moveY(1); - } - if(code == KeyCode::KEY_D) - { - activeCamera->getCameraComponent().moveY(-1); - } - } -} - -static bool mouseDown = false; - -void SceneView::mouseMoveCallback(double xPos, double yPos) -{ - static double prevXPos = 0.0f, prevYPos = 0.0f; - double deltaX = prevXPos - xPos; - double deltaY = prevYPos - yPos; - prevXPos = xPos; - prevYPos = yPos; - if(mouseDown) - { - activeCamera->getCameraComponent().mouseMove((float)deltaX, (float)deltaY); - } -} - -void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier) -{ - if(button == MouseButton::MOUSE_BUTTON_2 && action != InputAction::RELEASE) - { - mouseDown = true; - } - else - { - mouseDown = false; - } -} - -void SceneView::scrollCallback(double, double yOffset) -{ - activeCamera->getCameraComponent().mouseScroll(static_cast(yOffset)); -} - -void SceneView::fileCallback(int, const char**) -{ - -}