Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/svm/svm_math_util.h
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | else if (type == NODE_VECTOR_MATH_NORMALIZE) { | ||||
| *Vector = safe_normalize_len(Vector1, Fac); | *Vector = safe_normalize_len(Vector1, Fac); | ||||
| } | } | ||||
| else { | else { | ||||
| *Fac = 0.0f; | *Fac = 0.0f; | ||||
| *Vector = make_float3(0.0f, 0.0f, 0.0f); | *Vector = make_float3(0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| } | } | ||||
| ccl_device float svm_math(NodeMath type, float Fac1, float Fac2) | ccl_device float svm_math(NodeMathType type, float a, float b) | ||||
| { | { | ||||
| float Fac; | switch (type) { | ||||
| case NODE_MATH_ADD: | |||||
| if (type == NODE_MATH_ADD) | return a + b; | ||||
| Fac = Fac1 + Fac2; | case NODE_MATH_SUBTRACT: | ||||
| else if (type == NODE_MATH_SUBTRACT) | return a - b; | ||||
| Fac = Fac1 - Fac2; | case NODE_MATH_MULTIPLY: | ||||
| else if (type == NODE_MATH_MULTIPLY) | return a * b; | ||||
| Fac = Fac1 * Fac2; | case NODE_MATH_DIVIDE: | ||||
| else if (type == NODE_MATH_DIVIDE) | return safe_divide(a, b); | ||||
| Fac = safe_divide(Fac1, Fac2); | case NODE_MATH_POWER: | ||||
| else if (type == NODE_MATH_SINE) | return safe_powf(a, b); | ||||
| Fac = sinf(Fac1); | case NODE_MATH_LOGARITHM: | ||||
| else if (type == NODE_MATH_COSINE) | return safe_logf(a, b); | ||||
| Fac = cosf(Fac1); | case NODE_MATH_SQRT: | ||||
| else if (type == NODE_MATH_TANGENT) | return safe_sqrtf(a); | ||||
| Fac = tanf(Fac1); | case NODE_MATH_ABSOLUTE: | ||||
| else if (type == NODE_MATH_ARCSINE) | return fabsf(a); | ||||
| Fac = safe_asinf(Fac1); | case NODE_MATH_MINIMUM: | ||||
| else if (type == NODE_MATH_ARCCOSINE) | return fminf(a, b); | ||||
| Fac = safe_acosf(Fac1); | case NODE_MATH_MAXIMUM: | ||||
| else if (type == NODE_MATH_ARCTANGENT) | return fmaxf(a, b); | ||||
| Fac = atanf(Fac1); | case NODE_MATH_LESS_THAN: | ||||
| else if (type == NODE_MATH_POWER) | return a < b; | ||||
| Fac = safe_powf(Fac1, Fac2); | case NODE_MATH_GREATER_THAN: | ||||
| else if (type == NODE_MATH_LOGARITHM) | return a > b; | ||||
| Fac = safe_logf(Fac1, Fac2); | case NODE_MATH_ROUND: | ||||
| else if (type == NODE_MATH_MINIMUM) | return floorf(a + 0.5f); | ||||
| Fac = fminf(Fac1, Fac2); | case NODE_MATH_FLOOR: | ||||
| else if (type == NODE_MATH_MAXIMUM) | return floorf(a); | ||||
| Fac = fmaxf(Fac1, Fac2); | case NODE_MATH_CEIL: | ||||
| else if (type == NODE_MATH_ROUND) | return ceilf(a); | ||||
| Fac = floorf(Fac1 + 0.5f); | case NODE_MATH_FRACTION: | ||||
| else if (type == NODE_MATH_LESS_THAN) | return a - floorf(a); | ||||
| Fac = Fac1 < Fac2; | case NODE_MATH_MODULO: | ||||
| else if (type == NODE_MATH_GREATER_THAN) | return safe_modulo(a, b); | ||||
| Fac = Fac1 > Fac2; | case NODE_MATH_SINE: | ||||
| else if (type == NODE_MATH_MODULO) | return sinf(a); | ||||
| Fac = safe_modulo(Fac1, Fac2); | case NODE_MATH_COSINE: | ||||
| else if (type == NODE_MATH_ABSOLUTE) | return cosf(a); | ||||
| Fac = fabsf(Fac1); | case NODE_MATH_TANGENT: | ||||
| else if (type == NODE_MATH_ARCTAN2) | return tanf(a); | ||||
| Fac = atan2f(Fac1, Fac2); | case NODE_MATH_ARCSINE: | ||||
| else if (type == NODE_MATH_FLOOR) | return safe_asinf(a); | ||||
| Fac = floorf(Fac1); | case NODE_MATH_ARCCOSINE: | ||||
| else if (type == NODE_MATH_CEIL) | return safe_acosf(a); | ||||
| Fac = ceilf(Fac1); | case NODE_MATH_ARCTANGENT: | ||||
| else if (type == NODE_MATH_FRACT) | return atanf(a); | ||||
| Fac = Fac1 - floorf(Fac1); | case NODE_MATH_ARCTAN2: | ||||
| else if (type == NODE_MATH_SQRT) | return atan2f(a, b); | ||||
| Fac = safe_sqrtf(Fac1); | default: | ||||
| else if (type == NODE_MATH_CLAMP) | return 0.0f; | ||||
| Fac = saturate(Fac1); | } | ||||
| else | |||||
| Fac = 0.0f; | |||||
| return Fac; | |||||
| } | } | ||||
| /* Calculate color in range 800..12000 using an approximation | /* Calculate color in range 800..12000 using an approximation | ||||
| * a/x+bx+c for R and G and ((at + b)t + c)t + d) for B | * a/x+bx+c for R and G and ((at + b)t + c)t + d) for B | ||||
| * Max absolute error for RGB is (0.00095, 0.00077, 0.00057), | * Max absolute error for RGB is (0.00095, 0.00077, 0.00057), | ||||
| * which is enough to get the same 8 bit/channel color. | * which is enough to get the same 8 bit/channel color. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines | |||||