68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
|
using Microsoft.Xna.Framework;
|
||
|
using Microsoft.Xna.Framework.Graphics;
|
||
|
|
||
|
namespace Kav
|
||
|
{
|
||
|
public class LinearDepthEffectInstanced : Effect
|
||
|
{
|
||
|
EffectParameter viewProjectionParam;
|
||
|
EffectParameter lightPositionParam;
|
||
|
EffectParameter farPlaneParam;
|
||
|
|
||
|
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
|
||
|
|
||
|
Matrix view;
|
||
|
Matrix projection;
|
||
|
|
||
|
public Vector3 LightPosition { get; set; }
|
||
|
public float FarPlane { get; set; }
|
||
|
|
||
|
public Matrix View
|
||
|
{
|
||
|
get { return view; }
|
||
|
set
|
||
|
{
|
||
|
view = value;
|
||
|
dirtyFlags |= EffectDirtyFlags.ViewProj;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Matrix Projection
|
||
|
{
|
||
|
get { return projection; }
|
||
|
set
|
||
|
{
|
||
|
projection = value;
|
||
|
dirtyFlags |= EffectDirtyFlags.ViewProj;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public LinearDepthEffectInstanced(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.LinearDepthEffectInstanced)
|
||
|
{
|
||
|
CacheEffectParameters();
|
||
|
}
|
||
|
|
||
|
protected override void OnApply()
|
||
|
{
|
||
|
if ((dirtyFlags & EffectDirtyFlags.ViewProj) != 0)
|
||
|
{
|
||
|
Matrix.Multiply(ref view, ref projection, out Matrix viewProjection);
|
||
|
viewProjectionParam.SetValue(viewProjection);
|
||
|
|
||
|
dirtyFlags &= ~EffectDirtyFlags.ViewProj;
|
||
|
}
|
||
|
|
||
|
lightPositionParam.SetValue(LightPosition);
|
||
|
farPlaneParam.SetValue(FarPlane);
|
||
|
}
|
||
|
|
||
|
private void CacheEffectParameters()
|
||
|
{
|
||
|
viewProjectionParam = Parameters["ViewProjection"];
|
||
|
|
||
|
lightPositionParam = Parameters["LightPosition"];
|
||
|
farPlaneParam = Parameters["FarPlane"];
|
||
|
}
|
||
|
}
|
||
|
}
|