svn merge ^/trunk/blender -r48868:48888
This commit is contained in:
@@ -64,6 +64,8 @@ void BKE_mask_layer_copy_list(struct ListBase *masklayers_new, struct ListBase *
|
||||
/* splines */
|
||||
struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
|
||||
|
||||
int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, const int resol);
|
||||
|
||||
float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int *tot_diff_point))[2];
|
||||
float (*BKE_mask_spline_feather_differentiated_points(struct MaskSpline *spline, int *tot_feather_point))[2];
|
||||
|
||||
@@ -203,4 +205,21 @@ void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int w
|
||||
#define MASKPOINT_SEL_HANDLE(p) { (p)->bezt.f1 |= SELECT; (p)->bezt.f3 |= SELECT; } (void)0
|
||||
#define MASKPOINT_DESEL_HANDLE(p) { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0
|
||||
|
||||
#endif
|
||||
/* disable to test alternate rasterizer */
|
||||
#define USE_RASKTER
|
||||
|
||||
/* mask_rasterize.c */
|
||||
#ifndef USE_RASKTER
|
||||
struct MaskRasterHandle;
|
||||
typedef struct MaskRasterHandle MaskRasterHandle;
|
||||
|
||||
MaskRasterHandle *BLI_maskrasterize_handle_new(void);
|
||||
void BLI_maskrasterize_handle_free(MaskRasterHandle *mr_handle);
|
||||
void BLI_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask,
|
||||
const int width, const int height,
|
||||
const short do_aspect_correct, const short do_mask_aa,
|
||||
const short do_feather);
|
||||
float BLI_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);
|
||||
#endif /* USE_RASKTER */
|
||||
|
||||
#endif /* __BKE_MASK_H__ */
|
||||
|
||||
@@ -101,6 +101,7 @@ set(SRC
|
||||
intern/lamp.c
|
||||
intern/lattice.c
|
||||
intern/library.c
|
||||
intern/mask_rasterize.c
|
||||
intern/mask.c
|
||||
intern/material.c
|
||||
intern/mball.c
|
||||
|
||||
@@ -329,7 +329,7 @@ static int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int
|
||||
return resol;
|
||||
}
|
||||
|
||||
static int mask_spline_points_calc_tot(const MaskSpline *spline, const int resol)
|
||||
int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const int resol)
|
||||
{
|
||||
int len;
|
||||
|
||||
@@ -353,7 +353,7 @@ float (*BKE_mask_spline_differentiate_with_resolution_ex(MaskSpline *spline, con
|
||||
|
||||
MaskSplinePoint *point, *prev;
|
||||
float (*diff_points)[2], (*fp)[2];
|
||||
const int tot = mask_spline_points_calc_tot(spline, resol);
|
||||
const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
|
||||
int a;
|
||||
|
||||
if (spline->tot_point <= 1) {
|
||||
@@ -427,7 +427,7 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl
|
||||
MaskSplinePoint *point, *prev;
|
||||
float (*feather)[2], (*fp)[2];
|
||||
|
||||
const int tot = mask_spline_points_calc_tot(spline, resol);
|
||||
const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
|
||||
int a;
|
||||
|
||||
/* tot+1 because of 'forward_diff_bezier' function */
|
||||
|
||||
638
source/blender/blenkernel/intern/mask_rasterize.c
Normal file
638
source/blender/blenkernel/intern/mask_rasterize.c
Normal file
@@ -0,0 +1,638 @@
|
||||
/*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2012 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Contributor(s): Blender Foundation,
|
||||
* Campbell Barton
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/blenkernel/intern/mask_rasterize.c
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_vec_types.h"
|
||||
#include "DNA_mask_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_kdopbvh.h"
|
||||
#include "BLI_scanfill.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_rect.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_mempool.h"
|
||||
|
||||
#include "BKE_mask.h"
|
||||
|
||||
#ifndef USE_RASKTER
|
||||
|
||||
#define RESOL 32
|
||||
|
||||
/**
|
||||
* A single #MaskRasterHandle contains multile #MaskRasterLayer's,
|
||||
* each #MaskRasterLayer does its own lookup which contributes to
|
||||
* the final pixel with its own blending mode and the final pixel is blended between these.
|
||||
*/
|
||||
|
||||
/* internal use only */
|
||||
typedef struct MaskRasterLayer {
|
||||
/* xy raytree */
|
||||
BVHTree *bvhtree;
|
||||
|
||||
/* 2d bounds (to quickly skip raytree lookup) */
|
||||
rctf bounds;
|
||||
|
||||
/* geometry */
|
||||
unsigned int (*tri_array)[4]; /* access coords tri/quad */
|
||||
float (*tri_coords)[3]; /* xy, z 0-1 (1.0 == filled) */
|
||||
|
||||
|
||||
/* copied direct from #MaskLayer.--- */
|
||||
/* blending options */
|
||||
float alpha;
|
||||
char blend;
|
||||
char blend_flag;
|
||||
|
||||
} MaskRasterLayer;
|
||||
|
||||
|
||||
/**
|
||||
* opaque local struct for mask pixel lookup, each MaskLayer needs one of these
|
||||
*/
|
||||
struct MaskRasterHandle {
|
||||
MaskRasterLayer *layers;
|
||||
unsigned int layers_tot;
|
||||
|
||||
/* 2d bounds (to quickly skip raytree lookup) */
|
||||
rctf bounds;
|
||||
};
|
||||
|
||||
MaskRasterHandle *BLI_maskrasterize_handle_new(void)
|
||||
{
|
||||
MaskRasterHandle *mr_handle;
|
||||
|
||||
mr_handle = MEM_callocN(sizeof(MaskRasterHandle), STRINGIFY(MaskRasterHandle));
|
||||
|
||||
return mr_handle;
|
||||
}
|
||||
|
||||
void BLI_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
|
||||
{
|
||||
const unsigned int layers_tot = mr_handle->layers_tot;
|
||||
unsigned int i;
|
||||
MaskRasterLayer *raslayers = mr_handle->layers;
|
||||
|
||||
/* raycast vars */
|
||||
for (i = 0; i < layers_tot; i++, raslayers++) {
|
||||
BLI_bvhtree_free(raslayers->bvhtree);
|
||||
|
||||
if (raslayers->tri_array) {
|
||||
MEM_freeN(raslayers->tri_array);
|
||||
}
|
||||
|
||||
if (raslayers->tri_coords) {
|
||||
MEM_freeN(raslayers->tri_coords);
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(mr_handle->layers);
|
||||
MEM_freeN(mr_handle);
|
||||
}
|
||||
|
||||
#define PRINT_MASK_DEBUG printf
|
||||
|
||||
#define SF_EDGE_IS_BOUNDARY 0xff
|
||||
|
||||
#define SF_KEYINDEX_TEMP_ID ((unsigned int) -1)
|
||||
|
||||
|
||||
void maskrasterize_spline_differentiate_point_inset(float (*diff_feather_points)[2], float (*diff_points)[2],
|
||||
const int tot_diff_point, const float ofs, const int do_test)
|
||||
{
|
||||
int k_prev = tot_diff_point - 2;
|
||||
int k_curr = tot_diff_point - 1;
|
||||
int k_next = 0;
|
||||
|
||||
int k;
|
||||
|
||||
float d_prev[2];
|
||||
float d_next[2];
|
||||
float d[2];
|
||||
|
||||
const float *co_prev;
|
||||
const float *co_curr;
|
||||
const float *co_next;
|
||||
|
||||
const float ofs_squared = ofs * ofs;
|
||||
|
||||
co_prev = diff_points[k_prev];
|
||||
co_curr = diff_points[k_curr];
|
||||
co_next = diff_points[k_next];
|
||||
|
||||
/* precalc */
|
||||
sub_v2_v2v2(d_prev, co_prev, co_curr);
|
||||
normalize_v2(d_prev);
|
||||
|
||||
/* TODO, speedup by only doing one normalize per iter */
|
||||
|
||||
|
||||
for (k = 0; k < tot_diff_point; k++) {
|
||||
|
||||
co_prev = diff_points[k_prev];
|
||||
co_curr = diff_points[k_curr];
|
||||
co_next = diff_points[k_next];
|
||||
|
||||
/* sub_v2_v2v2(d_prev, co_prev, co_curr); */ /* precalc */
|
||||
sub_v2_v2v2(d_next, co_curr, co_next);
|
||||
|
||||
/* normalize_v2(d_prev); */ /* precalc */
|
||||
normalize_v2(d_next);
|
||||
|
||||
if ((do_test == FALSE) ||
|
||||
(len_squared_v2v2(diff_feather_points[k], diff_points[k]) < ofs_squared))
|
||||
{
|
||||
|
||||
add_v2_v2v2(d, d_prev, d_next);
|
||||
|
||||
normalize_v2(d);
|
||||
|
||||
diff_feather_points[k][0] = diff_points[k][0] + ( d[1] * ofs);
|
||||
diff_feather_points[k][1] = diff_points[k][1] + (-d[0] * ofs);
|
||||
}
|
||||
|
||||
/* use next iter */
|
||||
copy_v2_v2(d_prev, d_next);
|
||||
|
||||
k_prev = k_curr;
|
||||
k_curr = k_next;
|
||||
k_next++;
|
||||
}
|
||||
}
|
||||
|
||||
#define TRI_VERT ((unsigned int) -1)
|
||||
|
||||
void BLI_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask,
|
||||
const int width, const int height,
|
||||
const short do_aspect_correct, const short do_mask_aa,
|
||||
const short do_feather)
|
||||
{
|
||||
/* TODO: real size */
|
||||
const int resol = RESOL;
|
||||
const float aa_filter_size = 1.0f / MIN2(width, height);
|
||||
|
||||
const float zvec[3] = {0.0f, 0.0f, 1.0f};
|
||||
MaskLayer *masklay;
|
||||
int masklay_index;
|
||||
|
||||
mr_handle->layers_tot = BLI_countlist(&mask->masklayers);
|
||||
mr_handle->layers = MEM_mallocN(sizeof(MaskRasterLayer) * mr_handle->layers_tot, STRINGIFY(MaskRasterLayer));
|
||||
BLI_rctf_init_minmax(&mr_handle->bounds);
|
||||
|
||||
for (masklay = mask->masklayers.first, masklay_index = 0; masklay; masklay = masklay->next, masklay_index++) {
|
||||
|
||||
MaskSpline *spline;
|
||||
|
||||
/* scanfill */
|
||||
ScanFillContext sf_ctx;
|
||||
ScanFillVert *sf_vert = NULL;
|
||||
ScanFillVert *sf_vert_next = NULL;
|
||||
ScanFillFace *sf_tri;
|
||||
|
||||
unsigned int sf_vert_tot = 0;
|
||||
unsigned int tot_feather_quads = 0;
|
||||
|
||||
if (masklay->restrictflag & MASK_RESTRICT_RENDER) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BLI_scanfill_begin(&sf_ctx);
|
||||
|
||||
for (spline = masklay->splines.first; spline; spline = spline->next) {
|
||||
|
||||
float (*diff_points)[2];
|
||||
int tot_diff_point;
|
||||
|
||||
float (*diff_feather_points)[2];
|
||||
int tot_diff_feather_points;
|
||||
|
||||
diff_points = BKE_mask_spline_differentiate_with_resolution_ex(spline, resol, &tot_diff_point);
|
||||
|
||||
/* dont ch*/
|
||||
if (do_feather) {
|
||||
diff_feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, resol, &tot_diff_feather_points);
|
||||
}
|
||||
else {
|
||||
tot_diff_feather_points = 0;
|
||||
diff_feather_points = NULL;
|
||||
}
|
||||
|
||||
if (tot_diff_point > 3) {
|
||||
ScanFillVert *sf_vert_prev;
|
||||
int j;
|
||||
|
||||
float co[3];
|
||||
co[2] = 0.0f;
|
||||
|
||||
if (do_aspect_correct) {
|
||||
if (width != height) {
|
||||
float *fp;
|
||||
float *ffp;
|
||||
int i;
|
||||
float asp;
|
||||
|
||||
if (width < height) {
|
||||
fp = &diff_points[0][0];
|
||||
ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL;
|
||||
asp = (float)width / (float)height;
|
||||
}
|
||||
else {
|
||||
fp = &diff_points[0][1];
|
||||
ffp = tot_diff_feather_points ? &diff_feather_points[0][1] : NULL;
|
||||
asp = (float)height / (float)width;
|
||||
}
|
||||
|
||||
for (i = 0; i < tot_diff_point; i++, fp += 2) {
|
||||
(*fp) = (((*fp) - 0.5f) / asp) + 0.5f;
|
||||
}
|
||||
|
||||
if (tot_diff_feather_points) {
|
||||
for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) {
|
||||
(*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fake aa, using small feather */
|
||||
if (do_mask_aa == TRUE) {
|
||||
if (do_feather == FALSE) {
|
||||
tot_diff_feather_points = tot_diff_point;
|
||||
diff_feather_points = MEM_mallocN(sizeof(*diff_feather_points) * tot_diff_feather_points, __func__);
|
||||
/* add single pixel feather */
|
||||
maskrasterize_spline_differentiate_point_inset(diff_feather_points, diff_points,
|
||||
tot_diff_point, aa_filter_size, FALSE);
|
||||
}
|
||||
else {
|
||||
/* ensure single pixel feather, on any zero feather areas */
|
||||
maskrasterize_spline_differentiate_point_inset(diff_feather_points, diff_points,
|
||||
tot_diff_point, aa_filter_size, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
copy_v2_v2(co, diff_points[0]);
|
||||
sf_vert_prev = BLI_scanfill_vert_add(&sf_ctx, co);
|
||||
sf_vert_prev->tmp.u = sf_vert_tot;
|
||||
sf_vert_prev->keyindex = sf_vert_tot + tot_diff_point; /* absolute index of feather vert */
|
||||
sf_vert_tot++;
|
||||
|
||||
/* TODO, an alternate functions so we can avoid double vector copy! */
|
||||
for (j = 1; j < tot_diff_point; j++) {
|
||||
copy_v2_v2(co, diff_points[j]);
|
||||
sf_vert = BLI_scanfill_vert_add(&sf_ctx, co);
|
||||
sf_vert->tmp.u = sf_vert_tot;
|
||||
sf_vert->keyindex = sf_vert_tot + tot_diff_point; /* absolute index of feather vert */
|
||||
sf_vert_tot++;
|
||||
}
|
||||
|
||||
sf_vert = sf_vert_prev;
|
||||
sf_vert_prev = sf_ctx.fillvertbase.last;
|
||||
|
||||
for (j = 0; j < tot_diff_point; j++) {
|
||||
ScanFillEdge *sf_edge = BLI_scanfill_edge_add(&sf_ctx, sf_vert_prev, sf_vert);
|
||||
sf_edge->tmp.c = SF_EDGE_IS_BOUNDARY;
|
||||
|
||||
sf_vert_prev = sf_vert;
|
||||
sf_vert = sf_vert->next;
|
||||
}
|
||||
|
||||
if (diff_feather_points) {
|
||||
float co_feather[3];
|
||||
co_feather[2] = 1.0f;
|
||||
|
||||
BLI_assert(tot_diff_feather_points == tot_diff_point);
|
||||
|
||||
/* note: only added for convenience, we dont infact use these to scanfill,
|
||||
* only to create feather faces after scanfill */
|
||||
for (j = 0; j < tot_diff_feather_points; j++) {
|
||||
copy_v2_v2(co_feather, diff_feather_points[j]);
|
||||
sf_vert = BLI_scanfill_vert_add(&sf_ctx, co_feather);
|
||||
|
||||
/* no need for these attrs */
|
||||
#if 0
|
||||
sf_vert->tmp.u = sf_vert_tot;
|
||||
sf_vert->keyindex = sf_vert_tot + tot_diff_point; /* absolute index of feather vert */
|
||||
#endif
|
||||
sf_vert->keyindex = SF_KEYINDEX_TEMP_ID;
|
||||
sf_vert_tot++;
|
||||
}
|
||||
|
||||
if (diff_feather_points) {
|
||||
MEM_freeN(diff_feather_points);
|
||||
}
|
||||
|
||||
tot_feather_quads += tot_diff_point;
|
||||
}
|
||||
}
|
||||
|
||||
if (diff_points) {
|
||||
MEM_freeN(diff_points);
|
||||
}
|
||||
}
|
||||
|
||||
if (sf_ctx.fillvertbase.first) {
|
||||
unsigned int (*tri_array)[4], *tri; /* access coords */
|
||||
float (*tri_coords)[3], *cos; /* xy, z 0-1 (1.0 == filled) */
|
||||
int sf_tri_tot;
|
||||
rctf bounds;
|
||||
int tri_index;
|
||||
|
||||
BVHTree *bvhtree;
|
||||
float bvhcos[4][3];
|
||||
|
||||
/* now we have all the splines */
|
||||
tri_coords = MEM_mallocN((sizeof(float) * 3) * sf_vert_tot, "maskrast_tri_coords");
|
||||
|
||||
/* init bounds */
|
||||
BLI_rctf_init_minmax(&bounds);
|
||||
|
||||
/* coords */
|
||||
cos = (float *)tri_coords;
|
||||
for (sf_vert = sf_ctx.fillvertbase.first; sf_vert; sf_vert = sf_vert_next) {
|
||||
sf_vert_next = sf_vert->next;
|
||||
copy_v3_v3(cos, sf_vert->co);
|
||||
|
||||
/* remove so as not to interfear with fill (called after) */
|
||||
if (sf_vert->keyindex == SF_KEYINDEX_TEMP_ID) {
|
||||
BLI_remlink(&sf_ctx.fillvertbase, sf_vert);
|
||||
}
|
||||
|
||||
/* bounds */
|
||||
BLI_rctf_do_minmax_v(&bounds, cos);
|
||||
|
||||
cos += 3;
|
||||
}
|
||||
|
||||
/* main scanfill */
|
||||
sf_tri_tot = BLI_scanfill_calc_ex(&sf_ctx, FALSE, zvec);
|
||||
|
||||
tri_array = MEM_mallocN(sizeof(*tri_array) * (sf_tri_tot + tot_feather_quads), "maskrast_tri_index");
|
||||
|
||||
/* */
|
||||
bvhtree = BLI_bvhtree_new(sf_tri_tot + tot_feather_quads, 0.000001f, 8, 6);
|
||||
|
||||
/* tri's */
|
||||
tri = (unsigned int *)tri_array;
|
||||
for (sf_tri = sf_ctx.fillfacebase.first, tri_index = 0; sf_tri; sf_tri = sf_tri->next, tri_index++) {
|
||||
*(tri++) = sf_tri->v1->tmp.u;
|
||||
*(tri++) = sf_tri->v2->tmp.u;
|
||||
*(tri++) = sf_tri->v3->tmp.u;
|
||||
*(tri++) = TRI_VERT;
|
||||
|
||||
copy_v3_v3(bvhcos[0], tri_coords[*(tri - 4)]);
|
||||
copy_v3_v3(bvhcos[1], tri_coords[*(tri - 3)]);
|
||||
copy_v3_v3(bvhcos[2], tri_coords[*(tri - 2)]);
|
||||
|
||||
BLI_bvhtree_insert(bvhtree, tri_index, (float *)bvhcos, 3);
|
||||
}
|
||||
|
||||
/* start of feather faces... if we have this set,
|
||||
* 'tri_index' is kept from loop above */
|
||||
|
||||
BLI_assert(tri_index == sf_tri_tot);
|
||||
|
||||
if (tot_feather_quads) {
|
||||
ScanFillEdge *sf_edge;
|
||||
|
||||
for (sf_edge = sf_ctx.filledgebase.first; sf_edge; sf_edge = sf_edge->next) {
|
||||
if (sf_edge->tmp.c == SF_EDGE_IS_BOUNDARY) {
|
||||
*(tri++) = sf_edge->v1->tmp.u;
|
||||
*(tri++) = sf_edge->v2->tmp.u;
|
||||
*(tri++) = sf_edge->v2->keyindex;
|
||||
*(tri++) = sf_edge->v1->keyindex;
|
||||
|
||||
copy_v3_v3(bvhcos[0], tri_coords[*(tri - 4)]);
|
||||
copy_v3_v3(bvhcos[1], tri_coords[*(tri - 3)]);
|
||||
copy_v3_v3(bvhcos[2], tri_coords[*(tri - 2)]);
|
||||
copy_v3_v3(bvhcos[3], tri_coords[*(tri - 1)]);
|
||||
|
||||
BLI_bvhtree_insert(bvhtree, tri_index++, (const float *)bvhcos, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%d %d\n", tri_index, sf_tri_tot + tot_feather_quads);
|
||||
|
||||
BLI_assert(tri_index == sf_tri_tot + tot_feather_quads);
|
||||
|
||||
BLI_bvhtree_balance(bvhtree);
|
||||
|
||||
{
|
||||
MaskRasterLayer *raslayer = &mr_handle->layers[masklay_index];
|
||||
|
||||
raslayer->tri_coords = tri_coords;
|
||||
raslayer->tri_array = tri_array;
|
||||
raslayer->bounds = bounds;
|
||||
raslayer->bvhtree = bvhtree;
|
||||
|
||||
/* copy as-is */
|
||||
raslayer->alpha = masklay->alpha;
|
||||
raslayer->blend = masklay->blend;
|
||||
raslayer->blend_flag = masklay->blend_flag;
|
||||
|
||||
|
||||
BLI_union_rctf(&mr_handle->bounds, &bounds);
|
||||
}
|
||||
|
||||
PRINT_MASK_DEBUG("tris %d, feather tris %d\n", sf_tri_tot, tot_feather_quads);
|
||||
}
|
||||
|
||||
/* add trianges */
|
||||
BLI_scanfill_end(&sf_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
//static void tri_flip_tri(unsigned int tri[3])
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
/* 2D ray test */
|
||||
static float maskrasterize_layer_z_depth_tri(const float pt[2],
|
||||
const float v1[3], const float v2[3], const float v3[3])
|
||||
{
|
||||
float w[3];
|
||||
barycentric_weights_v2(v1, v2, v3, pt, w);
|
||||
return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static float maskrasterize_layer_z_depth_quad(const float pt[2],
|
||||
const float v1[3], const float v2[3], const float v3[3], const float v4[3])
|
||||
{
|
||||
float w[4];
|
||||
barycentric_weights_v2_quad(v1, v2, v3, v4, pt, w);
|
||||
return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]) + (v4[2] * w[3]);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void maskrasterize_layer_bvh_cb(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
||||
{
|
||||
MaskRasterLayer *layer = (struct MaskRasterLayer *)userdata;
|
||||
unsigned int *tri = layer->tri_array[index];
|
||||
float (*cos)[3] = layer->tri_coords;
|
||||
const float dist_orig = hit->dist;
|
||||
|
||||
/* we always cast from same place only need xy */
|
||||
if (tri[3] == TRI_VERT) {
|
||||
/* --- tri --- */
|
||||
|
||||
/* not essential but avoids unneeded extra lookups */
|
||||
if ((cos[0][2] < dist_orig) ||
|
||||
(cos[1][2] < dist_orig) ||
|
||||
(cos[2][2] < dist_orig))
|
||||
{
|
||||
if (isect_point_tri_v2(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]])) {
|
||||
/* we know all tris are close for now */
|
||||
#if 0
|
||||
const float dist = maskrasterize_layer_z_depth_tri(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]]);
|
||||
if (dist < dist_orig) {
|
||||
hit->index = index;
|
||||
hit->dist = dist;
|
||||
}
|
||||
#else
|
||||
hit->index = index;
|
||||
hit->dist = 0.0f;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* --- quad --- */
|
||||
|
||||
/* not essential but avoids unneeded extra lookups */
|
||||
if ((cos[0][2] < dist_orig) ||
|
||||
(cos[1][2] < dist_orig) ||
|
||||
(cos[2][2] < dist_orig) ||
|
||||
(cos[3][2] < dist_orig))
|
||||
{
|
||||
|
||||
/* needs work */
|
||||
#if 0
|
||||
if (isect_point_quad_v2(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]], cos[tri[3]])) {
|
||||
const float dist = maskrasterize_layer_z_depth_quad(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]], cos[tri[3]]);
|
||||
if (dist < dist_orig) {
|
||||
hit->index = index;
|
||||
hit->dist = dist;
|
||||
}
|
||||
}
|
||||
#elif 1
|
||||
if (isect_point_tri_v2(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]])) {
|
||||
const float dist = maskrasterize_layer_z_depth_tri(ray->origin, cos[tri[0]], cos[tri[1]], cos[tri[2]]);
|
||||
if (dist < dist_orig) {
|
||||
hit->index = index;
|
||||
hit->dist = dist;
|
||||
}
|
||||
}
|
||||
else if (isect_point_tri_v2(ray->origin, cos[tri[0]], cos[tri[2]], cos[tri[3]])) {
|
||||
const float dist = maskrasterize_layer_z_depth_tri(ray->origin, cos[tri[0]], cos[tri[2]], cos[tri[3]]);
|
||||
if (dist < dist_orig) {
|
||||
hit->index = index;
|
||||
hit->dist = dist;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* cheat - we know first 2 verts are z0.0f and second 2 are z 1.0f */
|
||||
/* ... worth looking into */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float BLI_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2])
|
||||
{
|
||||
/* TODO - AA jitter */
|
||||
|
||||
if (BLI_in_rctf_v(&mr_handle->bounds, xy)) {
|
||||
const unsigned int layers_tot = mr_handle->layers_tot;
|
||||
unsigned int i;
|
||||
MaskRasterLayer *layer = mr_handle->layers;
|
||||
|
||||
/* raycast vars*/
|
||||
const float co[3] = {xy[0], xy[1], 0.0f};
|
||||
const float dir[3] = {0.0f, 0.0f, 1.0f};
|
||||
const float radius = 1.0f;
|
||||
BVHTreeRayHit hit = {0};
|
||||
|
||||
/* return */
|
||||
float value = 0.0f;
|
||||
|
||||
for (i = 0; i < layers_tot; i++, layer++) {
|
||||
|
||||
if (BLI_in_rctf_v(&layer->bounds, xy)) {
|
||||
|
||||
hit.dist = FLT_MAX;
|
||||
hit.index = -1;
|
||||
|
||||
/* TODO, and axis aligned version of this function, avoids 2 casts */
|
||||
BLI_bvhtree_ray_cast(layer->bvhtree, co, dir, radius, &hit, maskrasterize_layer_bvh_cb, layer);
|
||||
|
||||
/* --- hit (start) --- */
|
||||
if (hit.index != -1) {
|
||||
const float dist = 1.0f - hit.dist;
|
||||
const float dist_ease = (3.0f * dist * dist - 2.0f * dist * dist * dist);
|
||||
|
||||
float v;
|
||||
/* apply alpha */
|
||||
v = dist_ease * layer->alpha;
|
||||
|
||||
if (layer->blend_flag & MASK_BLENDFLAG_INVERT) {
|
||||
v = 1.0f - v;
|
||||
}
|
||||
|
||||
switch (layer->blend) {
|
||||
case MASK_BLEND_SUBTRACT:
|
||||
{
|
||||
value -= v;
|
||||
break;
|
||||
}
|
||||
case MASK_BLEND_ADD:
|
||||
default:
|
||||
{
|
||||
value += v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* --- hit (end) --- */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return CLAMPIS(value, 0.0f, 1.0f);
|
||||
}
|
||||
else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* USE_RASKTER */
|
||||
@@ -1576,7 +1576,7 @@ static void initialize_all_particles(ParticleSimulationData *sim)
|
||||
}
|
||||
}
|
||||
|
||||
static void get_angular_velocity_vector(short avemode, ParticleKey *state, float *vec)
|
||||
static void get_angular_velocity_vector(short avemode, ParticleKey *state, float vec[3])
|
||||
{
|
||||
switch (avemode) {
|
||||
case PART_AVE_VELOCITY:
|
||||
|
||||
@@ -200,6 +200,8 @@ void barycentric_transform(float pt_tar[3], float const pt_src[3],
|
||||
|
||||
void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2],
|
||||
const float co[2], float w[3]);
|
||||
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2],
|
||||
const float co[2], float w[4]);
|
||||
|
||||
int barycentric_coords_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]);
|
||||
int barycentric_inside_triangle_v2(const float w[3]);
|
||||
|
||||
@@ -1942,6 +1942,46 @@ void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3
|
||||
}
|
||||
}
|
||||
|
||||
/* same as #barycentric_weights_v2 but works with a quad,
|
||||
* note: untested for values outside the quad's bounds.
|
||||
* note: there may be a more efficient method to do this, just figured it out - campbell */
|
||||
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2],
|
||||
const float co[2], float w[4])
|
||||
{
|
||||
float wtot;
|
||||
|
||||
const float areas_co[4] = {
|
||||
area_tri_signed_v2(v1, v2, co),
|
||||
area_tri_signed_v2(v2, v3, co),
|
||||
area_tri_signed_v2(v3, v4, co),
|
||||
area_tri_signed_v2(v4, v1, co),
|
||||
};
|
||||
|
||||
const float areas_diag[4] = {
|
||||
area_tri_signed_v2(v4, v1, v2),
|
||||
area_tri_signed_v2(v1, v2, v3),
|
||||
area_tri_signed_v2(v2, v3, v4),
|
||||
area_tri_signed_v2(v3, v4, v1),
|
||||
};
|
||||
|
||||
const float u = areas_co[3] / (areas_co[1] + areas_co[3]);
|
||||
const float v = areas_co[0] / (areas_co[0] + areas_co[2]);
|
||||
|
||||
w[0] = ((1.0f - u) * (1.0f - v)) * sqrtf(areas_diag[0] / areas_diag[2]);
|
||||
w[1] = (( u) * (1.0f - v)) * sqrtf(areas_diag[1] / areas_diag[3]);
|
||||
w[2] = (( u) * ( v)) * sqrtf(areas_diag[2] / areas_diag[0]);
|
||||
w[3] = ((1.0f - u) * ( v)) * sqrtf(areas_diag[3] / areas_diag[1]);
|
||||
|
||||
wtot = w[0] + w[1] + w[2] + w[3];
|
||||
|
||||
if (wtot != 0.0f) {
|
||||
mul_v4_fl(w, 1.0f / wtot);
|
||||
}
|
||||
else { /* dummy values for zero area face */
|
||||
copy_v4_fl(w, 1.0f / 4.0f);
|
||||
}
|
||||
}
|
||||
|
||||
/* given 2 triangles in 3D space, and a point in relation to the first triangle.
|
||||
* calculate the location of a point in relation to the second triangle.
|
||||
* Useful for finding relative positions with geometry */
|
||||
|
||||
@@ -121,7 +121,7 @@ void MemoryBuffer::writePixel(int x, int y, const float color[4])
|
||||
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
|
||||
y >= this->m_rect.ymin && y < this->m_rect.ymax)
|
||||
{
|
||||
const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
|
||||
const int offset = (this->m_chunkWidth * (y-this->m_rect.ymin) + x-this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
|
||||
copy_v4_v4(&this->m_buffer[offset], color);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4])
|
||||
if (x >= this->m_rect.xmin && x < this->m_rect.xmax &&
|
||||
y >= this->m_rect.ymin && y < this->m_rect.ymax)
|
||||
{
|
||||
const int offset = (this->m_chunkWidth * y + x) * COM_NUMBER_OF_CHANNELS;
|
||||
const int offset = (this->m_chunkWidth * (y-this->m_rect.ymin) + x-this->m_rect.xmin) * COM_NUMBER_OF_CHANNELS;
|
||||
add_v4_v4(&this->m_buffer[offset], color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void SingleThreadedNodeOperation::initExecution()
|
||||
|
||||
void SingleThreadedNodeOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
|
||||
{
|
||||
this->m_cachedInstance->read(color, x, y);
|
||||
this->m_cachedInstance->readNoCheck(color, x, y);
|
||||
}
|
||||
|
||||
void SingleThreadedNodeOperation::deinitExecution()
|
||||
|
||||
@@ -99,9 +99,7 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
InverseSearchRadiusOperation *search = new InverseSearchRadiusOperation();
|
||||
addLink(graph, radiusOperation->getOutputSocket(0), search->getInputSocket(0));
|
||||
addLink(graph, depthOperation, search->getInputSocket(1));
|
||||
search->setMaxBlur(data->maxblur);
|
||||
search->setThreshold(data->bthresh);
|
||||
graph->addOperation(search);
|
||||
#endif
|
||||
VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation();
|
||||
@@ -116,7 +114,7 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext
|
||||
addLink(graph, bokeh->getOutputSocket(), operation->getInputSocket(1));
|
||||
addLink(graph, radiusOperation->getOutputSocket(), operation->getInputSocket(2));
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
addLink(graph, search->getOutputSocket(), operation->getInputSocket(4));
|
||||
addLink(graph, search->getOutputSocket(), operation->getInputSocket(3));
|
||||
#endif
|
||||
if (data->gamco) {
|
||||
GammaCorrectOperation *correct = new GammaCorrectOperation();
|
||||
|
||||
@@ -86,7 +86,7 @@ void DisplaceOperation::executePixel(float *color, int x, int y, MemoryBuffer *i
|
||||
this->m_inputVectorProgram->read(inVector, x + 1, y, COM_PS_NEAREST, inputBuffers);
|
||||
d_dx = inVector[0] * xs;
|
||||
this->m_inputVectorProgram->read(inVector, x, y + 1, COM_PS_NEAREST, inputBuffers);
|
||||
d_dy = inVector[0] * ys;
|
||||
d_dy = inVector[1] * ys;
|
||||
|
||||
/* clamp derivatives to minimum displacement distance in UV space */
|
||||
dxt = p_dx - d_dx;
|
||||
|
||||
@@ -194,3 +194,156 @@ bool GaussianBokehBlurOperation::determineDependingAreaOfInterest(rcti *input, R
|
||||
return BlurBaseOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
}
|
||||
|
||||
// reference image
|
||||
GaussianBokehBlurReferenceOperation::GaussianBokehBlurReferenceOperation() : NodeOperation()
|
||||
{
|
||||
this->addInputSocket(COM_DT_COLOR);
|
||||
this->addInputSocket(COM_DT_VALUE);
|
||||
this->addOutputSocket(COM_DT_COLOR);
|
||||
this->setComplex(true);
|
||||
this->m_gausstab = NULL;
|
||||
this->m_inputImage = NULL;
|
||||
this->m_inputSize = NULL;
|
||||
}
|
||||
|
||||
void *GaussianBokehBlurReferenceOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
|
||||
{
|
||||
void *buffer = getInputOperation(0)->initializeTileData(NULL, memoryBuffers);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void GaussianBokehBlurReferenceOperation::initExecution()
|
||||
{
|
||||
// setup gaustab
|
||||
this->m_data->image_in_width = this->getWidth();
|
||||
this->m_data->image_in_height = this->getHeight();
|
||||
if (this->m_data->relative) {
|
||||
switch (this->m_data->aspect) {
|
||||
case CMP_NODE_BLUR_ASPECT_NONE:
|
||||
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
|
||||
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
|
||||
break;
|
||||
case CMP_NODE_BLUR_ASPECT_Y:
|
||||
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_width);
|
||||
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_width);
|
||||
break;
|
||||
case CMP_NODE_BLUR_ASPECT_X:
|
||||
this->m_data->sizex = (int)(this->m_data->percentx * 0.01f * this->m_data->image_in_height);
|
||||
this->m_data->sizey = (int)(this->m_data->percenty * 0.01f * this->m_data->image_in_height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateGauss();
|
||||
this->m_inputImage = this->getInputSocketReader(0);
|
||||
this->m_inputSize = this->getInputSocketReader(1);
|
||||
}
|
||||
|
||||
void GaussianBokehBlurReferenceOperation::updateGauss()
|
||||
{
|
||||
int n;
|
||||
float *dgauss;
|
||||
float *ddgauss;
|
||||
int j, i;
|
||||
|
||||
n = (2 * radx + 1) * (2 * rady + 1);
|
||||
|
||||
/* create a full filter image */
|
||||
ddgauss = new float[n];
|
||||
dgauss = ddgauss;
|
||||
for (j = -rady; j <= rady; j++) {
|
||||
for (i = -radx; i <= radx; i++, dgauss++) {
|
||||
float fj = (float)j / radyf;
|
||||
float fi = (float)i / radxf;
|
||||
float dist = sqrt(fj * fj + fi * fi);
|
||||
*dgauss = RE_filter_value(this->m_data->filtertype, dist);
|
||||
}
|
||||
}
|
||||
this->m_gausstab = ddgauss;
|
||||
}
|
||||
|
||||
void GaussianBokehBlurReferenceOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
|
||||
{
|
||||
float tempColor[4];
|
||||
float tempSize[4];
|
||||
tempColor[0] = 0;
|
||||
tempColor[1] = 0;
|
||||
tempColor[2] = 0;
|
||||
tempColor[3] = 0;
|
||||
float multiplier_accum = 0;
|
||||
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
|
||||
float *buffer = inputBuffer->getBuffer();
|
||||
int bufferwidth = inputBuffer->getWidth();
|
||||
int bufferstartx = inputBuffer->getRect()->xmin;
|
||||
int bufferstarty = inputBuffer->getRect()->ymin;
|
||||
this->m_inputSize->read(tempSize, x, y, inputBuffers, data);
|
||||
float size = tempSize[0];
|
||||
CLAMP(size, 0.0f, 1.0f);
|
||||
float sizeX = ceil(this->m_data->sizex * size);
|
||||
float sizeY = ceil(this->m_data->sizey * size);
|
||||
|
||||
if (sizeX <= 0.5f && sizeY <= 0.5f) {
|
||||
this->m_inputImage->read(color, x, y, inputBuffers, data);
|
||||
return;
|
||||
}
|
||||
|
||||
int miny = y - sizeY;
|
||||
int maxy = y + sizeY;
|
||||
int minx = x - sizeX;
|
||||
int maxx = x + sizeX;
|
||||
miny = max(miny, inputBuffer->getRect()->ymin);
|
||||
minx = max(minx, inputBuffer->getRect()->xmin);
|
||||
maxy = min(maxy, inputBuffer->getRect()->ymax);
|
||||
maxx = min(maxx, inputBuffer->getRect()->xmax);
|
||||
|
||||
int step = QualityStepHelper::getStep();
|
||||
int offsetadd = QualityStepHelper::getOffsetAdd();
|
||||
for (int ny = miny; ny < maxy; ny += step) {
|
||||
int u = ny - y;
|
||||
float uf = ((u/sizeY)*radyf)+radyf;
|
||||
int indexu = uf * (radx*2+1);
|
||||
int bufferindex = ((minx - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
|
||||
for (int nx = minx; nx < maxx; nx += step) {
|
||||
int v = nx - x;
|
||||
float vf = ((v/sizeX)*radxf)+radxf;
|
||||
int index = indexu + vf;
|
||||
const float multiplier = this->m_gausstab[index];
|
||||
madd_v4_v4fl(tempColor, &buffer[bufferindex], multiplier);
|
||||
multiplier_accum += multiplier;
|
||||
index += step;
|
||||
bufferindex += offsetadd;
|
||||
}
|
||||
}
|
||||
|
||||
mul_v4_v4fl(color, tempColor, 1.0f / multiplier_accum);
|
||||
}
|
||||
|
||||
void GaussianBokehBlurReferenceOperation::deinitExecution()
|
||||
{
|
||||
delete [] this->m_gausstab;
|
||||
this->m_gausstab = NULL;
|
||||
this->m_inputImage = NULL;
|
||||
this->m_inputSize = NULL;
|
||||
|
||||
}
|
||||
|
||||
bool GaussianBokehBlurReferenceOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
NodeOperation *operation = this->getInputOperation(1);
|
||||
|
||||
if (operation->determineDependingAreaOfInterest(input, readOperation, output)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
int addx = this->m_data->sizex+2;
|
||||
int addy = this->m_data->sizey+2;
|
||||
newInput.xmax = input->xmax + addx;
|
||||
newInput.xmin = input->xmin - addx;
|
||||
newInput.ymax = input->ymax + addy;
|
||||
newInput.ymin = input->ymin - addy;
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,38 @@ public:
|
||||
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
};
|
||||
|
||||
class GaussianBokehBlurReferenceOperation : public NodeOperation, public QualityStepHelper {
|
||||
private:
|
||||
SocketReader * m_inputImage;
|
||||
SocketReader * m_inputSize;
|
||||
float *m_gausstab;
|
||||
NodeBlurData *m_data;
|
||||
|
||||
void updateGauss();
|
||||
|
||||
static const int radxf = 256.0f;
|
||||
static const int radyf = 256.0f;
|
||||
static const int radx = 256;
|
||||
static const int rady = 256;
|
||||
|
||||
public:
|
||||
GaussianBokehBlurReferenceOperation();
|
||||
void initExecution();
|
||||
void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers);
|
||||
/**
|
||||
* the inner loop of this program
|
||||
*/
|
||||
void executePixel(float *color, int x, int y, MemoryBuffer * inputBuffers[], void *data);
|
||||
|
||||
/**
|
||||
* Deinitialize the execution
|
||||
*/
|
||||
void deinitExecution();
|
||||
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
|
||||
void setData(NodeBlurData *data) { this->m_data = data; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -118,17 +118,19 @@ void GaussianXBlurOperation::deinitExecution()
|
||||
bool GaussianXBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
rcti sizeInput;
|
||||
sizeInput.xmin = 0;
|
||||
sizeInput.ymin = 0;
|
||||
sizeInput.xmax = 5;
|
||||
sizeInput.ymax = 5;
|
||||
|
||||
NodeOperation *operation = this->getInputOperation(1);
|
||||
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
|
||||
return true;
|
||||
if (!this->m_sizeavailable) {
|
||||
rcti sizeInput;
|
||||
sizeInput.xmin = 0;
|
||||
sizeInput.ymin = 0;
|
||||
sizeInput.xmax = 5;
|
||||
sizeInput.ymax = 5;
|
||||
NodeOperation *operation = this->getInputOperation(1);
|
||||
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
{
|
||||
if (this->m_sizeavailable && this->m_gausstab != NULL) {
|
||||
newInput.xmax = input->xmax + this->m_rad;
|
||||
newInput.xmin = input->xmin - this->m_rad;
|
||||
|
||||
@@ -116,17 +116,19 @@ void GaussianYBlurOperation::deinitExecution()
|
||||
bool GaussianYBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newInput;
|
||||
rcti sizeInput;
|
||||
sizeInput.xmin = 0;
|
||||
sizeInput.ymin = 0;
|
||||
sizeInput.xmax = 5;
|
||||
sizeInput.ymax = 5;
|
||||
|
||||
NodeOperation *operation = this->getInputOperation(1);
|
||||
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
|
||||
return true;
|
||||
if (!m_sizeavailable) {
|
||||
rcti sizeInput;
|
||||
sizeInput.xmin = 0;
|
||||
sizeInput.ymin = 0;
|
||||
sizeInput.xmax = 5;
|
||||
sizeInput.ymax = 5;
|
||||
NodeOperation *operation = this->getInputOperation(1);
|
||||
if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
{
|
||||
if (this->m_sizeavailable && this->m_gausstab != NULL) {
|
||||
newInput.xmax = input->xmax;
|
||||
newInput.xmin = input->xmin;
|
||||
|
||||
@@ -30,8 +30,10 @@
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
|
||||
#ifdef USE_RASKTER
|
||||
|
||||
extern "C" {
|
||||
#include "BKE_mask.h"
|
||||
#include "../../../../intern/raskter/raskter.h"
|
||||
}
|
||||
|
||||
@@ -127,3 +129,72 @@ void MaskOperation::executePixel(float *color, int x, int y, MemoryBuffer *input
|
||||
color[0] = buffer[index];
|
||||
}
|
||||
}
|
||||
|
||||
#else /* mask rasterizer by campbell wip */
|
||||
|
||||
MaskOperation::MaskOperation() : NodeOperation()
|
||||
{
|
||||
this->addOutputSocket(COM_DT_VALUE);
|
||||
this->m_mask = NULL;
|
||||
this->m_maskWidth = 0;
|
||||
this->m_maskHeight = 0;
|
||||
this->m_framenumber = 0;
|
||||
this->m_rasterMaskHandle = NULL;
|
||||
setComplex(true);
|
||||
}
|
||||
|
||||
void MaskOperation::initExecution()
|
||||
{
|
||||
initMutex();
|
||||
|
||||
if (this->m_rasterMaskHandle == NULL) {
|
||||
const int width = this->getWidth();
|
||||
const int height = this->getHeight();
|
||||
|
||||
this->m_rasterMaskHandle = BLI_maskrasterize_handle_new();
|
||||
|
||||
BLI_maskrasterize_handle_init(this->m_rasterMaskHandle, this->m_mask, width, height, TRUE, this->m_do_smooth, this->m_do_feather);
|
||||
}
|
||||
}
|
||||
|
||||
void MaskOperation::deinitExecution()
|
||||
{
|
||||
if (this->m_rasterMaskHandle) {
|
||||
BLI_maskrasterize_handle_free(this->m_rasterMaskHandle);
|
||||
this->m_rasterMaskHandle = NULL;
|
||||
}
|
||||
|
||||
deinitMutex();
|
||||
}
|
||||
|
||||
void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
|
||||
{
|
||||
/* pass */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void MaskOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
|
||||
{
|
||||
if (this->m_maskWidth == 0 || this->m_maskHeight == 0) {
|
||||
NodeOperation::determineResolution(resolution, preferredResolution);
|
||||
}
|
||||
else {
|
||||
unsigned int nr[2];
|
||||
|
||||
nr[0] = this->m_maskWidth;
|
||||
nr[1] = this->m_maskHeight;
|
||||
|
||||
NodeOperation::determineResolution(resolution, nr);
|
||||
|
||||
resolution[0] = this->m_maskWidth;
|
||||
resolution[1] = this->m_maskHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void MaskOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
|
||||
{
|
||||
const float xy[2] = {x / (float)this->m_maskWidth, y / (float)this->m_maskHeight};
|
||||
color[0] = BLI_maskrasterize_handle_sample(this->m_rasterMaskHandle, xy);
|
||||
}
|
||||
|
||||
#endif /* USE_RASKTER */
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
#ifndef _COM_MaskOperation_h
|
||||
#define _COM_MaskOperation_h
|
||||
|
||||
/* XXX, remove when the USE_RASKTER option is also removed */
|
||||
extern "C" {
|
||||
#include "BKE_mask.h"
|
||||
}
|
||||
|
||||
#include "COM_NodeOperation.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_mask_types.h"
|
||||
@@ -46,10 +51,16 @@ protected:
|
||||
int m_framenumber;
|
||||
bool m_do_smooth;
|
||||
bool m_do_feather;
|
||||
|
||||
#ifdef USE_RASKTER
|
||||
float *m_rasterizedMask;
|
||||
|
||||
ListBase m_maskLayers;
|
||||
|
||||
#else /* USE_RASKTER */
|
||||
struct MaskRasterHandle *m_rasterMaskHandle;
|
||||
#endif /* USE_RASKTER */
|
||||
|
||||
/**
|
||||
* Determine the output resolution. The resolution is retrieved from the Renderer
|
||||
*/
|
||||
|
||||
@@ -45,12 +45,13 @@ void MixBaseOperation::executePixel(float *outputColor, float x, float y, PixelS
|
||||
{
|
||||
float inputColor1[4];
|
||||
float inputColor2[4];
|
||||
float value;
|
||||
float inputValue[4];
|
||||
|
||||
this->m_inputValueOperation->read(&value, x, y, sampler, inputBuffers);
|
||||
this->m_inputColor1Operation->read(&inputColor1[0], x, y, sampler, inputBuffers);
|
||||
this->m_inputColor2Operation->read(&inputColor2[0], x, y, sampler, inputBuffers);
|
||||
this->m_inputValueOperation->read(inputValue, x, y, sampler, inputBuffers);
|
||||
this->m_inputColor1Operation->read(inputColor1, x, y, sampler, inputBuffers);
|
||||
this->m_inputColor2Operation->read(inputColor2, x, y, sampler, inputBuffers);
|
||||
|
||||
float value = inputValue[0];
|
||||
if (this->useValueAlphaMultiply()) {
|
||||
value *= inputColor2[3];
|
||||
}
|
||||
@@ -93,13 +94,3 @@ void MixBaseOperation::determineResolution(unsigned int resolution[], unsigned i
|
||||
}
|
||||
NodeOperation::determineResolution(resolution, preferredResolution);
|
||||
}
|
||||
|
||||
void MixBaseOperation::clampIfNeeded(float *color)
|
||||
{
|
||||
if (this->m_useClamp) {
|
||||
CLAMP(color[0], 0.0f, 1.0f);
|
||||
CLAMP(color[1], 0.0f, 1.0f);
|
||||
CLAMP(color[2], 0.0f, 1.0f);
|
||||
CLAMP(color[3], 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,16 @@ protected:
|
||||
bool m_valueAlphaMultiply;
|
||||
bool m_useClamp;
|
||||
|
||||
void clampIfNeeded(float *color);
|
||||
inline void clampIfNeeded(float *color)
|
||||
{
|
||||
if (m_useClamp) {
|
||||
CLAMP(color[0], 0.0f, 1.0f);
|
||||
CLAMP(color[1], 0.0f, 1.0f);
|
||||
CLAMP(color[2], 0.0f, 1.0f);
|
||||
CLAMP(color[3], 0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor
|
||||
|
||||
@@ -112,7 +112,7 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2
|
||||
tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;
|
||||
if (tempSize > threshold) {
|
||||
if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) {
|
||||
float2 uv = { 256.0f + dx * 256.0f / tempSize, 256.0f + dy * 256.0f / tempSize};
|
||||
float2 uv = { 256.0f + dx * 255.0f / tempSize, 256.0f + dy * 255.0f / tempSize};
|
||||
bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);
|
||||
readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);
|
||||
color_accum += bokeh*readColor;
|
||||
|
||||
@@ -57,7 +57,7 @@ void VariableSizeBokehBlurOperation::initExecution()
|
||||
this->m_inputBokehProgram = getInputSocketReader(1);
|
||||
this->m_inputSizeProgram = getInputSocketReader(2);
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
this->m_inputSearchProgram = getInputSocketReader(4);
|
||||
this->m_inputSearchProgram = getInputSocketReader(3);
|
||||
#endif
|
||||
QualityStepHelper::initExecution(COM_QH_INCREASE);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me
|
||||
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
float search[4];
|
||||
this->inputSearchProgram->read(search, x/InverseSearchRadiusOperation::DIVIDER, y / InverseSearchRadiusOperation::DIVIDER, inputBuffers, NULL);
|
||||
this->m_inputSearchProgram->read(search, x/InverseSearchRadiusOperation::DIVIDER, y / InverseSearchRadiusOperation::DIVIDER, inputBuffers, NULL);
|
||||
int minx = search[0];
|
||||
int miny = search[1];
|
||||
int maxx = search[2];
|
||||
@@ -127,8 +127,8 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me
|
||||
float fsize = fabsf(size);
|
||||
float dx = nx - x;
|
||||
if (fsize > fabsf(dx) && fsize > fabsf(dy)) {
|
||||
float u = (256.0f + (dx/size) * 256.0f);
|
||||
float v = (256.0f + (dy/size) * 256.0f);
|
||||
float u = (256.0f + (dx/size) * 255.0f);
|
||||
float v = (256.0f + (dy/size) * 255.0f);
|
||||
inputBokehBuffer->readNoCheck(bokeh, u, v);
|
||||
madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetNxNy]);
|
||||
add_v4_v4(multiplier_accum, bokeh);
|
||||
@@ -211,7 +211,7 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu
|
||||
searchInput.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1;
|
||||
searchInput.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1;
|
||||
searchInput.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1;
|
||||
operation = getInputOperation(4);
|
||||
operation = getInputOperation(3);
|
||||
if (operation->determineDependingAreaOfInterest(&searchInput, readOperation, output) ) {
|
||||
return true;
|
||||
}
|
||||
@@ -228,65 +228,74 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu
|
||||
InverseSearchRadiusOperation::InverseSearchRadiusOperation() : NodeOperation()
|
||||
{
|
||||
this->addInputSocket(COM_DT_VALUE, COM_SC_NO_RESIZE); // radius
|
||||
this->addInputSocket(COM_DT_VALUE, COM_SC_NO_RESIZE); // depth
|
||||
this->addOutputSocket(COM_DT_COLOR);
|
||||
this->setComplex(true);
|
||||
this->inputRadius = NULL;
|
||||
this->inputDepth = NULL;
|
||||
this->m_inputRadius = NULL;
|
||||
}
|
||||
|
||||
void InverseSearchRadiusOperation::initExecution()
|
||||
{
|
||||
this->inputRadius = this->getInputSocketReader(0);
|
||||
this->inputDepth = this->getInputSocketReader(1);
|
||||
this->m_inputRadius = this->getInputSocketReader(0);
|
||||
}
|
||||
|
||||
void* InverseSearchRadiusOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
|
||||
{
|
||||
MemoryBuffer * data = new MemoryBuffer(NULL, rect);
|
||||
float* buffer = data->getBuffer();
|
||||
int x, y;
|
||||
float width = this->inputRadius->getWidth();
|
||||
float height = this->inputRadius->getHeight();
|
||||
|
||||
for (x = rect->xmin; x < rect->xmax ; x++) {
|
||||
for (y = rect->ymin; y < rect->ymax ; y++) {
|
||||
float[4] temp;
|
||||
int width = this->m_inputRadius->getWidth();
|
||||
int height = this->m_inputRadius->getHeight();
|
||||
float temp[4];
|
||||
int offset = 0;
|
||||
for (y = rect->ymin; y < rect->ymax ; y++) {
|
||||
for (x = rect->xmin; x < rect->xmax ; x++) {
|
||||
int rx = x * DIVIDER;
|
||||
int ry = y * DIVIDER;
|
||||
this->inputRadius->read(temp, rx, ry, memoryBuffers, NULL);
|
||||
float centerRadius = temp[0];
|
||||
this->inputDepth->read(temp, rx, ry, memoryBuffers, NULL);
|
||||
float centerDepth = temp[0];
|
||||
t[0] = MAX2(rx - this->maxBlur, 0.0f);
|
||||
t[1] = MAX2(ry - this->maxBlur, 0.0f);
|
||||
t[2] = MIN2(rx + this->maxBlur, width);
|
||||
t[3] = MIN2(ry + this->maxBlur, height);
|
||||
int minx = t[0];
|
||||
int miny = t[1];
|
||||
int maxx = t[2];
|
||||
int maxy = t[3];
|
||||
int sminx = rx;
|
||||
int smaxx = rx;
|
||||
int sminy = ry;
|
||||
int smaxy = ry;
|
||||
for (int nx = minx ; nx < maxx ; nx ++) {
|
||||
for (int ny = miny ; ny < maxy ; ny ++) {
|
||||
this->inputRadius->read(temp, nx, ny, memoryBuffers, NULL);
|
||||
if (nx < rx && temp[0])
|
||||
|
||||
}
|
||||
}
|
||||
float t[4];
|
||||
data->writePixel(x, y, t);
|
||||
buffer[offset] = MAX2(rx - m_maxBlur, 0);
|
||||
buffer[offset+1] = MAX2(ry- m_maxBlur, 0);
|
||||
buffer[offset+2] = MIN2(rx+DIVIDER + m_maxBlur, width);
|
||||
buffer[offset+3] = MIN2(ry+DIVIDER + m_maxBlur, height);
|
||||
offset += 4;
|
||||
}
|
||||
}
|
||||
// for (x = rect->xmin; x < rect->xmax ; x++) {
|
||||
// for (y = rect->ymin; y < rect->ymax ; y++) {
|
||||
// int rx = x * DIVIDER;
|
||||
// int ry = y * DIVIDER;
|
||||
// float radius = 0.0f;
|
||||
// float maxx = x;
|
||||
// float maxy = y;
|
||||
|
||||
// for (int x2 = 0 ; x2 < DIVIDER ; x2 ++) {
|
||||
// for (int y2 = 0 ; y2 < DIVIDER ; y2 ++) {
|
||||
// this->m_inputRadius->read(temp, rx+x2, ry+y2, COM_PS_NEAREST, NULL);
|
||||
// if (radius < temp[0]) {
|
||||
// radius = temp[0];
|
||||
// maxx = x2;
|
||||
// maxy = y2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// int impactRadius = ceil(radius / DIVIDER);
|
||||
// for (int x2 = x - impactRadius ; x2 < x + impactRadius ; x2 ++) {
|
||||
// for (int y2 = y - impactRadius ; y2 < y + impactRadius ; y2 ++) {
|
||||
// data->read(temp, x2, y2);
|
||||
// temp[0] = MIN2(temp[0], maxx);
|
||||
// temp[1] = MIN2(temp[1], maxy);
|
||||
// temp[2] = MAX2(temp[2], maxx);
|
||||
// temp[3] = MAX2(temp[3], maxy);
|
||||
// data->writePixel(x2, y2, temp);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return data;
|
||||
}
|
||||
|
||||
void InverseSearchRadiusOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data)
|
||||
{
|
||||
MemoryBuffer *buffer = (MemoryBuffer*)data;
|
||||
buffer->read(color, x, y);
|
||||
buffer->readNoCheck(color, x, y);
|
||||
}
|
||||
|
||||
void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data)
|
||||
@@ -299,8 +308,7 @@ void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, MemoryBuffer
|
||||
|
||||
void InverseSearchRadiusOperation::deinitExecution()
|
||||
{
|
||||
this->inputRadius = NULL;
|
||||
this->inputDepth = NULL;
|
||||
this->m_inputRadius = NULL;
|
||||
}
|
||||
|
||||
void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
|
||||
@@ -313,10 +321,10 @@ void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[]
|
||||
bool InverseSearchRadiusOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
{
|
||||
rcti newRect;
|
||||
newRect.ymin = input->ymin*DIVIDER;
|
||||
newRect.ymax = input->ymax*DIVIDER;
|
||||
newRect.xmin = input->xmin*DIVIDER;
|
||||
newRect.xmax = input->xmax*DIVIDER;
|
||||
newRect.ymin = input->ymin*DIVIDER - m_maxBlur;
|
||||
newRect.ymax = input->ymax*DIVIDER + m_maxBlur;
|
||||
newRect.xmin = input->xmin*DIVIDER - m_maxBlur;
|
||||
newRect.xmax = input->xmax*DIVIDER + m_maxBlur;
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newRect, readOperation, output);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "COM_NodeOperation.h"
|
||||
#include "COM_QualityStepHelper.h"
|
||||
|
||||
//#define COM_DEFOCUS_SEARCH
|
||||
|
||||
class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepHelper {
|
||||
private:
|
||||
@@ -34,7 +35,7 @@ private:
|
||||
SocketReader *m_inputBokehProgram;
|
||||
SocketReader *m_inputSizeProgram;
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
SocketReader *inputSearchProgram;
|
||||
SocketReader *m_inputSearchProgram;
|
||||
#endif
|
||||
|
||||
public:
|
||||
@@ -71,10 +72,8 @@ public:
|
||||
#ifdef COM_DEFOCUS_SEARCH
|
||||
class InverseSearchRadiusOperation : public NodeOperation {
|
||||
private:
|
||||
int maxBlur;
|
||||
float threshold;
|
||||
SocketReader *inputDepth;
|
||||
SocketReader *inputRadius;
|
||||
int m_maxBlur;
|
||||
SocketReader *m_inputRadius;
|
||||
public:
|
||||
static const int DIVIDER = 4;
|
||||
|
||||
@@ -100,9 +99,7 @@ public:
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]);
|
||||
|
||||
void setMaxBlur(int maxRadius) { this->maxBlur = maxRadius; }
|
||||
|
||||
void setThreshold(float threshold) { this->threshold = threshold; }
|
||||
void setMaxBlur(int maxRadius) { this->m_maxBlur = maxRadius; }
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -933,6 +933,7 @@ endif()
|
||||
#added for opencl compositor
|
||||
list(APPEND BLENDER_SORTED_LIBS bf_compositor)
|
||||
list(APPEND BLENDER_SORTED_LIBS bf_opencl)
|
||||
list(APPEND BLENDER_SORTED_LIBS bf_blenkernel) # hrmf, needed for BKE_mask only
|
||||
endif()
|
||||
|
||||
if(WITH_LIBMV)
|
||||
|
||||
Reference in New Issue
Block a user