Professional Documents
Culture Documents
//---------------------------------------------------------------------------------
-----
// Defines
//---------------------------------------------------------------------------------
-----
#define TONEMAPPING_MODE_0
//#define AA_MODE_0
//#define AA_MODE_1
#define AA_MODE_2
#define DoF
#define LensFlares
#define FakeGodRays //need to ajust, can not working
//#define DoF_Vignetting
#define DoF_Manual
//#define DoF_Auto
//#define DoF_PentagonShape
//---------------------------------------------------------------------------------
-----
// Vectors, floats and etc.
//---------------------------------------------------------------------------------
-----
static float2 screenRes = {1280,720};//Screen Resolution, for example 1024x768
//Dof params
float PI = 3.14159265;
//Bloom
static const float thresh = 0.10;
float4 threshhold = {thresh, 0/(0-thresh), 0.0, 0.0};
float BloomIntensity = 0.1;
//SSAA,NFAA,FXAA
float _OffsetScale = 9.0;
float _BlurRadius = 9.0;
//Tonemapping
float _ExposureAdjustment = 7.10;//Adjust Exposure;
static const float gray = 0.0;
static const float white = 0.0;
float4 _HdrParams = {gray,gray,gray,white*white};
//Bloom 2
static const float thresh2 = 0.92;// Treshold -
( )
float4 threshhold2 = {thresh2, 0/(0-thresh2), 0.0, 0.0};
float BloomIntensity2 = 18.5;
//+++++++++++++++++++++++++++++
//external parameters, do not modify
//+++++++++++++++++++++++++++++
//keyboard controlled temporary variables (in some versions exists in the config
file). Press and hold key 1,2,3...8 together with PageUp or PageDown to modify. By
default all set to 1.0
float4 tempF1; //0,1,2,3
float4 tempF2; //5,6,7,8
float4 tempF3; //9,0
//x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
float4 ScreenSize;
//x=generic timer in range 0..1, period of 16777216 ms (4.6 hours), w=frame time
elapsed (in seconds)
float4 Timer;
//adaptation delta time for focusing
float FadeFactor;
//---------------------------------------------------------------------------------
-----
// Textures
//---------------------------------------------------------------------------------
-----
texture2D texColor;
texture2D texDepth;
texture2D texNoise;
texture2D texPalette;
texture2D texFocus; //computed focusing depth
texture2D texCurr; //4*4 texture for focusing
texture2D texPrev; //4*4 texture for focusing
//---------------------------------------------------------------------------------
-----
// Functions
//---------------------------------------------------------------------------------
-----
//---------------------------------------------------------------------------------
-----
// Sampler Inputs
//---------------------------------------------------------------------------------
-----
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
//---------------------------------------------------------------------------------
-----
OUT.vpos=pos;
OUT.txcoord.xy=IN.txcoord.xy;
return OUT;
}
//---------------------------------------------------------------------------------
-----
// Pixel Shader Effects
//---------------------------------------------------------------------------------
-----
//---------------------------------------------------------------------------------
-----
//AntiAliasing
//---------------------------------------------------------------------------------
-----
float2 n = float2( -( t - b ), r - l );
float nl = length( n );
return outColor;
}
// 2 triangle subtractions
float sum0 = dot(float3(1,1,1), float3(rightTopL,bottomL,leftTopL));
float sum1 = dot(float3(1,1,1), float3(leftBottomL,topL,rightBottomL));
float sum2 = dot(float3(1,1,1), float3(leftTopL,rightL,leftBottomL));
float sum3 = dot(float3(1,1,1), float3(rightBottomL,leftL,rightTopL));
// reconstruct normal uv
float2 uv_ = (i.uv[0] + i.uv[1]) * 0.5;
struct VS_OUTPUT_POST_FXAA {
float4 vpos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 interpolatorA : TEXCOORD1;
float4 interpolatorB : TEXCOORD2;
float4 interpolatorC : TEXCOORD3;
};
o.uv = v.txcoord.xy;
float4 extents;
float2 offset = ( texel.xy ) * 0.5f;
extents.xy = v.txcoord.xy - offset;
extents.zw = v.txcoord.xy + offset;
float4 rcpSize;
rcpSize.xy = -texel.xy * 0.5f;
rcpSize.zw = texel.xy * 0.5f;
o.interpolatorA = extents;
o.interpolatorB = rcpSize;
o.interpolatorC = rcpSize;
o.interpolatorC.xy *= 4.0;
o.interpolatorC.zw *= 4.0;
return o;
}
float2 dir;
dir.x = dirSWMinusNE + dirSEMinusNW;
dir.y = dirSWMinusNE - dirSEMinusNW;
dir = normalize(dir);
float3 col1 = FxaaTexTop(InputSampler, pos.xy - dir * rcpSize.zw).rgb;
float3 col2 = FxaaTexTop(InputSampler, pos.xy + dir * rcpSize.zw).rgb;
//---------------------------------------------------------------------------------
-----
// Bloom
//---------------------------------------------------------------------------------
-----
return 1-(1.00-col)*(1.17-toBlend);
}
//---------------------------------------------------------------------------------
-----
//DoF (READY TO USE)
//---------------------------------------------------------------------------------
-----
//Bokeh
return float2(noiseX,noiseY);
}
#ifdef DoF_Auto
fDepth = linearize(tex2D(SamplerDepth,focus).x);
#endif
float a = (o*f)/(o-f);
float b = (d*f)/(d-f);
float c = (d-f)/(d*fstop*CoC);
blur = abs(a-b)*c;
#endif
blur = saturate(blur);
float2 noise = rand(IN.txcoord.xy)*namount*blur;
float w = (1.0/screenRes.x)*blur*maxblur+noise.x;
float h = (1.0/screenRes.y)*blur*maxblur+noise.y;
s += 1.0*lerp(1.0,i/rings,bias)*p;
}
}
col = col/s; //divide by sample count
}
#ifdef DoF_Vignetting
col *= vignette(IN.txcoord.xy,vignint);
#endif
return col;
}
float4 Color;
midtones.w = midtones.x;
midtones.x = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.x += midtones.w;
midtones.w = midtones.y;
midtones.y = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.y += midtones.w;
midtones.w = midtones.z;
midtones.z = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.z += midtones.w;
}
highlights.w = highlights.x;
highlights.x = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.x += highlights.w;
highlights.w = highlights.y;
highlights.y = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.y += highlights.w;
highlights.w = highlights.z;
highlights.z = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.z += highlights.w;
}
//---------------------------------------------------------------------------------
-----
// Bloom2
//---------------------------------------------------------------------------------
-----
return 1-(1.00-col)*(1.68-toBlend);
}
//---------------------------------------------------------------------------------
-----
// Compiler 1
//---------------------------------------------------------------------------------
-----
technique PostProcess
{
pass P0
{
#ifdef AA_MODE_0
VertexShader = compile vs_3_0 VS_PostProcessSSAA();
PixelShader = compile ps_3_0 SSAA();
#endif
#ifdef AA_MODE_1
VertexShader = compile vs_3_0 VS_PostProcessNFAA();
PixelShader = compile ps_3_0 NFAA();
#endif
#ifdef AA_MODE_2
VertexShader = compile vs_3_0 VS_PostProcessFXAA();
PixelShader = compile ps_3_0 FXAA();
#endif
}
}
technique PostProcess2
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 PS_ProcessBloom();
}
}
technique PostProcess3
{
#ifdef DoF
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 PS_ProcessDoFBokeh();
}
#endif
}
technique PostProcess4
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 CCShadow();
}
}
technique PostProcess5
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 PS_ProcessBloom2();
}
}