initial directional light test
parent
f38e3443bf
commit
062ad1b976
2
Kav
2
Kav
|
@ -1 +1 @@
|
||||||
Subproject commit 2d1a50e1c439e0d511de82eab6cd2481b1c011f8
|
Subproject commit 393b8bcb03510f2cd87bdef2c6a22731334407dd
|
|
@ -0,0 +1,17 @@
|
||||||
|
using Encompass;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
|
namespace KavTest.Components
|
||||||
|
{
|
||||||
|
public struct DirectionalLightComponent : IComponent
|
||||||
|
{
|
||||||
|
public Color Color { get; }
|
||||||
|
public float Intensity { get; }
|
||||||
|
|
||||||
|
public DirectionalLightComponent(Color color, float intensity)
|
||||||
|
{
|
||||||
|
Color = color;
|
||||||
|
Intensity = intensity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,11 +74,23 @@ namespace KavTest
|
||||||
));
|
));
|
||||||
|
|
||||||
WorldBuilder.SendMessage(new LightBulbSpawnMessage(
|
WorldBuilder.SendMessage(new LightBulbSpawnMessage(
|
||||||
new Transform3D(new Vector3(0, 2, -5)),
|
new Transform3D(new Vector3(-5, 2, -5)),
|
||||||
Color.White,
|
Color.White,
|
||||||
300f
|
300f
|
||||||
));
|
));
|
||||||
|
|
||||||
|
var directionalLightEntity = WorldBuilder.CreateEntity();
|
||||||
|
WorldBuilder.SetComponent(directionalLightEntity, new Transform3DComponent(
|
||||||
|
new Transform3D(
|
||||||
|
Vector3.Zero,
|
||||||
|
Quaternion.CreateFromAxisAngle(Vector3.Right, Microsoft.Xna.Framework.MathHelper.PiOver2)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
WorldBuilder.SetComponent(directionalLightEntity, new DirectionalLightComponent(
|
||||||
|
Color.Blue,
|
||||||
|
2f
|
||||||
|
));
|
||||||
|
|
||||||
var cameraEntity = WorldBuilder.CreateEntity();
|
var cameraEntity = WorldBuilder.CreateEntity();
|
||||||
WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent(
|
WorldBuilder.SetComponent(cameraEntity, new ArcballTransformComponent(
|
||||||
new ArcballTransform(
|
new ArcballTransform(
|
||||||
|
|
|
@ -3,15 +3,16 @@ using System.Collections.Generic;
|
||||||
using Encompass;
|
using Encompass;
|
||||||
using Kav;
|
using Kav;
|
||||||
using KavTest.Components;
|
using KavTest.Components;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace KavTest.Renderers
|
namespace KavTest.Renderers
|
||||||
{
|
{
|
||||||
public class SceneRenderer : GeneralRenderer
|
public class SceneRenderer : GeneralRenderer
|
||||||
{
|
{
|
||||||
private GraphicsDevice GraphicsDevice { get; }
|
private Kav.Renderer Renderer { get; }
|
||||||
|
|
||||||
private IEnumerable<Kav.Model> Models
|
private IEnumerable<(Kav.Model, Matrix)> ModelTransforms
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
@ -19,9 +20,7 @@ namespace KavTest.Renderers
|
||||||
{
|
{
|
||||||
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
||||||
var modelComponent = GetComponent<ModelComponent>(entity);
|
var modelComponent = GetComponent<ModelComponent>(entity);
|
||||||
|
yield return (modelComponent.Model, transformComponent.Transform.TransformMatrix);
|
||||||
modelComponent.Model.ApplyTransform(transformComponent.Transform.TransformMatrix);
|
|
||||||
yield return modelComponent.Model;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +35,7 @@ namespace KavTest.Renderers
|
||||||
var pointLightComponent = GetComponent<PointLightComponent>(entity);
|
var pointLightComponent = GetComponent<PointLightComponent>(entity);
|
||||||
|
|
||||||
yield return new PointLight(
|
yield return new PointLight(
|
||||||
transformComponent.Transform.TransformMatrix.Translation,
|
transformComponent.Transform.Position,
|
||||||
pointLightComponent.Color,
|
pointLightComponent.Color,
|
||||||
pointLightComponent.Intensity
|
pointLightComponent.Intensity
|
||||||
);
|
);
|
||||||
|
@ -44,9 +43,27 @@ namespace KavTest.Renderers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<Kav.DirectionalLight> DirectionalLights
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (var entity in ReadEntitiesAsEnumerable<DirectionalLightComponent>())
|
||||||
|
{
|
||||||
|
var transformComponent = GetComponent<Transform3DComponent>(entity);
|
||||||
|
var directionalLightComponent = GetComponent<DirectionalLightComponent>(entity);
|
||||||
|
|
||||||
|
yield return new Kav.DirectionalLight(
|
||||||
|
transformComponent.Transform.Forward,
|
||||||
|
directionalLightComponent.Color,
|
||||||
|
directionalLightComponent.Intensity
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SceneRenderer(GraphicsDevice graphicsDevice)
|
public SceneRenderer(GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
GraphicsDevice = graphicsDevice;
|
Renderer = new Kav.Renderer(graphicsDevice, graphicsDevice.PresentationParameters.BackBufferWidth, graphicsDevice.PresentationParameters.BackBufferHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Render()
|
public override void Render()
|
||||||
|
@ -62,11 +79,27 @@ namespace KavTest.Renderers
|
||||||
cameraComponent.Projection
|
cameraComponent.Projection
|
||||||
);
|
);
|
||||||
|
|
||||||
Kav.Renderer.Render(
|
// if (SomeComponent<DirectionalLightComponent>())
|
||||||
GraphicsDevice,
|
// {
|
||||||
|
// 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(
|
||||||
|
// ModelTransforms,
|
||||||
|
// new Kav.DirectionalLight(
|
||||||
|
// directionalLightTransformComponent.Transform.Forward,
|
||||||
|
// directionalLightComponent.Color,
|
||||||
|
// directionalLightComponent.Intensity
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
Renderer.Render(
|
||||||
camera,
|
camera,
|
||||||
Models,
|
ModelTransforms,
|
||||||
PointLights
|
PointLights,
|
||||||
|
DirectionalLights
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue