2020-08-11 12:07:21 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
2020-08-13 07:48:50 -04:00
|
|
|
#include <cmath>
|
|
|
|
|
2020-08-11 12:07:21 -04:00
|
|
|
#include "pass.hpp"
|
|
|
|
#include "matrix.hpp"
|
|
|
|
#include "object.hpp"
|
|
|
|
#include "common.hpp"
|
2020-09-20 23:31:03 -04:00
|
|
|
#include "render_options.hpp"
|
2020-09-21 09:37:52 -04:00
|
|
|
#include "path.hpp"
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
namespace ui {
|
|
|
|
class Screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
class GFX;
|
|
|
|
class GFXBuffer;
|
|
|
|
class GFXCommandBuffer;
|
|
|
|
class GFXFramebuffer;
|
|
|
|
class GFXPipeline;
|
|
|
|
class GFXRenderPass;
|
|
|
|
class GFXTexture;
|
|
|
|
class SMAAPass;
|
|
|
|
class ShadowPass;
|
|
|
|
class SceneCapture;
|
|
|
|
class GaussianHelper;
|
|
|
|
class DoFPass;
|
|
|
|
|
|
|
|
class Scene;
|
|
|
|
struct MeshData;
|
|
|
|
struct Camera;
|
|
|
|
|
|
|
|
constexpr int max_scene_materials = 25, max_scene_lights = 25;
|
|
|
|
|
|
|
|
struct RenderScreenOptions {
|
|
|
|
bool render_world = false;
|
|
|
|
Matrix4x4 mvp;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Material;
|
|
|
|
|
|
|
|
class Renderer {
|
|
|
|
public:
|
|
|
|
Renderer(GFX* gfx, const bool enable_imgui = true);
|
2020-09-21 09:37:52 -04:00
|
|
|
~Renderer();
|
2020-08-11 12:07:21 -04:00
|
|
|
|
2020-08-13 07:48:50 -04:00
|
|
|
void resize(const prism::Extent extent);
|
|
|
|
void resize_viewport(const prism::Extent extent);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
void set_screen(ui::Screen* screen);
|
|
|
|
void init_screen(ui::Screen* screen);
|
|
|
|
void update_screen();
|
|
|
|
|
|
|
|
void startCrossfade();
|
|
|
|
void startSceneBlur();
|
|
|
|
void stopSceneBlur();
|
|
|
|
|
|
|
|
float fade = 0.0f;
|
|
|
|
bool fading = false;
|
|
|
|
|
|
|
|
bool blurring = false;
|
|
|
|
bool hasToStore = true;
|
|
|
|
int blurFrame = 0;
|
|
|
|
|
|
|
|
GFXTexture* blurStore = nullptr;
|
|
|
|
|
|
|
|
struct ControllerContinuity {
|
|
|
|
int elementOffset = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void render(Scene* scene, int index);
|
|
|
|
|
|
|
|
void render_screen(GFXCommandBuffer* commandBuffer, ui::Screen* screen, ControllerContinuity& continuity, RenderScreenOptions options = RenderScreenOptions());
|
2020-08-17 08:45:28 -04:00
|
|
|
void render_camera(GFXCommandBuffer* command_buffer, Scene& scene, Object camera_object, Camera& camera, prism::Extent extent, ControllerContinuity& continuity);
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
void create_mesh_pipeline(Material& material);
|
|
|
|
|
|
|
|
// passes
|
|
|
|
template<class T, typename... Args>
|
|
|
|
T* addPass(Args&&... args) {
|
|
|
|
auto t = std::make_unique<T>(args...);
|
|
|
|
t->initialize();
|
|
|
|
|
|
|
|
return static_cast<T*>(passes.emplace_back(std::move(t)).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
GFXTexture* get_requested_texture(PassTextureType type) {
|
|
|
|
for(auto& pass : passes) {
|
|
|
|
auto texture = pass->get_requested_texture(type);
|
|
|
|
if(texture != nullptr)
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GFXRenderPass* getOffscreenRenderPass() const {
|
|
|
|
return offscreenRenderPass;
|
|
|
|
}
|
|
|
|
|
|
|
|
GFXTexture* offscreenColorTexture = nullptr;
|
|
|
|
GFXTexture* offscreenDepthTexture = nullptr;
|
|
|
|
|
|
|
|
GFXTexture* viewportColorTexture = nullptr;
|
|
|
|
|
|
|
|
bool viewport_mode = false;
|
2020-08-13 07:48:50 -04:00
|
|
|
prism::Extent viewport_extent;
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
bool gui_only_mode = false;
|
|
|
|
|
2020-08-13 07:48:50 -04:00
|
|
|
prism::Extent get_extent() const {
|
2020-08-11 12:07:21 -04:00
|
|
|
return viewport_mode ? viewport_extent : extent;
|
|
|
|
}
|
|
|
|
|
2020-08-13 07:48:50 -04:00
|
|
|
prism::Extent get_render_extent() const {
|
2020-08-11 12:07:21 -04:00
|
|
|
const auto extent = get_extent();
|
|
|
|
|
|
|
|
return {static_cast<uint32_t>(std::max(int(extent.width * render_options.render_scale), 1)),
|
|
|
|
static_cast<uint32_t>(std::max(int(extent.height * render_options.render_scale), 1))};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ShadowPass> shadow_pass;
|
|
|
|
std::unique_ptr<SceneCapture> scene_capture;
|
|
|
|
|
|
|
|
GFXTexture* dummyTexture = nullptr;
|
|
|
|
GFXRenderPass* unormRenderPass = nullptr;
|
|
|
|
GFXPipeline* renderToUnormTexturePipeline = nullptr;
|
|
|
|
GFXRenderPass* viewportRenderPass = nullptr;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createDummyTexture();
|
|
|
|
void createOffscreenResources();
|
|
|
|
void createMeshPipeline();
|
|
|
|
void createPostPipeline();
|
|
|
|
void createFontPipeline();
|
|
|
|
void createSkyPipeline();
|
|
|
|
void createUIPipeline();
|
|
|
|
void createGaussianResources();
|
|
|
|
void createBRDF();
|
2020-09-22 15:39:20 -04:00
|
|
|
void create_histogram_resources();
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
GFX* gfx = nullptr;
|
2020-08-13 07:48:50 -04:00
|
|
|
prism::Extent extent;
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
ui::Screen* current_screen = nullptr;
|
|
|
|
|
|
|
|
// offscreen
|
|
|
|
GFXTexture* offscreenBackTexture = nullptr;
|
|
|
|
GFXFramebuffer* offscreenFramebuffer = nullptr;
|
|
|
|
GFXRenderPass* offscreenRenderPass = nullptr;
|
|
|
|
|
|
|
|
GFXFramebuffer* viewportFramebuffer = nullptr;
|
|
|
|
|
|
|
|
// mesh
|
|
|
|
GFXBuffer* sceneBuffer = nullptr;
|
|
|
|
|
|
|
|
// sky
|
|
|
|
GFXPipeline* skyPipeline = nullptr;
|
|
|
|
|
|
|
|
// post
|
|
|
|
GFXPipeline* postPipeline = nullptr;
|
|
|
|
GFXPipeline* renderToTexturePipeline = nullptr;
|
|
|
|
GFXPipeline* renderToViewportPipeline = nullptr;
|
|
|
|
|
|
|
|
// font
|
|
|
|
GFXTexture* fontTexture = nullptr;
|
|
|
|
GFXPipeline* textPipeline, *worldTextPipeline = nullptr;
|
|
|
|
int instanceAlignment = 0;
|
|
|
|
|
|
|
|
// brdf
|
|
|
|
GFXPipeline* brdfPipeline = nullptr;
|
|
|
|
GFXTexture* brdfTexture = nullptr;
|
|
|
|
GFXFramebuffer* brdfFramebuffer = nullptr;
|
|
|
|
GFXRenderPass* brdfRenderPass = nullptr;
|
|
|
|
|
|
|
|
// general ui
|
|
|
|
GFXPipeline* generalPipeline, *worldGeneralPipeline = nullptr;
|
2020-09-22 15:39:20 -04:00
|
|
|
|
|
|
|
// histogram compute
|
2020-09-22 20:05:51 -04:00
|
|
|
GFXPipeline* histogram_pipeline = nullptr, *histogram_average_pipeline = nullptr;
|
2020-09-22 17:27:10 -04:00
|
|
|
GFXBuffer* histogram_buffer = nullptr;
|
2020-09-22 20:05:51 -04:00
|
|
|
GFXTexture* average_luminance_texture = nullptr;
|
2020-08-11 12:07:21 -04:00
|
|
|
|
|
|
|
std::unique_ptr<SMAAPass> smaaPass;
|
|
|
|
std::unique_ptr<GaussianHelper> gHelper;
|
|
|
|
std::unique_ptr<DoFPass> dofPass;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<Pass>> passes;
|
2020-09-22 22:10:02 -04:00
|
|
|
|
|
|
|
double current_render_scale = 1.0;
|
2020-08-11 12:07:21 -04:00
|
|
|
};
|