2020-08-27 18:14:17 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
|
|
|
public class DeferredPBREffect : Effect
|
|
|
|
{
|
|
|
|
EffectParameter gPositionParam;
|
|
|
|
EffectParameter gAlbedoParam;
|
|
|
|
EffectParameter gNormalParam;
|
|
|
|
EffectParameter gMetallicRoughnessParam;
|
2020-08-27 21:46:20 +00:00
|
|
|
EffectParameter shadowMapParam;
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
EffectParameter eyePositionParam;
|
2020-08-27 21:46:20 +00:00
|
|
|
EffectParameter lightSpaceMatrixParam;
|
|
|
|
|
2020-08-27 18:14:17 +00:00
|
|
|
PointLightCollection pointLightCollection;
|
|
|
|
DirectionalLightCollection directionalLightCollection;
|
|
|
|
|
|
|
|
public Texture2D GPosition { get; set; }
|
|
|
|
public Texture2D GAlbedo { get; set; }
|
|
|
|
public Texture2D GNormal { get; set; }
|
|
|
|
public Texture2D GMetallicRoughness { get; set; }
|
2020-08-27 21:46:20 +00:00
|
|
|
public Texture2D ShadowMap { get; set; }
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
public Vector3 EyePosition { get; set; }
|
2020-08-27 21:46:20 +00:00
|
|
|
public Matrix LightSpaceMatrix { get; set; }
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
public int MaxPointLights { get; } = 64;
|
|
|
|
|
|
|
|
public PointLightCollection PointLights
|
|
|
|
{
|
|
|
|
get { return pointLightCollection; }
|
|
|
|
private set { pointLightCollection = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public int MaxDirectionalLights { get; } = 4;
|
|
|
|
|
|
|
|
public DirectionalLightCollection DirectionalLights
|
|
|
|
{
|
|
|
|
get { return directionalLightCollection; }
|
|
|
|
private set { directionalLightCollection = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public DeferredPBREffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.DeferredPBREffect)
|
|
|
|
{
|
|
|
|
CacheEffectParameters();
|
|
|
|
|
|
|
|
pointLightCollection = new PointLightCollection(
|
|
|
|
Parameters["PointLightPositions"],
|
|
|
|
Parameters["PointLightColors"],
|
|
|
|
MaxPointLights
|
|
|
|
);
|
|
|
|
|
|
|
|
DirectionalLights = new DirectionalLightCollection(
|
|
|
|
Parameters["DirectionalLightDirections"],
|
|
|
|
Parameters["DirectionalLightColors"]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected DeferredPBREffect(DeferredPBREffect cloneSource) : base(cloneSource)
|
|
|
|
{
|
|
|
|
GPosition = cloneSource.GPosition;
|
|
|
|
GAlbedo = cloneSource.GAlbedo;
|
|
|
|
GNormal = cloneSource.GNormal;
|
|
|
|
GMetallicRoughness = cloneSource.GMetallicRoughness;
|
|
|
|
|
|
|
|
EyePosition = cloneSource.EyePosition;
|
|
|
|
|
|
|
|
PointLights = new PointLightCollection(
|
|
|
|
Parameters["LightPositions"],
|
|
|
|
Parameters["PositionLightColors"],
|
|
|
|
MaxPointLights
|
|
|
|
);
|
|
|
|
|
|
|
|
for (int i = 0; i < MaxPointLights; i++)
|
|
|
|
{
|
|
|
|
PointLights[i] = cloneSource.PointLights[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
DirectionalLights = new DirectionalLightCollection(
|
|
|
|
Parameters["DirectionalLightDirections"],
|
|
|
|
Parameters["DirectionalLightColors"]
|
|
|
|
);
|
|
|
|
|
|
|
|
for (int i = 0; i < MaxDirectionalLights; i++)
|
|
|
|
{
|
|
|
|
DirectionalLights[i] = cloneSource.DirectionalLights[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Effect Clone()
|
|
|
|
{
|
|
|
|
return new DeferredPBREffect(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnApply()
|
|
|
|
{
|
|
|
|
gPositionParam.SetValue(GPosition);
|
|
|
|
gAlbedoParam.SetValue(GAlbedo);
|
|
|
|
gNormalParam.SetValue(GNormal);
|
|
|
|
gMetallicRoughnessParam.SetValue(GMetallicRoughness);
|
2020-08-27 21:46:20 +00:00
|
|
|
shadowMapParam.SetValue(ShadowMap);
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
eyePositionParam.SetValue(EyePosition);
|
2020-08-27 21:46:20 +00:00
|
|
|
lightSpaceMatrixParam.SetValue(LightSpaceMatrix);
|
2020-08-27 18:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheEffectParameters()
|
|
|
|
{
|
|
|
|
gPositionParam = Parameters["gPosition"];
|
|
|
|
gAlbedoParam = Parameters["gAlbedo"];
|
|
|
|
gNormalParam = Parameters["gNormal"];
|
|
|
|
gMetallicRoughnessParam = Parameters["gMetallicRoughness"];
|
2020-08-27 21:46:20 +00:00
|
|
|
shadowMapParam = Parameters["shadowMap"];
|
2020-08-27 18:14:17 +00:00
|
|
|
|
|
|
|
eyePositionParam = Parameters["EyePosition"];
|
2020-08-27 21:46:20 +00:00
|
|
|
|
|
|
|
lightSpaceMatrixParam = Parameters["LightSpaceMatrix"];
|
2020-08-27 18:14:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|