Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/rand.cc')
-rw-r--r--source/blender/blenlib/intern/rand.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/rand.cc b/source/blender/blenlib/intern/rand.cc
index 224db31471d..c61e17e6627 100644
--- a/source/blender/blenlib/intern/rand.cc
+++ b/source/blender/blenlib/intern/rand.cc
@@ -141,6 +141,12 @@ void BLI_rng_get_tri_sample_float_v2(
copy_v2_v2(r_pt, rng->rng.get_triangle_sample(v1, v2, v3));
}
+void BLI_rng_get_tri_sample_float_v3(
+ RNG *rng, const float v1[3], const float v2[3], const float v3[3], float r_pt[3])
+{
+ copy_v3_v3(r_pt, rng->rng.get_triangle_sample_3d(v1, v2, v3));
+}
+
void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_tot)
{
const uint elem_size = elem_size_i;
@@ -425,6 +431,25 @@ float2 RandomNumberGenerator::get_triangle_sample(float2 v1, float2 v2, float2 v
return sample;
}
+float3 RandomNumberGenerator::get_triangle_sample_3d(float3 v1, float3 v2, float3 v3)
+{
+ float u = this->get_float();
+ float v = this->get_float();
+
+ if (u + v > 1.0f) {
+ u = 1.0f - u;
+ v = 1.0f - v;
+ }
+
+ float3 side_u = v2 - v1;
+ float3 side_v = v3 - v1;
+
+ float3 sample = v1;
+ sample += side_u * u;
+ sample += side_v * v;
+ return sample;
+}
+
void RandomNumberGenerator::get_bytes(MutableSpan<char> r_bytes)
{
constexpr int64_t mask_bytes = 2;