Add a nearest neighbor mode to the MAP UV compositor node. #115103

Merged
Martijn Versteegh merged 32 commits from Baardaap/blender:nearest_neighbopur_compositor_uvmap into main 2024-01-19 13:24:31 +01:00
1 changed files with 19 additions and 16 deletions
Showing only changes of commit 2cf8c24225 - Show all commits

View File

@ -235,24 +235,27 @@ void MapUVOperation::update_memory_buffer_partial(MemoryBuffer *output,
continue;
}
/* EWA filtering. */
input_image->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], it.out);
if (nearest_neighbour_) {
input_image->read_elem_sampled(uv[0], uv[1], PixelSampler::Nearest, it.out);
} else {
/* EWA filtering. */
input_image->read_elem_filtered(uv[0], uv[1], deriv[0], deriv[1], it.out);
/* UV to alpha threshold. */
const float threshold = alpha_ * 0.05f;
/* XXX alpha threshold is used to fade out pixels on boundaries with invalid derivatives.
* this calculation is not very well defined, should be looked into if it becomes a problem ...
*/
const float du = len_v2(deriv[0]);
const float dv = len_v2(deriv[1]);
const float factor = 1.0f - threshold * (du / image_width_ + dv / image_height_);
if (factor < 0.0f) {
alpha = 0.0f;
/* UV to alpha threshold. */
const float threshold = alpha_ * 0.05f;
/* XXX alpha threshold is used to fade out pixels on boundaries with invalid derivatives.
* this calculation is not very well defined, should be looked into if it becomes a problem ...
*/
const float du = len_v2(deriv[0]);
const float dv = len_v2(deriv[1]);
const float factor = 1.0f - threshold * (du / image_width_ + dv / image_height_);
if (factor < 0.0f) {
alpha = 0.0f;
}
else {
alpha *= factor;
}
}
else {
alpha *= factor;
}
/* "premul" */
if (alpha < 1.0f) {
mul_v4_fl(it.out, alpha);