   FFT slowdown
  Heres some code implementing the well known FFT equations that for some reason massively slows my game to a crawl. Help please?// W = Wind Vector// K = Water Currentfloat Phillips(float W, float K, float WindSpeed) {// Height global*natural log^(-1/((wind velo^2/grav const)*wavelength))/wavelength^4*(Normalized Wind*Normalized Water)^2*natural log^(-wavelength^2*minwave^2)float l = SQR(WindSpeed) / 9.8f;return (exp(-1.0f / SQR(l * 1.25f)) / 2.44140625f) * SQR(K * W);}Complex hKTime0(float W, float K, float WindSpeed) {// 1/SQRT(2) * (GaussRand + iGaussRand) * SQRT(Phillips spectrum result)return .7071067812f * Complex(GaussRand(1.0f, 0.0f), GaussRand(1.0f, 0.0f)) * SQRT(Phillips(W, K, WindSpeed), 4);}Complex hKTimeT(float W, float K, float WindSpeed, float time) {// h0(K)e^(i*SQRT(wavelength*grav*tanh(depth*wavelength))*time) + h0*(-K)e^(i*SQRT(wavelength*grav*tanh(wavelength*depth))*time)return hKTime0(W, K, WindSpeed) * Complex(cosf(SQRT(1.25f * 9.8f, 4) * time), sinf(SQRT(1.25f*9.8f, 4) * time)) +hKTime0(W, -K, WindSpeed).conj() * Complex(cosf(-(SQRT(1.25f * 9.8f, 4) * time)), sinf(-(SQRT(1.25f * 9.8f, 4) * time)));}Complex EvaluateFFT(float W[2], float K[2], float WindSpeed, float time, float XPos, float ZPos) {// Return Wave height// h(K[x],t)e^(iK[x]X) + h(K[z],t)e^(iK[z]Z) float mw = SQRT(SQR(W[0]) + SQR(W[1]), 4),kw = SQRT(SQR(K[0]) + SQR(K[1]), 4);return hKTimeT(W[0] / mw, K[0] / kw, WindSpeed, time) * Complex(cosf((K[0] * PI) * XPos), sinf((K[0] * PI) * XPos)) + hKTimeT(W[1] / mw, K[1] / kw, WindSpeed, time) * Complex(cosf((K[1] * PI) * ZPos), sinf((K[1] * PI) * ZPos));}<\code>And to use the FFT:// Generate FFT Arrayfor (int x = 0; x < 64; x++) {for (int z = 0; z < 64; z++) {mag = SQRT(SQR(wavewind->wind[0]) + SQR(wavewind->wind[1]), 7);FFT[x][z] = EvaluateFFT(W, wavewind->waves, wavewind->getWindSpeed(), time, 0.015625f * (float)x, 0.015625f * (float)z).real;}}<\code>This causes a massive slowdown in my engine; any help would be greatly appreciated. I''m thinking optimization to get rid of some sin/cos calls or sqrs or sqrts since they''re the most expensive. My SQRT is just regular sqrt with specifiable precision(4 is very low precision BTW).   --===LITHIC===----===WWW.Decimation.TK===--   
  Try the following...float Phillips(float W, float K, float WindSpeed) {// Height global*natural log^(-1/((wind velo^2/grav const)*wavelength))/wavelength^4*(Normalized Wind*Normalized Water)^2*natural log^(-wavelength^2*minwave^2)//float l = SQR(WindSpeed) / 9.8f;//return (exp(-1.0f / SQR(l * 1.25f)) / 2.44140625f) * SQR(K * W);float l = SQR(WindSpeed);return (exp(-1.0f / SQR(l * 1.25f /9.8f )) / 2.44140625f) * SQR(K * W);// The compiler should be able to turn above div to a constant saving a division}Complex hKTimeT(float W, float K, float WindSpeed, float time) {// h0(K)e^(i*SQRT(wavelength*grav*tanh(depth*wavelength))*time) + h0*(-K)e^(i*SQRT(wavelength*grav*tanh(wavelength*depth))*time)//return hKTime0(W, K, WindSpeed) * Complex(cosf(SQRT(1.25f * 9.8f, 4) * time), sinf(SQRT(1.25f*9.8f, 4) * time)) +//hKTime0(W, -K, WindSpeed).conj() * Complex(cosf(-(SQRT(1.25f * 9.8f, 4) * time)), sinf(-(SQRT(1.25f * 9.8f, 4) * time)));float val1 = SQRT(1.25f * 9.8f, 4) * time;float val2 = cosf(val1);float val3 = sinf(val1);return hKTime0(W, K, WindSpeed) * Complex(val2, val3) +hKTime0(W, -K, WindSpeed).conj() * Complex(val2, -val3);// see http://www.math.com/tables/trig/identities.htm//sin(-x) = -sin(x)//cos(-x) = cos(x)} [edited by - lokki on February 3, 2004 6:24:51 PM] [edited by - lokki on February 3, 2004 6:27:16 PM] [edited by - lokki on February 3, 2004 6:28:02 PM];  Thanks, your suggestions helped a bunch, I have it now in realtime, however the biggest speedup was when i removed HkTimeT() so it only calculated once before the loop. I''ll have a screenshot up soon on the graphics programming and theory forum soon as I get my fragment shader working. New to shaders and I can''t figure out how to get it to display.   --===LITHIC===----===WWW.Decimation.TK===-- 