16constexpr std::uint32_t k_taa_sampler_flags = BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP;
23 auto fs = am.get_asset<
gfx::shader>(
"engine:/data/shaders/taa/fs_taa.sc");
24 program_.program = std::make_unique<gpu_program>(vs,
fs);
25 program_.cache_uniforms();
26 return program_.program->is_valid();
32 const auto sz = reference_color->get_size();
33 const auto fmt = reference_color->get_texture(0)->info.format;
34 auto& history_tex = rview.tex_get_or_emplace(
"TAA_HISTORY");
38 history_tex = std::make_shared<gfx::texture>(sz.width,
43 BGFX_TEXTURE_RT | BGFX_TEXTURE_BLIT_DST);
51 const auto sz = reference_color->get_size();
52 const auto fmt = reference_color->get_texture(0)->info.format;
53 auto& out_tex = rview.tex_get_or_emplace(
"TAA_TEMP");
57 out_tex = std::make_shared<gfx::texture>(sz.width, sz.height,
false, 1, fmt, BGFX_TEXTURE_RT);
59 auto& fbo = rview.fbo_get_or_emplace(
"TAA_TEMP");
63 fbo = std::make_shared<gfx::frame_buffer>();
64 fbo->populate({out_tex});
71 const auto&
input = params.input;
72 if(!program_.program || !program_.program->is_valid() || !
input || !params.cam || !params.g_buffer)
77 auto old_history = rview.tex_safe_get(
"TAA_HISTORY");
78 auto history_tex = create_or_update_history_tex(rview,
input);
79 auto temp_fbo = create_or_update_temp_fb(rview,
input);
81 if(history_tex != old_history)
85 history_tex->native_handle(),
88 input->get_texture(0)->native_handle(),
97 pass.
bind(temp_fbo.get());
98 pass.
set_view_proj(params.cam->get_view(), params.cam->get_projection());
100 if(!program_.program->begin())
107 gfx::set_texture(program_.s_depth, 2, params.g_buffer->get_texture(4), k_taa_sampler_flags);
109 const auto prev_vp = params.cam->get_taa_prev_view_projection();
112 const float taa_params[4] = {params.config.history_blend,
113 params.config.sharpen,
114 params.config.depth_reject_scale,
115 params.config.variance_clip_scale};
119 gfx::set_state(topology | BGFX_STATE_DEPTH_TEST_NEVER | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A);
123 program_.program->end();
128 history_tex->native_handle(),
131 temp_fbo->get_texture(0)->native_handle(),
139 params.output->get_texture(0)->native_handle(),
142 temp_fbo->get_texture(0)->native_handle(),
145 return params.output;
std::shared_ptr< frame_buffer > ptr
void tex_remove(const hpp::string_view &id)
void fbo_remove(const hpp::string_view &id)
Manages assets, including loading, unloading, and storage.
auto get_asset(const std::string &key, load_flags flags=load_flags::standard, load_mode mode=load_mode::immediate) -> asset_handle< T >
Gets an asset by its key.
auto init(rtti::context &ctx) -> bool
void release_resources(gfx::render_view &rview)
auto run(gfx::render_view &rview, const run_params ¶ms) -> gfx::frame_buffer::ptr
void submit(view_id _id, program_handle _handle, int32_t _depth, bool _preserveState)
void set_state(uint64_t _state, uint32_t _rgba)
auto needs_recreate(const gfx::frame_buffer::ptr &fbo, const usize32_t &size) -> bool
void blit(view_id _id, texture_handle _dst, uint16_t _dstX, uint16_t _dstY, texture_handle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height)
void discard(uint8_t _flags)
void set_uniform(uniform_handle _handle, const void *_value, uint16_t _num)
auto clip_quad(float depth, float width, float height) -> uint64_t
void set_texture(uint8_t _stage, uniform_handle _sampler, texture_handle _handle, uint32_t _flags)
#define APP_SCOPE_PERF(name_literal)
Create a scoped performance timer that records to the timeline profiler. Only accepts string literals...
void set_view_proj(const float *v, const float *p)
void bind(const frame_buffer *fb=nullptr) const