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);
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()) {
202 float frame_delta_between_steps =
fabsf(
205 if (frame_delta_between_steps > 0.0f && !inst_.is_navigating) {
210 data_.motion_scale =
float2(0.5f, 0.5f) *
float2(shutter_time_ / frame_delta_between_steps);
215 data_.motion_scale =
float2(1.0f, 0.0f);
217 if (was_navigating_ != inst_.is_navigating) {
221 was_navigating_ = inst_.is_navigating;
225 was_navigating_ = inst_.is_navigating;
228 data_.motion_scale =
float2(1.0f);
231 data_.motion_scale.y = -data_.motion_scale.y;
232 data_.target_size_inv = 1.0f /
float2(extent);
234 if (inst_.camera.is_panoramic()) {
235 float overscan = inst_.camera.data_get().panoramic_view_overscan;
236 const float safety_factor = 0.7f;
237 data_.motion_max_offset_px = (1.0f - 1.0f / overscan) * 0.5f *
float(extent.x) * safety_factor;
245 input_color_tx_ = *input_tx;
246 output_color_tx_ = *output_tx;
248 dispatch_flatten_size_ =
int3(tiles_extent, 1);
254 tiles_tx_.acquire_2d(tiles_extent, gpu::TextureFormat::SFLOAT_16_16_16_16);
256 tile_indirection_buf_.clear_to_zero();
258 inst_.manager->submit(motion_blur_ps_, view);
265 *input_tx = output_color_tx_;
266 *output_tx = input_color_tx_;
#define BLI_assert_msg(a, msg)
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
@ 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)
T length(const VecBase< T, Size > &a)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE int max_ii(int a, int b)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
@ GPU_BARRIER_TEXTURE_FETCH
@ GPU_BARRIER_SHADER_STORAGE
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
static constexpr GPUSamplerState default_sampler()
struct CurveMapping mblur_shutter_curve
float motion_blur_shutter
float motion_blur_depth_scale