示例#1
0
void lognormalize(float *logp, int start, int length) {
  float m = max_arr(logp, start, length);
  for (int i = start; i < start + length; i++) {
    logp[i] = native_powr(exp(1.0f), logp[i] - m);
  }
  float p_sum = sum(logp, start, length);
  for (int i = start; i < start + length; i++) {
    logp[i] = logp[i] / p_sum;
  }
}
// This file has all commands which are executed inside iteration loop
//    for(i = 0; i < N; i++)
// example is based on Mandelbulb formula
// z is a main 3-dimentional iterated vector
// c is constant variable like in Mandelbrot set: z(n+1) = z(n)^2 + c
// r is a length of z vector

float th0 = asin(native_divide(z.z ,r)) + offset;
float ph0 = atan2(z.y, z.x) + offset;
float rp = native_powr(r, power - 1.0f);
float th = th0 * power;
float ph = ph0 * power ;
float cth = native_cos(th);
r_dz = rp * r_dz * power + 1.0f;
rp *= r;
z = (float3) {cth * native_cos(ph), cth * native_sin(ph), native_sin(th)};
z*=rp;
z+=c*mul;

//calculation of length of z vector
r = distance(z, orbitTrap);

//calculation of surface colour
if (r < colourMin) colourMin = r;

//needed for calculation of fake lights based on orbit traps
#if _orbitTrapsEnabled
if (i >= consts->fractal.fakeLightsMinIter && i <= consts->fractal.fakeLightsMaxIter) distFromOrbitTrap += (1.0f/(r*r));
#endif

//iteration terminate condition