Okay so I'm trying to do point to quad expansion on particle data that is being fed through the graphics pipeline. If I have a simple vertex and pixel shader everything works perfectly (rendered as points). However, when I add in the geometry shader stage everything disappears from the screen. I don't just mean the particles, even the text that is being rendered using spritebatch from the DirectXTK. Any ideas as to what might be causing this? I'll post my shader code.
It appears to happen more specifically when I use this line:
deviceContext->GSSetShader(geometryShader, 0, 0);
I've checked everything compiles correctly and that seems to be fine.
Here's the shader code I'm referring too:
//#pragma pack_matrix( row_major )
cbuffer ConstantBuffer : register(b0)
{
matrix World;
matrix View;
matrix Projection;
}
cbuffer cbFixed
{
//
// Compute texture coordinates to stretch texture over quad.
//
float2 gTexC[4] =
{
float2(0.0f, 1.0f),
float2(0.0f, 0.0f),
float2(1.0f, 1.0f),
float2(1.0f, 0.0f)
};
};
struct particles
{
float3 position : POSITION;
float3 velocity;
float life;
float age;
bool alive;
float startSize;
float endSize;
float4 startColour;
float4 endColour;
};
struct VS_INPUT
{
uint id : SV_VERTEXID;
};
struct GS_INPUT
{
float3 Pos : POSITION;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 Col : COLOUR;
float2 TexCoord : TEXCOORD;
};
struct GeoOut
{
float4 PosH : SV_POSITION;
float2 Tex : TEXCOORD;
uint PrimID : SV_PrimitiveID;
};
static const float scale = 0.5f;
static const float4 g_positions[4] =
{
float4(-scale, scale, 0, 0),
float4(scale, scale, 0, 0),
float4(-scale, -scale, 0, 0),
float4(scale, -scale, 0, 0),
};
static const float2 g_texcoords[4] =
{
float2(0, 1),
float2(1, 1),
float2(0, 0),
float2(1, 0),
};
StructuredBuffer<particles> particlesIn : register(t0);
GS_INPUT VS(VS_INPUT input)
{
GS_INPUT output;
output.Pos.xyz = particlesIn[input.id].position;
return output;
}
[maxvertexcount(4)]
void GS(point GS_INPUT input[1], inout TriangleStream<PS_INPUT> SpriteStream)
{
PS_INPUT output;
float3 CameraLocation = float3(0.0f, 1.0f, -5.0f);
float dist = saturate(length(input[0].Pos - CameraLocation.xyz) / 100.0f);
//float4 color = float4( 0.2f, 1.0f, 0.2f, 0.0f ) * dist + float4( 1.0f, 0.1f, 0.1f, 0.0f ) * ( 1.0f - dist );
//float4 color = float4( 0.2f, 1.0f, 1.0f, 0.0f ) * dist + float4( 1.0f, 0.1f, 0.1f, 0.0f ) * ( 1.0f - dist );
float4 color = float4(0.2f, 0.2f, 1.0f, 0.0f) * dist + float4(1.0f, 0.1f, 0.1f, 0.0f) * (1.0f - dist);
// Transform to view space
float4 viewposition = mul(float4(input[0].Pos, 1.0f), World);
// Emit two new triangles
for (int i = 0; i < 4; i++)
{
float4 p = mul(input[0].Pos, World);
p = mul(p, View);
p = mul(p, Projection);
output.Pos = p;
output.TexCoord = g_texcoords[i];
output.Col = color;
SpriteStream.Append(output);
}
SpriteStream.RestartStrip();
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PS_INPUT input) : SV_Target
{
return float4(1.0f, 1.0f, 0.0f, 1.0f);
}