Merge branch 'master' into blender2.8

This commit is contained in:
2018-05-25 10:04:25 +02:00
16 changed files with 71 additions and 0 deletions

View File

@@ -61,8 +61,13 @@ ccl_device_inline void kernel_filter_construct_gramian(int x, int y,
make_int2(x+dx, y+dy), buffer + q_offset,
pass_stride, *rank, design_row, transform, stride);
#ifdef __KERNEL_GPU__
math_trimatrix_add_gramian_strided(XtWX, (*rank)+1, design_row, weight, stride);
math_vec3_add_strided(XtWY, (*rank)+1, design_row, weight * q_color, stride);
#else
math_trimatrix_add_gramian(XtWX, (*rank)+1, design_row, weight);
math_vec3_add(XtWY, (*rank)+1, design_row, weight * q_color);
#endif
}
ccl_device_inline void kernel_filter_finalize(int x, int y,

View File

@@ -95,6 +95,8 @@ shader node_math(
Value = safe_modulo(Value1, Value2);
else if (type == "absolute")
Value = fabs(Value1);
else if (type == "arctan2")
Value = atan2(Value1, Value2);
if (use_clamp)
Value = clamp(Value, 0.0, 1.0);

View File

@@ -92,6 +92,8 @@ ccl_device float svm_math(NodeMath type, float Fac1, float Fac2)
Fac = safe_modulo(Fac1, Fac2);
else if(type == NODE_MATH_ABSOLUTE)
Fac = fabsf(Fac1);
else if(type == NODE_MATH_ARCTAN2)
Fac = atan2f(Fac1, Fac2);
else if(type == NODE_MATH_CLAMP)
Fac = saturate(Fac1);
else

View File

@@ -259,6 +259,7 @@ typedef enum NodeMath {
NODE_MATH_GREATER_THAN,
NODE_MATH_MODULO,
NODE_MATH_ABSOLUTE,
NODE_MATH_ARCTAN2,
NODE_MATH_CLAMP /* used for the clamp UI option */
} NodeMath;

View File

@@ -4953,6 +4953,7 @@ NODE_DEFINE(MathNode)
type_enum.insert("greater_than", NODE_MATH_GREATER_THAN);
type_enum.insert("modulo", NODE_MATH_MODULO);
type_enum.insert("absolute", NODE_MATH_ABSOLUTE);
type_enum.insert("arctan2", NODE_MATH_ARCTAN2);
SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD);
SOCKET_BOOLEAN(use_clamp, "Use Clamp", false);

View File

@@ -144,6 +144,18 @@ ccl_device_inline void math_trimatrix_add_gramian_strided(ccl_global float *A,
}
}
ccl_device_inline void math_trimatrix_add_gramian(ccl_global float *A,
int n,
const float *ccl_restrict v,
float weight)
{
for(int row = 0; row < n; row++) {
for(int col = 0; col <= row; col++) {
MATHS(A, row, col, 1) += v[row]*v[col]*weight;
}
}
}
/* Transpose matrix A inplace. */
ccl_device_inline void math_matrix_transpose(ccl_global float *A, int n, int stride)
{

View File

@@ -86,6 +86,9 @@ void MathNode::convertToOperations(NodeConverter &converter, const CompositorCon
case NODE_MATH_ABS:
operation = new MathAbsoluteOperation();
break;
case NODE_MATH_ATAN2:
operation = new MathArcTan2Operation();
break;
}
if (operation) {

View File

@@ -343,3 +343,16 @@ void MathAbsoluteOperation::executePixelSampled(float output[4], float x, float
clampIfNeeded(output);
}
void MathArcTan2Operation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputValue1[4];
float inputValue2[4];
this->m_inputValue1Operation->readSampled(inputValue1, x, y, sampler);
this->m_inputValue2Operation->readSampled(inputValue2, x, y, sampler);
output[0] = atan2(inputValue1[0], inputValue2[0]);
clampIfNeeded(output);
}

View File

@@ -169,4 +169,10 @@ public:
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
};
class MathArcTan2Operation : public MathBaseOperation {
public:
MathArcTan2Operation() : MathBaseOperation() {}
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
};
#endif

View File

@@ -227,6 +227,7 @@ eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *ar, const fl
eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]);

View File

@@ -282,6 +282,11 @@ float ED_view3d_pixel_size(const RegionView3D *rv3d, const float co[3])
return mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, co) * rv3d->pixsize * U.pixelsize;
}
float ED_view3d_pixel_size_no_ui_scale(const RegionView3D *rv3d, const float co[3])
{
return mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, co) * rv3d->pixsize;
}
/**
* Calculate a depth value from \a co, use with #ED_view3d_win_to_delta
*/

View File

@@ -396,6 +396,11 @@ void math_abs(float val1, out float outval)
outval = abs(val1);
}
void math_atan2(float val1, float val2, out float outval)
{
outval = atan(val1, val2);
}
void squeeze(float val, float width, float center, out float outval)
{
outval = 1.0 / (1.0 + pow(2.71828183, -((val - center) * width)));

View File

@@ -1058,6 +1058,7 @@ enum {
NODE_MATH_GREATER = 16,
NODE_MATH_MOD = 17,
NODE_MATH_ABS = 18,
NODE_MATH_ATAN2 = 19,
};
/* mix rgb node flags */

View File

@@ -143,6 +143,7 @@ const EnumPropertyItem rna_enum_node_math_items[] = {
{NODE_MATH_GREATER, "GREATER_THAN", 0, "Greater Than", ""},
{NODE_MATH_MOD, "MODULO", 0, "Modulo", ""},
{NODE_MATH_ABS, "ABSOLUTE", 0, "Absolute", ""},
{NODE_MATH_ATAN2, "ARCTAN2", 0, "Arctan2", ""},
{0, NULL, 0, NULL, NULL}
};

View File

@@ -221,6 +221,11 @@ static void node_shader_exec_math(void *UNUSED(data), int UNUSED(thread), bNode
r = fabsf(a);
break;
}
case NODE_MATH_ATAN2:
{
r = atan2(a, b);
break;
}
}
if (node->custom2 & SHD_MATH_CLAMP) {
CLAMP(r, 0.0f, 1.0f);
@@ -235,6 +240,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
"math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin",
"math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max",
"math_round", "math_less_than", "math_greater_than", "math_modulo", "math_abs",
"math_atan2"
};
switch (node->custom1) {
@@ -249,6 +255,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
case NODE_MATH_LESS:
case NODE_MATH_GREATER:
case NODE_MATH_MOD:
case NODE_MATH_ATAN2:
GPU_stack_link(mat, node, names[node->custom1], in, out);
break;
case NODE_MATH_SIN:

View File

@@ -189,6 +189,12 @@ static void valuefn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
break;
}
case NODE_MATH_ATAN2:
{
*out = atan2(in0, in1);
break;
}
default:
{
BLI_assert(0);