Viewport controls
This commit is contained in:
+15
-11
@@ -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 $<TARGET_FILE_DIR:Engine>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Engine>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,SLANG_BINARY> $<TARGET_FILE_DIR:Engine>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:slang,GLSLANG_BINARY> $<TARGET_FILE_DIR:Engine>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,NSAM_BINARY> $<TARGET_FILE_DIR:Engine>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:nsam,LLVM_BINARY> $<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:Editor> $<TARGET_FILE_DIR:Editor>
|
||||
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:Editor>
|
||||
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:Editor>
|
||||
COMMAND_EXPAND_LISTS
|
||||
DEPENDS Editor slang-build)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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<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.
|
||||
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
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
add_subdirectory(System/)
|
||||
add_subdirectory(Window/)
|
||||
|
||||
target_sources(Editor
|
||||
PRIVATE
|
||||
main.cpp)
|
||||
@@ -0,0 +1,2 @@
|
||||
target_sources(Editor
|
||||
PRIVATE)
|
||||
@@ -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 "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)
|
||||
@@ -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;
|
||||
@@ -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
|
||||
#include <thread_pool/thread_pool.h>
|
||||
#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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
@@ -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();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Entity.h"
|
||||
#include "Scene/Component/Transform.h"
|
||||
#include "Component/Transform.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Actor.cpp
|
||||
Actor.h
|
||||
CameraActor.cpp
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "Actor.h"
|
||||
#include "Scene/Component/Camera.h"
|
||||
#include "Component/Camera.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Asset.h
|
||||
Asset.cpp
|
||||
AssetRegistry.h
|
||||
|
||||
@@ -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/)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
Component.h
|
||||
PRIVATE
|
||||
Camera.h
|
||||
Camera.cpp
|
||||
Component.h
|
||||
StaticMesh.h
|
||||
Transform.h
|
||||
Transform.cpp)
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Camera.h"
|
||||
#include "Scene/Actor/Actor.h"
|
||||
#include "Actor/Actor.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
@@ -705,6 +705,16 @@ public:
|
||||
{
|
||||
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
|
||||
{
|
||||
assert(index < N);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Array.h
|
||||
Map.h
|
||||
List.h)
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
GraphicsResources.h
|
||||
GraphicsResources.cpp
|
||||
GraphicsInitializer.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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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<Gfx::PDescriptorSet> 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<float>(viewport->getSizeX()), static_cast<float>(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");
|
||||
|
||||
@@ -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<Gfx::PDescriptorSet> descriptorSets,
|
||||
@@ -34,9 +34,11 @@ struct BasePassData
|
||||
class BasePass : public RenderPass<BasePassData>
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Gfx::PDescriptorSet> 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<float>(viewport->getSizeX()), static_cast<float>(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();
|
||||
|
||||
@@ -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<Gfx::PDescriptorSet> descriptorSets,
|
||||
int32 staticMeshId = -1) override;
|
||||
|
||||
private:
|
||||
Gfx::PViewport target;
|
||||
};
|
||||
DEFINE_REF(DepthPrepassMeshProcessor)
|
||||
DECLARE_REF(CameraActor)
|
||||
struct DepthPrepassData
|
||||
{
|
||||
Array<StaticMeshBatch> staticDrawList;
|
||||
@@ -31,9 +30,11 @@ struct DepthPrepassData
|
||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||
{
|
||||
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<Gfx::PDescriptorSet> descriptorSets;
|
||||
PCameraActor source;
|
||||
Gfx::PPipelineLayout depthPrepassLayout;
|
||||
// Set 0: viewParameter
|
||||
static constexpr uint32 INDEX_VIEW_PARAMS = 0;
|
||||
|
||||
@@ -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<float>(viewportWidth), static_cast<float>(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;
|
||||
|
||||
@@ -15,9 +15,9 @@ struct LightCullingPassData
|
||||
class LightCullingPass : public RenderPass<LightCullingPassData>
|
||||
{
|
||||
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
|
||||
|
||||
@@ -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<Gfx::PDescriptorSet> descriptorSets,
|
||||
|
||||
@@ -1,29 +1,95 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Graphics/GraphicsResources.h"
|
||||
#include "RenderPass.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(ViewFrame)
|
||||
template<typename... RenderPasses>
|
||||
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<std::string, Gfx::PRenderTargetAttachment> registeredAttachments;
|
||||
Map<std::string, Gfx::PTexture> registeredTextures;
|
||||
Map<std::string, Gfx::PStructuredBuffer> registeredBuffers;
|
||||
Map<std::string, Gfx::PUniformBuffer> registeredUniforms;
|
||||
void setViewport(Gfx::PViewport) {}
|
||||
void createRenderPass() {}
|
||||
void beginFrame(const Component::Camera&) {}
|
||||
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
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "RenderGraph.h"
|
||||
#include "RenderGraphResources.h"
|
||||
|
||||
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
|
||||
@@ -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<typename RenderPassDataType>
|
||||
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<typename T>
|
||||
concept RenderPassType = true;
|
||||
template<typename RP, typename T>
|
||||
concept RenderPassType = std::derived_from<RP, RenderPass<T>>;
|
||||
|
||||
} // namespace Seele
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -25,9 +25,9 @@ struct TextPassData
|
||||
class TextPass : public RenderPass<TextPassData>
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -15,15 +15,16 @@ struct UIPassData
|
||||
class UIPass : public RenderPass<UIPassData>
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
NsightAftermathGpuCrashTracker.h
|
||||
NsightAftermathGpuCrashTracker.cpp
|
||||
NsightAftermathHelpers.h
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -355,10 +355,10 @@ void Window::choosePresentMode(const Array<VkPresentModeKHR> &modes)
|
||||
Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &viewportInfo)
|
||||
: Gfx::Viewport(owner, viewportInfo), graphics(graphics)
|
||||
{
|
||||
handle.width = static_cast<float>(viewportInfo.sizeX);
|
||||
handle.height = static_cast<float>(viewportInfo.sizeY);
|
||||
handle.x = static_cast<float>(viewportInfo.offsetX);
|
||||
handle.y = static_cast<float>(viewportInfo.offsetY) + handle.height;
|
||||
handle.width = static_cast<float>(viewportInfo.dimensions.size.x);
|
||||
handle.height = static_cast<float>(viewportInfo.dimensions.size.y);
|
||||
handle.x = static_cast<float>(viewportInfo.dimensions.offset.x);
|
||||
handle.y = static_cast<float>(viewportInfo.dimensions.offset.y) + handle.height;
|
||||
handle.height = -handle.height;
|
||||
handle.minDepth = 0.f;
|
||||
handle.maxDepth = 1.f;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
BRDF.h
|
||||
BRDF.cpp
|
||||
MaterialAsset.h
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Math.h
|
||||
Matrix.h
|
||||
Transform.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
|
||||
} // 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,9 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Util.h
|
||||
Scene.cpp
|
||||
Scene.h)
|
||||
|
||||
add_subdirectory(Actor/)
|
||||
add_subdirectory(Component/)
|
||||
add_subdirectory(System/)
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Executor.h
|
||||
Executor.cpp
|
||||
CameraSystem.h
|
||||
CameraSystem.cpp
|
||||
SystemBase.h)
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <entt/entt.hpp>
|
||||
#include <thread_pool/thread_pool.h>
|
||||
#include "Scene/Component/Component.h"
|
||||
#include "Component/Component.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
HorizontalLayout.h
|
||||
HorizontalLayout.cpp
|
||||
Layout.h
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
Button.h
|
||||
Button.cpp
|
||||
Element.h
|
||||
|
||||
@@ -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 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
target_sources(Engine
|
||||
PUBLIC
|
||||
InspectorView.h
|
||||
InspectorView.cpp
|
||||
SceneView.h
|
||||
SceneView.cpp
|
||||
PRIVATE
|
||||
View.h
|
||||
View.cpp
|
||||
Window.cpp
|
||||
|
||||
@@ -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**)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user