move more rendering responsibilities to application
parent
d896707506
commit
8f570e04f0
2
Kav
2
Kav
|
@ -1 +1 @@
|
||||||
Subproject commit c9a4e3581699ce3c1a03837be0a9c9492560a706
|
Subproject commit 8b43e8f45ee6fa35f5c4d4924a62a3fcafe61301
|
|
@ -15,6 +15,14 @@ namespace KavTest.Renderers
|
||||||
private SpriteBatch SpriteBatch { get; }
|
private SpriteBatch SpriteBatch { get; }
|
||||||
|
|
||||||
private Kav.Renderer Renderer { 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 DeferredTarget { get; }
|
||||||
private RenderTarget2D BillboardTarget { get; }
|
private RenderTarget2D BillboardTarget { get; }
|
||||||
|
|
||||||
|
@ -111,18 +119,23 @@ namespace KavTest.Renderers
|
||||||
|
|
||||||
public SceneRenderer(GraphicsDevice graphicsDevice)
|
public SceneRenderer(GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
|
GraphicsDevice = graphicsDevice;
|
||||||
|
|
||||||
|
var renderDimensionsX = GraphicsDevice.PresentationParameters.BackBufferWidth;
|
||||||
|
var renderDimensionsY = GraphicsDevice.PresentationParameters.BackBufferHeight;
|
||||||
|
|
||||||
Renderer = new Kav.Renderer(
|
Renderer = new Kav.Renderer(
|
||||||
graphicsDevice,
|
GraphicsDevice,
|
||||||
graphicsDevice.PresentationParameters.BackBufferWidth,
|
renderDimensionsX,
|
||||||
graphicsDevice.PresentationParameters.BackBufferHeight,
|
renderDimensionsY,
|
||||||
4,
|
4,
|
||||||
4096
|
4096
|
||||||
);
|
);
|
||||||
|
|
||||||
DeferredTarget = new RenderTarget2D(
|
DeferredTarget = new RenderTarget2D(
|
||||||
graphicsDevice,
|
GraphicsDevice,
|
||||||
graphicsDevice.PresentationParameters.BackBufferWidth,
|
renderDimensionsX,
|
||||||
graphicsDevice.PresentationParameters.BackBufferHeight,
|
renderDimensionsY,
|
||||||
false,
|
false,
|
||||||
SurfaceFormat.Color,
|
SurfaceFormat.Color,
|
||||||
DepthFormat.Depth24Stencil8,
|
DepthFormat.Depth24Stencil8,
|
||||||
|
@ -131,9 +144,9 @@ namespace KavTest.Renderers
|
||||||
);
|
);
|
||||||
|
|
||||||
BillboardTarget = new RenderTarget2D(
|
BillboardTarget = new RenderTarget2D(
|
||||||
graphicsDevice,
|
GraphicsDevice,
|
||||||
graphicsDevice.PresentationParameters.BackBufferWidth,
|
renderDimensionsX,
|
||||||
graphicsDevice.PresentationParameters.BackBufferHeight,
|
renderDimensionsY,
|
||||||
false,
|
false,
|
||||||
SurfaceFormat.Color,
|
SurfaceFormat.Color,
|
||||||
DepthFormat.Depth24Stencil8,
|
DepthFormat.Depth24Stencil8,
|
||||||
|
@ -141,7 +154,49 @@ namespace KavTest.Renderers
|
||||||
RenderTargetUsage.PreserveContents
|
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);
|
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,37 +218,67 @@ namespace KavTest.Renderers
|
||||||
cameraComponent.FarPlane
|
cameraComponent.FarPlane
|
||||||
);
|
);
|
||||||
|
|
||||||
// if (SomeComponent<DirectionalLightComponent>())
|
GraphicsDevice.SetRenderTargets(GBuffer);
|
||||||
// {
|
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);
|
||||||
// ref readonly var directionalLightEntity = ref ReadEntity<DirectionalLightComponent>();
|
|
||||||
// ref readonly var directionalLightTransformComponent = ref GetComponent<Transform3DComponent>(directionalLightEntity);
|
|
||||||
// ref readonly var directionalLightComponent = ref GetComponent<DirectionalLightComponent>(directionalLightEntity);
|
|
||||||
|
|
||||||
// Renderer.DepthRender(
|
Renderer.GBufferRender(
|
||||||
// ModelTransforms,
|
GBuffer,
|
||||||
// new Kav.DirectionalLight(
|
camera,
|
||||||
// directionalLightTransformComponent.Transform.Forward,
|
ModelTransforms
|
||||||
// directionalLightComponent.Color,
|
);
|
||||||
// directionalLightComponent.Intensity
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Renderer.DeferredRender(
|
GraphicsDevice.SetRenderTarget(DeferredTarget);
|
||||||
// camera,
|
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1f, 0);
|
||||||
// ModelTransforms,
|
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
|
||||||
// AmbientLight,
|
|
||||||
// PointLights,
|
|
||||||
// DirectionalLight()
|
|
||||||
// );
|
|
||||||
|
|
||||||
Renderer.DeferredToonRender(
|
Renderer.DepthRender(
|
||||||
DeferredTarget,
|
DeferredTarget,
|
||||||
camera,
|
camera,
|
||||||
|
ModelTransforms
|
||||||
|
);
|
||||||
|
|
||||||
|
Renderer.AmbientLightRender(
|
||||||
|
DeferredTarget,
|
||||||
|
GPosition,
|
||||||
|
GAlbedo,
|
||||||
|
AmbientLight
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var pointLight in PointLights)
|
||||||
|
{
|
||||||
|
Renderer.PointLightRender(
|
||||||
|
DeferredTarget,
|
||||||
|
GPosition,
|
||||||
|
GAlbedo,
|
||||||
|
GNormal,
|
||||||
|
GMetallicRoughness,
|
||||||
|
camera,
|
||||||
ModelTransforms,
|
ModelTransforms,
|
||||||
AmbientLight,
|
pointLight
|
||||||
PointLights,
|
);
|
||||||
DirectionalLight(),
|
}
|
||||||
|
|
||||||
|
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
|
ReadComponent<SkyboxComponent>().Skybox
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -212,14 +297,6 @@ namespace KavTest.Renderers
|
||||||
SpriteBatch.Draw(DeferredTarget, Vector2.Zero, Color.White);
|
SpriteBatch.Draw(DeferredTarget, Vector2.Zero, Color.White);
|
||||||
SpriteBatch.Draw(BillboardTarget, Vector2.Zero, Color.White);
|
SpriteBatch.Draw(BillboardTarget, Vector2.Zero, Color.White);
|
||||||
SpriteBatch.End();
|
SpriteBatch.End();
|
||||||
|
|
||||||
// foreach (var directionalLight in DirectionalLights)
|
|
||||||
// {
|
|
||||||
// Renderer.DepthRender(
|
|
||||||
// ModelTransforms,
|
|
||||||
// directionalLight
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue