new render structure
parent
6833ad5a24
commit
ba994797b1
2
Kav
2
Kav
|
@ -1 +1 @@
|
||||||
Subproject commit fe222e266ffc296ffacbed82dccecedb45204537
|
Subproject commit 96f6d228966e900a511164a176d1f2ae1f1caaa4
|
|
@ -219,47 +219,44 @@ namespace KavTest
|
||||||
// floorModel
|
// floorModel
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
||||||
// new Transform3D(
|
new Transform3D(
|
||||||
// new Vector3(0, 1, 0),
|
new Vector3(0, 3, 0),
|
||||||
// Quaternion.CreateFromAxisAngle(
|
Quaternion.CreateFromAxisAngle(
|
||||||
// Vector3.Right,
|
Vector3.Right,
|
||||||
// -Microsoft.Xna.Framework.MathHelper.PiOver2
|
-Microsoft.Xna.Framework.MathHelper.PiOver2
|
||||||
// ),
|
),
|
||||||
// new Vector3(1f, 1f, 1f)
|
new Vector3(1f, 1f, 1f)
|
||||||
// ),
|
),
|
||||||
// redCylinderModel
|
redCylinderModel
|
||||||
// ));
|
));
|
||||||
|
|
||||||
// WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
|
||||||
// new Transform3D(
|
new Transform3D(
|
||||||
// new Vector3(-3, 1, 0),
|
new Vector3(-3, 3, 0),
|
||||||
// Quaternion.CreateFromAxisAngle(
|
Quaternion.CreateFromAxisAngle(
|
||||||
// Vector3.Right,
|
Vector3.Right,
|
||||||
// -Microsoft.Xna.Framework.MathHelper.PiOver2
|
-Microsoft.Xna.Framework.MathHelper.PiOver2
|
||||||
// ),
|
),
|
||||||
// new Vector3(1f, 1f, 1f)
|
new Vector3(1f, 1f, 1f)
|
||||||
// ),
|
),
|
||||||
// blueTorusModel
|
blueTorusModel
|
||||||
// ));
|
));
|
||||||
|
|
||||||
for (int i = -10; i < 10; i++)
|
for (int i = -10; i < 10; i++)
|
||||||
{
|
{
|
||||||
for (int j = -10; j < 10; j++)
|
for (int j = -10; j < 10; j++)
|
||||||
{
|
|
||||||
for (int k = -10; k < 10; k++)
|
|
||||||
{
|
{
|
||||||
var entity = WorldBuilder.CreateEntity();
|
var entity = WorldBuilder.CreateEntity();
|
||||||
WorldBuilder.SetComponent(entity, new Transform3DComponent(
|
WorldBuilder.SetComponent(entity, new Transform3DComponent(
|
||||||
new Transform3D(
|
new Transform3D(
|
||||||
new Vector3(i * 3, j * 3, k * 3)
|
new Vector3(i * 3, -1, j * 3)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
WorldBuilder.SetComponent(entity, new InstancedCubeComponent());
|
WorldBuilder.SetComponent(entity, new InstancedCubeComponent());
|
||||||
WorldBuilder.SetComponent(entity, new StaticComponent());
|
WorldBuilder.SetComponent(entity, new StaticComponent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
WorldBuilder.SendMessage(new MeshSpriteSpawnMessage(
|
WorldBuilder.SendMessage(new MeshSpriteSpawnMessage(
|
||||||
new Transform3D(new Vector3(3, 0, 11), Quaternion.CreateFromAxisAngle(Vector3.Up, (float)System.Math.PI), Vector3.One),
|
new Transform3D(new Vector3(3, 0, 11), Quaternion.CreateFromAxisAngle(Vector3.Up, (float)System.Math.PI), Vector3.One),
|
||||||
|
@ -293,13 +290,13 @@ namespace KavTest
|
||||||
|
|
||||||
for (var i = 0; i < 1; i++)
|
for (var i = 0; i < 1; i++)
|
||||||
{
|
{
|
||||||
var start = RandomHelper.RandomVector3(2, 5);
|
var start = new Vector3(-2, 5, 0);
|
||||||
|
|
||||||
WorldBuilder.SendMessage(new LightBulbSpawnMessage(
|
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(),
|
RandomHelper.RandomColor(),
|
||||||
50f,
|
50f,
|
||||||
RandomHelper.RandomLoop(start, 2, 5, 3, 10)
|
RandomHelper.RandomLoop(new System.Numerics.Vector3(-2, 5, 0), 2, 5, 3, 10)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace KavTest.Renderers
|
||||||
|
|
||||||
private RenderTarget2D DeferredTarget { get; }
|
private RenderTarget2D DeferredTarget { get; }
|
||||||
private RenderTarget2D BillboardTarget { 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>>();
|
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
|
get
|
||||||
{
|
{
|
||||||
|
@ -54,20 +56,22 @@ namespace KavTest.Renderers
|
||||||
/* FIXME: this transformation should definitely not go here */
|
/* FIXME: this transformation should definitely not go here */
|
||||||
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
||||||
var modelComponent = GetComponent<ModelComponent>(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.DisableAlbedoMap = true;
|
||||||
meshPart.Albedo = overrideAlbedoComponent.Color;
|
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;
|
var renderDimensionsY = GraphicsDevice.PresentationParameters.BackBufferHeight;
|
||||||
|
|
||||||
Renderer = new Kav.Renderer(
|
Renderer = new Kav.Renderer(
|
||||||
GraphicsDevice,
|
GraphicsDevice
|
||||||
renderDimensionsX,
|
|
||||||
renderDimensionsY,
|
|
||||||
4,
|
|
||||||
4096
|
|
||||||
);
|
);
|
||||||
|
|
||||||
DeferredTarget = new RenderTarget2D(
|
DeferredTarget = new RenderTarget2D(
|
||||||
|
@ -221,6 +221,17 @@ namespace KavTest.Renderers
|
||||||
new RenderTargetBinding(GMetallicRoughness)
|
new RenderTargetBinding(GMetallicRoughness)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ShadowCubeMap = Kav.Renderer.CreateShadowCubeMap(
|
||||||
|
GraphicsDevice,
|
||||||
|
2048
|
||||||
|
);
|
||||||
|
|
||||||
|
DirectionalShadowMapData = Kav.Renderer.CreateDirectionalShadowMaps(
|
||||||
|
graphicsDevice,
|
||||||
|
2048,
|
||||||
|
4
|
||||||
|
);
|
||||||
|
|
||||||
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
SpriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,7 +266,7 @@ namespace KavTest.Renderers
|
||||||
// ModelTransforms
|
// ModelTransforms
|
||||||
// );
|
// );
|
||||||
|
|
||||||
Renderer.InstancedGBufferRender(
|
Renderer.RenderGBufferInstanced(
|
||||||
GBuffer,
|
GBuffer,
|
||||||
DeferredTarget,
|
DeferredTarget,
|
||||||
camera,
|
camera,
|
||||||
|
@ -263,13 +274,19 @@ namespace KavTest.Renderers
|
||||||
CubeTransforms
|
CubeTransforms
|
||||||
);
|
);
|
||||||
|
|
||||||
//Renderer.DepthRender(
|
Renderer.RenderGBufferIndexed(
|
||||||
// DeferredTarget,
|
GBuffer,
|
||||||
// camera,
|
camera,
|
||||||
// ModelTransforms
|
MeshPartTransforms
|
||||||
//);
|
);
|
||||||
|
|
||||||
Renderer.AmbientLightRender(
|
Renderer.RenderDepthIndexed(
|
||||||
|
DeferredTarget,
|
||||||
|
camera,
|
||||||
|
MeshPartTransforms
|
||||||
|
);
|
||||||
|
|
||||||
|
Renderer.RenderAmbientLight(
|
||||||
DeferredTarget,
|
DeferredTarget,
|
||||||
GPosition,
|
GPosition,
|
||||||
GAlbedo,
|
GAlbedo,
|
||||||
|
@ -278,14 +295,27 @@ namespace KavTest.Renderers
|
||||||
|
|
||||||
foreach (var pointLight in PointLights)
|
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,
|
DeferredTarget,
|
||||||
GPosition,
|
GPosition,
|
||||||
GAlbedo,
|
GAlbedo,
|
||||||
GNormal,
|
GNormal,
|
||||||
GMetallicRoughness,
|
GMetallicRoughness,
|
||||||
|
ShadowCubeMap,
|
||||||
camera,
|
camera,
|
||||||
ModelTransforms,
|
|
||||||
pointLight
|
pointLight
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -294,21 +324,30 @@ namespace KavTest.Renderers
|
||||||
|
|
||||||
if (directionalLight.HasValue)
|
if (directionalLight.HasValue)
|
||||||
{
|
{
|
||||||
Renderer.DirectionalLightToonRender(
|
DirectionalShadowMapData.Clear(GraphicsDevice);
|
||||||
|
|
||||||
|
Renderer.RenderDirectionalShadowsIndexed(
|
||||||
|
DirectionalShadowMapData,
|
||||||
|
camera,
|
||||||
|
MeshPartTransforms,
|
||||||
|
directionalLight.Value
|
||||||
|
);
|
||||||
|
|
||||||
|
Renderer.RenderDirectionalLightToon(
|
||||||
DeferredTarget,
|
DeferredTarget,
|
||||||
GPosition,
|
GPosition,
|
||||||
GAlbedo,
|
GAlbedo,
|
||||||
GNormal,
|
GNormal,
|
||||||
GMetallicRoughness,
|
GMetallicRoughness,
|
||||||
|
DirectionalShadowMapData,
|
||||||
camera,
|
camera,
|
||||||
ModelTransforms,
|
MeshPartTransforms,
|
||||||
directionalLight.Value,
|
directionalLight.Value,
|
||||||
4,
|
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer.SkyboxRender(
|
Renderer.RenderSkybox(
|
||||||
DeferredTarget,
|
DeferredTarget,
|
||||||
camera,
|
camera,
|
||||||
ReadComponent<SkyboxComponent>().Skybox
|
ReadComponent<SkyboxComponent>().Skybox
|
||||||
|
|
Loading…
Reference in New Issue