2020-08-27 18:14:17 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
|
|
|
public class DirectionalLightCollection
|
|
|
|
{
|
2020-08-28 08:12:17 +00:00
|
|
|
private readonly Vector3[] directions = new Vector3[6];
|
|
|
|
private readonly Vector3[] colors = new Vector3[6];
|
|
|
|
private readonly float[] intensities = new float[6];
|
2020-09-08 06:50:49 +00:00
|
|
|
private readonly Matrix[] viewMatrices = new Matrix[6];
|
|
|
|
private readonly Matrix[] projectionMatrices = new Matrix[6];
|
|
|
|
private readonly Matrix[] viewProjectionMatrices = new Matrix[6];
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
readonly EffectParameter lightDirectionsParam;
|
|
|
|
readonly EffectParameter lightColorsParam;
|
2020-08-28 05:57:15 +00:00
|
|
|
readonly EffectParameter lightSpaceMatricesParam;
|
2020-08-27 18:14:17 +00:00
|
|
|
|
2020-08-28 05:57:15 +00:00
|
|
|
public DirectionalLightCollection(
|
|
|
|
EffectParameter lightDirectionsParam,
|
|
|
|
EffectParameter lightColorsParam,
|
|
|
|
EffectParameter lightSpaceMatricesParam
|
|
|
|
) {
|
2020-08-27 18:14:17 +00:00
|
|
|
this.lightDirectionsParam = lightDirectionsParam;
|
|
|
|
this.lightColorsParam = lightColorsParam;
|
2020-08-28 05:57:15 +00:00
|
|
|
this.lightSpaceMatricesParam = lightSpaceMatricesParam;
|
2020-08-27 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 06:50:49 +00:00
|
|
|
public void SetMatrices(int index, Matrix view, Matrix projection)
|
|
|
|
{
|
|
|
|
viewMatrices[index] = view;
|
|
|
|
projectionMatrices[index] = projection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Apply()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
viewProjectionMatrices[i] = viewMatrices[i] * projectionMatrices[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
lightSpaceMatricesParam.SetValue(viewProjectionMatrices);
|
|
|
|
}
|
|
|
|
|
2020-08-27 18:14:17 +00:00
|
|
|
public DirectionalLight this[int i]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
var color = colors[i] / intensities[i];
|
|
|
|
return new DirectionalLight(
|
|
|
|
directions[i],
|
|
|
|
new Color(
|
|
|
|
color.X,
|
|
|
|
color.Y,
|
|
|
|
color.Z,
|
|
|
|
1f
|
|
|
|
),
|
|
|
|
intensities[i]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
directions[i] = value.Direction;
|
|
|
|
colors[i] = value.Color.ToVector3() * value.Intensity;
|
|
|
|
intensities[i] = value.Intensity;
|
|
|
|
lightDirectionsParam.SetValue(directions);
|
|
|
|
lightColorsParam.SetValue(colors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|