27 const Scene *scene = inst_.scene;
28 const ViewLayer *view_layer = inst_.view_layer;
32 enabled_ = (scene->
r.
mode &
R_MBLUR) != 0 && (inst_.is_image_render || inst_.is_playback);
38 motion_blur_fx_enabled_ =
false;
45 time_steps_.resize(steps_count);
47 initial_frame_ = scene->
r.
cfra;
49 frame_time_ = initial_frame_ + initial_subframe_;
54 motion_blur_fx_enabled_ =
true;
57 if (inst_.is_viewport()) {
69 for (
float &time : time_steps_) {
70 time = this->shutter_time_to_scene_time(time);
75 if (motion_blur_fx_enabled_) {
79 inst_.velocity.step_sync(
STEP_NEXT, time_steps_[2]);
82 inst_.set_time(time_steps_[1]);
91 if (inst_.sampling.finished()) {
95 else if (inst_.sampling.do_render_sync()) {
100 if (motion_blur_fx_enabled_) {
101 inst_.velocity.step_swap();
104 inst_.set_time(time_steps_[step_id_]);
108float MotionBlurModule::shutter_time_to_scene_time(
float time)
110 switch (shutter_position_) {
124 time *= shutter_time_;
133 if (inst_.velocity.camera_changed_projection() ||
134 (inst_.is_viewport() && (inst_.camera.overscan_changed() || inst_.camera.camera_changed())))
136 motion_blur_fx_enabled_ =
false;
139 if (!motion_blur_fx_enabled_) {
146 motion_blur_ps_.
init();
147 motion_blur_ps_.bind_resources(inst_.velocity);
148 motion_blur_ps_.bind_resources(inst_.sampling);
153 eShaderType shader = vector_tx_format == gpu::TextureFormat::SFLOAT_16_16 ?
156 sub.
shader_set(inst_.shaders.static_shader_get(shader));
157 sub.
bind_ubo(
"motion_blur_buf", data_);
161 sub.
dispatch(&dispatch_flatten_size_);
168 sub.
bind_ssbo(
"tile_indirection_buf", tile_indirection_buf_);
170 sub.
dispatch(&dispatch_dilate_size_);
177 sub.
bind_ubo(
"motion_blur_buf", data_);
178 sub.
bind_ssbo(
"tile_indirection_buf", tile_indirection_buf_);
181 sub.
bind_texture(
"in_color_tx", &input_color_tx_, no_filter);
183 sub.
bind_image(
"out_color_img", &output_color_tx_);
185 sub.
dispatch(&dispatch_gather_size_);
192 if (!motion_blur_fx_enabled_) {
196 const Texture &depth_tx = inst_.render_buffers.depth_tx;
201 if (inst_.is_viewport()) {
204 if (frame_delta > 0.0f && !inst_.is_navigating) {
207 data_.motion_scale =
float2(shutter_time_ / frame_delta);
212 data_.motion_scale =
float2(1.0f, 0.0f);
214 if (was_navigating_ != inst_.is_navigating) {
218 was_navigating_ = inst_.is_navigating;
222 was_navigating_ = inst_.is_navigating;
225 data_.motion_scale =
float2(1.0f);
228 data_.motion_scale.y = -data_.motion_scale.y;
229 data_.target_size_inv = 1.0f /
float2(extent);
232 input_color_tx_ = *input_tx;
233 output_color_tx_ = *output_tx;
235 dispatch_flatten_size_ =
int3(tiles_extent, 1);
241 tiles_tx_.acquire(tiles_extent, gpu::TextureFormat::SFLOAT_16_16_16_16);
243 tile_indirection_buf_.clear_to_zero();
245 inst_.manager->submit(motion_blur_ps_,
view);
252 *input_tx = output_color_tx_;
253 *output_tx = input_color_tx_;
#define BLI_assert_msg(a, msg)
MINLINE int max_ii(int a, int b)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
@ GPU_BARRIER_SHADER_STORAGE
@ GPU_BARRIER_TEXTURE_FETCH
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, gpu::Texture *image)
void dispatch(int group_len)
void barrier(GPUBarrier type)
void bind_ubo(const char *name, gpu::UniformBuf *buffer)
void bind_ssbo(const char *name, gpu::StorageBuf *buffer)
detail::PassBase< command::DrawCommandBuf > Sub
void render(View &view, gpu::Texture **input_tx, gpu::Texture **output_tx)
TextureFromPool vector_tx
static void cdf_invert(Vector< float > &cdf, Vector< float > &inverted_cdf)
static void cdf_from_curvemapping(const CurveMapping &curve, Vector< float > &cdf)
#define MOTION_BLUR_GROUP_SIZE
#define MOTION_BLUR_TILE_SIZE
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
@ MOTION_BLUR_TILE_FLATTEN_RGBA
@ MOTION_BLUR_TILE_FLATTEN_RG
@ MOTION_BLUR_TILE_DILATE
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
static constexpr GPUSamplerState default_sampler()
float motion_blur_shutter
struct CurveMapping mblur_shutter_curve
float motion_blur_depth_scale