21#define MotionTilePayload uint
59 return (
velocity << 18u) | ((payload.
x & 0x1FFu) << 9u) | (payload.
y & 0x1FFu);
65 return int2((data >> 9u) & 0x1FFu, data & 0x1FFu);
75 if (len_sqr >
square(max_offset)) {
84template<enum TextureWriteFormat velocity_format>
struct Resources {
105 return (
min(uint(
ceil(
length(motion))), 0xFFFFu) << 16u) | (thread_id.y << 8) | thread_id.x;
111 return uint2(payload & 0xFFu, (payload >> 8) & 0xFFu);
125template<enum TextureWriteFormat velocity_format>
136 if (local_index == 0u) {
137 srt.payload_prev = 0u;
138 srt.payload_next = 0u;
142 uint local_payload_prev = 0u;
143 uint local_payload_next = 0u;
144 float2 local_max_motion_prev;
145 float2 local_max_motion_next;
152 float4 motion = srt.camera.resolve_local(view,
imageLoad(srt.velocity_img, texel), uv, depth);
155 motion = motion.xyxy;
166 motion *=
min(line_clip,
float2(1.0f)).xxyy;
168 motion *= render_size.xyxy;
170 motion *= srt.motion_blur_buf.motion_scale.xxyy;
174 float max_offset = srt.motion_blur_buf.motion_max_offset_px;
175 float2 motion_prev = motion.xy;
176 float2 motion_next = motion.zw;
179 motion =
float4(motion_prev, motion_next);
181 uint sample_payload_prev =
pack_payload(motion.xy, local_id.xy);
182 if (local_payload_prev < sample_payload_prev) {
183 local_payload_prev = sample_payload_prev;
184 local_max_motion_prev = motion.xy;
187 uint sample_payload_next =
pack_payload(motion.zw, local_id.xy);
188 if (local_payload_next < sample_payload_next) {
189 local_payload_next = sample_payload_next;
190 local_max_motion_next = motion.zw;
194 atomicMax(srt.payload_prev, local_payload_prev);
195 atomicMax(srt.payload_next, local_payload_next);
200 srt.max_motion_prev = local_max_motion_prev;
203 srt.max_motion_next = local_max_motion_next;
207 if (local_index == 0u) {
209 imageStore(srt.out_tiles_img, tile_co,
float4(srt.max_motion_prev, srt.max_motion_next));
230#define DEBUG_BYPASS_DILATION 0
245#if DEBUG_BYPASS_DILATION
269#if DEBUG_BYPASS_DILATION
276 int2 max_point =
max(point1, point2);
277 int2 min_point =
min(point1, point2);
280 min_point =
max(min_point,
int2(0));
282 return {.bottom_left = min_point, .extent = 1 + max_point - min_point};
306 MotionRect motion_rect = srt.compute_motion_rect(src_tile, max_motion.xy);
307 MotionLine motion_line = srt.compute_motion_line(src_tile, max_motion.xy);
309 for (
int x = 0;
x < motion_rect.
extent.
x;
x++) {
310 for (
int y = 0;
y < motion_rect.
extent.
y;
y++) {
324 MotionRect motion_rect = srt.compute_motion_rect(src_tile, max_motion.zw);
325 MotionLine motion_line = srt.compute_motion_line(src_tile, max_motion.zw);
327 for (
int x = 0;
x < motion_rect.
extent.
x;
x++) {
328 for (
int y = 0;
y < motion_rect.
extent.
y;
y++) {
345#define gather_sample_count 8
373 float sample_motion_length,
376 return saturate(
float2(center_motion_length, sample_motion_length) - offset_length + 1.0f);
382 return saturate(0.5f + depth_scale * (sample_depth - center_depth));
388 if (sample_motion_length < 0.5f) {
391 return (
dot(offset, sample_motion) > 0.0f) ? 1.0f : 0.0f;
397 float center_motion_length,
398 float sample_motion_length,
405 center_motion_length, sample_motion_length, offset_length);
406 return depth_weight * spread_weight;
412 float center_motion_len,
420 float2 sample_motion = (next) ? sample_vectors.zw : sample_vectors.xy;
431 center_depth, sample_depth, center_motion_len, sample_motion_len, offset_len);
432 weights.
z =
dir_compare(offset, sample_motion, sample_motion_len);
433 weights.xy *= weights.
z;
435 accum.
fg += sample_color * weights.
y;
436 accum.
bg += sample_color * weights.
x;
457 if (max_motion_len < center_motion_len) {
458 max_motion_len = center_motion_len;
459 max_motion = center_motion;
462 if (max_motion_len < 0.5f) {
479 if (center_motion_len < 0.5f) {
492 center_motion_len * t,
528 float4 center_motion = srt.motion_blur_sample_velocity(uv);
532 float noise_offset = sampling.rng_1D_get(SAMPLING_TIME);
539 rand.
x = rand.
x * 2.0f - 1.0f;
547 max_motion.xy =
imageLoad(srt.in_tiles_img, tile_prev).xy;
549 max_motion.zw =
imageLoad(srt.in_tiles_img, tile_next).zw;
556 srt.gather_blur(view, uv, center_motion.xy, center_depth, max_motion.xy, rand.
y,
false, accum);
558 srt.gather_blur(view, uv, center_motion.zw, center_depth, max_motion.zw, rand.
y,
true, accum);
564 bool no_motion =
length(center_motion.xy) +
length(center_motion.zw) < 0.5;
565 if (accum.
weight.
x < 1.0 && no_motion) {
568 accum.
bg += center_color *
w;
574 center_color = accum.
bg / accum.
weight.
x;
577 accum.
fg += accum.
bg;
582 float4 out_color = (accum.
fg / accum.
weight.
z) + center_color * blend_fac;
585 out_color.rgb = out_color.ggg;
586 out_color.rg += max_motion.xy;
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
float line_unit_square_intersect_dist_safe(float2 line_origin, float2 line_direction)
float point_line_projection_dist(float2 point, float2 line_origin, float2 line_normal)
#define MOTION_BLUR_GROUP_SIZE
#define MotionTilePayload
PipelineCompute eevee_motion_blur_gather(eevee::motion_blur::gather::gather_comp)
PipelineCompute eevee_motion_blur_tiles_flatten_rg(eevee::motion_blur::flatten::flatten_comp< SFLOAT_16_16 >)
PipelineCompute eevee_motion_blur_tiles_dilate(eevee::motion_blur::dilate::dilate_comp)
PipelineCompute eevee_motion_blur_tiles_flatten_rgba(eevee::motion_blur::flatten::flatten_comp< SFLOAT_16_16_16_16 >)
#define gather_sample_count
#define MOTION_BLUR_TILE_SIZE
#define MOTION_BLUR_MAX_TILE
#define local_invocation_index
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
#define global_invocation_id
#define local_invocation_id
VecBase< bool, D > greaterThanEqual(VecOp< T, D >, VecOp< T, D >) RET
bool any(VecOp< bool, D >) RET
int atomicMax(int &, int) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T inversesqrt(T) RET
bool all(VecOp< bool, D >) RET
VecBase< bool, D > equal(VecOp< T, D >, VecOp< T, D >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
ImageBase< float, 2 > image2D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
float length_squared(VecT a)
VecT safe_normalize(VecT vector)
#define in_texture_range(texel, tex)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
const ccl_global KernelWorkTile * tile
void dilate_comp(Resources &srt, TileBuf &tiles, const uint3 global_id)
uint pack_payload(float2 motion, uint2 thread_id)
void flatten_comp(Resources< velocity_format > &srt, const draw::View &views, const uint3 group_id, const uint3 global_id, const uint3 local_id, const uint local_index)
uint2 unpack_payload(uint payload)
void gather_comp(Resources &srt, const Sampling &sampling, const draw::View &views, const TileBuf &tiles, const uint3 global_id)
float clamp_motion_and_get_length(float max_offset, float2 &motion)
float4 unpack(float4 data)
float interleaved_gradient(float2 pixel, float seed, float offset)
T read(T depth_buffer_value)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float depth_screen_to_view(float ss_depth) const
int2 load(MotionStep motion_step, uint2 tile) const
static MotionTilePayload pack_payload(float2 motion, uint2 payload)
static uint indirection_index(uint motion_step, uint2 tile)
void store(MotionStep motion_step, uint2 tile, MotionTilePayload payload)
static int2 unpack_payload(uint data)
uint(& tile_indirection_buf)[]
bool is_inside_motion_line(int2 tile) const
MotionRect compute_motion_rect(int2 tile, float2 motion)
const image2D in_tiles_img
MotionLine compute_motion_line(int2 tile, float2 motion)
const MotionBlurData & motion_blur_buf
const image2D in_tiles_img
float2 spread_compare(float center_motion_length, float sample_motion_length, float offset_length)
float2 sample_weights(float center_depth, float sample_depth, float center_motion_length, float sample_motion_length, float offset_length)
const MotionBlurData & motion_blur_buf
void gather_blur(ViewMatrices view, float2 screen_uv, float2 center_motion, float center_depth, float2 max_motion, float ofs, const bool next, Accumulator &accum)
float2 depth_compare(float center_depth, float sample_depth)
void gather_sample(ViewMatrices view, float2 screen_uv, float center_depth, float center_motion_len, float2 offset, float offset_len, const bool next, Accumulator &accum)
float dir_compare(float2 offset, float2 sample_motion, float sample_motion_length)
float4 motion_blur_sample_velocity(float2 uv)