Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (4 posts)

how to get output from vertex shadder?

Last post 8/8/2008 12:57 AM by Shawn Hargreaves. 3 replies.
  • 8/7/2008 12:57 AM

    how to get output from vertex shadder?

    I have my vertex shader to compute new positions of vertices. My vertex shader is as follows:

    struct VertexShaderInput
        float3 Position : POSITION0;
        float3 Velocity : TEXCOORD0;
        float3 Force    : TEXCOORD1;
        float InvMass   : TEXCOORD2;
        float Time        : TEXCOORD3;
        // TODO: add input channels such as texture
        // coordinates and vertex colors here.

    struct VertexShaderOutput
        float4 Position : POSITION0;

        // TODO: add vertex shader outputs such as colors and texture
        // coordinates here. These values will automatically be interpolated
        // over the triangle, and provided as input to your pixel shader.

    VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
        VertexShaderOutput output;
        float3 Acceleration;
         Acceleration = input.Force*input.InvMass;
         input.Velocity += Acceleration * input.Time;
         input.Position += input.Velocity * input.Time;
         output.Position = float4(input.Position,1.0f);
         return output;

     I used effect.Parameter["  "].SetValue(..) to set the value for vertexShaderInput. How can I get and set for the output since my output is the new position.. how can I get the output in my main program. Thanks.. jaja

  • 8/7/2008 4:18 PM In reply to

    Re: how to get output from vertex shadder?

    It doesn't work like that. The GPU is a one way pipeline:

    • CPU sets parameter values
    • CPU stores vertex data in a vertex buffer, or passes it to DrawUserPrimitives (btw. your vertex shader input comes from one of these vertex data sources: you cannot specify the vertex data using effect parameters)
    • Vertex shader runs
    • Vertex shader outputs are rasterized to form triangles
    • Triangles are rendered by the pixel shader
    • Pixel shader outputs are written to the framebuffer

    There is no way to read any of these intermediate results back to the CPU. If you draw into a rendertarget, you can then GetData to fetch back the contents of this target after all your rendering has completed, but that will cause a pipeline stall, so is not usually a good idea if you care about performance.
  • 8/7/2008 10:09 PM In reply to

    Re: how to get output from vertex shadder?

    Do you have any suggestion or example of collision among particles on GPU? I'm simulating deformable objects and I would like to detect collision on the GPU. I need some example how to setup to find the distance between each point to detect collision. What I understand is that vertexes are vertex data or vertex buffer. How can we loop to each point on GPU? Similar to this peice of code on CPU. Do I have to do multi-pass .. somehow? But how? please help..

        for (i=0; i<numberofvertices; i++)

            for (j=0; j<number of vertices; j++)

              a = distance(p[i],p[j]);



  • 8/8/2008 12:57 AM In reply to

    Re: how to get output from vertex shadder?

    How much shader programming have you done before?

    This kind of thing is possible, at least on the more recent higher end GPUs, but far from trivial. I get the impression you're kind of new to shader programming? (my apologies if not...) in which case I probably wouldn't start with something as complicated as this - you really need a deep understanding of the GPU pipeline and shader capabilities before you can tackle something so complicated as simulating physics on the GPU.

Page 1 of 1 (4 posts) Previous Discussion Next Discussion