new render structure

main
cosmonaut 2020-12-07 21:37:05 -08:00
parent 6833ad5a24
commit ba994797b1
3 changed files with 98 additions and 62 deletions

2
Kav

@ -1 +1 @@
Subproject commit fe222e266ffc296ffacbed82dccecedb45204537
Subproject commit 96f6d228966e900a511164a176d1f2ae1f1caaa4

View File

@ -219,45 +219,42 @@ namespace KavTest
// floorModel
// ));
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
// new Transform3D(
// new Vector3(0, 1, 0),
// Quaternion.CreateFromAxisAngle(
// Vector3.Right,
// -Microsoft.Xna.Framework.MathHelper.PiOver2
// ),
// new Vector3(1f, 1f, 1f)
// ),
// redCylinderModel
// ));
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
new Transform3D(
new Vector3(0, 3, 0),
Quaternion.CreateFromAxisAngle(
Vector3.Right,
-Microsoft.Xna.Framework.MathHelper.PiOver2
),
new Vector3(1f, 1f, 1f)
),
redCylinderModel
));
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
// new Transform3D(
// new Vector3(-3, 1, 0),
// Quaternion.CreateFromAxisAngle(
// Vector3.Right,
// -Microsoft.Xna.Framework.MathHelper.PiOver2
// ),
// new Vector3(1f, 1f, 1f)
// ),
// blueTorusModel
// ));
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
new Transform3D(
new Vector3(-3, 3, 0),
Quaternion.CreateFromAxisAngle(
Vector3.Right,
-Microsoft.Xna.Framework.MathHelper.PiOver2
),
new Vector3(1f, 1f, 1f)
),
blueTorusModel
));
for (int i = -10; i < 10; i++)
{
for (int j = -10; j < 10; j++)
{
for (int k = -10; k < 10; k++)
{
var entity = WorldBuilder.CreateEntity();
WorldBuilder.SetComponent(entity, new Transform3DComponent(
new Transform3D(
new Vector3(i * 3, j * 3, k * 3)
)
));
WorldBuilder.SetComponent(entity, new InstancedCubeComponent());
WorldBuilder.SetComponent(entity, new StaticComponent());
}
var entity = WorldBuilder.CreateEntity();
WorldBuilder.SetComponent(entity, new Transform3DComponent(
new Transform3D(
new Vector3(i * 3, -1, j * 3)
)
));
WorldBuilder.SetComponent(entity, new InstancedCubeComponent());
WorldBuilder.SetComponent(entity, new StaticComponent());
}
}
@ -293,13 +290,13 @@ namespace KavTest
for (var i = 0; i < 1; i++)
{
var start = RandomHelper.RandomVector3(2, 5);
var start = new Vector3(-2, 5, 0);
WorldBuilder.SendMessage(new LightBulbSpawnMessage(
new Transform3D(start.ToXNAVector(), Quaternion.Identity, new Vector3(0.1f, 0.1f, 0.1f)),
new Transform3D(start, Quaternion.Identity, new Vector3(0.1f, 0.1f, 0.1f)),
RandomHelper.RandomColor(),
50f,
RandomHelper.RandomLoop(start, 2, 5, 3, 10)
RandomHelper.RandomLoop(new System.Numerics.Vector3(-2, 5, 0), 2, 5, 3, 10)
));
}

View File

@ -26,6 +26,8 @@ namespace KavTest.Renderers
private RenderTarget2D DeferredTarget { get; }
private RenderTarget2D BillboardTarget { get; }
private RenderTargetCube ShadowCubeMap { get; }
private DirectionalShadowMapData DirectionalShadowMapData { get; }
private readonly Dictionary<Kav.MeshPart, List<Matrix>> InstanceMap = new Dictionary<MeshPart, List<Matrix>>();
@ -45,7 +47,7 @@ namespace KavTest.Renderers
}
}
private IEnumerable<(Kav.Model, Matrix)> ModelTransforms
private IEnumerable<(Kav.MeshPart, Matrix)> MeshPartTransforms
{
get
{
@ -54,20 +56,22 @@ namespace KavTest.Renderers
/* FIXME: this transformation should definitely not go here */
var transformComponent = GetComponent<Transform3DComponent>(entity);
var modelComponent = GetComponent<ModelComponent>(entity);
if (HasComponent<OverrideAlbedoComponent>(entity))
{
var overrideAlbedoComponent = GetComponent<OverrideAlbedoComponent>(entity);
foreach (var mesh in modelComponent.Model.Meshes)
foreach (var mesh in modelComponent.Model.Meshes)
{
foreach (var meshPart in mesh.MeshParts)
{
foreach (var meshPart in mesh.MeshParts)
if (HasComponent<OverrideAlbedoComponent>(entity))
{
var overrideAlbedoComponent = GetComponent<OverrideAlbedoComponent>(entity);
meshPart.DisableAlbedoMap = true;
meshPart.Albedo = overrideAlbedoComponent.Color;
}
yield return (meshPart, transformComponent.Transform.TransformMatrix);
}
}
yield return (modelComponent.Model, transformComponent.Transform.TransformMatrix);
}
}
}
@ -147,11 +151,7 @@ namespace KavTest.Renderers
var renderDimensionsY = GraphicsDevice.PresentationParameters.BackBufferHeight;
Renderer = new Kav.Renderer(
GraphicsDevice,
renderDimensionsX,
renderDimensionsY,
4,
4096
GraphicsDevice
);
DeferredTarget = new RenderTarget2D(
@ -221,6 +221,17 @@ namespace KavTest.Renderers
new RenderTargetBinding(GMetallicRoughness)
};
ShadowCubeMap = Kav.Renderer.CreateShadowCubeMap(
GraphicsDevice,
2048
);
DirectionalShadowMapData = Kav.Renderer.CreateDirectionalShadowMaps(
graphicsDevice,
2048,
4
);
SpriteBatch = new SpriteBatch(GraphicsDevice);
}
@ -255,7 +266,7 @@ namespace KavTest.Renderers
// ModelTransforms
// );
Renderer.InstancedGBufferRender(
Renderer.RenderGBufferInstanced(
GBuffer,
DeferredTarget,
camera,
@ -263,13 +274,19 @@ namespace KavTest.Renderers
CubeTransforms
);
//Renderer.DepthRender(
// DeferredTarget,
// camera,
// ModelTransforms
//);
Renderer.RenderGBufferIndexed(
GBuffer,
camera,
MeshPartTransforms
);
Renderer.AmbientLightRender(
Renderer.RenderDepthIndexed(
DeferredTarget,
camera,
MeshPartTransforms
);
Renderer.RenderAmbientLight(
DeferredTarget,
GPosition,
GAlbedo,
@ -278,14 +295,27 @@ namespace KavTest.Renderers
foreach (var pointLight in PointLights)
{
Renderer.PointLightRender(
foreach (CubeMapFace face in Enum.GetValues(typeof(CubeMapFace)))
{
GraphicsDevice.SetRenderTarget(ShadowCubeMap, face);
GraphicsDevice.Clear(Color.White);
}
Renderer.RenderPointShadowsIndexed(
ShadowCubeMap,
camera,
MeshPartTransforms,
pointLight
);
Renderer.RenderPointLight(
DeferredTarget,
GPosition,
GAlbedo,
GNormal,
GMetallicRoughness,
ShadowCubeMap,
camera,
ModelTransforms,
pointLight
);
}
@ -294,21 +324,30 @@ namespace KavTest.Renderers
if (directionalLight.HasValue)
{
Renderer.DirectionalLightToonRender(
DirectionalShadowMapData.Clear(GraphicsDevice);
Renderer.RenderDirectionalShadowsIndexed(
DirectionalShadowMapData,
camera,
MeshPartTransforms,
directionalLight.Value
);
Renderer.RenderDirectionalLightToon(
DeferredTarget,
GPosition,
GAlbedo,
GNormal,
GMetallicRoughness,
DirectionalShadowMapData,
camera,
ModelTransforms,
MeshPartTransforms,
directionalLight.Value,
4,
false
);
}
Renderer.SkyboxRender(
Renderer.RenderSkybox(
DeferredTarget,
camera,
ReadComponent<SkyboxComponent>().Skybox