Documente Academic
Documente Profesional
Documente Cultură
// FXAA antialiasing
// Copyright 2014 (c)
// Settings by Hollow Man
//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------// Defines
//------------------------------------------------------------------------------------//#define AA_MODE_0
//#define AA_MODE_1
#define AA_MODE_2
//------------------------------------------------------------------------------------// Vectors, floats and etc.
//------------------------------------------------------------------------------------static const float ScreenScaleY;
static const float ScreenSize;
float _OffsetScale = 0.2;
float _BlurRadius = 18.0;
float2 texel = {0.0009765625,0.00130208333333333333333333333333};
//------------------------------------------------------------------------------------// Textures
//------------------------------------------------------------------------------------texture2D texColor;
//------------------------------------------------------------------------------------// Functions
//------------------------------------------------------------------------------------float Luminance( float3 c )
{
return dot( c, float3(0.22, 0.707, 0.071) );
}
//------------------------------------------------------------------------------------// Sampler Inputs
//------------------------------------------------------------------------------------sampler2D InputSampler = sampler_state
{
Texture = (texColor);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
struct VS_OUTPUT_POST
{
float4 vpos : POSITION;
float2 txcoord : TEXCOORD0;
};
struct VS_INPUT_POST
{
float3 pos : POSITION;
float2 txcoord : TEXCOORD0;
};
struct VS_OUTPUT_POST_SSAA
{
float4 vpos : POSITION;
float2 uv[5] : TEXCOORD0;
};
struct VS_OUTPUT_POST_NFAA
{
float4 vpos : POSITION;
float2 uv[8] : TEXCOORD0;
};
//------------------------------------------------------------------------------------// Functions
//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------// Vertex Shader Input
//------------------------------------------------------------------------------------VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
VS_OUTPUT_POST OUT;
float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
OUT.vpos=pos;
OUT.txcoord.xy=IN.txcoord.xy;
return OUT;
}
VS_OUTPUT_POST_SSAA VS_PostProcessSSAA(VS_INPUT_POST IN)
{
VS_OUTPUT_POST_SSAA o;
float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
o.vpos=pos;
float2 uv = IN.txcoord.xy;
float w = 1.75;
float2 up = float2(0.0, texel.y) * w;
float2 right = float2(texel.x, 0.0) * w;
o.uv[0].xy
o.uv[1].xy
o.uv[2].xy
o.uv[3].xy
=
=
=
=
uv
uv
uv
uv
+
+
up;
right;
right;
up;
o.uv[4].xy = uv;
return o;
}
VS_OUTPUT_POST_NFAA VS_PostProcessNFAA(VS_INPUT_POST IN)
{
VS_OUTPUT_POST_NFAA o;
float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
o.vpos=pos;
float2 uv = IN.txcoord.xy;
float2 up = float2(0.0, texel.y) * _OffsetScale;
float2 right = float2(texel.x, 0.0) * _OffsetScale;
o.uv[0].xy
o.uv[1].xy
o.uv[2].xy
o.uv[3].xy
o.uv[4].xy
o.uv[5].xy
o.uv[6].xy
o.uv[7].xy
=
=
=
=
=
=
=
=
uv
uv
uv
uv
uv
uv
uv
uv
+
+
+
+
up;
up;
right;
right;
right + up;
right -up;
right + up;
right -up;
return o;
}
//------------------------------------------------------------------------------------// Pixel Shader Effects
//------------------------------------------------------------------------------------//------------------------------------------------------------------------------------//AntiAliasing
//------------------------------------------------------------------------------------float4 SSAA(VS_OUTPUT_POST_SSAA i, float2 vPos : VPOS) : COLOR
{
float4 outColor;
float t =
float
float
float
float2 n = float2( -( t - b ), r - l );
float nl = length( n );
if ( nl < (1.0 / 16.0) )
outColor = tex2D( InputSampler, i.uv[4] );
else {
n *= texel.xy / nl;
float4 o = tex2D( InputSampler, i.uv[4]);
float4 t0 = tex2D( InputSampler, i.uv[4] + n * 0.5) * 0.
9;
float4 t1 = tex2D( InputSampler, i.uv[4] - n * 0.5) * 0.
9;
float4 t2 = tex2D( InputSampler, i.uv[4] + n) * 0.75;
float4 t3 = tex2D( InputSampler, i.uv[4] - n) * 0.75;
outColor = (o + t0 + t1 + t2 + t3) / 4.3;
}
return outColor;
}
float4 NFAA (VS_OUTPUT_POST_NFAA i, float2 vPos : VPOS) : COLOR
{
// get luminance values
// maybe: experiment with different luminance calculations
float topL = Luminance( tex2D(InputSampler, i.uv[0]).rgb );
float bottomL = Luminance( tex2D(InputSampler, i.uv[1]).rgb );
float rightL = Luminance( tex2D(InputSampler, i.uv[2]).rgb );
float leftL = Luminance( tex2D(InputSampler, i.uv[3]).rgb );
float leftTopL = Luminance( tex2D(InputSampler, i.uv[4]).rgb );
float leftBottomL = Luminance( tex2D(InputSampler, i.uv[5]).rgb );
float rightBottomL = Luminance( tex2D(InputSampler, i.uv[6]).rgb );
float rightTopL = Luminance( tex2D(InputSampler, i.uv[7]).rgb );
// 2 triangle subtractions
float sum0 = dot(float3(1,1,1),
float sum1 = dot(float3(1,1,1),
float sum2 = dot(float3(1,1,1),
float sum3 = dot(float3(1,1,1),
float3(rightTopL,bottomL,leftTopL));
float3(leftBottomL,topL,rightBottomL));
float3(leftTopL,rightL,leftBottomL));
float3(rightBottomL,leftL,rightTopL));
technique PostProcess
{
pass P0
{
#ifdef AA_MODE_0
VertexShader
PixelShader
#endif
#ifdef AA_MODE_1
VertexShader
PixelShader
#endif
#ifdef AA_MODE_2
VertexShader
PixelShader
#endif
}
}