Files
test2/intern/cycles/util/math_float2.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

242 lines
4.7 KiB
C
Raw Normal View History

/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
*
* SPDX-License-Identifier: Apache-2.0 */
#ifndef __UTIL_MATH_FLOAT2_H__
#define __UTIL_MATH_FLOAT2_H__
#ifndef __UTIL_MATH_H__
# error "Do not include this file directly, include util/types.h instead."
#endif
CCL_NAMESPACE_BEGIN
ccl_device_inline float2 zero_float2()
{
return make_float2(0.0f, 0.0f);
}
ccl_device_inline float2 one_float2()
{
return make_float2(1.0f, 1.0f);
}
#if !defined(__KERNEL_METAL__)
ccl_device_inline float2 operator-(const float2 &a)
{
return make_float2(-a.x, -a.y);
}
ccl_device_inline float2 operator*(const float2 a, const float2 b)
{
return make_float2(a.x * b.x, a.y * b.y);
}
ccl_device_inline float2 operator*(const float2 a, float f)
{
return make_float2(a.x * f, a.y * f);
}
ccl_device_inline float2 operator*(float f, const float2 a)
{
return make_float2(a.x * f, a.y * f);
}
ccl_device_inline float2 operator/(float f, const float2 a)
{
return make_float2(f / a.x, f / a.y);
}
ccl_device_inline float2 operator/(const float2 a, float f)
{
float invf = 1.0f / f;
return make_float2(a.x * invf, a.y * invf);
}
ccl_device_inline float2 operator/(const float2 a, const float2 b)
{
return make_float2(a.x / b.x, a.y / b.y);
}
ccl_device_inline float2 operator+(const float2 a, const float2 b)
{
return make_float2(a.x + b.x, a.y + b.y);
}
ccl_device_inline float2 operator+(const float2 a, const float f)
{
return a + make_float2(f, f);
}
ccl_device_inline float2 operator-(const float2 a, const float2 b)
{
return make_float2(a.x - b.x, a.y - b.y);
}
ccl_device_inline float2 operator-(const float2 a, const float f)
{
return a - make_float2(f, f);
}
ccl_device_inline float2 operator+=(float2 &a, const float2 b)
{
return a = a + b;
}
ccl_device_inline float2 operator*=(float2 &a, const float2 b)
{
return a = a * b;
}
ccl_device_inline float2 operator*=(float2 &a, float f)
{
return a = a * f;
}
ccl_device_inline float2 operator/=(float2 &a, const float2 b)
{
return a = a / b;
}
ccl_device_inline float2 operator/=(float2 &a, float f)
{
float invf = 1.0f / f;
return a = a * invf;
}
ccl_device_inline bool operator==(const float2 a, const float2 b)
{
return (a.x == b.x && a.y == b.y);
}
ccl_device_inline bool operator!=(const float2 a, const float2 b)
{
return !(a == b);
}
ccl_device_inline bool is_zero(const float2 a)
{
return (a.x == 0.0f && a.y == 0.0f);
}
ccl_device_inline float average(const float2 a)
{
return (a.x + a.y) * (1.0f / 2.0f);
}
ccl_device_inline float dot(const float2 a, const float2 b)
{
return a.x * b.x + a.y * b.y;
}
#endif
ccl_device_inline float len(const float2 a)
{
return sqrtf(dot(a, a));
}
ccl_device_inline float reduce_min(const float2 a)
{
return min(a.x, a.y);
}
ccl_device_inline float reduce_max(const float2 a)
{
return max(a.x, a.y);
}
ccl_device_inline float reduce_add(const float2 a)
{
return a.x + a.y;
}
ccl_device_inline float len_squared(const float2 a)
{
return dot(a, a);
}
#if !defined(__KERNEL_METAL__)
ccl_device_inline float distance(const float2 a, const float2 b)
{
return len(a - b);
}
ccl_device_inline float cross(const float2 a, const float2 b)
{
return (a.x * b.y - a.y * b.x);
}
ccl_device_inline float2 normalize(const float2 a)
{
return a / len(a);
}
ccl_device_inline float2 normalize_len(const float2 a, ccl_private float *t)
{
*t = len(a);
return a / (*t);
}
ccl_device_inline float2 safe_normalize(const float2 a)
{
float t = len(a);
return (t != 0.0f) ? a / t : a;
}
ccl_device_inline float2 min(const float2 a, const float2 b)
{
return make_float2(min(a.x, b.x), min(a.y, b.y));
}
ccl_device_inline float2 max(const float2 a, const float2 b)
{
return make_float2(max(a.x, b.x), max(a.y, b.y));
}
ccl_device_inline float2 clamp(const float2 a, const float2 mn, const float2 mx)
{
return min(max(a, mn), mx);
}
ccl_device_inline float2 fabs(const float2 a)
{
return make_float2(fabsf(a.x), fabsf(a.y));
}
ccl_device_inline float2 as_float2(const float4 &a)
{
return make_float2(a.x, a.y);
}
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
{
return a + t * (b - a);
}
ccl_device_inline float2 mix(const float2 a, const float2 b, float t)
{
return a + t * (b - a);
}
ccl_device_inline float2 floor(const float2 a)
{
return make_float2(floorf(a.x), floorf(a.y));
}
#endif /* !__KERNEL_METAL__ */
Nodes: add Fractal Voronoi Noise Fractal noise is the idea of evaluating the same noise function multiple times with different input parameters on each layer and then mixing the results. The individual layers are usually called octaves. The number of layers is controlled with a "Detail" slider. The "Lacunarity" input controls a factor by which each successive layer gets scaled. The existing Noise node already supports fractal noise. Now the Voronoi Noise node supports it as well. The node also has a new "Normalize" property that ensures that the output values stay in a [0.0, 1.0] range. That is except for the F2 feature where in rare cases the output may be outside that range even with "Normalize" turned on. How the individual octaves are mixed depends on the feature and output socket: - F1/Smooth F1/F2: - Distance/Color output: The individual Distance/Color octaves are first multiplied by a factor of `Roughness ^ (#layers - 1.0)` then added together to create the final output. - Position output: Each Position octave gets linearly interpolated with the combined output of the previous octaves. The Roughness input serves as an interpolation factor with 0.0 resutling in only using the combined output of the previous octaves and 1.0 resulting in only using the current highest octave. - Distance to Edge: - Distance output: The Distance octaves are mixed exactly like the Position octaves for F1/Smooth F1/F2. It should be noted that Voronoi Noise is a relatively slow noise function, especially at higher dimensions. Increasing the "Detail" makes it even slower. Therefore, when optimizing a scene one should consider trying to use simpler noise functions instead of Voronoi if the final result is close enough. Pull Request: https://projects.blender.org/blender/blender/pulls/106827
2023-06-13 09:18:12 +02:00
/* Consistent name for this would be pow, but HIP compiler crashes in name mangling. */
ccl_device_inline float2 power(float2 v, float e)
{
return make_float2(powf(v.x, e), powf(v.y, e));
}
ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
{
return (b != 0.0f) ? a / b : zero_float2();
}
CCL_NAMESPACE_END
#endif /* __UTIL_MATH_FLOAT2_H__ */