Viewport controls

This commit is contained in:
Dynamitos
2022-11-17 16:47:42 +01:00
parent f635ee2100
commit 4ba0bf3b45
73 changed files with 627 additions and 449 deletions
+15 -11
View File
@@ -10,6 +10,7 @@ option (USE_SUPERBUILD "Whether or not a superbuild should be invoked" ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF) set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
set(BUILD_SHARED_LIBS OFF)
set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine) set(ENGINE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/Engine)
set(EXTERNAL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/external) set(EXTERNAL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/external)
@@ -56,8 +57,7 @@ if(CMAKE_DEBUG_POSTFIX)
add_compile_definitions(SEELE_DEBUG) add_compile_definitions(SEELE_DEBUG)
endif() endif()
add_library(Engine SHARED "") add_library(Engine STATIC "")
add_executable(Editor "")
target_compile_definitions(Engine PUBLIC GLFW_WINDOWS) target_compile_definitions(Engine PUBLIC GLFW_WINDOWS)
target_include_directories(Engine PUBLIC src/Engine) target_include_directories(Engine PUBLIC src/Engine)
target_link_libraries(Engine PUBLIC Vulkan::Vulkan) 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 nlohmann_json::nlohmann_json)
target_link_libraries(Engine PUBLIC dp::thread-pool) target_link_libraries(Engine PUBLIC dp::thread-pool)
if(UNIX) if(UNIX)
target_link_libraries(Engine Threads::Threads) target_link_libraries(Engine PUBLIC Threads::Threads)
target_link_libraries(Engine dl) target_link_libraries(Engine PUBLIC dl)
endif() endif()
target_precompile_headers(Engine target_precompile_headers(Engine
PUBLIC PUBLIC
@@ -97,11 +97,15 @@ target_precompile_headers(Engine
if(MSVC) if(MSVC)
set(_CRT_SECURE_NO_WARNINGS) 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() else()
target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines)
endif() endif()
add_executable(Editor "")
target_include_directories(Editor PRIVATE src/Editor)
target_link_libraries(Editor PUBLIC Engine) target_link_libraries(Editor PUBLIC Engine)
add_subdirectory(src/) add_subdirectory(src/)
@@ -110,12 +114,12 @@ add_executable(Seele_unit_tests "")
add_subdirectory(test/) add_subdirectory(test/)
add_custom_target(SeeleEngine ALL add_custom_target(SeeleEngine ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:Editor> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,SLANG_BINARY> $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,SLANG_BINARY> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,GLSLANG_BINARY> $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,GLSLANG_BINARY> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,NSAM_BINARY> $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,NSAM_BINARY> $<TARGET_FILE_DIR:Editor>
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,LLVM_BINARY> $<TARGET_FILE_DIR:Engine> COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,LLVM_BINARY> $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS COMMAND_EXPAND_LISTS
DEPENDS Editor slang-build) DEPENDS Editor slang-build)
+7 -6
View File
@@ -1,11 +1,14 @@
include (ExternalProject) include (ExternalProject)
#--------------FreeType------------------------------
set(FT_DISABLE_ZLIB ON)
add_subdirectory(${FREETYPE_ROOT})
#------------ASSIMP--------------- #------------ASSIMP---------------
set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "") set(ASSIMP_BUILD_TESTS OFF CACHE INTERNAL "")
set(ASSIMP_BUILD_SAMPLES OFF CACHE INTERNAL "") set(ASSIMP_BUILD_SAMPLES OFF CACHE INTERNAL "")
set(ASSIMP_BUILD_OVERALLS OFF CACHE INTERNAL "") set(ASSIMP_BUILD_OVERALLS OFF CACHE INTERNAL "")
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "")
add_subdirectory(${ASSIMP_ROOT}) add_subdirectory(${ASSIMP_ROOT})
target_compile_definitions(assimp PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) target_compile_definitions(assimp PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
if(WIN32) if(WIN32)
@@ -31,7 +34,7 @@ add_subdirectory(${JSON_ROOT})
#--------------GLM------------------------------ #--------------GLM------------------------------
add_subdirectory(${GLM_ROOT}) add_subdirectory(${GLM_ROOT})
target_compile_options(glm_shared INTERFACE /W0) target_compile_options(glm INTERFACE /W0)
#--------------GLFW------------------------------ #--------------GLFW------------------------------
set(ENKITS_BUILD_EXAMPLES OFF CACHE BOOL "Build basic example applications" ) set(ENKITS_BUILD_EXAMPLES OFF CACHE BOOL "Build basic example applications" )
@@ -46,9 +49,6 @@ add_subdirectory(${GLFW_ROOT})
#--------------EnTT------------------------------ #--------------EnTT------------------------------
add_subdirectory(${ENTT_ROOT}) add_subdirectory(${ENTT_ROOT})
#--------------FreeType------------------------------
add_subdirectory(${FREETYPE_ROOT})
#--------------STB----------------------------------- #--------------STB-----------------------------------
add_library(stb INTERFACE) add_library(stb INTERFACE)
@@ -92,3 +92,4 @@ target_include_directories(slang INTERFACE ${SLANG_ROOT})
target_link_libraries(slang INTERFACE ${SLANG_BINARY_DIR}/*.lib) 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 SLANG_BINARY ${SLANG_BINARY_DIR}/slang.dll)
set_target_properties(slang PROPERTIES GLSLANG_BINARY ${SLANG_BINARY_DIR}/slang-glslang.dll) set_target_properties(slang PROPERTIES GLSLANG_BINARY ${SLANG_BINARY_DIR}/slang-glslang.dll)
+1 -1
View File
@@ -38,7 +38,7 @@ void computeFrustums(ComputeShaderInput in)
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++)
{ {
viewSpace[i] = screenToView(screenSpace[i]).xyz; viewSpace[i] = screenToClip(screenSpace[i]).xyz;
} }
//Compute frustum //Compute frustum
+3 -3
View File
@@ -105,9 +105,9 @@ void cullLights(ComputeShaderInput in)
float fMinDepth = asfloat(uMinDepth); float fMinDepth = asfloat(uMinDepth);
float fMaxDepth = asfloat(uMaxDepth); float fMaxDepth = asfloat(uMaxDepth);
float minDepthVS = clipToView(float4(0, 0, fMinDepth, 1)).z; float minDepthVS = fMinDepth;
float maxDepthVS = clipToView(float4(0, 0, fMaxDepth, 1)).z; float maxDepthVS = fMaxDepth;
float nearClipVS = clipToView(float4(0, 0, 0, 1.0f)).z; float nearClipVS = 0.1f;
Plane minPlane = {float3(0, 0, -1), -minDepthVS}; Plane minPlane = {float3(0, 0, -1), -minDepthVS};
+3 -16
View File
@@ -6,34 +6,21 @@ struct ViewParameter
{ {
float4x4 viewMatrix; float4x4 viewMatrix;
float4x4 projectionMatrix; float4x4 projectionMatrix;
float4x4 inverseProjection;
float4 cameraPos_WS; float4 cameraPos_WS;
float2 screenDimensions; float2 screenDimensions;
} }
layout(set = INDEX_VIEW_PARAMS, binding = 0, std430) layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
ConstantBuffer<ViewParameter> gViewParams; ConstantBuffer<ViewParameter> 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. // Convert screen space coordinates to view space.
float4 screenToView( float4 screen ) float4 screenToClip( float4 screen )
{ {
// Convert to normalized texture coordinates // Convert to normalized texture coordinates
float2 texCoord = screen.xy / gViewParams.screenDimensions; float2 texCoord = screen.xy / gViewParams.screenDimensions;
// Convert to clip space // Convert to clip space
float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
return clipToView( clip );
} }
struct Plane struct Plane
+3
View File
@@ -1,3 +1,6 @@
add_subdirectory(System/)
add_subdirectory(Window/)
target_sources(Editor target_sources(Editor
PRIVATE PRIVATE
main.cpp) main.cpp)
View File
+2
View File
@@ -0,0 +1,2 @@
target_sources(Editor
PRIVATE)
+8
View File
@@ -0,0 +1,8 @@
target_sources(Editor
PRIVATE
InspectorView.h
InspectorView.cpp
SceneView.h
SceneView.cpp
ViewportControl.h
ViewportControl.cpp)
@@ -1,7 +1,7 @@
#include "InspectorView.h" #include "InspectorView.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Scene/Actor/Actor.h" #include "Actor/Actor.h"
#include "Window.h" #include "Window/Window.h"
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
#include "UI/System.h" #include "UI/System.h"
@@ -9,18 +9,15 @@ using namespace Seele;
InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo) InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &createInfo)
: View(graphics, window, createInfo, "InspectorView") : View(graphics, window, createInfo, "InspectorView")
, uiPass(UIPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle()))) , renderGraph(RenderGraphBuilder::build(
, textPass(TextPass(graphics, viewport, new Gfx::SwapchainAttachment(window->getGfxHandle()))) UIPass(graphics),
TextPass(graphics)
))
, uiSystem(new UI::System()) , uiSystem(new UI::System())
{ {
AssetRegistry::importFile("./fonts/Calibri.ttf"); AssetRegistry::importFile("./fonts/Calibri.ttf");
PRenderGraphResources resources = new RenderGraphResources(); renderGraph.updateViewport(viewport);
uiPass.setResources(resources); uiSystem->updateViewport(viewport);
textPass.setResources(resources);
uiPass.publishOutputs();
textPass.publishOutputs();
uiPass.createRenderPass();
textPass.createRenderPass();
} }
InspectorView::~InspectorView() InspectorView::~InspectorView()
@@ -43,18 +40,15 @@ void InspectorView::commitUpdate()
void InspectorView::prepareRender() void InspectorView::prepareRender()
{ {
uiPass.updateViewFrame(uiSystem->getUIPassData()); renderGraph.updatePassData(
textPass.updateViewFrame(uiSystem->getTextPassData()); uiSystem->getUIPassData(),
uiSystem->getTextPassData()
);
} }
void InspectorView::render() void InspectorView::render()
{ {
uiPass.beginFrame(); renderGraph.render(uiSystem->getVirtualCamera());
textPass.beginFrame();
uiPass.render();
textPass.render();
uiPass.endFrame();
textPass.endFrame();
} }
void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier)
@@ -1,5 +1,5 @@
#pragma once #pragma once
#include "View.h" #include "Window/View.h"
#include "Graphics/RenderPass/RenderGraph.h" #include "Graphics/RenderPass/RenderGraph.h"
#include "Graphics/RenderPass/UIPass.h" #include "Graphics/RenderPass/UIPass.h"
#include "Graphics/RenderPass/TextPass.h" #include "Graphics/RenderPass/TextPass.h"
@@ -22,8 +22,9 @@ public:
virtual void render() override; virtual void render() override;
void selectActor(); void selectActor();
protected: protected:
UIPass uiPass; RenderGraph<
TextPass textPass; UIPass,
TextPass> renderGraph;
UIPassData uiPassData; UIPassData uiPassData;
TextPassData textPassData; TextPassData textPassData;
+108
View File
@@ -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<Component::StaticMesh>(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<float>(Gfx::currentFrameDelta));
renderGraph.updateViewport(viewport);
}
SceneView::~SceneView()
{
}
void SceneView::beginUpdate()
{
scene->beginUpdate(Gfx::currentFrameDelta);
//co_return;
}
void SceneView::update()
{
cameraSystem.update(viewportCamera, static_cast<float>(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**)
{
}
@@ -1,20 +1,23 @@
#pragma once #pragma once
#include <thread_pool/thread_pool.h> #include <thread_pool/thread_pool.h>
#include "View.h" #include "Window/View.h"
#include "Graphics/RenderPass/DepthPrepass.h" #include "Graphics/RenderPass/DepthPrepass.h"
#include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/LightCullingPass.h"
#include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/BasePass.h"
#include "Scene/System/CameraSystem.h" #include "ViewportControl.h"
namespace Seele namespace Seele
{ {
DECLARE_REF(Scene) DECLARE_REF(Scene)
DECLARE_REF(CameraActor) namespace Editor
{
class SceneView : public View class SceneView : public View
{ {
public: public:
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo); SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
~SceneView(); ~SceneView();
virtual void beginUpdate() override; virtual void beginUpdate() override;
virtual void update() override; virtual void update() override;
virtual void commitUpdate() override; virtual void commitUpdate() override;
@@ -25,18 +28,19 @@ public:
PScene getScene() const { return scene; } PScene getScene() const { return scene; }
private: private:
PScene scene; PScene scene;
PCameraActor activeCamera; Component::Camera viewportCamera;
DepthPrepass depthPrepass; RenderGraph<
LightCullingPass lightCullingPass; DepthPrepass,
BasePass basePass; LightCullingPass,
BasePass> renderGraph;
DepthPrepassData depthPrepassData; DepthPrepassData depthPrepassData;
LightCullingPassData lightCullingPassData; LightCullingPassData lightCullingPassData;
BasePassData basePassData; BasePassData basePassData;
dp::thread_pool<> pool; dp::thread_pool<> pool;
System::CameraSystem cameraSystem; ViewportControl cameraSystem;
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override; virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
virtual void mouseMoveCallback(double xPos, double yPos) override; virtual void mouseMoveCallback(double xPos, double yPos) override;
@@ -45,4 +49,5 @@ private:
virtual void fileCallback(int count, const char** paths) override; virtual void fileCallback(int count, const char** paths) override;
}; };
DEFINE_REF(SceneView) DEFINE_REF(SceneView)
} // namespace Editor
} // namespace Seele } // namespace Seele
+102
View File
@@ -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<float>(viewportDimensions.size.x) / viewportDimensions.size.y)
, yaw(glm::pi<float>()/-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<size_t>(key)] = action != InputAction::RELEASE;
}
void ViewportControl::mouseMoveCallback(double xPos, double yPos)
{
mouseX = static_cast<float>(xPos);
mouseY = static_cast<float>(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<float>(dimensions.size.x) / dimensions.size.y;
}
+31
View File
@@ -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<bool, static_cast<size_t>(KeyCode::KEY_LAST)> keys;
bool mouse1 = false;
bool mouse2 = false;
float mouseX;
float mouseY;
float pitch;
float yaw;
};
} // namespace Seele
+10 -9
View File
@@ -4,6 +4,7 @@
#include "Asset/AssetRegistry.h" #include "Asset/AssetRegistry.h"
using namespace Seele; using namespace Seele;
using namespace Seele::Editor;
int main() int main()
{ {
@@ -18,20 +19,20 @@ int main()
mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM; mainWindowInfo.pixelFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM;
auto window = windowManager->addWindow(mainWindowInfo); auto window = windowManager->addWindow(mainWindowInfo);
ViewportCreateInfo sceneViewInfo; ViewportCreateInfo sceneViewInfo;
sceneViewInfo.sizeX = 640; sceneViewInfo.dimensions.size.x = 1280;
sceneViewInfo.sizeY = 720; sceneViewInfo.dimensions.size.y = 720;
sceneViewInfo.offsetX = 0; sceneViewInfo.dimensions.offset.x = 0;
sceneViewInfo.offsetY = 0; sceneViewInfo.dimensions.offset.y = 0;
PSceneView sceneView = new SceneView(windowManager->getGraphics(), window, sceneViewInfo); PSceneView sceneView = new SceneView(windowManager->getGraphics(), window, sceneViewInfo);
window->addView(sceneView); window->addView(sceneView);
ViewportCreateInfo inspectorViewInfo; ViewportCreateInfo inspectorViewInfo;
inspectorViewInfo.sizeX = 640; inspectorViewInfo.dimensions.size.x = 640;
inspectorViewInfo.sizeY = 720; inspectorViewInfo.dimensions.size.y = 720;
inspectorViewInfo.offsetX = 640; inspectorViewInfo.dimensions.offset.x = 640;
inspectorViewInfo.offsetY = 0; inspectorViewInfo.dimensions.offset.y = 0;
PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo); PInspectorView inspectorView = new InspectorView(windowManager->getGraphics(), window, inspectorViewInfo);
window->addView(inspectorView); //window->addView(inspectorView);
sceneView->setFocused(); sceneView->setFocused();
window->render(); window->render();
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Entity.h" #include "Entity.h"
#include "Scene/Component/Transform.h" #include "Component/Transform.h"
namespace Seele namespace Seele
{ {
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Actor.cpp Actor.cpp
Actor.h Actor.h
CameraActor.cpp CameraActor.cpp
@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Actor.h" #include "Actor.h"
#include "Scene/Component/Camera.h" #include "Component/Camera.h"
namespace Seele namespace Seele
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Asset.h Asset.h
Asset.cpp Asset.cpp
AssetRegistry.h AssetRegistry.h
+4 -1
View File
@@ -1,14 +1,17 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
EngineTypes.h EngineTypes.h
MinimalEngine.h MinimalEngine.h
MinimalEngine.cpp) MinimalEngine.cpp)
add_subdirectory(Actor/)
add_subdirectory(Asset/) add_subdirectory(Asset/)
add_subdirectory(Component/)
add_subdirectory(Containers/) add_subdirectory(Containers/)
add_subdirectory(Graphics/) add_subdirectory(Graphics/)
add_subdirectory(Material/) add_subdirectory(Material/)
add_subdirectory(Math/) add_subdirectory(Math/)
add_subdirectory(Scene/) add_subdirectory(Scene/)
add_subdirectory(System/)
add_subdirectory(UI/) add_subdirectory(UI/)
add_subdirectory(Window/) add_subdirectory(Window/)
@@ -1,8 +1,8 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Component.h
Camera.h Camera.h
Camera.cpp Camera.cpp
Component.h
StaticMesh.h StaticMesh.h
Transform.h Transform.h
Transform.cpp) Transform.cpp)
@@ -1,5 +1,5 @@
#include "Camera.h" #include "Camera.h"
#include "Scene/Actor/Actor.h" #include "Actor/Actor.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@@ -10,8 +10,8 @@ using namespace Seele::Math;
Camera::Camera() Camera::Camera()
: aspectRatio(0) : aspectRatio(0)
, fieldOfView(glm::radians(70.f)) , fieldOfView(glm::radians(70.f))
, bNeedsViewBuild(true) , bNeedsViewBuild(false)
, bNeedsProjectionBuild(true) , bNeedsProjectionBuild(false)
, viewMatrix(Matrix4()) , viewMatrix(Matrix4())
, projectionMatrix(Matrix4()) , projectionMatrix(Matrix4())
{ {
@@ -65,7 +65,7 @@ void Camera::setViewport(Gfx::PViewport newViewport)
void Camera::buildViewMatrix() void Camera::buildViewMatrix()
{ {
Vector eyePos = getTransform().getPosition();//getAbsoluteTransform().getPosition(); 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; //std::cout << "Eye: " << eyePos << " lookAt: " << lookAt << std::endl;
viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0)); viewMatrix = glm::lookAt(eyePos, lookAt, Vector(0, 1, 0));
@@ -15,19 +15,19 @@ struct Camera
Camera(); Camera();
~Camera(); ~Camera();
Math::Matrix4 getViewMatrix() Math::Matrix4 getViewMatrix() const
{ {
assert (!bNeedsViewBuild); assert (!bNeedsViewBuild);
return viewMatrix; return viewMatrix;
} }
Math::Matrix4 getProjectionMatrix() Math::Matrix4 getProjectionMatrix() const
{ {
assert (!bNeedsProjectionBuild); assert (!bNeedsProjectionBuild);
return projectionMatrix; return projectionMatrix;
} }
Math::Vector getCameraPosition() Math::Vector getCameraPosition() const
{ {
return getTransform().getPosition(); return Math::Vector(viewMatrix[3]);
} }
void setViewport(Gfx::PViewport viewport); void setViewport(Gfx::PViewport viewport);
void mouseMove(float deltaX, float deltaY); void mouseMove(float deltaX, float deltaY);
@@ -38,6 +38,8 @@ struct Camera
float fieldOfView; float fieldOfView;
void buildViewMatrix(); void buildViewMatrix();
void buildProjectionMatrix(); void buildProjectionMatrix();
Math::Matrix4 viewMatrix;
Math::Matrix4 projectionMatrix;
private: private:
bool bNeedsViewBuild; bool bNeedsViewBuild;
bool bNeedsProjectionBuild; bool bNeedsProjectionBuild;
@@ -45,8 +47,6 @@ private:
Gfx::PViewport viewport; Gfx::PViewport viewport;
//Transforms relative to actor //Transforms relative to actor
Math::Matrix4 viewMatrix;
Math::Matrix4 projectionMatrix;
float yaw; float yaw;
float pitch; float pitch;
}; };
+10
View File
@@ -705,6 +705,16 @@ public:
{ {
return _data; return _data;
} }
template<typename I>
constexpr reference operator[](I index) noexcept
{
return operator[](static_cast<size_t>(index));
}
template<typename I>
constexpr const_reference operator[](I index) const noexcept
{
return operator[](static_cast<size_t>(index));
}
constexpr reference operator[](size_type index) noexcept constexpr reference operator[](size_type index) noexcept
{ {
assert(index < N); assert(index < N);
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Array.h Array.h
Map.h Map.h
List.h) List.h)
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
GraphicsResources.h GraphicsResources.h
GraphicsResources.cpp GraphicsResources.cpp
GraphicsInitializer.h GraphicsInitializer.h
+2 -1
View File
@@ -3,7 +3,7 @@
namespace Seele namespace Seele
{ {
enum class KeyCode enum class KeyCode : size_t
{ {
/* Printable keys */ /* Printable keys */
KEY_SPACE = 32, KEY_SPACE = 32,
@@ -127,6 +127,7 @@ enum class KeyCode
KEY_RIGHT_ALT = 346, KEY_RIGHT_ALT = 346,
KEY_RIGHT_SUPER = 347, KEY_RIGHT_SUPER = 347,
KEY_MENU = 348, KEY_MENU = 348,
KEY_LAST = KEY_MENU
}; };
enum class MouseButton enum class MouseButton
+6 -4
View File
@@ -42,10 +42,7 @@ struct WindowCreateInfo
}; };
struct ViewportCreateInfo struct ViewportCreateInfo
{ {
uint32 sizeX; Math::URect dimensions;
uint32 sizeY;
uint32 offsetX;
uint32 offsetY;
}; };
// doesnt own the data, only proxy it // doesnt own the data, only proxy it
struct BulkResourceData struct BulkResourceData
@@ -235,6 +232,11 @@ struct GraphicsPipelineCreateInfo
colorBlend.blendConstants[1] = 1.0f; colorBlend.blendConstants[1] = 1.0f;
colorBlend.blendConstants[2] = 1.0f; colorBlend.blendConstants[2] = 1.0f;
colorBlend.blendConstants[3] = 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 struct ComputePipelineCreateInfo
+4 -4
View File
@@ -504,10 +504,10 @@ Window::~Window()
} }
Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo) Viewport::Viewport(PWindow owner, const ViewportCreateInfo &viewportInfo)
: sizeX(viewportInfo.sizeX) : sizeX(viewportInfo.dimensions.size.x)
, sizeY(viewportInfo.sizeY) , sizeY(viewportInfo.dimensions.size.y)
, offsetX(viewportInfo.offsetX) , offsetX(viewportInfo.dimensions.offset.x)
, offsetY(viewportInfo.offsetY) , offsetY(viewportInfo.dimensions.offset.y)
, owner(owner) , owner(owner)
{ {
} }
+15 -16
View File
@@ -1,17 +1,16 @@
#include "BasePass.h" #include "BasePass.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Window/Window.h" #include "Window/Window.h"
#include "Scene/Component/Camera.h" #include "Component/Camera.h"
#include "Scene/Actor/CameraActor.h" #include "Actor/CameraActor.h"
#include "Math/Vector.h" #include "Math/Vector.h"
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Material/MaterialAsset.h" #include "Material/MaterialAsset.h"
using namespace Seele; using namespace Seele;
BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass) BasePassMeshProcessor::BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass)
: MeshProcessor(graphics) : MeshProcessor(graphics)
, target(viewport)
, translucentBasePass(translucentBasePass) , translucentBasePass(translucentBasePass)
//, cachedPrimitiveIndex(0) //, cachedPrimitiveIndex(0)
{ {
@@ -23,8 +22,8 @@ BasePassMeshProcessor::~BasePassMeshProcessor()
void BasePassMeshProcessor::processMeshBatch( void BasePassMeshProcessor::processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, Gfx::PViewport target,
const Gfx::PRenderPass& renderPass, Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout baseLayout, Gfx::PPipelineLayout baseLayout,
Gfx::PDescriptorLayout primitiveLayout, Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
@@ -70,11 +69,10 @@ void BasePassMeshProcessor::processMeshBatch(
//co_return; //co_return;
} }
BasePass::BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) BasePass::BasePass(Gfx::PGraphics graphics)
: RenderPass(graphics, viewport) : RenderPass(graphics)
, processor(new BasePassMeshProcessor(viewport, graphics, false)) , processor(new BasePassMeshProcessor(graphics, false))
, descriptorSets(4) , descriptorSets(4)
, source(source)
{ {
UniformBufferCreateInfo uniformInitializer; UniformBufferCreateInfo uniformInitializer;
basePassLayout = graphics->createPipelineLayout(); basePassLayout = graphics->createPipelineLayout();
@@ -115,16 +113,15 @@ BasePass::~BasePass()
{ {
} }
void BasePass::beginFrame() void BasePass::beginFrame(const Component::Camera& cam)
{ {
processor->clearCommands(); processor->clearCommands();
primitiveLayout->reset(); primitiveLayout->reset();
BulkResourceData uniformUpdate; BulkResourceData uniformUpdate;
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); viewParams.projectionMatrix = cam.getProjectionMatrix();
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY())); viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams; uniformUpdate.data = (uint8*)&viewParams;
@@ -158,7 +155,7 @@ void BasePass::render()
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
for (auto &&meshBatch : passData.staticDrawList) 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->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
@@ -186,6 +183,8 @@ void BasePass::createRenderPass()
numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS"); numPointLightBuffer = resources->requestUniform("NUM_POINT_LIGHTS");
Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); Gfx::PRenderTargetAttachment depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
depthAttachment->loadOp = Gfx::SE_ATTACHMENT_LOAD_OP_LOAD; 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); Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout, viewport); renderPass = graphics->createRenderPass(layout, viewport);
oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST"); oLightIndexList = resources->requestBuffer("LIGHTCULLING_OLIGHTLIST");
+7 -5
View File
@@ -8,13 +8,13 @@ namespace Seele
class BasePassMeshProcessor : public MeshProcessor class BasePassMeshProcessor : public MeshProcessor
{ {
public: public:
BasePassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics, uint8 translucentBasePass); BasePassMeshProcessor(Gfx::PGraphics graphics, uint8 translucentBasePass);
virtual ~BasePassMeshProcessor(); virtual ~BasePassMeshProcessor();
virtual void processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, Gfx::PViewport target,
const Gfx::PRenderPass& renderPass, Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout, Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout, Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
@@ -34,9 +34,11 @@ struct BasePassData
class BasePass : public RenderPass<BasePassData> class BasePass : public RenderPass<BasePassData>
{ {
public: public:
BasePass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); BasePass(Gfx::PGraphics graphics);
BasePass(BasePass&& other) = default;
virtual ~BasePass(); 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 render() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual void publishOutputs() override; virtual void publishOutputs() override;
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
BasePass.h BasePass.h
BasePass.cpp BasePass.cpp
DepthPrepass.h DepthPrepass.h
@@ -9,7 +9,8 @@ target_sources(Engine
MeshProcessor.h MeshProcessor.h
MeshProcessor.cpp MeshProcessor.cpp
RenderGraph.h RenderGraph.h
RenderGraph.cpp RenderGraphResources.h
RenderGraphResources.cpp
RenderPass.h RenderPass.h
TextPass.h TextPass.h
TextPass.cpp TextPass.cpp
+13 -16
View File
@@ -1,17 +1,16 @@
#include "DepthPrepass.h" #include "DepthPrepass.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Window/Window.h" #include "Window/Window.h"
#include "Scene/Component/Camera.h" #include "Component/Camera.h"
#include "Scene/Actor/CameraActor.h" #include "Actor/CameraActor.h"
#include "Math/Vector.h" #include "Math/Vector.h"
#include "RenderGraph.h" #include "RenderGraph.h"
#include "Material/MaterialAsset.h" #include "Material/MaterialAsset.h"
using namespace Seele; using namespace Seele;
DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics) DepthPrepassMeshProcessor::DepthPrepassMeshProcessor(Gfx::PGraphics graphics)
: MeshProcessor(graphics) : MeshProcessor(graphics)
, target(viewport)
{ {
} }
@@ -21,8 +20,8 @@ DepthPrepassMeshProcessor::~DepthPrepassMeshProcessor()
void DepthPrepassMeshProcessor::processMeshBatch( void DepthPrepassMeshProcessor::processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, Gfx::PViewport target,
const Gfx::PRenderPass& renderPass, Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout baseLayout, Gfx::PPipelineLayout baseLayout,
Gfx::PDescriptorLayout primitiveLayout, Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
@@ -69,11 +68,10 @@ void DepthPrepassMeshProcessor::processMeshBatch(
//co_return; //co_return;
} }
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source) DepthPrepass::DepthPrepass(Gfx::PGraphics graphics)
: RenderPass(graphics, viewport) : RenderPass(graphics)
, processor(new DepthPrepassMeshProcessor(viewport, graphics)) , processor(new DepthPrepassMeshProcessor(graphics))
, descriptorSets(3) , descriptorSets(3)
, source(source)
{ {
UniformBufferCreateInfo uniformInitializer; UniformBufferCreateInfo uniformInitializer;
@@ -98,16 +96,15 @@ DepthPrepass::~DepthPrepass()
{ {
} }
void DepthPrepass::beginFrame() void DepthPrepass::beginFrame(const Component::Camera& cam)
{ {
processor->clearCommands(); processor->clearCommands();
primitiveLayout->reset(); primitiveLayout->reset();
BulkResourceData uniformUpdate; BulkResourceData uniformUpdate;
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); viewParams.projectionMatrix = cam.getProjectionMatrix();
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY())); viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewport->getSizeX()), static_cast<float>(viewport->getSizeY()));
uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams; uniformUpdate.data = (uint8*)&viewParams;
@@ -129,7 +126,7 @@ void DepthPrepass::render()
graphics->beginRenderPass(renderPass); graphics->beginRenderPass(renderPass);
for (auto &&meshBatch : passData.staticDrawList) 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->executeCommands(processor->getRenderCommands());
graphics->endRenderPass(); graphics->endRenderPass();
@@ -8,22 +8,21 @@ namespace Seele
class DepthPrepassMeshProcessor : public MeshProcessor class DepthPrepassMeshProcessor : public MeshProcessor
{ {
public: public:
DepthPrepassMeshProcessor(Gfx::PViewport viewport, Gfx::PGraphics graphics); DepthPrepassMeshProcessor(Gfx::PGraphics graphics);
virtual ~DepthPrepassMeshProcessor(); virtual ~DepthPrepassMeshProcessor();
virtual void processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
const Gfx::PRenderPass& renderPass, Gfx::PViewport target,
Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout, Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout, Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
int32 staticMeshId = -1) override; int32 staticMeshId = -1) override;
private: private:
Gfx::PViewport target;
}; };
DEFINE_REF(DepthPrepassMeshProcessor) DEFINE_REF(DepthPrepassMeshProcessor)
DECLARE_REF(CameraActor)
struct DepthPrepassData struct DepthPrepassData
{ {
Array<StaticMeshBatch> staticDrawList; Array<StaticMeshBatch> staticDrawList;
@@ -31,9 +30,11 @@ struct DepthPrepassData
class DepthPrepass : public RenderPass<DepthPrepassData> class DepthPrepass : public RenderPass<DepthPrepassData>
{ {
public: public:
DepthPrepass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor source); DepthPrepass(Gfx::PGraphics graphics);
DepthPrepass(DepthPrepass&& other) = default;
~DepthPrepass(); ~DepthPrepass();
virtual void beginFrame() override; DepthPrepass& operator=(DepthPrepass& other) = default;
virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override; virtual void render() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual void publishOutputs() override; virtual void publishOutputs() override;
@@ -45,7 +46,6 @@ private:
UPDepthPrepassMeshProcessor processor; UPDepthPrepassMeshProcessor processor;
Array<Gfx::PDescriptorSet> descriptorSets; Array<Gfx::PDescriptorSet> descriptorSets;
PCameraActor source;
Gfx::PPipelineLayout depthPrepassLayout; Gfx::PPipelineLayout depthPrepassLayout;
// Set 0: viewParameter // Set 0: viewParameter
static constexpr uint32 INDEX_VIEW_PARAMS = 0; static constexpr uint32 INDEX_VIEW_PARAMS = 0;
@@ -1,15 +1,14 @@
#include "LightCullingPass.h" #include "LightCullingPass.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Scene/Scene.h" #include "Scene/Scene.h"
#include "Scene/Actor/CameraActor.h" #include "Actor/CameraActor.h"
#include "Scene/Component/Camera.h" #include "Component/Camera.h"
#include "RenderGraph.h" #include "RenderGraph.h"
using namespace Seele; using namespace Seele;
LightCullingPass::LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera) LightCullingPass::LightCullingPass(Gfx::PGraphics graphics)
: RenderPass(graphics, viewport) : RenderPass(graphics)
, source(camera)
{ {
} }
@@ -18,16 +17,15 @@ LightCullingPass::~LightCullingPass()
} }
void LightCullingPass::beginFrame() void LightCullingPass::beginFrame(const Component::Camera& cam)
{ {
uint32_t viewportWidth = viewport->getSizeX(); uint32_t viewportWidth = viewport->getSizeX();
uint32_t viewportHeight = viewport->getSizeY(); uint32_t viewportHeight = viewport->getSizeY();
BulkResourceData uniformUpdate; BulkResourceData uniformUpdate;
viewParams.viewMatrix = source->getCameraComponent().getViewMatrix(); viewParams.viewMatrix = cam.getViewMatrix();
viewParams.projectionMatrix = source->getCameraComponent().getProjectionMatrix(); viewParams.projectionMatrix = cam.getProjectionMatrix();
viewParams.cameraPosition = Math::Vector4(source->getCameraComponent().getCameraPosition(), 0); viewParams.cameraPosition = Math::Vector4(cam.getCameraPosition(), 0);
viewParams.inverseProjectionMatrix = glm::inverse(viewParams.projectionMatrix);
viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight)); viewParams.screenDimensions = Math::Vector2(static_cast<float>(viewportWidth), static_cast<float>(viewportHeight));
uniformUpdate.size = sizeof(ViewParameter); uniformUpdate.size = sizeof(ViewParameter);
uniformUpdate.data = (uint8*)&viewParams; 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)); glm::uvec3 numThreadGroups = glm::ceil(glm::vec3(numThreads.x / (float)BLOCK_SIZE, numThreads.y / (float)BLOCK_SIZE, 1));
viewParams = { viewParams = {
.viewMatrix = source->getCameraComponent().getViewMatrix(), .viewMatrix = Math::Matrix4(),
.projectionMatrix = source->getCameraComponent().getProjectionMatrix(), .projectionMatrix = Math::Matrix4(),
.inverseProjectionMatrix = glm::inverse(source->getCameraComponent().getProjectionMatrix()), .cameraPosition = Math::Vector4(),
.cameraPosition = Math::Vector4(source->getTransform().getPosition(), 0),
.screenDimensions = glm::vec2(viewportWidth, viewportHeight), .screenDimensions = glm::vec2(viewportWidth, viewportHeight),
}; };
dispatchParams.numThreads = numThreads; dispatchParams.numThreads = numThreads;
@@ -15,9 +15,9 @@ struct LightCullingPassData
class LightCullingPass : public RenderPass<LightCullingPassData> class LightCullingPass : public RenderPass<LightCullingPassData>
{ {
public: public:
LightCullingPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, PCameraActor camera); LightCullingPass(Gfx::PGraphics graphics);
virtual ~LightCullingPass(); virtual ~LightCullingPass();
virtual void beginFrame() override; virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override; virtual void render() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual void publishOutputs() override; virtual void publishOutputs() override;
@@ -71,7 +71,6 @@ private:
Gfx::PComputeShader cullingShader; Gfx::PComputeShader cullingShader;
Gfx::PPipelineLayout cullingLayout; Gfx::PPipelineLayout cullingLayout;
Gfx::PComputePipeline cullingPipeline; Gfx::PComputePipeline cullingPipeline;
PCameraActor source;
}; };
DEFINE_REF(LightCullingPass) DEFINE_REF(LightCullingPass)
} // namespace Seele } // namespace Seele
@@ -18,8 +18,8 @@ protected:
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
virtual void processMeshBatch( virtual void processMeshBatch(
const MeshBatch& batch, const MeshBatch& batch,
// const PPrimitiveComponent primitiveComponent, Gfx::PViewport target,
const Gfx::PRenderPass& renderPass, Gfx::PRenderPass renderPass,
Gfx::PPipelineLayout pipelineLayout, Gfx::PPipelineLayout pipelineLayout,
Gfx::PDescriptorLayout primitiveLayout, Gfx::PDescriptorLayout primitiveLayout,
Array<Gfx::PDescriptorSet> descriptorSets, Array<Gfx::PDescriptorSet> descriptorSets,
+85 -19
View File
@@ -1,29 +1,95 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "RenderPass.h"
#include "Graphics/GraphicsResources.h"
namespace Seele namespace Seele
{ {
DECLARE_REF(ViewFrame) template<typename... RenderPasses>
class RenderGraph;
class RenderGraphResources template<>
class RenderGraph<>
{ {
public: public:
RenderGraphResources(); RenderGraph(PRenderGraphResources) {}
~RenderGraphResources(); void updatePassData() {}
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: protected:
Map<std::string, Gfx::PRenderTargetAttachment> registeredAttachments; void setViewport(Gfx::PViewport) {}
Map<std::string, Gfx::PTexture> registeredTextures; void createRenderPass() {}
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers; void beginFrame(const Component::Camera&) {}
Map<std::string, Gfx::PUniformBuffer> registeredUniforms; void render() {}
void endFrame() {}
}; };
DEFINE_REF(RenderGraphResources)
template<typename This, typename... Rest>
class RenderGraph<This, Rest...> : private RenderGraph<Rest...>
{
public:
RenderGraph(PRenderGraphResources resources, This&& pass, Rest&&... rest)
: RenderGraph<Rest...>(resources, std::move(rest)...)
, resources(resources)
, rp(std::move(pass))
{
rp.setResources(resources);
}
template<typename PassData, typename... OtherData>
void updatePassData(PassData passData, OtherData... otherData)
{
rp.updateViewFrame(std::move(passData));
RenderGraph<Rest...>::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<Rest...>::setViewport(viewport);
}
void createRenderPass()
{
rp.createRenderPass();
RenderGraph<Rest...>::createRenderPass();
}
void beginFrame(const Component::Camera& cam)
{
rp.beginFrame(cam);
RenderGraph<Rest...>::beginFrame(cam);
}
void render()
{
rp.render();
RenderGraph<Rest...>::render();
}
void endFrame()
{
rp.endFrame();
RenderGraph<Rest...>::endFrame();
}
private:
PRenderGraphResources resources;
This rp;
};
class RenderGraphBuilder
{
public:
template<typename... RenderPasses>
static RenderGraph<RenderPasses...> build(RenderPasses&&... renderPasses)
{
PRenderGraphResources resources = new RenderGraphResources();
return RenderGraph<RenderPasses...>(resources, std::move(renderPasses)...);
}
private:
RenderGraphBuilder() = delete;
};
} // namespace Seele } // namespace Seele
@@ -1,4 +1,4 @@
#include "RenderGraph.h" #include "RenderGraphResources.h"
using namespace Seele; using namespace Seele;
@@ -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<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
Map<std::string, Gfx::PTexture> registeredTextures;
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers;
Map<std::string, Gfx::PUniformBuffer> registeredUniforms;
};
DEFINE_REF(RenderGraphResources)
} // namespace Seele
+11 -7
View File
@@ -1,7 +1,8 @@
#pragma once #pragma once
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "Math/Math.h" #include "Math/Math.h"
#include "RenderGraph.h" #include "RenderGraphResources.h"
#include "Component/Camera.h"
namespace Seele namespace Seele
{ {
@@ -12,27 +13,30 @@ template<typename RenderPassDataType>
class RenderPass class RenderPass
{ {
public: public:
RenderPass(Gfx::PGraphics graphics, Gfx::PViewport viewport) RenderPass(Gfx::PGraphics graphics)
: graphics(graphics) : graphics(graphics)
, viewport(viewport)
{} {}
virtual ~RenderPass() virtual ~RenderPass()
{} {}
void updateViewFrame(RenderPassDataType viewFrame) { void updateViewFrame(RenderPassDataType viewFrame) {
passData = std::move(viewFrame); passData = std::move(viewFrame);
} }
virtual void beginFrame() = 0; virtual void beginFrame(const Component::Camera& cam) = 0;
virtual void render() = 0; virtual void render() = 0;
virtual void endFrame() = 0; virtual void endFrame() = 0;
virtual void publishOutputs() = 0; virtual void publishOutputs() = 0;
virtual void createRenderPass() = 0; virtual void createRenderPass() = 0;
void setResources(PRenderGraphResources _resources) { resources = _resources; } void setResources(PRenderGraphResources _resources) { resources = _resources; }
void setViewport(Gfx::PViewport _viewport)
{
viewport = _viewport;
publishOutputs();
}
protected: protected:
struct ViewParameter struct ViewParameter
{ {
Math::Matrix4 viewMatrix; Math::Matrix4 viewMatrix;
Math::Matrix4 projectionMatrix; Math::Matrix4 projectionMatrix;
Math::Matrix4 inverseProjectionMatrix;
Math::Vector4 cameraPosition; Math::Vector4 cameraPosition;
Math::Vector2 screenDimensions; Math::Vector2 screenDimensions;
Math::Vector2 pad0; Math::Vector2 pad0;
@@ -43,7 +47,7 @@ protected:
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
Gfx::PViewport viewport; Gfx::PViewport viewport;
}; };
template<typename T> template<typename RP, typename T>
concept RenderPassType = true; concept RenderPassType = std::derived_from<RP, RenderPass<T>>;
} // namespace Seele } // namespace Seele
+14 -7
View File
@@ -5,9 +5,8 @@
using namespace Seele; using namespace Seele;
TextPass::TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment) TextPass::TextPass(Gfx::PGraphics graphics)
: RenderPass(graphics, viewport) : RenderPass(graphics)
, renderTarget(attachment)
{ {
} }
@@ -16,7 +15,7 @@ TextPass::~TextPass()
} }
void TextPass::beginFrame() void TextPass::beginFrame(const Component::Camera& cam)
{ {
for(TextRender& render : passData.texts) for(TextRender& render : passData.texts)
{ {
@@ -60,6 +59,13 @@ void TextPass::beginFrame()
.scale = render.scale, .scale = render.scale,
}; };
} }
BulkResourceData projectionUpdate = {
.size = sizeof(Math::Matrix4),
.data = (uint8*)&cam.projectionMatrix,
};
projectionBuffer->updateContents(projectionUpdate);
generalSet->updateBuffer(1, projectionBuffer);
generalSet->writeChanges();
//co_return; //co_return;
} }
@@ -99,7 +105,9 @@ void TextPass::publishOutputs()
void TextPass::createRenderPass() void TextPass::createRenderPass()
{ {
renderTarget = resources->requestRenderTarget("UIPASS_COLOR");
depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH"); depthAttachment = resources->requestRenderTarget("UIPASS_DEPTH");
ShaderCreateInfo createInfo; ShaderCreateInfo createInfo;
createInfo.mainModule = "TextPass"; createInfo.mainModule = "TextPass";
createInfo.defines["INDEX_VIEW_PARAMS"] = "0"; 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->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
textureArrayLayout->create(); textureArrayLayout->create();
Math::Matrix4 projectionMatrix = glm::ortho(0.f, (float)viewport->getSizeX(), 0.f, (float)viewport->getSizeY());
projectionBuffer = graphics->createUniformBuffer({ projectionBuffer = graphics->createUniformBuffer({
.resourceData = { .resourceData = {
.size = sizeof(Math::Matrix4), .size = sizeof(Math::Matrix4),
.data = (uint8*)&projectionMatrix, .data = nullptr,
}, },
.bDynamic = false, .bDynamic = true,
}); });
glyphSampler = graphics->createSamplerState({ glyphSampler = graphics->createSamplerState({
+2 -3
View File
@@ -25,9 +25,9 @@ struct TextPassData
class TextPass : public RenderPass<TextPassData> class TextPass : public RenderPass<TextPassData>
{ {
public: public:
TextPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); TextPass(Gfx::PGraphics graphics);
virtual ~TextPass(); virtual ~TextPass();
virtual void beginFrame() override; virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override; virtual void render() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual void publishOutputs() override; virtual void publishOutputs() override;
@@ -69,7 +69,6 @@ private:
Gfx::PRenderTargetAttachment renderTarget; Gfx::PRenderTargetAttachment renderTarget;
Gfx::PRenderTargetAttachment depthAttachment; Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer;
Gfx::PDescriptorLayout generalLayout; Gfx::PDescriptorLayout generalLayout;
Gfx::PDescriptorLayout textureArrayLayout; Gfx::PDescriptorLayout textureArrayLayout;
+22 -13
View File
@@ -4,9 +4,8 @@
using namespace Seele; using namespace Seele;
UIPass::UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment attachment) UIPass::UIPass(Gfx::PGraphics graphics)
: RenderPass(graphics, viewport) : RenderPass(graphics)
, renderTarget(attachment)
{ {
} }
@@ -15,7 +14,7 @@ UIPass::~UIPass()
} }
void UIPass::beginFrame() void UIPass::beginFrame(const Component::Camera&)
{ {
VertexBufferCreateInfo info = { VertexBufferCreateInfo info = {
.resourceData = { .resourceData = {
@@ -58,20 +57,30 @@ void UIPass::endFrame()
void UIPass::publishOutputs() void UIPass::publishOutputs()
{ {
TextureCreateInfo depthBufferInfo; TextureCreateInfo depthBufferInfo = {
// Even if we only render to part of an image, we need to make sure .width = viewport->getSizeX(),
// that the depthbuffer is the same size or they can't be used in the same .height = viewport->getSizeY(),
// framebuffer .format = Gfx::SE_FORMAT_D32_SFLOAT,
depthBufferInfo.width = viewport->getOwner()->getSizeX(); .usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
depthBufferInfo.height = viewport->getOwner()->getSizeY(); };
depthBufferInfo.format = Gfx::SE_FORMAT_D32_SFLOAT;
depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
depthAttachment = depthAttachment =
new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); 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); 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() void UIPass::createRenderPass()
+3 -2
View File
@@ -15,15 +15,16 @@ struct UIPassData
class UIPass : public RenderPass<UIPassData> class UIPass : public RenderPass<UIPassData>
{ {
public: public:
UIPass(Gfx::PGraphics graphics, Gfx::PViewport viewport, Gfx::PRenderTargetAttachment renderTarget); UIPass(Gfx::PGraphics graphics);
virtual ~UIPass(); virtual ~UIPass();
virtual void beginFrame() override; virtual void beginFrame(const Component::Camera& cam) override;
virtual void render() override; virtual void render() override;
virtual void endFrame() override; virtual void endFrame() override;
virtual void publishOutputs() override; virtual void publishOutputs() override;
virtual void createRenderPass() override; virtual void createRenderPass() override;
private: private:
Gfx::PRenderTargetAttachment renderTarget; Gfx::PRenderTargetAttachment renderTarget;
Gfx::PTexture2D colorBuffer;
Gfx::PRenderTargetAttachment depthAttachment; Gfx::PRenderTargetAttachment depthAttachment;
Gfx::PTexture2D depthBuffer; Gfx::PTexture2D depthBuffer;
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
NsightAftermathGpuCrashTracker.h NsightAftermathGpuCrashTracker.h
NsightAftermathGpuCrashTracker.cpp NsightAftermathGpuCrashTracker.cpp
NsightAftermathHelpers.h NsightAftermathHelpers.h
@@ -283,7 +283,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp; blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp;
blendAttachment.blendEnable = attachment.blendEnable; blendAttachment.blendEnable = attachment.blendEnable;
blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp; blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp;
blendAttachment.colorWriteMask = colorAttachments[i]->componentFlags; blendAttachment.colorWriteMask = attachment.colorWriteMask;
blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor; blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor;
blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor; blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor;
blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor; blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor;
@@ -355,10 +355,10 @@ void Window::choosePresentMode(const Array<VkPresentModeKHR> &modes)
Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo) Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo)
: Gfx::Viewport(owner, viewportInfo), graphics(graphics) : Gfx::Viewport(owner, viewportInfo), graphics(graphics)
{ {
handle.width = static_cast<float>(viewportInfo.sizeX); handle.width = static_cast<float>(viewportInfo.dimensions.size.x);
handle.height = static_cast<float>(viewportInfo.sizeY); handle.height = static_cast<float>(viewportInfo.dimensions.size.y);
handle.x = static_cast<float>(viewportInfo.offsetX); handle.x = static_cast<float>(viewportInfo.dimensions.offset.x);
handle.y = static_cast<float>(viewportInfo.offsetY) + handle.height; handle.y = static_cast<float>(viewportInfo.dimensions.offset.y) + handle.height;
handle.height = -handle.height; handle.height = -handle.height;
handle.minDepth = 0.f; handle.minDepth = 0.f;
handle.maxDepth = 1.f; handle.maxDepth = 1.f;
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
BRDF.h BRDF.h
BRDF.cpp BRDF.cpp
MaterialAsset.h MaterialAsset.h
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Math.h Math.h
Matrix.h Matrix.h
Transform.h Transform.h
+6 -5
View File
@@ -27,10 +27,6 @@ typedef glm::quat Quaternion;
Vector parseVector(const char*); 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) static inline float square(float x)
{ {
return x * x; return x * x;
@@ -101,4 +97,9 @@ static inline Vector toRotator(const Quaternion &other)
return rotatorFromQuat; return rotatorFromQuat;
} }
} // namespace Math } // namespace Math
} // namespace Seele } // 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);
+1 -5
View File
@@ -1,9 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Util.h Util.h
Scene.cpp Scene.cpp
Scene.h) Scene.h)
add_subdirectory(Actor/)
add_subdirectory(Component/)
add_subdirectory(System/)
-11
View File
@@ -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();
}
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include "SystemBase.h"
#include "Scene/Component/Camera.h"
namespace Seele
{
namespace System
{
class CameraSystem : public SystemBase<Component::Camera>
{
public:
CameraSystem(entt::registry& registry) : SystemBase(registry) {}
virtual ~CameraSystem() {}
virtual void update(Component::Camera& component);
private:
};
} // namespace System
} // namespace Seele
@@ -1,7 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Executor.h Executor.h
Executor.cpp Executor.cpp
CameraSystem.h
CameraSystem.cpp
SystemBase.h) SystemBase.h)
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <entt/entt.hpp> #include <entt/entt.hpp>
#include <thread_pool/thread_pool.h> #include <thread_pool/thread_pool.h>
#include "Scene/Component/Component.h" #include "Component/Component.h"
namespace Seele namespace Seele
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
HorizontalLayout.h HorizontalLayout.h
HorizontalLayout.cpp HorizontalLayout.cpp
Layout.h Layout.h
+1 -1
View File
@@ -1,5 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
Button.h Button.h
Button.cpp Button.cpp
Element.h Element.h
+10
View File
@@ -22,6 +22,11 @@ void System::update()
} }
void System::updateViewport(Gfx::PViewport viewport)
{
virtualCamera.projectionMatrix = glm::ortho<float>(0.0f, static_cast<float>(viewport->getSizeX()), 0.0f, static_cast<float>(viewport->getSizeY()));
}
UIPassData System::getUIPassData() UIPassData System::getUIPassData()
{ {
UIPassData uiPassData; UIPassData uiPassData;
@@ -46,3 +51,8 @@ TextPassData System::getTextPassData()
render.textColor = Math::Vector4(1, 0, 0, 1); render.textColor = Math::Vector4(1, 0, 0, 1);
return textPassData; return textPassData;
} }
Component::Camera System::getVirtualCamera() const
{
return virtualCamera;
}
+3
View File
@@ -15,9 +15,12 @@ public:
System(); System();
virtual ~System(); virtual ~System();
void update(); void update();
void updateViewport(Gfx::PViewport viewport);
UIPassData getUIPassData(); UIPassData getUIPassData();
TextPassData getTextPassData(); TextPassData getTextPassData();
Component::Camera getVirtualCamera() const;
private: private:
Component::Camera virtualCamera;
PPanel rootPanel; PPanel rootPanel;
RenderHierarchy hierarchy; RenderHierarchy hierarchy;
}; };
+1 -5
View File
@@ -1,9 +1,5 @@
target_sources(Engine target_sources(Engine
PUBLIC PRIVATE
InspectorView.h
InspectorView.cpp
SceneView.h
SceneView.cpp
View.h View.h
View.cpp View.cpp
Window.cpp Window.cpp
-170
View File
@@ -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<Component::StaticMesh>(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<float>(yOffset));
}
void SceneView::fileCallback(int, const char**)
{
}