Jump to content
  • Advertisement

Recommended Posts

Hi,

I'm currently trying to write a shader which shoud compute a fast fourier transform of some data, manipulating the transformed data, do an inverse FFT an then displaying the result as vertex offset and color. I use Unity3d and HLSL as shader language. One of the main problems is that the data should not be passed from CPU to GPU for every frame if possible. My original plan was to use a vertex shader and do the fft there, but I fail to find out how to store changing data betwen shader calls/passes. I found a technique called ping-ponging which seems to be based on writing and exchangeing render targets, but I couldn't find an example for HLSL as a vertex shader yet.

I found https://social.msdn.microsoft.com/Forums/en-US/c79a3701-d028-41d9-ad74-a2b3b3958383/how-to-render-to-multiple-render-targets-in-hlsl?forum=xnaframework

which seem to use COLOR0 and COLOR1 as such render targets.

Is it even possible to do such calculations on the gpu only? (/in this shader stage?, because I need the result of the calculation to modify the vertex offsets there)

I also saw the use of compute shaders in simmilar projects (ocean wave simulation), do they realy copy data between CPU / GPU for every frame?

How does this ping-ponging / rendertarget switching technique work in HLSL?

Have you seen an example of usage?

Any answer would be helpfull.

Thank you

appswert

Share this post


Link to post
Share on other sites
Advertisement
18 hours ago, Beny Benz said:

Is it even possible to do such calculations on the gpu only?

Yes, absolutely.

18 hours ago, Beny Benz said:

I also saw the use of compute shaders in simmilar projects (ocean wave simulation), do they realy copy data between CPU / GPU for every frame?

Not sure where you heard this. Unless you explicitly ask the GPU to give you the data on CPU, it'll stay on the GPU.

18 hours ago, Beny Benz said:

How does this ping-ponging / rendertarget switching technique work in HLSL?

Have you seen an example of usage?

It's an extremely common technique. Every frame you just swap the render target you are rendering to and use the previous one as the new input.

Looks something like:

  • Frame #1:
    • Set Texture0 as Render Target
    • Bind Texture1 as input
    • Draw shader
  • Frame #2:
    • Set Texture1 as Render Target
    • Bind Texture0 as input
    • Draw Shader
  • Frame #3: Same as Frame #1
  • Frame #4: Same as Frame #2
  • etc.

Hence the name "ping ponging", you're bouncing between two textures every frame.

Edited by Styves

Share this post


Link to post
Share on other sites
3 hours ago, Styves said:

Yes, absolutely.

Not sure where you heard this. Unless you explicitly ask the GPU to give you the data on CPU, it'll stay on the GPU.

It's an extremely common technique. Every frame you just swap the render target you are rendering to and use the previous one as the new input.

Looks something like:

  • Frame #1:
    • Set Texture0 as Render Target
    • Bind Texture1 as input
    • Draw shader
  • Frame #2:
    • Set Texture1 as Render Target
    • Bind Texture0 as input
    • Draw Shader
  • Frame #3: Same as Frame #1
  • Frame #4: Same as Frame #2
  • etc.

Hence the name "ping ponging", you're bouncing between two textures every frame.

Thank you so much for your answer.

I'll then try to focus on compute shaders, because they seem to have advantages in terms of usable functions e.g. bitreverse...

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!