2021-05-06 17:02:10 +02:00
|
|
|
#pragma once
|
2022-11-17 16:47:42 +01:00
|
|
|
#include "Component/Camera.h"
|
2023-10-24 15:01:09 +02:00
|
|
|
#include "Graphics/VertexData.h"
|
2024-06-09 12:20:04 +02:00
|
|
|
#include "Material/MaterialInstance.h"
|
|
|
|
|
#include "Math/Math.h"
|
|
|
|
|
#include "MinimalEngine.h"
|
|
|
|
|
#include "RenderGraphResources.h"
|
|
|
|
|
#include "Scene/Scene.h"
|
2021-05-06 17:02:10 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
|
|
|
|
|
namespace Seele {
|
2021-09-23 10:10:39 +02:00
|
|
|
DECLARE_NAME_REF(Gfx, Viewport)
|
|
|
|
|
DECLARE_NAME_REF(Gfx, Graphics)
|
2021-05-06 17:02:10 +02:00
|
|
|
DECLARE_NAME_REF(Gfx, RenderPass)
|
2024-06-09 12:20:04 +02:00
|
|
|
class RenderPass {
|
|
|
|
|
public:
|
2025-01-08 19:15:12 +01:00
|
|
|
RenderPass(Gfx::PGraphics graphics);
|
2023-11-05 10:36:01 +01:00
|
|
|
RenderPass(RenderPass&&) = default;
|
|
|
|
|
RenderPass& operator=(RenderPass&&) = default;
|
|
|
|
|
virtual ~RenderPass();
|
2025-05-06 19:36:43 +02:00
|
|
|
virtual void beginFrame(const Component::Camera& cam, const Component::Transform& transform) = 0;
|
2022-04-15 23:45:44 +02:00
|
|
|
virtual void render() = 0;
|
|
|
|
|
virtual void endFrame() = 0;
|
2021-05-06 17:02:10 +02:00
|
|
|
virtual void publishOutputs() = 0;
|
|
|
|
|
virtual void createRenderPass() = 0;
|
2023-11-05 10:36:01 +01:00
|
|
|
void setResources(PRenderGraphResources _resources);
|
|
|
|
|
void setViewport(Gfx::PViewport _viewport);
|
2024-06-09 12:20:04 +02:00
|
|
|
|
|
|
|
|
protected:
|
2025-07-14 21:10:07 +02:00
|
|
|
void updateViewParameters(const Component::Camera& cam, const Component::Transform& transform);
|
2025-08-10 19:16:55 +02:00
|
|
|
Gfx::ODescriptorSet createViewParamsSet();
|
2024-10-07 20:14:00 +02:00
|
|
|
struct Plane {
|
|
|
|
|
Vector n;
|
|
|
|
|
float d;
|
|
|
|
|
};
|
|
|
|
|
struct Frustum {
|
|
|
|
|
Plane planes[4];
|
|
|
|
|
};
|
2024-10-21 22:12:50 +02:00
|
|
|
Plane computePlane(Vector p0, Vector p1, Vector p2) {
|
|
|
|
|
Plane plane;
|
|
|
|
|
|
|
|
|
|
Vector v0 = p1 - p0;
|
|
|
|
|
Vector v2 = p2 - p0;
|
|
|
|
|
|
|
|
|
|
plane.n = normalize(cross(v0, v2));
|
|
|
|
|
|
|
|
|
|
plane.d = dot(plane.n, p0);
|
|
|
|
|
|
|
|
|
|
return plane;
|
|
|
|
|
}
|
2024-10-22 13:31:58 +02:00
|
|
|
void normalize_plane(Plane& plane);
|
|
|
|
|
void extract_planes_from_view_projection_matrix(const Matrix4 viewProj, Frustum& frustum);
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
struct ViewParameter {
|
2023-01-21 18:43:21 +01:00
|
|
|
Matrix4 viewMatrix;
|
2024-05-04 09:25:13 +02:00
|
|
|
Matrix4 inverseViewMatrix;
|
2023-01-21 18:43:21 +01:00
|
|
|
Matrix4 projectionMatrix;
|
2024-02-23 08:31:21 +01:00
|
|
|
Matrix4 inverseProjection;
|
2024-10-21 22:12:50 +02:00
|
|
|
Matrix4 viewProjectionMatrix;
|
|
|
|
|
Matrix4 inverseViewProjectionMatrix;
|
2024-10-07 20:14:00 +02:00
|
|
|
Vector4 cameraPosition_WS;
|
|
|
|
|
Vector4 cameraForward_WS;
|
2023-01-21 18:43:21 +01:00
|
|
|
Vector2 screenDimensions;
|
2024-10-07 20:14:00 +02:00
|
|
|
Vector2 invScreenDimensions;
|
|
|
|
|
uint32 frameIndex;
|
|
|
|
|
float time;
|
2025-02-02 09:39:01 +01:00
|
|
|
uint32 pad0;
|
|
|
|
|
uint32 pad1;
|
2021-05-10 23:57:55 +02:00
|
|
|
} viewParams;
|
2021-10-01 19:55:04 +02:00
|
|
|
PRenderGraphResources resources;
|
2023-11-05 10:36:01 +01:00
|
|
|
Gfx::ODescriptorLayout viewParamsLayout;
|
|
|
|
|
Gfx::ORenderPass renderPass;
|
2021-09-23 10:10:39 +02:00
|
|
|
Gfx::PGraphics graphics;
|
|
|
|
|
Gfx::PViewport viewport;
|
2021-05-06 17:02:10 +02:00
|
|
|
};
|
2024-04-05 10:41:59 +02:00
|
|
|
DEFINE_REF(RenderPass)
|
2024-06-09 12:20:04 +02:00
|
|
|
template <typename RP>
|
2023-10-24 15:01:09 +02:00
|
|
|
concept RenderPassType = std::derived_from<RP, RenderPass>;
|
2021-10-01 19:55:04 +02:00
|
|
|
|
2021-05-06 17:02:10 +02:00
|
|
|
} // namespace Seele
|