28 const Scene *scene = inst_.scene;
29 const ViewLayer *view_layer = inst_.view_layer;
33 enabled_ = (scene->
r.
mode &
R_MBLUR) != 0 && (inst_.is_image_render() || inst_.is_playback());
39 motion_blur_fx_enabled_ =
false;
46 time_steps_.resize(steps_count);
48 initial_frame_ = scene->
r.
cfra;
50 frame_time_ = initial_frame_ + initial_subframe_;
55 motion_blur_fx_enabled_ =
true;
58 if (inst_.is_viewport()) {
70 for (
float &time : time_steps_) {
71 time = this->shutter_time_to_scene_time(time);
76 if (motion_blur_fx_enabled_) {
80 inst_.velocity.step_sync(
STEP_NEXT, time_steps_[2]);
83 inst_.set_time(time_steps_[1]);
93 if (inst_.sampling.finished()) {
97 else if (inst_.sampling.do_render_sync()) {
102 if (motion_blur_fx_enabled_) {
103 inst_.velocity.step_swap();
106 inst_.set_time(time_steps_[step_id_]);
110float MotionBlurModule::shutter_time_to_scene_time(
float time)
112 switch (shutter_position_) {
126 time *= shutter_time_;
135 if (inst_.velocity.camera_changed_projection() ||
136 (inst_.is_viewport() && (inst_.camera.overscan_changed() || inst_.camera.camera_changed())))
138 motion_blur_fx_enabled_ =
false;
141 if (!motion_blur_fx_enabled_) {
148 motion_blur_ps_.
init();
149 motion_blur_ps_.bind_resources(inst_.velocity);
150 motion_blur_ps_.bind_resources(inst_.sampling);
157 sub.
shader_set(inst_.shaders.static_shader_get(shader));
158 sub.
bind_ubo(
"motion_blur_buf", data_);
162 sub.
dispatch(&dispatch_flatten_size_);
169 sub.
bind_ssbo(
"tile_indirection_buf", tile_indirection_buf_);
171 sub.
dispatch(&dispatch_dilate_size_);
178 sub.
bind_ubo(
"motion_blur_buf", data_);
179 sub.
bind_ssbo(
"tile_indirection_buf", tile_indirection_buf_);
184 sub.
bind_image(
"out_color_img", &output_color_tx_);
186 sub.
dispatch(&dispatch_gather_size_);
193 if (!motion_blur_fx_enabled_) {
197 const Texture &depth_tx = inst_.render_buffers.depth_tx;
202 if (inst_.is_viewport()) {
205 if (frame_delta > 0.0f && !inst_.is_navigating()) {
208 data_.motion_scale =
float2(shutter_time_ / frame_delta);
213 data_.motion_scale =
float2(1.0f, 0.0f);
215 if (was_navigating_ != inst_.is_navigating()) {
219 was_navigating_ = inst_.is_navigating();
223 was_navigating_ = inst_.is_navigating();
226 data_.motion_scale =
float2(1.0f);
229 data_.motion_scale.y = -data_.motion_scale.y;
230 data_.target_size_inv = 1.0f /
float2(extent);
234 output_color_tx_ = *output_tx;
236 dispatch_flatten_size_ =
int3(tiles_extent, 1);
244 tile_indirection_buf_.clear_to_zero();
246 const bool do_motion_vectors_swizzle = inst_.render_buffers.vector_tx_format() ==
GPU_RG16F;
247 if (do_motion_vectors_swizzle) {
252 inst_.manager->submit(motion_blur_ps_,
view);
254 if (do_motion_vectors_swizzle) {
265 *output_tx = input_color_tx_;
#define BLI_assert_msg(a, msg)
MINLINE int max_ii(int a, int b)
#define MOTION_BLUR_TILE_SIZE
@ GPU_BARRIER_SHADER_STORAGE
@ GPU_BARRIER_TEXTURE_FETCH
@ GPU_BARRIER_SHADER_IMAGE_ACCESS
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, GPUTexture *image)
void dispatch(int group_len)
void barrier(eGPUBarrier type)
void bind_ubo(const char *name, GPUUniformBuf *buffer)
void bind_ssbo(const char *name, GPUStorageBuf *buffer)
void shader_set(GPUShader *shader)
detail::PassBase< command::DrawCommandBuf > Sub
void render(View &view, GPUTexture **input_tx, GPUTexture **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)
void DRW_stats_group_start(const char *name)
void DRW_stats_group_end()
#define MOTION_BLUR_GROUP_SIZE
void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
constexpr GPUSamplerState no_filter
@ 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