hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/rendering/black_hole_renderer.h
blob: 563fa9b0096cec93ac3bf8e2c30646d0329513e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "rhi.h"
#include "renderer_backend.h"
#include <glm/glm.hpp>

namespace Donut
{
    struct GeodesicView
    {
        glm::vec3 position, right, up, forward;
        float tan_half_fov = 1.0f;
        float aspect       = 16.0f / 9.0f;
        bool  moving       = false;
        float time         = 0.0f;
    };

    class BlackHoleRenderer
    {
    public:
        static constexpr int GEO_LO_W = 480, GEO_LO_H = 270;
        static constexpr int GEO_HI_W = 960, GEO_HI_H = 540;

        auto init(RHI::Device& device) -> bool;

        auto render_geodesic(RHI::CommandList& cmd, const GeodesicView& view,
                             const BlackHoleParams& params, RHI::Texture* cubemap) -> void;

        auto blit(RHI::CommandList& cmd, int fb_width, int fb_height) -> void;

    private:
        RHI::Device* m_device = nullptr;

        Ref<RHI::Pipeline>     m_geo_pipeline;
        Ref<RHI::RenderTarget> m_geo_lo;
        Ref<RHI::RenderTarget> m_geo_hi;
        Ref<RHI::Buffer>       m_quad_vb;
        Ref<RHI::Buffer>       m_cam_ubo;
        Ref<RHI::Buffer>       m_disk_ubo;
        Ref<RHI::Buffer>       m_obj_ubo;
        Ref<RHI::Buffer>       m_sim_ubo;

        Ref<RHI::Pipeline>     m_present_pipeline;
        RHI::RenderTarget*     m_last_target = nullptr;
    };
}