Jump to content
  • Advertisement
Sign in to follow this  

Pixel Shader with 1D computed texture (FFT spectrum actually)

This topic is 3974 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 All, I have been perusing this forum for months learning DirectX, it has been a great help thus far. (And so many great articles and tutorials!!!) Thank you everyone. I've made a DSP DirectShow filter that use Fourier Transforms to speed up or slow down speech without changing timber/pitch. I now want to display the spectrum output using DirectX. I already did it using pretransformed line primitives no problem, but I want to make it flashy now. (Really, I want to play around with shaders for the first time.) I am creating a 1D texture, locking the texels and storing the FFT spectrum in there. >> pdev->CreateTexture((UINT)count, 1, 1, D3DUSAGE_DYNAMIC, D3DFMT_R32F, D3DPOOL_DEFAULT, &m_tex_data, NULL) Then a make a pretransformed rectangle (two triangles) on the screen. Since these are transformed vertices the vertex shader is not executed (Right?!). I confirm that the pixel shader is being executed, changes I make to my effect file change the output. Except, what I get is a solid red filled square that beats to the music..it seems to beat to the low frequencies. Here is my vertex definition: (I am defining an FVFDECL, but converting it to new decl array format later for SetVertexDeclaration().) typedef struct { FLOAT x, y, z, rhw; // The transformed position for the vertex. DWORD color; // The vertex color. FLOAT tu, tv; // texture coordinates } VERTEX; const static DWORD s_fvfVertex = (D3DFVF_XYZRHW |D3DFVF_DIFFUSE |D3DFVF_TEX0 |D3DFVF_TEXCOORDSIZE2(0)); The texture coordinates are set for 0,0 for bottom left of square, 1,1 for top right. The u coord will index the 1D spectrum texture, the v coord will be used by the pixel shader to know the y value of the pixel we are coloring. I expect to see each column of the rectangle fade from dark to bright red as it approaches the value of the spectrum magnitude (the value stored in the 1d texture). I.e. a spectrum line but softly rendered. Since I am getting a solid colored box, but changing in time to the music it seems to be only indexing one value of the 1D texture. Also, the v component seems to be staying constant since the pixels are not fading in the y direction. Here is the pixel shader (basic) fx file: texture g_MeshTexture; // Color texture for mesh sampler tex_sampler = sampler_state { Texture = <g_MeshTexture>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; struct PS_OUTPUT { float4 RGBColor : COLOR0; // Pixel color }; PS_OUTPUT pixel_shader( float4 color : COLOR0, float2 t : TEXCOORD0 ) { float s = tex1D(tex_sampler, t[0])[0]; float v = 1.0 - abs(t[1]-s); // color pixel based on distance from spectrum magnitude value PS_OUTPUT Output = { {1, 0, 0, v } }; return Output; } technique RenderScene { pass P0 { PixelShader = compile ps_2_0 pixel_shader( ); } } Thanks for your time. Colin

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!