slm: OpenCL code base  0.1
computestep.cl
Go to the documentation of this file.
1 
9 #if defined(KERNEL_INTEGRATE_TRAJECTORY) || defined(KERNEL_CONNECT_CHANNELS) \
10  || defined(KERNEL_MAP_CHANNEL_HEADS) || defined(KERNEL_COUNT_DOWNCHANNELS) \
11  || defined(KERNEL_LINK_HILLSLOPES) || defined(KERNEL_SEGMENT_HILLSLOPES) \
12  || defined(KERNEL_SUBSEGMENT_FLANKS) || defined(KERNEL_HILLSLOPE_LENGTHS)
13 static inline void compute_step_vec(const float dt,
42  const __global float2 *uv_array,
43  float2 *dxy1_vec, float2 *dxy2_vec,
44  float2 *uv1_vec, float2 *uv2_vec,
45  const float2 vec,
46  float2 *next_vec, uint *idx) {
47  // Calculate RK2 next pt vector and approx into a fixed-point-res vector.
48  // Do this using randomly biased =jittered flow vector field.
49  // Then get the next pixel's data array index.
50  *uv1_vec = speed_interpolator(vec,uv_array);
51  *dxy1_vec = approximate(*uv1_vec*COMBO_FACTOR*dt);
52  *uv2_vec = speed_interpolator(vec+*dxy1_vec,uv_array);
53  *dxy2_vec = approximate(0.5f*(*dxy1_vec+*uv2_vec*COMBO_FACTOR*dt));
54  *next_vec = vec+*dxy2_vec;
55  *idx = get_array_idx(*next_vec);
56 }
57 #endif
58 
59 #if defined(KERNEL_INTEGRATE_TRAJECTORY) && defined(IS_RNG_AVAILABLE)
60 static inline void compute_step_vec_jittered(const float dt,
86  const __global float2 *uv_array,
87  uint *rng_state,
88  float2 *dxy1_vec, float2 *dxy2_vec,
89  float2 *uv1_vec, float2 *uv2_vec,
90  const float2 vec, float2 *next_vec,
91  uint *idx) {
92  // Calculate RK2 next pt vector and approx into a fixed-point-res vector.
93  // Do this using randomly biased aka jittered flow vector field.
94  // Then get the next pixel's data array index.
95  *uv1_vec = speed_interpolator(vec,uv_array);
96  *uv1_vec += lehmer_rand_vec(rng_state)*JITTER_MAGNITUDE;
97  *uv1_vec /= fast_length(*uv1_vec);
98  *dxy1_vec = approximate(*uv1_vec*COMBO_FACTOR*dt);
99  *uv2_vec = speed_interpolator(vec+*dxy1_vec,uv_array);
100  *uv2_vec += lehmer_rand_vec(rng_state)*JITTER_MAGNITUDE;
101  *uv2_vec /= fast_length(*uv2_vec);
102  *dxy2_vec = approximate(0.5f*(*dxy1_vec+*uv2_vec*COMBO_FACTOR*dt));
103  *next_vec = vec+*dxy2_vec;
104  *idx = get_array_idx(*next_vec);
105 }
106 #endif
static float2 speed_interpolator(float2 vec, __global const float2 *uv_array)
Bilinearly interpolate a velocity vector (choice of row-major or column-major arrays).
Definition: essentials.cl:28
static float2 approximate(float2 raw_position)
Approximate a float vector at the resolution provided by a scaled byte vector.
Definition: essentials.cl:164
static void compute_step_vec(const float dt, const __global float2 *uv_array, float2 *dxy1_vec, float2 *dxy2_vec, float2 *uv1_vec, float2 *uv2_vec, const float2 vec, float2 *next_vec, uint *idx)
Compute a 2nd-order Runge-Kutta integration step along a streamline.
Definition: computestep.cl:41
#define COMBO_FACTOR
Definition: info.h:47
static uint get_array_idx(float2 vec)
Compute the array index of the padded grid pixel pointed to by a float2 grid position vector (choice ...
Definition: essentials.cl:62
#define JITTER_MAGNITUDE
Definition: info.h:85
static float2 lehmer_rand_vec(uint *rng_state)
Generate a Lehmer RNG float2 vector random variate .
Definition: rng.cl:62
static void compute_step_vec_jittered(const float dt, const __global float2 *uv_array, uint *rng_state, float2 *dxy1_vec, float2 *dxy2_vec, float2 *uv1_vec, float2 *uv2_vec, const float2 vec, float2 *next_vec, uint *idx)
Compute a jittered 2nd-order Runge-Kutta integration step along a streamline.
Definition: computestep.cl:85