142 lines
4.3 KiB
C#
142 lines
4.3 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
namespace Kav
|
|
{
|
|
public class DeferredPBR_PointLightEffect : Effect
|
|
{
|
|
EffectParameter gPositionParam;
|
|
EffectParameter gAlbedoParam;
|
|
EffectParameter gNormalParam;
|
|
EffectParameter gMetallicRoughnessParam;
|
|
EffectParameter shadowMapParam;
|
|
|
|
EffectParameter eyePositionParam;
|
|
|
|
EffectParameter pointLightColorParam;
|
|
EffectParameter pointLightPositionParam;
|
|
|
|
EffectParameter farPlaneParam;
|
|
|
|
EffectParameter worldViewProjectionParam;
|
|
|
|
public Texture2D GPosition { get; set; }
|
|
public Texture2D GAlbedo { get; set; }
|
|
public Texture2D GNormal { get; set; }
|
|
public Texture2D GMetallicRoughness { get; set; }
|
|
public TextureCube ShadowMap { get; set; }
|
|
|
|
public Vector3 EyePosition { get; set; }
|
|
|
|
public Vector3 PointLightPosition { get; set; }
|
|
public Vector3 PointLightColor { get; set; }
|
|
|
|
public float FarPlane { get; set; }
|
|
|
|
Matrix world = Matrix.Identity;
|
|
Matrix view = Matrix.Identity;
|
|
Matrix projection = Matrix.Identity;
|
|
|
|
EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
|
|
|
|
public Matrix World
|
|
{
|
|
get { return world; }
|
|
set
|
|
{
|
|
world = 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;
|
|
}
|
|
}
|
|
|
|
public DeferredPBR_PointLightEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.DeferredPBR_PointLightEffect)
|
|
{
|
|
CacheEffectParameters();
|
|
}
|
|
|
|
public DeferredPBR_PointLightEffect(DeferredPBR_PointLightEffect cloneSource) : base(cloneSource)
|
|
{
|
|
CacheEffectParameters();
|
|
|
|
GPosition = cloneSource.GPosition;
|
|
GAlbedo = cloneSource.GAlbedo;
|
|
GNormal = cloneSource.GNormal;
|
|
GMetallicRoughness = cloneSource.GMetallicRoughness;
|
|
ShadowMap = cloneSource.ShadowMap;
|
|
|
|
EyePosition = cloneSource.EyePosition;
|
|
|
|
PointLightPosition = cloneSource.PointLightPosition;
|
|
PointLightColor = cloneSource.PointLightColor;
|
|
|
|
FarPlane = cloneSource.FarPlane;
|
|
}
|
|
|
|
public override Effect Clone()
|
|
{
|
|
return new DeferredPBR_PointLightEffect(this);
|
|
}
|
|
|
|
protected override void OnApply()
|
|
{
|
|
gPositionParam.SetValue(GPosition);
|
|
gAlbedoParam.SetValue(GAlbedo);
|
|
gNormalParam.SetValue(GNormal);
|
|
gMetallicRoughnessParam.SetValue(GMetallicRoughness);
|
|
shadowMapParam.SetValue(ShadowMap);
|
|
|
|
eyePositionParam.SetValue(EyePosition);
|
|
|
|
pointLightPositionParam.SetValue(PointLightPosition);
|
|
pointLightColorParam.SetValue(PointLightColor);
|
|
|
|
farPlaneParam.SetValue(FarPlane);
|
|
|
|
if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
|
|
{
|
|
worldViewProjectionParam.SetValue(world * view * projection);
|
|
|
|
dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
|
|
}
|
|
}
|
|
|
|
void CacheEffectParameters()
|
|
{
|
|
gPositionParam = Parameters["gPosition"];
|
|
gAlbedoParam = Parameters["gAlbedo"];
|
|
gNormalParam = Parameters["gNormal"];
|
|
gMetallicRoughnessParam = Parameters["gMetallicRoughness"];
|
|
shadowMapParam = Parameters["shadowMap"];
|
|
|
|
eyePositionParam = Parameters["EyePosition"];
|
|
|
|
pointLightPositionParam = Parameters["PointLightPosition"];
|
|
pointLightColorParam = Parameters["PointLightColor"];
|
|
|
|
farPlaneParam = Parameters["FarPlane"];
|
|
|
|
worldViewProjectionParam = Parameters["WorldViewProjection"];
|
|
}
|
|
}
|
|
}
|