Advertisement Jump to content
Sign in to follow this  

generating FFT butterfly texture

This topic is 3643 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been trying to get FFT for images working on D3D HLSL 3.0. I don't understand or rather can't get the butterfly texture working. I tried using the code from ATI website to generate the butterfly textures, but I'am wondering if that is still OK to use for DirectX. Here is the code for generating the butterfly textures from ATI website: for(int kk = 1024, pow2 = 10; kk > 8; kk >>=1, pow2--) { Vector4D* colours = new Vector4D[kk*16*4]; float angle; float wre, wim, wpre, wpim, tempre, tempim; int jj; int N, half_N; float wtemp; N=1; for(int ii=0; ii < pow2; ii++) { half_N = N; N <<= 1; angle = -2.0f * 3.1415927f / (float) N; //*dir wtemp = sinf( 0.5f * angle); wpre = -2.0f * wtemp *wtemp; wpim = sinf( angle); wre = 1.0f; wim = 0.0f; for(int offset = 0; offset < half_N; offset++) { for(int gg=offset; gg < kk; gg += N) { jj = gg + half_N; colours[(ii*kk+jj)*4][0] = -((jj+0.5f)/(float)kk); colours[(ii*kk+jj)*4][1] = (gg+0.5f)/(float)kk; colours[(ii*kk+gg)*4][0] = (jj+0.5f)/(float)kk; colours[(ii*kk+gg)*4][1] = (gg+0.5f)/(float)kk; colours[(ii*kk+jj)*4][2] = wre; colours[(ii*kk+jj)*4][3] = wim; colours[(ii*kk+gg)*4][2] = wre; colours[(ii*kk+gg)*4][3] = wim; } wtemp = wre; wre = wtemp*wpre - wim*wpim + wre; wim = wim*wpre + wtemp*wpim + wim; } } //...... here I just copy the colours as RGB values. //one loop is one texture delete[] colours; } Also in the algorithm to use the texture as the source I followed the ShaderX2, Advanced Image Processing with DirectX 9 pixel shaders. But interestingly enough, they use: SetSurfaceAsTexture( surfaceA); //input image SetRenderTarget( surfaceB); LoadShader( HorizontalScramble); SetTexture( ButterflyTexture[log2(width)]); DrawQuad(); // Horizontal butterflies LoadShader( HorizontalButterfly); SetTexture( ButterflyTexture[log2(width)]); for ( i = 0; i < log2( width); i++) { SwapSurfacesAandB(); SetShaderConstant( “pass”, i/log2(width)); DrawQuad(); } // Vertical scramble SwapSurfacesAandB(); LoadShader( VerticalScramble); SetTexture( ButterflyTexture[log2(height)]); DrawQuad(); // Vertical butterflies LoadShader( VerticalButterfly); SetTexture( ButterflyTexture[log2(height)]); for ( i = 0; i < log2( height); i++) { SwapSurfacesAandB(); SetShaderConstant( “pass”, i/log2(height)); DrawQuad(); } But the pass value, passed to the pixel shader in the ATI version is i/16, since their butterfly texture has always 16 pixels in height, as you can see form the code above. Any suggestions on what should I use?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!