From a92a8de50a5c2a9d687d08498547047038a8d0b8 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 16 Sep 2020 12:59:31 -0700 Subject: [PATCH] shadow map with fixed projection --- .gitmodules | 3 ++ Kav | 2 +- KavTest/Content/floor.glb | Bin 0 -> 2300 bytes .../Spawners/DirectionalLightSpawner.cs | 18 ++++++++ .../Engines/Spawners/StaticModelSpawner.cs | 17 ++++++++ KavTest/KavTest.Core.csproj | 1 + KavTest/KavTest.Framework.csproj | 1 + KavTest/KavTestGame.cs | 40 +++++++++++++----- .../Messages/DirectionalLightSpawnMessage.cs | 19 +++++++++ KavTest/Messages/StaticModelSpawnMessage.cs | 17 ++++++++ KavTest/Renderers/SceneRenderer.cs | 25 +++++------ MoonTools.Bonk | 1 + 12 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 KavTest/Content/floor.glb create mode 100644 KavTest/Engines/Spawners/DirectionalLightSpawner.cs create mode 100644 KavTest/Engines/Spawners/StaticModelSpawner.cs create mode 100644 KavTest/Messages/DirectionalLightSpawnMessage.cs create mode 100644 KavTest/Messages/StaticModelSpawnMessage.cs create mode 160000 MoonTools.Bonk diff --git a/.gitmodules b/.gitmodules index b2694e7..b74f8b4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "MoonTools.Curve"] path = MoonTools.Curve url = https://gitea.moonside.games/MoonsideGames/MoonTools.Curve.git +[submodule "MoonTools.Bonk"] + path = MoonTools.Bonk + url = https://gitea.moonside.games/MoonsideGames/MoonTools.Bonk.git diff --git a/Kav b/Kav index 28bc8c7..3540e09 160000 --- a/Kav +++ b/Kav @@ -1 +1 @@ -Subproject commit 28bc8c79e75dd0fbc60d57586b82de89523ee5f8 +Subproject commit 3540e098d55e3b8edc4e78504487576e07537ec8 diff --git a/KavTest/Content/floor.glb b/KavTest/Content/floor.glb new file mode 100644 index 0000000000000000000000000000000000000000..4c763b5acfbc3410d4abc3fafc202046552fd621 GIT binary patch literal 2300 zcmb7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ot80(6k? z=>?nvm`F*BM@m|pr(PfF`xb{3nW otpf-`I0;#PhovZz9L_fZ^$!PpOJ6Lza*?D#{d8T literal 0 HcmV?d00001 diff --git a/KavTest/Engines/Spawners/DirectionalLightSpawner.cs b/KavTest/Engines/Spawners/DirectionalLightSpawner.cs new file mode 100644 index 0000000..04186e8 --- /dev/null +++ b/KavTest/Engines/Spawners/DirectionalLightSpawner.cs @@ -0,0 +1,18 @@ +using Encompass; +using KavTest.Components; +using KavTest.Messages; +using Microsoft.Xna.Framework; + +namespace KavTest.Spawners +{ + public class DirectionalLightSpawner : Spawner + { + 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)); + } + } +} diff --git a/KavTest/Engines/Spawners/StaticModelSpawner.cs b/KavTest/Engines/Spawners/StaticModelSpawner.cs new file mode 100644 index 0000000..772d3e3 --- /dev/null +++ b/KavTest/Engines/Spawners/StaticModelSpawner.cs @@ -0,0 +1,17 @@ +using Encompass; +using KavTest.Components; +using KavTest.Messages; + +namespace KavTest.Spawners +{ + public class StaticModelSpawner : Spawner + { + protected override void Spawn(in StaticModelSpawnMessage message) + { + var entity = CreateEntity(); + + AddComponent(entity, new Transform3DComponent(message.Transform)); + AddComponent(entity, new ModelComponent(message.Model)); + } + } +} diff --git a/KavTest/KavTest.Core.csproj b/KavTest/KavTest.Core.csproj index 9659426..c2c879a 100644 --- a/KavTest/KavTest.Core.csproj +++ b/KavTest/KavTest.Core.csproj @@ -28,6 +28,7 @@ + diff --git a/KavTest/KavTest.Framework.csproj b/KavTest/KavTest.Framework.csproj index 61efb2a..c5d1593 100644 --- a/KavTest/KavTest.Framework.csproj +++ b/KavTest/KavTest.Framework.csproj @@ -31,6 +31,7 @@ + diff --git a/KavTest/KavTestGame.cs b/KavTest/KavTestGame.cs index 04eb265..3c53b70 100644 --- a/KavTest/KavTestGame.cs +++ b/KavTest/KavTestGame.cs @@ -58,6 +58,11 @@ namespace KavTest 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 AngularVelocityEngine()); WorldBuilder.AddEngine(new MoveAlongCurve3DEngine()); @@ -65,6 +70,8 @@ namespace KavTest WorldBuilder.AddEngine(new CameraEngine()); WorldBuilder.AddEngine(new RustyBallSpawner(rustyBallModel)); WorldBuilder.AddEngine(new LightBulbSpawner(lightBulbModel)); + WorldBuilder.AddEngine(new StaticModelSpawner()); + WorldBuilder.AddEngine(new DirectionalLightSpawner()); WorldBuilder.AddGeneralRenderer(new SceneRenderer(GraphicsDevice), 0); WorldBuilder.SendMessage(new RustyBallSpawnMessage( @@ -82,6 +89,11 @@ namespace KavTest 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++) { var start = RandomHelper.RandomVector3(-5, 5); @@ -94,18 +106,24 @@ namespace KavTest )); } - var directionalLightEntity = WorldBuilder.CreateEntity(); - WorldBuilder.SetComponent(directionalLightEntity, new Transform3DComponent( - new Transform3D( - Vector3.Zero, - 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.PiOver2 + 0.1f), + Color.GhostWhite, + 0.1f )); + // 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(); WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent( new ArcballTransform( @@ -119,7 +137,7 @@ namespace KavTest Microsoft.Xna.Framework.MathHelper.PiOver4, 16f / 9f, 0.1f, - 200f + 100f ) )); diff --git a/KavTest/Messages/DirectionalLightSpawnMessage.cs b/KavTest/Messages/DirectionalLightSpawnMessage.cs new file mode 100644 index 0000000..6f21616 --- /dev/null +++ b/KavTest/Messages/DirectionalLightSpawnMessage.cs @@ -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; + } + } +} diff --git a/KavTest/Messages/StaticModelSpawnMessage.cs b/KavTest/Messages/StaticModelSpawnMessage.cs new file mode 100644 index 0000000..7a1f103 --- /dev/null +++ b/KavTest/Messages/StaticModelSpawnMessage.cs @@ -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; + } + } +} diff --git a/KavTest/Renderers/SceneRenderer.cs b/KavTest/Renderers/SceneRenderer.cs index 3fdd54e..1ec5c90 100644 --- a/KavTest/Renderers/SceneRenderer.cs +++ b/KavTest/Renderers/SceneRenderer.cs @@ -60,22 +60,17 @@ namespace KavTest.Renderers } } - private IEnumerable DirectionalLights + private Kav.DirectionalLight DirectionalLight() { - get - { - foreach (var entity in ReadEntitiesAsEnumerable()) - { - var transformComponent = GetComponent(entity); - var directionalLightComponent = GetComponent(entity); + var entity = ReadEntity(); + var transformComponent = GetComponent(entity); + var directionalLightComponent = GetComponent(entity); - yield return new Kav.DirectionalLight( - transformComponent.Transform.Forward, - directionalLightComponent.Color, - directionalLightComponent.Intensity - ); - } - } + return new Kav.DirectionalLight( + transformComponent.Transform.Forward, + directionalLightComponent.Color, + directionalLightComponent.Intensity + ); } public SceneRenderer(GraphicsDevice graphicsDevice) @@ -116,7 +111,7 @@ namespace KavTest.Renderers camera, ModelTransforms, PointLights, - DirectionalLights + DirectionalLight() ); // foreach (var directionalLight in DirectionalLights) diff --git a/MoonTools.Bonk b/MoonTools.Bonk new file mode 160000 index 0000000..2f341aa --- /dev/null +++ b/MoonTools.Bonk @@ -0,0 +1 @@ +Subproject commit 2f341aaeae07d2cb9b8f9be0ff5688543dcd582b