78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace Kav
|
|
{
|
|
public class SkyboxEffect : Effect
|
|
{
|
|
EffectParameter viewProjectionParam;
|
|
EffectParameter skyboxParam;
|
|
|
|
Matrix view;
|
|
Matrix projection;
|
|
TextureCube skybox;
|
|
|
|
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
|
|
|
|
public Matrix View
|
|
{
|
|
get { return view; }
|
|
set
|
|
{
|
|
view = value;
|
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
|
}
|
|
}
|
|
|
|
public Matrix Projection
|
|
{
|
|
get { return projection; }
|
|
set
|
|
{
|
|
projection = value;
|
|
dirtyFlags |= EffectDirtyFlags.WorldViewProj;
|
|
}
|
|
}
|
|
|
|
public TextureCube Skybox
|
|
{
|
|
get { return skybox; }
|
|
set
|
|
{
|
|
skybox = value;
|
|
dirtyFlags |= EffectDirtyFlags.World; // hack flag but whatever
|
|
}
|
|
}
|
|
|
|
public SkyboxEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.SkyboxEffect)
|
|
{
|
|
CacheEffectParameters();
|
|
}
|
|
|
|
protected override void OnApply()
|
|
{
|
|
if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
|
|
{
|
|
Matrix.Multiply(ref view, ref projection, out Matrix viewProjection);
|
|
|
|
viewProjectionParam.SetValue(viewProjection);
|
|
|
|
dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
|
|
}
|
|
|
|
if ((dirtyFlags & EffectDirtyFlags.World) != 0)
|
|
{
|
|
skyboxParam.SetValue(skybox);
|
|
|
|
dirtyFlags &= ~EffectDirtyFlags.World;
|
|
}
|
|
}
|
|
|
|
private void CacheEffectParameters()
|
|
{
|
|
viewProjectionParam = Parameters["ViewProjection"];
|
|
skyboxParam = Parameters["skybox"];
|
|
}
|
|
}
|
|
}
|