move more rendering responsibilities to application

main
cosmonaut 2020-12-07 01:59:43 -08:00
parent d896707506
commit 8f570e04f0
2 changed files with 122 additions and 45 deletions

2
Kav

@ -1 +1 @@
Subproject commit c9a4e3581699ce3c1a03837be0a9c9492560a706
Subproject commit 8b43e8f45ee6fa35f5c4d4924a62a3fcafe61301

View File

@ -15,6 +15,14 @@ namespace KavTest.Renderers
private SpriteBatch SpriteBatch { get; }
private Kav.Renderer Renderer { get; }
private RenderTargetBinding[] GBuffer { get; }
private RenderTarget2D GPosition { get; }
private RenderTarget2D GNormal { get; }
private RenderTarget2D GAlbedo { get; }
private RenderTarget2D GMetallicRoughness { get; }
private RenderTarget2D DeferredTarget { get; }
private RenderTarget2D BillboardTarget { get; }
@ -111,18 +119,23 @@ namespace KavTest.Renderers
public SceneRenderer(GraphicsDevice graphicsDevice)
{
GraphicsDevice = graphicsDevice;
var renderDimensionsX = GraphicsDevice.PresentationParameters.BackBufferWidth;
var renderDimensionsY = GraphicsDevice.PresentationParameters.BackBufferHeight;
Renderer = new Kav.Renderer(
graphicsDevice,
graphicsDevice.PresentationParameters.BackBufferWidth,
graphicsDevice.PresentationParameters.BackBufferHeight,
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
4,
4096
);
DeferredTarget = new RenderTarget2D(
graphicsDevice,
graphicsDevice.PresentationParameters.BackBufferWidth,
graphicsDevice.PresentationParameters.BackBufferHeight,
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.Color,
DepthFormat.Depth24Stencil8,
@ -131,9 +144,9 @@ namespace KavTest.Renderers
);
BillboardTarget = new RenderTarget2D(
graphicsDevice,
graphicsDevice.PresentationParameters.BackBufferWidth,
graphicsDevice.PresentationParameters.BackBufferHeight,
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.Color,
DepthFormat.Depth24Stencil8,
@ -141,7 +154,49 @@ namespace KavTest.Renderers
RenderTargetUsage.PreserveContents
);
GraphicsDevice = graphicsDevice;
GPosition = new RenderTarget2D(
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.Vector4,
DepthFormat.Depth24
);
GNormal = new RenderTarget2D(
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.Vector4,
DepthFormat.None
);
GAlbedo = new RenderTarget2D(
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.Color,
DepthFormat.None
);
GMetallicRoughness = new RenderTarget2D(
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
false,
SurfaceFormat.HalfVector2,
DepthFormat.None
);
GBuffer = new RenderTargetBinding[4] {
new RenderTargetBinding(GPosition),
new RenderTargetBinding(GNormal),
new RenderTargetBinding(GAlbedo),
new RenderTargetBinding(GMetallicRoughness)
};
SpriteBatch = new SpriteBatch(GraphicsDevice);
}
@ -163,37 +218,67 @@ namespace KavTest.Renderers
cameraComponent.FarPlane
);
// if (SomeComponent<DirectionalLightComponent>())
// {
// ref readonly var directionalLightEntity = ref ReadEntity<DirectionalLightComponent>();
// ref readonly var directionalLightTransformComponent = ref GetComponent<Transform3DComponent>(directionalLightEntity);
// ref readonly var directionalLightComponent = ref GetComponent<DirectionalLightComponent>(directionalLightEntity);
GraphicsDevice.SetRenderTargets(GBuffer);
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);
// Renderer.DepthRender(
// ModelTransforms,
// new Kav.DirectionalLight(
// directionalLightTransformComponent.Transform.Forward,
// directionalLightComponent.Color,
// directionalLightComponent.Intensity
// )
// );
// }
Renderer.GBufferRender(
GBuffer,
camera,
ModelTransforms
);
// Renderer.DeferredRender(
// camera,
// ModelTransforms,
// AmbientLight,
// PointLights,
// DirectionalLight()
// );
GraphicsDevice.SetRenderTarget(DeferredTarget);
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
Renderer.DeferredToonRender(
Renderer.DepthRender(
DeferredTarget,
camera,
ModelTransforms
);
Renderer.AmbientLightRender(
DeferredTarget,
GPosition,
GAlbedo,
AmbientLight
);
foreach (var pointLight in PointLights)
{
Renderer.PointLightRender(
DeferredTarget,
GPosition,
GAlbedo,
GNormal,
GMetallicRoughness,
camera,
ModelTransforms,
AmbientLight,
PointLights,
DirectionalLight(),
pointLight
);
}
var directionalLight = DirectionalLight();
if (directionalLight.HasValue)
{
Renderer.DirectionalLightToonRender(
DeferredTarget,
GPosition,
GAlbedo,
GNormal,
GMetallicRoughness,
camera,
ModelTransforms,
directionalLight.Value,
4,
false
);
}
Renderer.SkyboxRender(
DeferredTarget,
camera,
ReadComponent<SkyboxComponent>().Skybox
);
@ -212,14 +297,6 @@ namespace KavTest.Renderers
SpriteBatch.Draw(DeferredTarget, Vector2.Zero, Color.White);
SpriteBatch.Draw(BillboardTarget, Vector2.Zero, Color.White);
SpriteBatch.End();
// foreach (var directionalLight in DirectionalLights)
// {
// Renderer.DepthRender(
// ModelTransforms,
// directionalLight
// );
// }
}
}
}