Exemplo n.º 1
0
void APerlinNoise2D::GetValue(float x, float y, float * pvValue, int nNumValue)
{
  int      i, k;
  float    vx, sx, vy, sy;
  int      x1, x2, y1, y2;
  float    value1[3], value2[3];
  float    valueX1[3], valueX2[3];
  float    value[3];
  float    vFinal[3];

  memset(vFinal, 0, sizeof(float) * nNumValue);
  for(i=0; i<m_nOctaveNum; i++)
  {
    if( m_nActiveOctave != -1 && m_nActiveOctave != i )
      continue;

    // Get Horizon interpolated value;
    vx = m_nStartPos[i] % m_nBufferWidth + x / m_nWaveLength[i];
    x1 = int(vx);
    sx = vx - x1;
    sx = S_CURVE(sx);
    x2 = x1 + 1;

    vy = m_nStartPos[i] / m_nBufferWidth + y / m_nWaveLength[i];
    y1 = int(vy);
    sy = vy - y1;
    sy = S_CURVE(sy);
    y2 = y1 + 1;
    
    GetRandValues(x1, y1, value1, nNumValue);
    GetRandValues(x2, y1, value2, nNumValue);
    for(k=0; k<nNumValue; k++)
      valueX1[k] = LERP(sx, value1[k], value2[k]);

    GetRandValues(x1, y2, value1, nNumValue);
    GetRandValues(x2, y2, value2, nNumValue);
    for(k=0; k<nNumValue; k++)
      valueX2[k] = LERP(sx, value1[k], value2[k]);

    if( m_bTurbulence )
    {
      for(k=0; k<nNumValue; k++)
      {
        value[k] = (float)fabs(LERP(sy, valueX1[k], valueX2[k]));
        vFinal[k] += m_vAmplitude[i] * value[k];
      }
    }
    else
    {
      for(k=0; k<nNumValue; k++)
      {
        value[k] = LERP(sy, valueX1[k], valueX2[k]);
        vFinal[k] += m_vAmplitude[i] * value[k];
      }
    }
  }

  for(k=0; k<nNumValue; k++)
    pvValue[k] = vFinal[k];
}
fastf_t
texture_perlin_omega(struct texture_perlin_s *P, vect_t V)
{
    vect_t q;
    fastf_t r0[3], r1[3], sy, sz, a, b, c, d, t, u, v;
    int b0[3], b1[3], b00, b10, b01, b11;
    int i, j;


    for (i = 0; i < 3; i++) {
	t = V[i] + N;
	b0[i] = ((int)t) & BM;
	b1[i] = (b0[i]+1) & BM;
	r0[i] = t - (int)t;
	r1[i] = r0[i] - 1.0;
    }

    i = P->PV[b0[0]];
    j = P->PV[b1[0]];

    b00 = P->PV[i + b0[1]];
    b10 = P->PV[j + b0[1]];
    b01 = P->PV[i + b1[1]];
    b11 = P->PV[j + b1[1]];

    t = S_CURVE(r0[0]);
    sy = S_CURVE(r0[1]);
    sz = S_CURVE(r0[2]);

    VMOVE(q, P->RV[b00 + b0[2]]);
    u = AT3(r0[0], r0[1], r0[2]);
    VMOVE(q, P->RV[b10 + b0[2]]);
    v = AT3(r1[0], r0[1], r0[2]);
    a = LERP(t, u, v);

    VMOVE(q, P->RV[b01 + b0[2]]);
    u = AT3(r0[0], r1[1], r0[2]);
    VMOVE(q, P->RV[b11 + b0[2]]);
    v = AT3(r1[0], r1[1], r0[2]);
    b = LERP(t, u, v);

    c = LERP(sy, a, b);

    VMOVE(q, P->RV[b00 + b1[2]]);
    u = AT3(r0[0], r0[1], r1[2]);
    VMOVE(q, P->RV[b10 + b1[2]]);
    v = AT3(r1[0], r0[1], r1[2]);
    a = LERP(t, u, v);

    VMOVE(q, P->RV[b01 + b1[2]]);
    u = AT3(r0[0], r1[1], r1[2]);
    VMOVE(q, P->RV[b11 + b1[2]]);
    v = AT3(r1[0], r1[1], r1[2]);
    b = LERP(t, u, v);

    d = LERP(sy, a, b);

    return LERP(sz, c, d);
}
double
SVGFETurbulenceElement::Noise2(int aColorChannel, double aVec[2],
                               StitchInfo *aStitchInfo)
{
  int bx0, bx1, by0, by1, b00, b10, b01, b11;
  double rx0, rx1, ry0, ry1, *q, sx, sy, a, b, t, u, v;
  long i, j;
  t = aVec[0] + sPerlinN;
  bx0 = (int) t;
  bx1 = bx0 + 1;
  rx0 = t - (int) t;
  rx1 = rx0 - 1.0f;
  t = aVec[1] + sPerlinN;
  by0 = (int) t;
  by1 = by0 + 1;
  ry0 = t - (int) t;
  ry1 = ry0 - 1.0f;
  // If stitching, adjust lattice points accordingly.
  if (aStitchInfo != NULL) {
    if (bx0 >= aStitchInfo->mWrapX)
      bx0 -= aStitchInfo->mWidth;
    if (bx1 >= aStitchInfo->mWrapX)
      bx1 -= aStitchInfo->mWidth;
    if (by0 >= aStitchInfo->mWrapY)
      by0 -= aStitchInfo->mHeight;
    if (by1 >= aStitchInfo->mWrapY)
      by1 -= aStitchInfo->mHeight;
  }
  bx0 &= sBM;
  bx1 &= sBM;
  by0 &= sBM;
  by1 &= sBM;
  i = mLatticeSelector[bx0];
  j = mLatticeSelector[bx1];
  b00 = mLatticeSelector[i + by0];
  b10 = mLatticeSelector[j + by0];
  b01 = mLatticeSelector[i + by1];
  b11 = mLatticeSelector[j + by1];
  sx = double (S_CURVE(rx0));
  sy = double (S_CURVE(ry0));
  q = mGradient[aColorChannel][b00];
  u = rx0 * q[0] + ry0 * q[1];
  q = mGradient[aColorChannel][b10];
  v = rx1 * q[0] + ry0 * q[1];
  a = LERP(sx, u, v);
  q = mGradient[aColorChannel][b01];
  u = rx0 * q[0] + ry1 * q[1];
  q = mGradient[aColorChannel][b11];
  v = rx1 * q[0] + ry1 * q[1];
  b = LERP(sx, u, v);
  return LERP(sy, a, b);
}