2020-08-07 00:58:50 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
|
|
|
public class SimpleDepthEffect : Effect
|
|
|
|
{
|
|
|
|
EffectParameter modelViewProjectionParam;
|
|
|
|
|
|
|
|
Matrix model;
|
|
|
|
Matrix view;
|
|
|
|
Matrix projection;
|
|
|
|
|
|
|
|
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
|
|
|
|
|
|
|
|
public Matrix Model
|
|
|
|
{
|
|
|
|
get { return model; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
model = value;
|
|
|
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Matrix View
|
|
|
|
{
|
|
|
|
get { return view; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
view = value;
|
|
|
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Matrix Projection
|
|
|
|
{
|
|
|
|
get { return projection; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
projection = value;
|
|
|
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
|
|
|
}
|
|
|
|
}
|
2020-10-01 19:46:25 +00:00
|
|
|
|
2020-08-07 00:58:50 +00:00
|
|
|
public SimpleDepthEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.SimpleDepthEffect)
|
|
|
|
{
|
|
|
|
CacheEffectParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnApply()
|
|
|
|
{
|
|
|
|
if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
|
|
|
|
{
|
2020-10-01 19:46:25 +00:00
|
|
|
Matrix.Multiply(ref view, ref projection, out Matrix viewProjection);
|
|
|
|
Matrix.Multiply(ref model, ref viewProjection, out Matrix worldViewProj);
|
2020-08-07 00:58:50 +00:00
|
|
|
|
|
|
|
modelViewProjectionParam.SetValue(worldViewProj);
|
|
|
|
|
|
|
|
dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CacheEffectParameters()
|
|
|
|
{
|
|
|
|
modelViewProjectionParam = Parameters["ModelViewProjection"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|