started instance based depth render

instancing
cosmonaut 2020-12-07 18:46:53 -08:00
parent bb694d3dbe
commit fe222e266f
1 changed files with 41 additions and 16 deletions

View File

@ -128,18 +128,12 @@ namespace Kav
public void MeshSpriteRender(
RenderTarget2D renderTarget,
PerspectiveCamera camera,
IEnumerable<(Model, Matrix)> modelTransforms,
IEnumerable<(MeshSprite, Matrix)> meshSpriteTransforms,
AmbientLight ambientLight,
IEnumerable<PointLight> pointLights,
DirectionalLight? directionalLight
) {
GraphicsDevice.SetRenderTarget(ColorRenderTarget);
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
DepthRender(ColorRenderTarget, camera, modelTransforms);
GraphicsDevice.Clear(ClearOptions.Target, new Color(0, 0, 0, 0), 1f, 0);
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
GraphicsDevice.RasterizerState = RasterizerState.CullNone;
@ -224,12 +218,6 @@ namespace Kav
);
}
}
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(new Color(0, 0, 0, 0));
SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null);
SpriteBatch.Draw(ColorRenderTarget, Vector2.Zero, Color.White);
SpriteBatch.End();
}
public void DepthRender(
@ -248,7 +236,7 @@ namespace Kav
{
foreach (var meshPart in modelMesh.MeshParts)
{
SimpleDepthEffect.Model = transform;
SimpleDepthEffect.World = transform;
SimpleDepthEffect.View = camera.View;
SimpleDepthEffect.Projection = camera.Projection;
@ -280,6 +268,8 @@ namespace Kav
) {
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.RasterizerState.CullMode = CullMode.CullClockwiseFace;
GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
SkyboxEffect.Skybox = skybox;
var view = camera.View;
@ -312,6 +302,7 @@ namespace Kav
/// </summary>
public void InstancedGBufferRender<T>(
RenderTargetBinding[] gBuffer,
RenderTarget2D depthBuffer,
PerspectiveCamera camera,
T drawable,
IEnumerable<Matrix> transforms
@ -339,7 +330,6 @@ namespace Kav
foreach (var transform in FrustumCull(boundingFrustum, drawable, transforms))
{
GBufferInstanceVertices[numInstances].World = transform;
numInstances += 1;
}
@ -372,6 +362,41 @@ namespace Kav
numInstances
);
}
GraphicsDevice.SetRenderTarget(depthBuffer);
foreach (var pass in Deferred_GBufferEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawInstancedPrimitives(
PrimitiveType.TriangleList,
0,
0,
drawable.VertexBuffer.VertexCount,
0,
drawable.IndexBuffer.IndexCount / 3,
numInstances
);
}
//SimpleDepthEffect.HardwareInstancingEnabled = true;
//SimpleDepthEffect.View = camera.View;
//SimpleDepthEffect.Projection = camera.Projection;
//foreach (var pass in SimpleDepthEffect.CurrentTechnique.Passes)
//{
// pass.Apply();
// GraphicsDevice.DrawInstancedPrimitives(
// PrimitiveType.TriangleList,
// 0,
// 0,
// drawable.VertexBuffer.VertexCount,
// 0,
// drawable.IndexBuffer.IndexCount / 3,
// numInstances
// );
//}
}
public void GBufferRender(
@ -694,7 +719,7 @@ namespace Kav
GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer);
GraphicsDevice.Indices = meshPart.IndexBuffer;
SimpleDepthEffect.Model = transform;
SimpleDepthEffect.World = transform;
foreach (var pass in SimpleDepthEffect.CurrentTechnique.Passes)
{