2020-10-01 19:46:25 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
|
|
|
public class DeferredPBR_PointLightEffect : Effect
|
|
|
|
{
|
|
|
|
EffectParameter gPositionParam;
|
|
|
|
EffectParameter gAlbedoParam;
|
|
|
|
EffectParameter gNormalParam;
|
|
|
|
EffectParameter gMetallicRoughnessParam;
|
2020-10-19 10:01:37 +00:00
|
|
|
EffectParameter shadowMapParam;
|
2020-10-01 19:46:25 +00:00
|
|
|
|
|
|
|
EffectParameter eyePositionParam;
|
|
|
|
|
|
|
|
EffectParameter pointLightColorParam;
|
|
|
|
EffectParameter pointLightPositionParam;
|
|
|
|
|
2020-10-19 10:01:37 +00:00
|
|
|
EffectParameter farPlaneParam;
|
|
|
|
|
2020-12-10 00:10:53 +00:00
|
|
|
EffectParameter worldViewProjectionParam;
|
|
|
|
|
2020-10-01 19:46:25 +00:00
|
|
|
public Texture2D GPosition { get; set; }
|
|
|
|
public Texture2D GAlbedo { get; set; }
|
|
|
|
public Texture2D GNormal { get; set; }
|
|
|
|
public Texture2D GMetallicRoughness { get; set; }
|
2020-10-19 10:01:37 +00:00
|
|
|
public TextureCube ShadowMap { get; set; }
|
2020-10-01 19:46:25 +00:00
|
|
|
|
|
|
|
public Vector3 EyePosition { get; set; }
|
|
|
|
|
|
|
|
public Vector3 PointLightPosition { get; set; }
|
|
|
|
public Vector3 PointLightColor { get; set; }
|
|
|
|
|
2020-10-19 10:01:37 +00:00
|
|
|
public float FarPlane { get; set; }
|
|
|
|
|
2020-12-10 00:10:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-01 19:46:25 +00:00
|
|
|
public DeferredPBR_PointLightEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.DeferredPBR_PointLightEffect)
|
|
|
|
{
|
|
|
|
CacheEffectParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeferredPBR_PointLightEffect(DeferredPBR_PointLightEffect cloneSource) : base(cloneSource)
|
|
|
|
{
|
2020-10-19 10:01:37 +00:00
|
|
|
CacheEffectParameters();
|
|
|
|
|
2020-10-01 19:46:25 +00:00
|
|
|
GPosition = cloneSource.GPosition;
|
|
|
|
GAlbedo = cloneSource.GAlbedo;
|
|
|
|
GNormal = cloneSource.GNormal;
|
|
|
|
GMetallicRoughness = cloneSource.GMetallicRoughness;
|
2020-10-19 10:01:37 +00:00
|
|
|
ShadowMap = cloneSource.ShadowMap;
|
2020-10-01 19:46:25 +00:00
|
|
|
|
|
|
|
EyePosition = cloneSource.EyePosition;
|
|
|
|
|
|
|
|
PointLightPosition = cloneSource.PointLightPosition;
|
|
|
|
PointLightColor = cloneSource.PointLightColor;
|
2020-10-19 10:01:37 +00:00
|
|
|
|
|
|
|
FarPlane = cloneSource.FarPlane;
|
2020-10-01 19:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-10-19 10:01:37 +00:00
|
|
|
shadowMapParam.SetValue(ShadowMap);
|
2020-10-01 19:46:25 +00:00
|
|
|
|
|
|
|
eyePositionParam.SetValue(EyePosition);
|
|
|
|
|
|
|
|
pointLightPositionParam.SetValue(PointLightPosition);
|
|
|
|
pointLightColorParam.SetValue(PointLightColor);
|
2020-10-19 10:01:37 +00:00
|
|
|
|
|
|
|
farPlaneParam.SetValue(FarPlane);
|
2020-12-10 00:10:53 +00:00
|
|
|
|
|
|
|
if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
|
|
|
|
{
|
|
|
|
worldViewProjectionParam.SetValue(world * view * projection);
|
|
|
|
|
|
|
|
dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
|
|
|
|
}
|
2020-10-01 19:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheEffectParameters()
|
|
|
|
{
|
|
|
|
gPositionParam = Parameters["gPosition"];
|
|
|
|
gAlbedoParam = Parameters["gAlbedo"];
|
|
|
|
gNormalParam = Parameters["gNormal"];
|
|
|
|
gMetallicRoughnessParam = Parameters["gMetallicRoughness"];
|
2020-10-19 10:01:37 +00:00
|
|
|
shadowMapParam = Parameters["shadowMap"];
|
2020-10-01 19:46:25 +00:00
|
|
|
|
|
|
|
eyePositionParam = Parameters["EyePosition"];
|
|
|
|
|
|
|
|
pointLightPositionParam = Parameters["PointLightPosition"];
|
|
|
|
pointLightColorParam = Parameters["PointLightColor"];
|
2020-10-19 10:01:37 +00:00
|
|
|
|
|
|
|
farPlaneParam = Parameters["FarPlane"];
|
2020-12-10 00:10:53 +00:00
|
|
|
|
|
|
|
worldViewProjectionParam = Parameters["WorldViewProjection"];
|
2020-10-01 19:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|