shadow map with fixed projection

pull/1/head
cosmonaut 2020-09-16 12:59:31 -07:00
parent 6de9ee7434
commit a92a8de50a
12 changed files with 117 additions and 27 deletions

3
.gitmodules vendored
View File

@ -13,3 +13,6 @@
[submodule "MoonTools.Curve"] [submodule "MoonTools.Curve"]
path = MoonTools.Curve path = MoonTools.Curve
url = https://gitea.moonside.games/MoonsideGames/MoonTools.Curve.git url = https://gitea.moonside.games/MoonsideGames/MoonTools.Curve.git
[submodule "MoonTools.Bonk"]
path = MoonTools.Bonk
url = https://gitea.moonside.games/MoonsideGames/MoonTools.Bonk.git

2
Kav

@ -1 +1 @@
Subproject commit 28bc8c79e75dd0fbc60d57586b82de89523ee5f8 Subproject commit 3540e098d55e3b8edc4e78504487576e07537ec8

BIN
KavTest/Content/floor.glb Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
using Encompass;
using KavTest.Components;
using KavTest.Messages;
using Microsoft.Xna.Framework;
namespace KavTest.Spawners
{
public class DirectionalLightSpawner : Spawner<DirectionalLightSpawnMessage>
{
protected override void Spawn(in DirectionalLightSpawnMessage message)
{
var entity = CreateEntity();
AddComponent(entity, new Transform3DComponent(new Transform3D(Vector3.Zero, message.Orientation)));
AddComponent(entity, new DirectionalLightComponent(message.Color, message.Intensity));
}
}
}

View File

@ -0,0 +1,17 @@
using Encompass;
using KavTest.Components;
using KavTest.Messages;
namespace KavTest.Spawners
{
public class StaticModelSpawner : Spawner<StaticModelSpawnMessage>
{
protected override void Spawn(in StaticModelSpawnMessage message)
{
var entity = CreateEntity();
AddComponent(entity, new Transform3DComponent(message.Transform));
AddComponent(entity, new ModelComponent(message.Model));
}
}
}

View File

@ -28,6 +28,7 @@
<ProjectReference Include="..\Kav\Kav.Core.csproj" /> <ProjectReference Include="..\Kav\Kav.Core.csproj" />
<ProjectReference Include="..\Smuggler\Smuggler.Core.csproj" /> <ProjectReference Include="..\Smuggler\Smuggler.Core.csproj" />
<ProjectReference Include="..\MoonTools.Curve\Curve\Curve.csproj" /> <ProjectReference Include="..\MoonTools.Curve\Curve\Curve.csproj" />
<ProjectReference Include="..\MoonTools.Bonk\Bonk\Bonk.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\build\CopyFNALibs.targets"/> <Import Project="..\build\CopyFNALibs.targets"/>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" /> <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

View File

@ -31,6 +31,7 @@
<ProjectReference Include="..\Kav\Kav.Framework.csproj" /> <ProjectReference Include="..\Kav\Kav.Framework.csproj" />
<ProjectReference Include="..\Smuggler\Smuggler.Framework.csproj" /> <ProjectReference Include="..\Smuggler\Smuggler.Framework.csproj" />
<ProjectReference Include="..\MoonTools.Curve\Curve\Curve.csproj" /> <ProjectReference Include="..\MoonTools.Curve\Curve\Curve.csproj" />
<ProjectReference Include="..\MoonTools.Bonk\Bonk\Bonk.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\build\CopyFNALibs.targets"/> <Import Project="..\build\CopyFNALibs.targets"/>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" /> <Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />

View File

@ -58,6 +58,11 @@ namespace KavTest
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/cube.glb")) Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/cube.glb"))
); );
var floorModel = Kav.ModelLoader.Load(
GraphicsDevice,
Smuggler.Importer.ImportGLB(GraphicsDevice, File.OpenRead("Content/floor.glb"))
);
WorldBuilder.AddEngine(new InputEngine(this)); WorldBuilder.AddEngine(new InputEngine(this));
WorldBuilder.AddEngine(new AngularVelocityEngine()); WorldBuilder.AddEngine(new AngularVelocityEngine());
WorldBuilder.AddEngine(new MoveAlongCurve3DEngine()); WorldBuilder.AddEngine(new MoveAlongCurve3DEngine());
@ -65,6 +70,8 @@ namespace KavTest
WorldBuilder.AddEngine(new CameraEngine()); WorldBuilder.AddEngine(new CameraEngine());
WorldBuilder.AddEngine(new RustyBallSpawner(rustyBallModel)); WorldBuilder.AddEngine(new RustyBallSpawner(rustyBallModel));
WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel)); WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel));
WorldBuilder.AddEngine(new StaticModelSpawner());
WorldBuilder.AddEngine(new DirectionalLightSpawner());
WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0); WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0);
WorldBuilder.SendMessage(new RustyBallSpawnMessage( WorldBuilder.SendMessage(new RustyBallSpawnMessage(
@ -82,6 +89,11 @@ namespace KavTest
new Vector3(-1, 1, 1) new Vector3(-1, 1, 1)
)); ));
WorldBuilder.SendMessage(new StaticModelSpawnMessage(
new Transform3D(new Vector3(0, -3, 0), Quaternion.Identity, new Vector3(10f, 1f, 10f)),
floorModel
));
for (var i = 0; i < 1; i++) for (var i = 0; i < 1; i++)
{ {
var start = RandomHelper.RandomVector3(-5, 5); var start = RandomHelper.RandomVector3(-5, 5);
@ -94,18 +106,24 @@ namespace KavTest
)); ));
} }
var directionalLightEntity = WorldBuilder.CreateEntity(); WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
WorldBuilder.SetComponent(directionalLightEntity, new Transform3DComponent( Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2 + 0.1f),
new Transform3D( Color.GhostWhite,
Vector3.Zero, 0.1f
Quaternion.CreateFromAxisAngle(Vector3.Up, Microsoft.Xna.Framework.MathHelper.PiOver2)
)
));
WorldBuilder.SetComponent(directionalLightEntity, new DirectionalLightComponent(
Color.Blue,
2f
)); ));
// WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
// Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver4),
// Color.GhostWhite,
// 0.1f
// ));
// WorldBuilder.SendMessage(new DirectionalLightSpawnMessage(
// Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2 + Microsoft.Xna.Framework.MathHelper.PiOver4),
// Color.GhostWhite,
// 0.1f
// ));
var cameraEntity = WorldBuilder.CreateEntity(); var cameraEntity = WorldBuilder.CreateEntity();
WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent( WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent(
new ArcballTransform( new ArcballTransform(
@ -119,7 +137,7 @@ namespace KavTest
Microsoft.Xna.Framework.MathHelper.PiOver4, Microsoft.Xna.Framework.MathHelper.PiOver4,
16f / 9f, 16f / 9f,
0.1f, 0.1f,
200f 100f
) )
)); ));

View File

@ -0,0 +1,19 @@
using Encompass;
using Microsoft.Xna.Framework;
namespace KavTest.Messages
{
public struct DirectionalLightSpawnMessage : IMessage
{
public Quaternion Orientation { get; }
public Color Color { get; }
public float Intensity { get; }
public DirectionalLightSpawnMessage(Quaternion orientation, Color color, float intensity)
{
Orientation = orientation;
Color = color;
Intensity = intensity;
}
}
}

View File

@ -0,0 +1,17 @@
using Encompass;
using Kav;
namespace KavTest.Messages
{
public struct StaticModelSpawnMessage : IMessage
{
public Transform3D Transform { get; }
public Model Model { get; }
public StaticModelSpawnMessage(Transform3D transform, Model model)
{
Transform = transform;
Model = model;
}
}
}

View File

@ -60,23 +60,18 @@ namespace KavTest.Renderers
} }
} }
private IEnumerable<Kav.DirectionalLight> DirectionalLights private Kav.DirectionalLight DirectionalLight()
{
get
{
foreach (var entity in ReadEntitiesAsEnumerable<DirectionalLightComponent>())
{ {
var entity = ReadEntity<DirectionalLightComponent>();
var transformComponent = GetComponent<Transform3DComponent>(entity); var transformComponent = GetComponent<Transform3DComponent>(entity);
var directionalLightComponent = GetComponent<DirectionalLightComponent>(entity); var directionalLightComponent = GetComponent<DirectionalLightComponent>(entity);
yield return new Kav.DirectionalLight( return new Kav.DirectionalLight(
transformComponent.Transform.Forward, transformComponent.Transform.Forward,
directionalLightComponent.Color, directionalLightComponent.Color,
directionalLightComponent.Intensity directionalLightComponent.Intensity
); );
} }
}
}
public SceneRenderer(GraphicsDevice graphicsDevice) public SceneRenderer(GraphicsDevice graphicsDevice)
{ {
@ -116,7 +111,7 @@ namespace KavTest.Renderers
camera, camera,
ModelTransforms, ModelTransforms,
PointLights, PointLights,
DirectionalLights DirectionalLight()
); );
// foreach (var directionalLight in DirectionalLights) // foreach (var directionalLight in DirectionalLights)

1
MoonTools.Bonk Submodule

@ -0,0 +1 @@
Subproject commit 2f341aaeae07d2cb9b8f9be0ff5688543dcd582b