1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include "BLI_noise.h"
#include "forces.hpp"
namespace BParticles {
Force::~Force()
{
}
void GravityForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
{
FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_acceleration_body, fn_in, fn_out);
FN::ExecutionStack stack;
FN::ExecutionContext execution_context(stack);
m_compute_acceleration_body->call(fn_in, fn_out, execution_context);
float3 acceleration = fn_out.get<float3>(0);
for (uint i = 0; i < block.active_amount(); i++) {
r_force[i] += acceleration;
}
};
void TurbulenceForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
{
auto positions = block.attributes().get_float3("Position");
FN_TUPLE_CALL_ALLOC_TUPLES(m_compute_strength_body, fn_in, fn_out);
FN::ExecutionStack stack;
FN::ExecutionContext execution_context(stack);
m_compute_strength_body->call(fn_in, fn_out, execution_context);
float3 strength = fn_out.get<float3>(0);
for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
float3 pos = positions[pindex];
float x = (BLI_gNoise(0.5f, pos.x, pos.y, pos.z + 1000.0f, false, 1) - 0.5f) * strength.x;
float y = (BLI_gNoise(0.5f, pos.x, pos.y + 1000.0f, pos.z, false, 1) - 0.5f) * strength.y;
float z = (BLI_gNoise(0.5f, pos.x + 1000.0f, pos.y, pos.z, false, 1) - 0.5f) * strength.z;
r_force[pindex] += {x, y, z};
}
}
} // namespace BParticles
|