Kav/Effects/PointLightCollection.cs

50 lines
1.5 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Kav
{
public class PointLightCollection
{
private readonly Vector3[] positions;
private readonly Vector3[] colors;
private readonly float[] intensities;
readonly EffectParameter lightPositionsParam;
readonly EffectParameter lightColorsParam;
public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam, int maxLights)
{
this.positions = new Vector3[maxLights];
this.colors = new Vector3[maxLights];
this.intensities = new float[maxLights];
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;
2020-12-10 00:28:40 +00:00
colors[i] = value.Color.ToVector3() * value.Radius;
lightPositionsParam.SetValue(positions);
lightColorsParam.SetValue(colors);
}
}
}
}