Kav/Effects/PointLightCollection.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2020-08-23 00:52:44 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Kav
{
public class PointLightCollection
{
private readonly Vector3[] positions;
private readonly Vector3[] colors;
2020-08-23 01:00:04 +00:00
private readonly float[] intensities;
2020-08-23 00:52:44 +00:00
readonly EffectParameter lightPositionsParam;
readonly EffectParameter lightColorsParam;
public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam, int maxLights)
{
this.positions = new Vector3[maxLights];
this.colors = new Vector3[maxLights];
2020-08-23 01:00:04 +00:00
this.intensities = new float[maxLights];
2020-08-23 00:52:44 +00:00
this.lightPositionsParam = lightPositionsParam;
this.lightColorsParam = lightColorsParam;
}
public PointLight this[int i]
{
get
{
var color = colors[i] / intensities[i];
return new PointLight(
positions[i],
new Color(
color.X,
color.Y,
color.Z,
1f
),
intensities[i]
);
}
set
{
positions[i] = value.Position;
colors[i] = value.Color.ToVector3() * value.Intensity;
intensities[i] = value.Intensity;
lightPositionsParam.SetValue(positions);
lightColorsParam.SetValue(colors);
}
}
}
}