Fix for half pixel offset rasterizing masks
This commit is contained in:
parent
b3972aeea0
commit
d1b1d194dc
Notes:
blender-bot
2023-02-14 10:48:24 +01:00
Referenced by issue #39750, Bones disappearing with strange transforms
|
@ -1434,6 +1434,10 @@ void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
|
|||
const unsigned int width, const unsigned int height,
|
||||
float *buffer)
|
||||
{
|
||||
const float x_inv = 1.0f / (float)width;
|
||||
const float y_inv = 1.0f / (float)height;
|
||||
const float x_px_ofs = x_inv * 0.5f;
|
||||
const float y_px_ofs = y_inv * 0.5f;
|
||||
#ifdef _MSC_VER
|
||||
int y; /* msvc requires signed for some reason */
|
||||
|
||||
|
@ -1449,9 +1453,9 @@ void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
|
|||
unsigned int i = y * width;
|
||||
unsigned int x;
|
||||
float xy[2];
|
||||
xy[1] = (float)y / (float)height;
|
||||
xy[1] = ((float)y * y_inv) + y_px_ofs;
|
||||
for (x = 0; x < width; x++, i++) {
|
||||
xy[0] = (float)x / (float)width;
|
||||
xy[0] = ((float)x * x_inv) + x_px_ofs;
|
||||
|
||||
buffer[i] = BKE_maskrasterize_handle_sample(mr_handle, xy);
|
||||
}
|
||||
|
|
|
@ -129,8 +129,9 @@ void MaskOperation::determineResolution(unsigned int resolution[2], unsigned int
|
|||
|
||||
void MaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
|
||||
{
|
||||
const float xy[2] = {x * this->m_maskWidthInv,
|
||||
y * this->m_maskHeightInv};
|
||||
const float xy[2] = {
|
||||
(x * this->m_maskWidthInv) + this->m_mask_px_ofs[0],
|
||||
(y * this->m_maskHeightInv) + this->m_mask_px_ofs[1]};
|
||||
|
||||
if (this->m_rasterMaskHandleTot == 1) {
|
||||
if (this->m_rasterMaskHandles[0]) {
|
||||
|
|
|
@ -43,6 +43,7 @@ protected:
|
|||
int m_maskHeight;
|
||||
float m_maskWidthInv; /* 1 / m_maskWidth */
|
||||
float m_maskHeightInv; /* 1 / m_maskHeight */
|
||||
float m_mask_px_ofs[2];
|
||||
|
||||
float m_frame_shutter;
|
||||
int m_frame_number;
|
||||
|
@ -70,11 +71,13 @@ public:
|
|||
{
|
||||
this->m_maskWidth = width;
|
||||
this->m_maskWidthInv = 1.0f / (float)width;
|
||||
this->m_mask_px_ofs[0] = this->m_maskWidthInv * 0.5f;
|
||||
}
|
||||
void setMaskHeight(int height)
|
||||
{
|
||||
this->m_maskHeight = height;
|
||||
this->m_maskHeightInv = 1.0f / (float)height;
|
||||
this->m_mask_px_ofs[1] = this->m_maskHeightInv * 0.5f;
|
||||
}
|
||||
void setFramenumber(int frame_number) { this->m_frame_number = frame_number; }
|
||||
void setSmooth(bool smooth) { this->m_do_smooth = smooth; }
|
||||
|
|
|
@ -643,15 +643,21 @@ static void mask_rasterize_func(TaskPool *pool, void *taskdata, int UNUSED(threa
|
|||
ThreadedMaskRasterizeState *state = (ThreadedMaskRasterizeState *) BLI_task_pool_userdata(pool);
|
||||
ThreadedMaskRasterizeData *data = (ThreadedMaskRasterizeData *) taskdata;
|
||||
int scanline;
|
||||
const float x_inv = 1.0f / (float)state->width;
|
||||
const float y_inv = 1.0f / (float)state->height;
|
||||
const float x_px_ofs = x_inv * 0.5f;
|
||||
const float y_px_ofs = y_inv * 0.5f;
|
||||
|
||||
for (scanline = 0; scanline < data->num_scanlines; scanline++) {
|
||||
float xy[2];
|
||||
int x, y = data->start_scanline + scanline;
|
||||
|
||||
xy[1] = ((float)y * y_inv) + y_px_ofs;
|
||||
|
||||
for (x = 0; x < state->width; x++) {
|
||||
int index = y * state->width + x;
|
||||
float xy[2];
|
||||
|
||||
xy[0] = (float) x / state->width;
|
||||
xy[1] = (float) y / state->height;
|
||||
xy[0] = ((float)x * x_inv) + x_px_ofs;
|
||||
|
||||
state->buffer[index] = BKE_maskrasterize_handle_sample(state->handle, xy);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue