diff --git a/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_mask.hh b/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_mask.hh index 3a6482abf42..f512b432682 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_mask.hh +++ b/source/blender/compositor/realtime_compositor/cached_resources/COM_cached_mask.hh @@ -28,11 +28,16 @@ class Context; class CachedMaskKey { public: int2 size; + float aspect_ratio; bool use_feather; int motion_blur_samples; float motion_blur_shutter; - CachedMaskKey(int2 size, bool use_feather, int motion_blur_samples, float motion_blur_shutter); + CachedMaskKey(int2 size, + float aspect_ratio, + bool use_feather, + int motion_blur_samples, + float motion_blur_shutter); uint64_t hash() const; }; @@ -53,6 +58,7 @@ class CachedMask : public CachedResource { Mask *mask, int2 size, int frame, + float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter); @@ -81,6 +87,7 @@ class CachedMaskContainer : CachedResourceContainer { CachedMask &get(Context &context, Mask *mask, int2 size, + float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter); diff --git a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_mask.cc b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_mask.cc index dfca915ea4d..3c9b8bb4420 100644 --- a/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_mask.cc +++ b/source/blender/compositor/realtime_compositor/cached_resources/intern/cached_mask.cc @@ -31,10 +31,12 @@ namespace blender::realtime_compositor { */ CachedMaskKey::CachedMaskKey(int2 size, + float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter) : size(size), + aspect_ratio(aspect_ratio), use_feather(use_feather), motion_blur_samples(motion_blur_samples), motion_blur_shutter(motion_blur_shutter) @@ -43,12 +45,13 @@ CachedMaskKey::CachedMaskKey(int2 size, uint64_t CachedMaskKey::hash() const { - return get_default_hash_4(size, use_feather, motion_blur_samples, motion_blur_shutter); + return get_default_hash_4( + size, use_feather, motion_blur_samples, float2(motion_blur_shutter, aspect_ratio)); } bool operator==(const CachedMaskKey &a, const CachedMaskKey &b) { - return a.size == b.size && a.use_feather == b.use_feather && + return a.size == b.size && a.aspect_ratio == b.aspect_ratio && a.use_feather == b.use_feather && a.motion_blur_samples == b.motion_blur_samples && a.motion_blur_shutter == b.motion_blur_shutter; } @@ -104,6 +107,7 @@ CachedMask::CachedMask(Context &context, Mask *mask, int2 size, int frame, + float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter) @@ -117,7 +121,10 @@ CachedMask::CachedMask(Context &context, for (const int64_t x : IndexRange(size.x)) { /* Compute the coordinates in the [0, 1] range and add 0.5 to evaluate the mask at the * center of pixels. */ - const float2 coordinates = (float2(x, y) + 0.5f) / float2(size); + float2 coordinates = (float2(x, y) + 0.5f) / float2(size); + /* Do aspect ratio correction around the center 0.5 point. */ + coordinates = (coordinates - float2(0.5)) * float2(1.0, aspect_ratio) + float2(0.5); + float mask_value = 0.0f; for (MaskRasterHandle *handle : handles) { mask_value += BKE_maskrasterize_handle_sample(handle, coordinates); @@ -175,11 +182,13 @@ void CachedMaskContainer::reset() CachedMask &CachedMaskContainer::get(Context &context, Mask *mask, int2 size, + float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter) { - const CachedMaskKey key(size, use_feather, motion_blur_samples, motion_blur_shutter); + const CachedMaskKey key( + size, aspect_ratio, use_feather, motion_blur_samples, motion_blur_shutter); auto &cached_masks_for_id = map_.lookup_or_add_default(mask->id.name); @@ -193,6 +202,7 @@ CachedMask &CachedMaskContainer::get(Context &context, mask, size, context.get_frame_number(), + aspect_ratio, use_feather, motion_blur_samples, motion_blur_shutter); diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.cc b/source/blender/nodes/composite/nodes/node_composite_mask.cc index 8c9a4f10cf7..6f1a0375900 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mask.cc +++ b/source/blender/nodes/composite/nodes/node_composite_mask.cc @@ -97,6 +97,7 @@ class MaskOperation : public NodeOperation { context(), get_mask(), domain.size, + get_aspect_ratio(), get_use_feather(), get_motion_blur_samples(), get_motion_blur_shutter()); @@ -127,6 +128,15 @@ class MaskOperation : public NodeOperation { return int2(node_storage(bnode()).size_x, node_storage(bnode()).size_y); } + float get_aspect_ratio() + { + if (get_flags() & (CMP_NODE_MASK_FLAG_SIZE_FIXED | CMP_NODE_MASK_FLAG_SIZE_FIXED_SCENE)) { + return 1.0f; + } + + return context().get_render_data().yasp / context().get_render_data().xasp; + } + bool get_use_feather() { return !bool(get_flags() & CMP_NODE_MASK_FLAG_NO_FEATHER);