Blender V5.3
node_composite_vector_blur.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <cstdint>
6
7#include "BLI_index_range.hh"
8#include "BLI_math_base.hh"
9#include "BLI_math_vector.hh"
11
12#include "GPU_compute.hh"
13#include "GPU_shader.hh"
14#include "GPU_state.hh"
15#include "GPU_storage_buffer.hh"
16#include "GPU_vertex_buffer.hh"
17
18#include "COM_node_operation.hh"
19#include "COM_result.hh"
20#include "COM_utilities.hh"
21
23
25
27{
28 b.use_custom_socket_order();
29 b.allow_any_socket_order();
30 b.add_input<decl::Color>("Image"_ustr)
31 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 .hide_value()
33 .structure_type(StructureType::Dynamic);
34 b.add_output<decl::Color>("Image"_ustr)
35 .structure_type(StructureType::Dynamic)
36 .align_with_previous();
37
38 b.add_input<decl::Vector>("Speed"_ustr)
39 .dimensions(4)
40 .default_value({0.0f, 0.0f, 0.0f})
41 .min(0.0f)
42 .max(1.0f)
43 .subtype(PROP_VELOCITY)
44 .structure_type(StructureType::Dynamic);
45 b.add_input<decl::Float>("Depth"_ustr, "Z"_ustr)
46 .default_value(0.0f)
47 .min(0.0f)
48 .structure_type(StructureType::Dynamic);
49 b.add_input<decl::Int>("Samples"_ustr)
50 .default_value(32)
51 .min(1)
52 .max(256)
53 .description("The number of samples used to approximate the motion blur");
54 b.add_input<decl::Float>("Shutter"_ustr)
55 .default_value(0.5f)
56 .min(0.0f)
57 .description("Time between shutter opening and closing in frames");
58}
59
60using namespace blender::compositor;
61
62#define MOTION_BLUR_TILE_SIZE 32
63#define DEPTH_SCALE 100.0f
64
65/* Returns the input velocity that has the larger magnitude. */
66static float2 max_velocity(const float2 &a, const float2 &b)
67{
69}
70
71/* Identical to motion_blur_tile_indirection_pack_payload, encodes the value and its texel such
72 * that the integer length of the value is encoded in the most significant bits, then the x value
73 * of the texel are encoded in the middle bits, then the y value of the texel is stored in the
74 * least significant bits. */
75static uint32_t velocity_atomic_max_value(const float2 &value, const int2 &texel)
76{
77 const uint32_t length_bits = math::min(uint32_t(math::ceil(math::length(value))), 0x3FFFu);
78 return (length_bits << 18u) | ((texel.x & 0x1FFu) << 9u) | (texel.y & 0x1FFu);
79}
80
81/* Returns the input velocity that has the larger integer magnitude, and if equal the larger x
82 * texel coordinates, and if equal, the larger y texel coordinates. It might be weird that we use
83 * an approximate comparison, but this is used for compatibility with the GPU code, which uses
84 * atomic integer operations, hence the limited precision. See velocity_atomic_max_value for more
85 * information. */
87 const float2 &b,
88 const int2 &a_texel,
89 const int2 &b_texel)
90{
91 return velocity_atomic_max_value(a, a_texel) > velocity_atomic_max_value(b, b_texel) ? a : b;
92}
93
94/* Reduces each 32x32 block of velocity pixels into a single velocity whose magnitude is largest.
95 * Each of the previous and next velocities are reduces independently. */
96static Result compute_max_tile_velocity_cpu(Context &context, const Result &velocity_image)
97{
98 if (velocity_image.is_single_value()) {
99 Result output = context.create_result(ResultType::Float4);
100 output.allocate_single_value();
101 output.set_single_value(velocity_image.get_single_value<float4>());
102 return output;
103 }
104
105 const int2 tile_size = int2(MOTION_BLUR_TILE_SIZE);
106 const int2 velocity_size = velocity_image.domain().data_size;
107 const int2 tiles_count = math::divide_ceil(velocity_size, tile_size);
108 Result output = context.create_result(ResultType::Float4);
109 output.allocate_texture(Domain(tiles_count));
110
111 parallel_for(tiles_count, [&](const int2 texel) {
112 float2 max_previous_velocity = float2(0.0f);
113 float2 max_next_velocity = float2(0.0f);
114
115 for (int j = 0; j < tile_size.y; j++) {
116 for (int i = 0; i < tile_size.x; i++) {
117 int2 sub_texel = texel * tile_size + int2(i, j);
118 const float4 velocity = velocity_image.load_pixel_extended<float4>(sub_texel);
119 max_previous_velocity = max_velocity(velocity.xy(), max_previous_velocity);
120 max_next_velocity = max_velocity(velocity.zw(), max_next_velocity);
121 }
122 }
123
124 const float4 max_velocity = float4(max_previous_velocity, max_next_velocity);
125 output.store_pixel(texel, max_velocity);
126 });
127
128 return output;
129}
130
135
136static MotionRect compute_motion_rect(const int2 &tile, const float2 &motion, const int2 &size)
137{
138 /* `ceil()` to number of tile touched. */
139 int2 point1 = tile + int2(math::sign(motion) *
140 math::ceil(math::abs(motion) / float(MOTION_BLUR_TILE_SIZE)));
141 int2 point2 = tile;
142
143 int2 max_point = math::max(point1, point2);
144 int2 min_point = math::min(point1, point2);
145 /* Clamp to bounds. */
146 max_point = math::min(max_point, size - 1);
147 min_point = math::max(min_point, int2(0));
148
149 MotionRect rect;
150 rect.bottom_left = min_point;
151 rect.extent = 1 + max_point - min_point;
152 return rect;
153}
154
161
162static MotionLine compute_motion_line(const int2 &tile, const float2 &motion)
163{
164 float magnitude = math::length(motion);
165 float2 dir = magnitude != 0.0f ? motion / magnitude : motion;
166
167 MotionLine line;
168 line.origin = float2(tile);
169 /* Rotate 90 degrees counter-clockwise. */
170 line.normal = float2(-dir.y, dir.x);
171 return line;
172}
173
174static bool is_inside_motion_line(const int2 &tile, const MotionLine &motion_line)
175{
176 /* NOTE: Everything in is tile unit. */
177 float distance_to_line = math::dot(motion_line.normal, motion_line.origin - float2(tile));
178 /* In order to be conservative and for simplicity, we use the tiles bounding circles.
179 * Consider that both the tile and the line have bounding radius of M_SQRT1_2. */
180 return math::abs(distance_to_line) < std::numbers::sqrt2_v<float>;
181}
182
183/* The max tile velocity image computes the maximum within 32x32 blocks, while the velocity can
184 * in fact extend beyond such a small block. So we dilate the max blocks by taking the maximum
185 * along the path of each of the max velocity tiles. */
187 const Result &max_tile_velocity,
188 const float shutter_speed)
189{
190 if (max_tile_velocity.is_single_value()) {
191 Result output = context.create_result(ResultType::Float4);
192 output.allocate_single_value();
193 output.set_single_value(max_tile_velocity.get_single_value<float4>() *
194 float4(float2(shutter_speed), float2(-shutter_speed)));
195 return output;
196 }
197
198 const int2 size = max_tile_velocity.domain().data_size;
199 Result output = context.create_result(ResultType::Float4);
200 output.allocate_texture(Domain(size));
201
202 parallel_for(size, [&](const int2 texel) { output.store_pixel(texel, float4(0.0f)); });
203
204 for (const int64_t y : IndexRange(size.y)) {
205 for (const int64_t x : IndexRange(size.x)) {
206 const int2 src_tile = int2(x, y);
207
208 const float4 max_motion = max_tile_velocity.load_pixel<float4>(src_tile);
209 const float2 max_previous_velocity = max_motion.xy() * shutter_speed;
210 const float2 max_next_velocity = max_motion.zw() * -shutter_speed;
211
212 {
213 /* Rectangular area (in tiles) where the motion vector spreads. */
214 MotionRect motion_rect = compute_motion_rect(src_tile, max_previous_velocity, size);
215 MotionLine motion_line = compute_motion_line(src_tile, max_previous_velocity);
216 /* Do a conservative rasterization of the line of the motion vector line. */
217 for (int j = 0; j < motion_rect.extent.y; j++) {
218 for (int i = 0; i < motion_rect.extent.x; i++) {
219 int2 tile = motion_rect.bottom_left + int2(i, j);
220 if (is_inside_motion_line(tile, motion_line)) {
221 const float4 current_max_velocity = output.load_pixel<float4>(tile);
222 const float2 new_max_previous_velocity = max_velocity_approximate(
223 current_max_velocity.xy(), max_previous_velocity, tile, src_tile);
224 const float2 new_max_next_velocity = max_velocity_approximate(
225 current_max_velocity.zw(), max_next_velocity, tile, src_tile);
226 output.store_pixel(tile, float4(new_max_previous_velocity, new_max_next_velocity));
227 }
228 }
229 }
230 }
231
232 {
233 /* Rectangular area (in tiles) where the motion vector spreads. */
234 MotionRect motion_rect = compute_motion_rect(src_tile, max_next_velocity, size);
235 MotionLine motion_line = compute_motion_line(src_tile, max_next_velocity);
236 /* Do a conservative rasterization of the line of the motion vector line. */
237 for (int j = 0; j < motion_rect.extent.y; j++) {
238 for (int i = 0; i < motion_rect.extent.x; i++) {
239 int2 tile = motion_rect.bottom_left + int2(i, j);
240 if (is_inside_motion_line(tile, motion_line)) {
241 const float4 current_max_velocity = output.load_pixel<float4>(tile);
242 const float2 new_max_previous_velocity = max_velocity_approximate(
243 current_max_velocity.xy(), max_previous_velocity, tile, src_tile);
244 const float2 new_max_next_velocity = max_velocity_approximate(
245 current_max_velocity.zw(), max_next_velocity, tile, src_tile);
246 output.store_pixel(tile, float4(new_max_previous_velocity, new_max_next_velocity));
247 }
248 }
249 }
250 }
251 }
252 }
253
254 return output;
255}
256
257/* Interleaved gradient noise by Jorge Jimenez
258 * http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare. */
259static float interleaved_gradient_noise(const int2 &p)
260{
261 return math::fract(52.9829189f * math::fract(0.06711056f * p.x + 0.00583715f * p.y));
262}
263
264static float2 spread_compare(const float center_motion_length,
265 const float sample_motion_length,
266 const float offset_length)
267{
268 return math::clamp(
269 float2(center_motion_length, sample_motion_length) - offset_length + 1.0f, 0.0f, 1.0f);
270}
271
272static float2 depth_compare(const float center_depth, const float sample_depth)
273{
274 float2 depth_scale = float2(DEPTH_SCALE, -DEPTH_SCALE);
275 return math::clamp(0.5f + depth_scale * (sample_depth - center_depth), 0.0f, 1.0f);
276}
277
278/* Kill contribution if not going the same direction. */
279static float dir_compare(const float2 &offset,
280 const float2 &sample_motion,
281 const float &sample_motion_length)
282{
283 if (sample_motion_length < 0.5f) {
284 return 1.0f;
285 }
286 return (math::dot(offset, sample_motion) > 0.0f) ? 1.0f : 0.0f;
287}
288
289/* Return background (x) and foreground (y) weights. */
290static float2 sample_weights(const float center_depth,
291 const float sample_depth,
292 const float center_motion_length,
293 const float sample_motion_length,
294 const float offset_length)
295{
296 /* Classify foreground/background. */
297 float2 depth_weight = depth_compare(center_depth, sample_depth);
298 /* Weight if sample is overlapping or under the center pixel. */
299 float2 spread_weight = spread_compare(center_motion_length, sample_motion_length, offset_length);
300 return depth_weight * spread_weight;
301}
302
309
310static void gather_sample(const Result &input_image,
311 const Result &input_depth,
312 const Result &input_velocity,
313 const int2 &size,
314 const float2 &screen_uv,
315 const float center_depth,
316 const float center_motion_len,
317 const float2 &offset,
318 const float offset_len,
319 const bool next,
320 const float shutter_speed,
321 Accumulator &accum)
322{
323 float2 sample_uv = screen_uv - offset / float2(size);
324 float4 sample_vectors = input_velocity.sample_bilinear_extended<float4, true>(sample_uv) *
325 float4(float2(shutter_speed), float2(-shutter_speed));
326 float2 sample_motion = (next) ? sample_vectors.zw() : sample_vectors.xy();
327 float sample_motion_len = math::length(sample_motion);
328 float sample_depth = input_depth.sample_bilinear_extended<float, true>(sample_uv);
329 float4 sample_color = float4(input_image.sample_bilinear_extended<Color>(sample_uv));
330
331 float2 direct_weights = sample_weights(
332 center_depth, sample_depth, center_motion_len, sample_motion_len, offset_len);
333
334 float3 weights;
335 weights.x = direct_weights.x;
336 weights.y = direct_weights.y;
337 weights.z = dir_compare(offset, sample_motion, sample_motion_len);
338 weights.x *= weights.z;
339 weights.y *= weights.z;
340
341 accum.fg += sample_color * weights.y;
342 accum.bg += sample_color * weights.x;
343 accum.weight += weights;
344}
345
346static void gather_blur(const Result &input_image,
347 const Result &input_depth,
348 const Result &input_velocity,
349 const int2 &size,
350 const float2 &screen_uv,
351 const float2 &center_motion,
352 const float center_depth,
353 const float2 &max_motion,
354 const float ofs,
355 const bool next,
356 const int samples_count,
357 const float shutter_speed,
358 Accumulator &accum)
359{
360 float center_motion_len = math::length(center_motion);
361 float max_motion_len = math::length(max_motion);
362
363 /* Tile boundaries randomization can fetch a tile where there is less motion than this pixel.
364 * Fix this by overriding the max_motion. */
365 float2 sanitized_max_motion = max_motion;
366 if (max_motion_len < center_motion_len) {
367 max_motion_len = center_motion_len;
368 sanitized_max_motion = center_motion;
369 }
370
371 if (max_motion_len < 0.5f) {
372 return;
373 }
374
375 int i;
376 float t, inc = 1.0f / float(samples_count);
377 for (i = 0, t = ofs * inc; i < samples_count; i++, t += inc) {
378 gather_sample(input_image,
379 input_depth,
380 input_velocity,
381 size,
382 screen_uv,
383 center_depth,
384 center_motion_len,
385 sanitized_max_motion * t,
386 max_motion_len * t,
387 next,
388 shutter_speed,
389 accum);
390 }
391
392 if (center_motion_len < 0.5f) {
393 return;
394 }
395
396 for (i = 0, t = ofs * inc; i < samples_count; i++, t += inc) {
397 /* Also sample in center motion direction.
398 * Allow recovering motion where there is conflicting
399 * motion between foreground and background. */
400 gather_sample(input_image,
401 input_depth,
402 input_velocity,
403 size,
404 screen_uv,
405 center_depth,
406 center_motion_len,
407 center_motion * t,
408 center_motion_len * t,
409 next,
410 shutter_speed,
411 accum);
412 }
413}
414
415static void motion_blur_cpu(const Result &input_image,
416 const Result &input_depth,
417 const Result &input_velocity,
418 const Result &max_velocity,
419 Result &output,
420 const int samples_count,
421 const float shutter_speed)
422{
423 const int2 size = input_image.domain().data_size;
424 threading::parallel_for(IndexRange(size.y), 1, [&](const IndexRange sub_y_range) {
425 for (const int64_t y : sub_y_range) {
426 for (const int64_t x : IndexRange(size.x)) {
427 const int2 texel = int2(x, y);
428 float2 uv = (float2(texel) + 0.5f) / float2(size);
429
430 /* Data of the center pixel of the gather (target). */
431 float center_depth = input_depth.load_pixel<float, true>(texel);
432 float4 center_motion = input_velocity.load_pixel<float4, true>(texel);
433 float2 center_previous_motion = center_motion.xy() * shutter_speed;
434 float2 center_next_motion = center_motion.zw() * -shutter_speed;
435 float4 center_color = float4(input_image.load_pixel<Color>(texel));
436
437 /* Randomize tile boundary to avoid ugly discontinuities. Randomize 1/4th of the tile.
438 * Note this randomize only in one direction but in practice it's enough. */
439 float rand = interleaved_gradient_noise(texel);
440 int2 tile = (texel + int2(rand * 2.0f - 1.0f * float(MOTION_BLUR_TILE_SIZE) * 0.25f)) /
441 MOTION_BLUR_TILE_SIZE;
442
443 /* No need to multiply by the shutter speed and invert the next velocities since this was
444 * already done in dilate_max_velocity. */
445 float4 max_motion = max_velocity.load_pixel<float4, true>(tile);
446
447 Accumulator accum;
448 accum.weight = float3(0.0f, 0.0f, 1.0f);
449 accum.bg = float4(0.0f);
450 accum.fg = float4(0.0f);
451 /* First linear gather. time = [T - delta, T] */
452 gather_blur(input_image,
453 input_depth,
454 input_velocity,
455 size,
456 uv,
457 center_previous_motion,
458 center_depth,
459 max_motion.xy(),
460 rand,
461 false,
462 samples_count,
463 shutter_speed,
464 accum);
465 /* Second linear gather. time = [T, T + delta] */
466 gather_blur(input_image,
467 input_depth,
468 input_velocity,
469 size,
470 uv,
471 center_next_motion,
472 center_depth,
473 max_motion.zw(),
474 rand,
475 true,
476 samples_count,
477 shutter_speed,
478 accum);
479
480#if 1 /* Own addition. Not present in reference implementation. */
481 /* Avoid division by 0.0. */
482 float w = 1.0f / (50.0f * float(samples_count) * 4.0f);
483 accum.bg += center_color * w;
484 accum.weight.x += w;
485 /* NOTE: In Jimenez's presentation, they used center sample.
486 * We use background color as it contains more information for foreground
487 * elements that have not enough weights.
488 * Yield better blur in complex motion. */
489 center_color = accum.bg / accum.weight.x;
490#endif
491 /* Merge background. */
492 accum.fg += accum.bg;
493 accum.weight.y += accum.weight.x;
494 /* Balance accumulation for failed samples.
495 * We replace the missing foreground by the background. */
496 float blend_fac = math::clamp(1.0f - accum.weight.y / accum.weight.z, 0.0f, 1.0f);
497 float4 out_color = (accum.fg / accum.weight.z) + center_color * blend_fac;
498
499 output.store_pixel(texel, Color(out_color));
500 }
501 }
502 });
503}
504
506 public:
508
509 void execute() override
510 {
511 const Result &input = this->get_input("Image");
512 if (input.is_single_value()) {
513 Result &output = this->get_result("Image");
514 output.share_data(input);
515 return;
516 }
517
518 if (this->context().use_gpu()) {
519 this->execute_gpu();
520 }
521 else {
522 this->execute_cpu();
523 }
524 }
525
527 {
528 Result max_tile_velocity = this->compute_max_tile_velocity_gpu();
529 gpu::StorageBuf *tile_indirection_buffer = this->dilate_max_velocity_gpu(max_tile_velocity);
530 this->compute_motion_blur(max_tile_velocity, tile_indirection_buffer);
531 max_tile_velocity.release();
532 GPU_storagebuf_free(tile_indirection_buffer);
533 }
534
535 /* Reduces each 32x32 block of velocity pixels into a single velocity whose magnitude is largest.
536 * Each of the previous and next velocities are reduces independently. */
538 {
539 Result &velocity = get_input("Speed");
540 if (velocity.is_single_value()) {
541 Result output = this->context().create_result(ResultType::Float4);
542 output.allocate_single_value();
543 output.set_single_value(velocity.get_single_value<float4>());
544 return output;
545 }
546
547 gpu::Shader *shader = context().get_shader("compositor_max_velocity");
549
550 GPU_shader_uniform_1b(shader, "is_initial_reduction", true);
551
552 velocity.bind_as_texture(shader, "input_tx");
553
554 Result output = context().create_result(ResultType::Float4);
555 const int2 tiles_count = math::divide_ceil(velocity.domain().data_size, int2(32));
556 output.allocate_texture(Domain(tiles_count));
557 output.bind_as_image(shader, "output_img");
558
559 GPU_compute_dispatch(shader, tiles_count.x, tiles_count.y, 1);
560
562 velocity.unbind_as_texture();
563 output.unbind_as_image();
564
565 return output;
566 }
567
568 /* The max tile velocity image computes the maximum within 32x32 blocks, while the velocity can
569 * in fact extend beyond such a small block. So we dilate the max blocks by taking the maximum
570 * along the path of each of the max velocity tiles. Since the shader uses custom max atomics,
571 * the output will be an indirection buffer that points to a particular tile in the original max
572 * tile velocity image. This is done as a form of performance optimization, see the shader for
573 * more information. */
575 {
576 gpu::Shader *shader = context().get_shader("compositor_motion_blur_max_velocity_dilate");
578
579 GPU_shader_uniform_1f(shader, "shutter_speed", this->get_shutter());
580
581 gpu::Texture *max_tile_veloicty_texture = max_tile_velocity.bind_as_texture_or_single_value(
582 shader, "input_tx");
583
584 /* The shader assumes a maximum input size of 16k, and since the max tile velocity image is
585 * composed of blocks of 32, we get 16k / 32 = 512. So the table is 512x512, but we store two
586 * tables for the previous and next velocities, so we double that. */
587 const int size = sizeof(uint32_t) * 512 * 512 * 2;
588 gpu::StorageBuf *tile_indirection_buffer = GPU_storagebuf_create_ex(
589 size, nullptr, GPU_USAGE_DEVICE_ONLY, __func__);
590 GPU_storagebuf_clear_to_zero(tile_indirection_buffer);
591 const int slot = GPU_shader_get_ssbo_binding(shader, "tile_indirection_buf");
592 GPU_storagebuf_bind(tile_indirection_buffer, slot);
593
595
597 max_tile_velocity.unbind_as_texture_or_single_value(max_tile_veloicty_texture);
598 GPU_storagebuf_unbind(tile_indirection_buffer);
599
600 return tile_indirection_buffer;
601 }
602
603 void compute_motion_blur(Result &max_tile_velocity, gpu::StorageBuf *tile_indirection_buffer)
604 {
605 gpu::Shader *shader = context().get_shader("compositor_motion_blur");
607
608 GPU_shader_uniform_1i(shader, "samples_count", this->get_samples_count());
609 GPU_shader_uniform_1f(shader, "shutter_speed", this->get_shutter());
610
611 Result &input = get_input("Image");
612 input.bind_as_texture(shader, "input_tx");
613
614 Result &depth = get_input("Z");
615 gpu::Texture *depth_texture = depth.bind_as_texture_or_single_value(shader, "depth_tx");
616
617 Result &velocity = get_input("Speed");
618 gpu::Texture *velocity_texture = velocity.bind_as_texture_or_single_value(shader,
619 "velocity_tx");
620
621 gpu::Texture *max_tile_velocity_texture = max_tile_velocity.bind_as_texture_or_single_value(
622 shader, "max_velocity_tx");
623
625 const int slot = GPU_shader_get_ssbo_binding(shader, "tile_indirection_buf");
626 GPU_storagebuf_bind(tile_indirection_buffer, slot);
627
628 Result &output = get_result("Image");
629 const Domain domain = compute_domain();
630 output.allocate_texture(domain);
631 output.bind_as_image(shader, "output_img");
632
634
636 input.unbind_as_texture();
637 depth.unbind_as_texture_or_single_value(depth_texture);
638 velocity.unbind_as_texture_or_single_value(velocity_texture);
639 max_tile_velocity.unbind_as_texture_or_single_value(max_tile_velocity_texture);
640 output.unbind_as_image();
641 }
642
644 {
645 const float shutter_speed = this->get_shutter();
646 const int samples_count = this->get_samples_count();
647
648 const Result &input_image = get_input("Image");
649 const Result &input_depth = get_input("Z");
650 const Result &input_velocity = get_input("Speed");
651
652 Result &output = get_result("Image");
653 const Domain domain = compute_domain();
654 output.allocate_texture(domain);
655
656 Result max_tile_velocity = compute_max_tile_velocity_cpu(this->context(), input_velocity);
658 this->context(), max_tile_velocity, shutter_speed);
659 max_tile_velocity.release();
660 motion_blur_cpu(input_image,
661 input_depth,
662 input_velocity,
664 output,
665 samples_count,
666 shutter_speed);
667 max_velocity.release();
668 }
669
671 {
672 return math::clamp(this->get_input("Samples").get_single_value_default<int>(), 1, 256);
673 }
674
676 {
677 /* Divide by two since the motion blur algorithm expects shutter per motion step and has two
678 * motion steps, while the user inputs the entire shutter across all steps. */
679 return math::max(0.0f, this->get_input("Shutter").get_single_value_default<float>()) / 2.0f;
680 }
681};
682
684{
685 return new VectorBlurOperation(context, node);
686}
687
688static void node_register()
689{
690 static bke::bNodeType ntype;
691
692 cmp_node_type_base(&ntype, "CompositorNodeVecBlur"_ustr, CMP_NODE_VECBLUR);
693 ntype.ui_name = "Vector Blur";
694 ntype.ui_description = "Uses the vector speed render pass to blur the image pixels in 2D";
695 ntype.enum_name_legacy = "VECBLUR";
697 ntype.declare = node_declare;
699
701}
702NOD_REGISTER_NODE(node_register)
703
704} // namespace blender::nodes::node_composite_vector_blur_cc
#define NODE_CLASS_OP_FILTER
Definition BKE_node.hh:482
#define CMP_NODE_VECBLUR
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define output
constexpr IndexRange()=default
Domain(const int2 &size)
Definition domain.cc:20
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Definition operation.cc:40
Context & context() const
Definition operation.cc:57
Result & get_input(StringRef identifier) const
Definition operation.cc:35
virtual Domain compute_domain()
Definition operation.cc:62
T sample_bilinear_extended(const float2 &coordinates) const
void unbind_as_texture_or_single_value(gpu::Texture *single_value_texture) const
Definition result.cc:970
void unbind_as_texture() const
Definition result.cc:964
void bind_as_texture(gpu::Shader *shader, const char *texture_name) const
Definition result.cc:854
T load_pixel_extended(const int2 &texel) const
T load_pixel(const int2 &texel) const
gpu::Texture * bind_as_texture_or_single_value(gpu::Shader *shader, const char *texture_name) const
Definition result.cc:861
const T & get_single_value() const
void compute_motion_blur(Result &max_tile_velocity, gpu::StorageBuf *tile_indirection_buffer)
#define MOTION_BLUR_TILE_SIZE
const ccl_global KernelWorkTile * tile
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
Definition utilities.cc:235
ColorSceneLinear4f< eAlpha::Premultiplied > Color
Definition COM_result.hh:96
void parallel_for(const int2 range, const Function &function)
T length_squared(const VecBase< T, Size > &a)
T clamp(const T &a, const T &min, const T &max)
T sign(const T &a)
VecBase< T, Size > divide_ceil(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T fract(const T &a)
T ceil(const T &a)
T max(const T &a, const T &b)
T abs(const T &a)
static float2 max_velocity(const float2 &a, const float2 &b)
static uint32_t velocity_atomic_max_value(const float2 &value, const int2 &texel)
static float2 spread_compare(const float center_motion_length, const float sample_motion_length, const float offset_length)
static float dir_compare(const float2 &offset, const float2 &sample_motion, const float &sample_motion_length)
static Result compute_max_tile_velocity_cpu(Context &context, const Result &velocity_image)
static float2 sample_weights(const float center_depth, const float sample_depth, const float center_motion_length, const float sample_motion_length, const float offset_length)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
static void gather_blur(const Result &input_image, const Result &input_depth, const Result &input_velocity, const int2 &size, const float2 &screen_uv, const float2 &center_motion, const float center_depth, const float2 &max_motion, const float ofs, const bool next, const int samples_count, const float shutter_speed, Accumulator &accum)
static bool is_inside_motion_line(const int2 &tile, const MotionLine &motion_line)
static MotionLine compute_motion_line(const int2 &tile, const float2 &motion)
static MotionRect compute_motion_rect(const int2 &tile, const float2 &motion, const int2 &size)
static Result dilate_max_velocity_cpu(Context &context, const Result &max_tile_velocity, const float shutter_speed)
static void motion_blur_cpu(const Result &input_image, const Result &input_depth, const Result &input_velocity, const Result &max_velocity, Result &output, const int samples_count, const float shutter_speed)
static void node_declare(NodeDeclarationBuilder &b)
static void gather_sample(const Result &input_image, const Result &input_depth, const Result &input_velocity, const int2 &size, const float2 &screen_uv, const float center_depth, const float center_motion_len, const float2 &offset, const float offset_len, const bool next, const float shutter_speed, Accumulator &accum)
static float2 depth_compare(const float center_depth, const float sample_depth)
static float2 max_velocity_approximate(const float2 &a, const float2 &b, const int2 &a_texel, const int2 &b_texel)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
__int64 int64_t
Definition BKE_text.h:90
void GPU_storagebuf_clear_to_zero(gpu::StorageBuf *ssbo)
gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
void GPU_compute_dispatch(gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
unsigned int uint32_t
Definition BKE_text.h:81
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
void GPU_shader_unbind()
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
@ GPU_BARRIER_SHADER_STORAGE
Definition GPU_state.hh:51
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
void GPU_storagebuf_unbind(gpu::StorageBuf *ssbo)
void GPU_shader_uniform_1f(gpu::Shader *sh, const char *name, float value)
@ PROP_VELOCITY
Definition RNA_types.hh:320
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define DEPTH_SCALE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGetCompositorOperationFunction get_compositor_operation
Definition BKE_node.hh:379
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393