My forward rendering draw method is as follows:
protected override void Draw(GameTime gameTime)
{
graphicsDevice.Clear(clearColour);
SetSharedParameters(activeCamera);
// [Deferred Rendering]
//deferredRendering.Draw(gameTime);
// [Forward Rendering]
// [Draw 3D]
modelDrawer.Begin(activeCamera);
quadrangleDrawer.Begin(activeCamera);
shapeDrawer.Begin(activeCamera);
wireShapeDrawer.Begin(activeCamera);
octree.Draw(gameTime);
modelDrawer.End();
quadrangleDrawer.End();
shapeDrawer.End();
wireShapeDrawer.End();
}
The octree used to draw all the entities in view of the camera, but now it draws nothing.
Here is an example of a draw method for wire shapes:
private void FlushDrawing()
{
if (IndexCount > 0)
{
//game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
Effect effect = game.Effects["PreTransformed"];
// Set parameters for current camera
game.SetSharedParameters(camera);
vertexBuffer.SetData(Vertices, 0, VertexCount, SetDataOptions.Discard);
indexBuffer.SetData(Indices, 0, IndexCount, SetDataOptions.Discard);
game.GraphicsDevice.Indices = indexBuffer;
game.GraphicsDevice.SetVertexBuffer(vertexBuffer);
effect.CurrentTechnique.Passes[0].Apply();
game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.LineList, 0, 0, VertexCount, 0, IndexCount / 2);
}
IndexCount = 0;
VertexCount = 0;
}
The shared parameters are set to an .fx file that uses the 'shared' keyword:
public void SetSharedParameters(Camera camera)
{
Vector2 halfPixel = new Vector2();
halfPixel.X = 1.0f / graphicsDevice.Viewport.Width;
halfPixel.Y = -1.0f / graphicsDevice.Viewport.Height;
parameter_CameraPosition.SetValue(camera.Position);
parameter_CameraUp.SetValue(camera.Up);
parameter_HalfPixel.SetValue(halfPixel);
parameter_InverseViewProjection.SetValue(Matrix.Invert(camera.ViewProjectionMatrix));
parameter_Projection.SetValue(camera.ProjectionMatrix);
parameter_View.SetValue(camera.ViewMatrix);
parameter_ViewProjection.SetValue(camera.ViewProjectionMatrix);
}
The .fx file for drawing lines is as follows:
//=============================================
//----------- [XNA to HLSL Variables] ---------
//=============================================
shared float4x4 ViewProjection;
//=============================================
//------------------ [Structs] ----------------
//=============================================
struct VertexShaderInput
{
float4 Position : POSITION0;
float4 Colour : COLOR0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float4 Colour : COLOR0;
};
struct PixelShaderOutput
{
float4 Colour : COLOR0;
};
//=============================================
//------------ Technique: Default -------------
//=============================================
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = mul(input.Position, ViewProjection);
output.Colour = input.Colour;
return output;
}
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
PixelShaderOutput output;
output.Colour = input.Colour;
return output;
}
technique Default
{
pass Pass0
{
AlphaBlendEnable = false; // No transparency
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
What haven't I set correctly?