I'm trying to make a particle system where I send a pointlist and expand quads from it. I'd done this years ago but lost the code. Everything seems to be fine except that the constant buffers (2 of them at 0 and 1) are somehow considered unreferenced for that draw call. I've also noticed that the same happens when drawing sprites, though I had not noticed until now because I had no need of the constant buffers then.
I've tried taking out the geometry shader, using triangle lists, moving the order at which it is rendered, and setting the constant buffers to the vertex shader immediately before calling draw on the device context, and still no luck. I'm using the Nsight plugin for Visual Studio to debug. All the buffers contain the correct data, and every shader except the vertex shaders used for sprites and for the particles lists the constant buffers correctly. I've checked the output with the Debug flag enabled and nothing appears between the time I prepare the particles to be rendered and after the call has been sent.
Only thing that I can think of is that it has something to do with the hlsl compiler not defining the buffers as referenced somehow.
Here's the code that renders (should render) the particles:
internal override void Render()
{
//So I can tell where this begins in the output window
System.Diagnostics.Debug.WriteLine("BEGIN PARTICLE");
//base.Render is an empty method at the moment
base.Render();
if (buffer.Elements == 0)
return;
var o = Renderer.Context.InputAssembler.PrimitiveTopology;
Renderer.Context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.PointList;
Renderer.SetPSRes(ResLibrary.GetTex2D(Texture), 0);
Renderer.Set(vs);
Renderer.Set(fs);
//storing the current geometry shader so that it can be set back after
//probably will just remove this and set the geometry shader back to none
var ogs = Renderer.Context.GeometryShader.Get();
Renderer.Set(gs);
//Setting the constant buffers. These should already be set but just making sure.
ShaderGlobals.SetWorld(Matrix.Identity);
ShaderGlobals.UpdateCamera(Renderer.Scene.CurrentCamera.GetLocation(), Renderer.Scene.CurrentCamera.View, Renderer.Scene.CurrentCamera.Projection);
Renderer.Set(buffer, 0, 0);
Renderer.Draw(buffer.Elements, 0);
Renderer.Context.GeometryShader.Set(ogs);
Renderer.Context.InputAssembler.PrimitiveTopology = o;
System.Diagnostics.Debug.WriteLine("END PARTICLE");
}
Here are the vertex shaders that cause problems:
Particle Vertex Shader:
cbuffer MatrixBuffer: register(b0)
{
matrix G_View;
matrix G_Projection;
float3 G_CamPos;
float G_gt;
};
cbuffer WorldBuffer: register(b1)
{
matrix G_World;
float3x3 G_World3x3;
};
struct VertexInputType
{
float4 position : POSITION;
float4 color : COLOR;
float2 texcoord0 : TEXCOORD0;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR;
float2 texcoord0 : TEXCOORD0;
};
PixelInputType VS_Shader(VertexInputType input)
{
PixelInputType output;
output.position = mul(input.position, G_World);
output.position = mul(output.position, G_View);
output.position = mul(output.position, G_Projection);
output.position = input.position;
output.texcoord0 = input.texcoord0;
output.color = input.color;
return output;
}
Sprite Vertex Shader:
cbuffer MatrixBuffer: register(b0)
{
matrix G_View;
matrix G_Projection;
float3 G_CamPos;
float G_gt;
};
cbuffer WorldBuffer: register(b1)
{
matrix G_World;
float3x3 G_World3x3;
};
struct VertexInputType
{
float4 position : POSITION;
float4 color : COLOR;
float2 texcoord0 : TEXCOORD0;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float4 color : COLOR;
float2 texcoord0 : TEXCOORD0;
};
PixelInputType VS_Shader(VertexInputType input)
{
PixelInputType output;
input.position.w = 1.0f;
output.position = input.position;
output.texcoord0 = input.texcoord0;
output.color = input.color;
return output;
}
Any help at all is appreciated. I've looked at this for several hours now trying to figure anything out and I'm out of ideas.
Also if there's any more information I can give that might help let me know.