2020-10-01 21:52:19 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace Kav
|
|
|
|
{
|
2020-10-02 19:28:28 +00:00
|
|
|
public class Deferred_ToonEffect : Effect, ShadowCascadeEffect
|
2020-10-01 21:52:19 +00:00
|
|
|
{
|
|
|
|
EffectParameter gPositionParam;
|
|
|
|
EffectParameter gAlbedoParam;
|
|
|
|
EffectParameter gNormalParam;
|
2020-10-05 22:45:10 +00:00
|
|
|
EffectParameter gMetallicRoughnessParam;
|
2020-10-01 21:52:19 +00:00
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
EffectParameter shadowMapOneParam;
|
|
|
|
EffectParameter shadowMapTwoParam;
|
|
|
|
EffectParameter shadowMapThreeParam;
|
|
|
|
EffectParameter shadowMapFourParam;
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
EffectParameter eyePositionParam;
|
|
|
|
EffectParameter directionalLightDirectionParam;
|
2020-10-02 05:26:40 +00:00
|
|
|
EffectParameter directionalLightColorParam;
|
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
EffectParameter cascadeFarPlanesParam;
|
|
|
|
EffectParameter shadowMapSizeParam;
|
|
|
|
|
|
|
|
EffectParameter lightSpaceMatrixOneParam;
|
|
|
|
EffectParameter lightSpaceMatrixTwoParam;
|
|
|
|
EffectParameter lightSpaceMatrixThreeParam;
|
|
|
|
EffectParameter lightSpaceMatrixFourParam;
|
|
|
|
|
|
|
|
EffectParameter viewMatrixParam;
|
|
|
|
|
2020-10-16 01:19:43 +00:00
|
|
|
EffectParameter shaderIndexParam;
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
public Texture2D GPosition { get; set; }
|
|
|
|
public Texture2D GAlbedo { get; set; }
|
|
|
|
public Texture2D GNormal { get; set; }
|
2020-10-05 22:45:10 +00:00
|
|
|
public Texture2D GMetallicRoughness { get; set; }
|
2020-10-01 21:52:19 +00:00
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
public Texture2D ShadowMapOne { get; set; }
|
|
|
|
public Texture2D ShadowMapTwo { get; set; }
|
|
|
|
public Texture2D ShadowMapThree { get; set; }
|
|
|
|
public Texture2D ShadowMapFour { get; set; }
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
public Vector3 EyePosition { get; set; }
|
|
|
|
public Vector3 DirectionalLightDirection { get; set; }
|
2020-10-02 05:26:40 +00:00
|
|
|
public Vector3 DirectionalLightColor { get; set; }
|
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
public float[] CascadeFarPlanes { get; }
|
|
|
|
public float ShadowMapSize { get; set; }
|
|
|
|
|
|
|
|
public Matrix LightSpaceMatrixOne { get; set; }
|
|
|
|
public Matrix LightSpaceMatrixTwo { get; set; }
|
|
|
|
public Matrix LightSpaceMatrixThree { get; set; }
|
|
|
|
public Matrix LightSpaceMatrixFour { get; set; }
|
|
|
|
|
|
|
|
public Matrix ViewMatrix { get; set; }
|
|
|
|
|
2020-10-16 01:19:43 +00:00
|
|
|
private bool ditheredShadowValue = false;
|
|
|
|
public bool DitheredShadows
|
|
|
|
{
|
|
|
|
get { return ditheredShadowValue; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
ditheredShadowValue = value;
|
|
|
|
CalculateShaderIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int shaderIndex = 0;
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
public Deferred_ToonEffect(GraphicsDevice graphicsDevice) : base(graphicsDevice, Resources.Deferred_ToonEffect)
|
|
|
|
{
|
2020-10-02 19:28:28 +00:00
|
|
|
CascadeFarPlanes = new float[4];
|
2020-10-01 21:52:19 +00:00
|
|
|
CacheEffectParameters();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnApply()
|
|
|
|
{
|
|
|
|
gPositionParam.SetValue(GPosition);
|
|
|
|
gAlbedoParam.SetValue(GAlbedo);
|
|
|
|
gNormalParam.SetValue(GNormal);
|
2020-10-05 22:45:10 +00:00
|
|
|
gMetallicRoughnessParam.SetValue(GMetallicRoughness);
|
2020-10-02 05:26:40 +00:00
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
shadowMapOneParam.SetValue(ShadowMapOne);
|
|
|
|
shadowMapTwoParam.SetValue(ShadowMapTwo);
|
|
|
|
shadowMapThreeParam.SetValue(ShadowMapThree);
|
|
|
|
shadowMapFourParam.SetValue(ShadowMapFour);
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
eyePositionParam.SetValue(EyePosition);
|
|
|
|
directionalLightDirectionParam.SetValue(DirectionalLightDirection);
|
2020-10-02 05:26:40 +00:00
|
|
|
directionalLightColorParam.SetValue(DirectionalLightColor);
|
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
cascadeFarPlanesParam.SetValue(CascadeFarPlanes);
|
|
|
|
shadowMapSizeParam.SetValue(ShadowMapSize);
|
|
|
|
|
|
|
|
lightSpaceMatrixOneParam.SetValue(LightSpaceMatrixOne);
|
|
|
|
lightSpaceMatrixTwoParam.SetValue(LightSpaceMatrixTwo);
|
|
|
|
lightSpaceMatrixThreeParam.SetValue(LightSpaceMatrixThree);
|
|
|
|
lightSpaceMatrixFourParam.SetValue(LightSpaceMatrixFour);
|
|
|
|
|
|
|
|
viewMatrixParam.SetValue(ViewMatrix);
|
2020-10-16 01:19:43 +00:00
|
|
|
|
|
|
|
shaderIndexParam.SetValue(shaderIndex);
|
2020-10-01 21:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheEffectParameters()
|
|
|
|
{
|
|
|
|
gPositionParam = Parameters["gPosition"];
|
|
|
|
gAlbedoParam = Parameters["gAlbedo"];
|
|
|
|
gNormalParam = Parameters["gNormal"];
|
2020-10-05 22:45:10 +00:00
|
|
|
gMetallicRoughnessParam = Parameters["gMetallicRoughness"];
|
2020-10-01 21:52:19 +00:00
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
shadowMapOneParam = Parameters["shadowMapOne"];
|
|
|
|
shadowMapTwoParam = Parameters["shadowMapTwo"];
|
|
|
|
shadowMapThreeParam = Parameters["shadowMapThree"];
|
|
|
|
shadowMapFourParam = Parameters["shadowMapFour"];
|
|
|
|
|
2020-10-01 21:52:19 +00:00
|
|
|
eyePositionParam = Parameters["EyePosition"];
|
|
|
|
directionalLightDirectionParam = Parameters["DirectionalLightDirection"];
|
2020-10-02 05:26:40 +00:00
|
|
|
directionalLightColorParam = Parameters["DirectionalLightColor"];
|
|
|
|
|
2020-10-02 19:28:28 +00:00
|
|
|
cascadeFarPlanesParam = Parameters["CascadeFarPlanes"];
|
|
|
|
shadowMapSizeParam = Parameters["ShadowMapSize"];
|
|
|
|
|
|
|
|
lightSpaceMatrixOneParam = Parameters["LightSpaceMatrixOne"];
|
|
|
|
lightSpaceMatrixTwoParam = Parameters["LightSpaceMatrixTwo"];
|
|
|
|
lightSpaceMatrixThreeParam = Parameters["LightSpaceMatrixThree"];
|
|
|
|
lightSpaceMatrixFourParam = Parameters["LightSpaceMatrixFour"];
|
|
|
|
|
|
|
|
viewMatrixParam = Parameters["ViewMatrix"];
|
2020-10-16 01:19:43 +00:00
|
|
|
|
|
|
|
shaderIndexParam = Parameters["ShaderIndex"];
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CalculateShaderIndex()
|
|
|
|
{
|
|
|
|
if (ditheredShadowValue)
|
|
|
|
{
|
|
|
|
shaderIndex = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shaderIndex = 0;
|
|
|
|
}
|
2020-10-01 21:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|