Sign in to follow this  
thedodgeruk

shader problem ?

Recommended Posts

[code]

**********************************************
PassThruGS.vsh

Vertex shader that passes on particle data
to the geometry shader without change
The geometry shaders do all the update
& rendering work for this particle system
***********************************************/

//-----------------------------------------------------------------------------
// Input / output structures
//-----------------------------------------------------------------------------

// Input and output from vertex shader - particle data

float4x4 ViewProjMatrix;
float4x4 InvViewMatrix;

// GPU is performing some scene update, so it needs timing info
float Time;


struct VS_InputOutput
{
float3 Position : POSITION;
float3 Velocity : TEXCOORD0;
float Life : PSIZE0;
float Delay : PSIZE1;
};
struct GS_VertInOut
{
float3 Position : POSITION;
float3 Velocity : TEXCOORD0;
float Life : PSIZE0;
float Delay : PSIZE1;

};




//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------

VS_InputOutput VS( in VS_InputOutput i)
{
VS_InputOutput o;
o = i;
return o;
}

//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------

[maxvertexcount(1)] // This shader deals with particles one at a time. When a particle dies, it is immediately respawned,
// so this shader will always output one particle as well
void GS
(
point GS_VertInOut inParticle[1], // One particle in, as a point
inout PointStream<GS_VertInOut> outParticles // Must output a point stream, will only contain the one updated point
)
{
const float3 Gravity = { 0, -9.8f, 0 };

inParticle[0].Delay -= Time;
if (inParticle[0].Delay < 0)
{
// Fairly general purpose particle update code
inParticle[0].Life -= Time;
inParticle[0].Position += inParticle[0].Velocity * Time;
inParticle[0].Velocity += Gravity * Time;
outParticles.Append( inParticle );
}
}


technique10 particleUpdate
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( CompileShader( gs_4_0, GS() ) );
SetPixelShader( NULL );

//SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
//SetRasterizerState( CullNone );
//SetDepthStencilState( DepthWritesOff, 0 );
}
}
[/code]

its for an update for paricles so all the particle maths are done on the gpu .

fx composer says " not all elements of SV_Position were writen .

i cant figure out its meaning or how to get around it , any ideas

Share this post


Link to post
Share on other sites
When you output SV_Position from a vertex or geometry shader (which is typedef'ed as POSITION if you compatibility mode enabled when compiling shaders) it needs to be a float4 position that's in post-projection clip space. You seem to just be outputting some sort of world-space position from your geometry shader, which isn't going to work. You need to apply your projection matrix and output the resulting float4 as SV_Position in order for the pipeline to be able to rasterize the triangles.

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

Sign in to follow this