XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

gpu particles pixelshader-only

Last post 10/04/2009 19:44 by schobbejak. 2 replies.
  • 08/04/2009 19:53

    gpu particles pixelshader-only

    I want to simulate some particles, and display them as pixels, so i can do the calculations with a shader, and no data needs to be sent back to the cpu-side.
    I am doing the following steps:

    -There is a positions-texture that holds the uv coordinate of where the pixel should be displayed.
    -There is a velocitys-texture which holds the velocitys of the particles.
     
    1: calculate velocities, and render them in to the RT (rendertarget)
    2: set the velocitys-texture (from RT)
    3: add velocities to positions, render to RT.
    4: set the positions-texture (from RT)
    5: renderpass:get the uv coordinates from the positions-texture, and render the pixel at that location white.

    Step 5 is a problem: if a pixel gets processed by the pixelshader, it has to draw a pixel somewhere else, which is not possible.
    A solution would be using an array: step 4 would than also include something like:
    ColorArray[PosU][PosV] = Color;
    Step 5 would be:
    return ColorArray[uv,x][uv.y];
    But the maximum size of an array is 65536 (256 * 256), which is not big enough for me.

    Can you think of a way to make this work, without a lot of data-traffic, and without rendering the particles with vertices (using vtf)?
  • 10/04/2009 11:06 In reply to

    Re: gpu particles pixelshader-only

    This is a common problem. Unfortunately all solutions require at least a shader model 3 GPU.
    1. On nvidia SM3 hardware you can read texture from the vertex shader. If you write ll your positions to such a texture you can use a second pass. This pass needs to read the position from this texture and use it as position output for the vertex shader.
    2. On ATI SM3 hardware there is an extension that allows you to render to special texture that can be used as vertex buffer.  You will find the details on the ATI side. Look for R2VB.
    3. All SM4 hardware (Direct3D 10.0) supports reading textures inside the vertex shader. You can although use the geometry shader to generate your particles.
  • 10/04/2009 19:44 In reply to

    Re: gpu particles pixelshader-only

    Thanks!
    I have an ati card, so i cant do vertex texture fetch. Render to vertexbuffer does not work in xna as far as i know.
    I tried doing the movement math in the PS, getting the positions from rendertarget and the setting the positions of vertices, and got 45fps with 262144 particles on a 3ghz C2duo with ati 4870. I get 100fps if i do only the pixelshader calculations. (but then i obviously see nothing on screen)
    I was hoping to exceed a million, but i guess i have to get a nvidia card then.
Page 1 of 1 (3 items) Previous Next