Kav/Effects/SimpleDepthEffect.cs

77 lines
1.9 KiB
C#
Raw Permalink Normal View History

2020-08-07 00:58:50 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Kav
{
2020-12-08 04:10:27 +00:00
public class SimpleDepthEffect : Effect, IHasWorldMatrix
2020-08-07 00:58:50 +00:00
{
2020-12-08 04:10:27 +00:00
EffectParameter worldParam;
EffectParameter viewProjectionParam;
2020-08-07 00:58:50 +00:00
2020-12-08 04:10:27 +00:00
Matrix world;
2020-08-07 00:58:50 +00:00
Matrix view;
Matrix projection;
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
2020-12-08 04:10:27 +00:00
public Matrix World
2020-08-07 00:58:50 +00:00
{
2020-12-08 04:10:27 +00:00
get { return world; }
2020-08-07 00:58:50 +00:00
set
{
2020-12-08 04:10:27 +00:00
world = value;
dirtyFlags |= EffectDirtyFlags.World;
2020-08-07 00:58:50 +00:00
}
}
public Matrix View
{
get { return view; }
set
{
view = value;
2020-12-08 04:10:27 +00:00
dirtyFlags |= EffectDirtyFlags.ViewProj;
2020-08-07 00:58:50 +00:00
}
}
public Matrix Projection
{
get { return projection; }
set
{
projection = value;
2020-12-08 04:10:27 +00:00
dirtyFlags |= EffectDirtyFlags.ViewProj;
}
}
2020-08-07 00:58:50 +00:00
public SimpleDepthEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.SimpleDepthEffect)
{
CacheEffectParameters();
}
protected override void OnApply()
{
2020-12-08 04:10:27 +00:00
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
{
worldParam.SetValue(world);
dirtyFlags &= ~EffectDirtyFlags.World;
}
if ((dirtyFlags & EffectDirtyFlags.ViewProj) != 0)
2020-08-07 00:58:50 +00:00
{
Matrix.Multiply(ref view, ref projection, out Matrix viewProjection);
2020-12-08 04:10:27 +00:00
viewProjectionParam.SetValue(viewProjection);
dirtyFlags &= ~EffectDirtyFlags.ViewProj;
}
2020-08-07 00:58:50 +00:00
}
private void CacheEffectParameters()
{
2020-12-08 04:10:27 +00:00
worldParam = Parameters["World"];
viewProjectionParam = Parameters["ViewProjection"];
2020-08-07 00:58:50 +00:00
}
}
}