enbeffect.fx from Portal2x2 config:
Code: Select all
///////EFLC SERIES BY PORTAL2X2 BABY :D////////////////
//////raigen,ice,Boris,dp3,AAA,fake,.........//
/////HELPERS:DRON4ik194,Vlad_,OrangeBrains,AAA,dp3,gtf323,simple999,
float DOFSizeMulti = 1; // Set this to 2 if you use SSAA
float DOFAmount = 0.003;
float ISaturation = 0.8;
float IBrightness = 0.9;
float IContrast = 1.2;
float IWhiteAmount = 1;
float BloomAmount = 0.035;
float BloomAmountAdd = 0;
float BloomR = 1;
float BloomG = 0.9;
float BloomB = 0.8;
float VignetteAmount = 0;
//////SSAO///////////////////////
float Script : STANDARDSGLOBAL
<
string UIWidget = "none";
string ScriptClass = "scene";
string ScriptOrder = "postprocess";
string ScriptOutput = "color";
//string Script = "Technique=Main;";
> = 0.8;
float2 ViewportSize : VIEWPORTPIXELSIZE
<
string UIName="Screen Size";
string UIWidget="None";
>;
// Standard full-screen imaging value
float4 ClearColor
<
string UIWidget = "color";
string UIName = "Clear (Bg) Color";
> = {0,0,0,1.0};
float ClearDepth
<
string UIWidget = "None";
> = 1.0;
float Near
<
string UIWidget = "slider";
string UIName = "Near Plane";
float UIMin = 0.0;
float UIMax = 10.0;
float UIStep = 0.00001;
> = 1.0;
float Far
<
string UIWidget = "slider";
string UIName = "Far Plane";
float UIMin = 0.0;
float UIMax = 100.0;
float UIStep = 0.00001;
> = 50.0;
float gTimer : TIME < string UIWidget = "None"; >;
///////////////////////////////////////////////////////////
///////////////////////////// Render-to-Texture Targets ///
///////////////////////////////////////////////////////////
texture ScnMap : RENDERCOLORTARGET
<
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "X8R8G8B8" ;
string UIWidget = "None";
>;
sampler2D ScnSamp = sampler_state
{
Texture = <ScnMap>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//NONE;//LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
/*
sampler2D ScnSamp = sampler_state
{
texture = <ScnMap>;
//WrapS = ClampToEdge;
//WrapT = ClampToEdge;
MinFilter = ClampToEdge;//
MagFilter = ClampToEdge;//
MinFilter = linear;
MagFilter = linear;
};
*/
texture DepthBuffer : RENDERDEPTHSTENCILTARGET
<
float2 ViewPortRatio = { 1.0, 1.0 };
string Format = "D24S8";
string UIWidget = "None";
>;
sampler2D DepthSamp = sampler_state
{
Texture = <DepthBuffer>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//NONE;//LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
/*
sampler2D DepthSamp = sampler_state
{
texture = <DepthBuffer>;
//WrapS = ClampToEdge;
//WrapT = ClampToEdge;
MinFilter = ClampToEdge;//
MagFilter = ClampToEdge;//
MinFilter = linear;
MagFilter = linear;
};
*/
float readDepth( in float2 coord )
{
return( ( 2.0 * Near ) / ( Far + Near - tex2D( DepthSamp, coord ).x * ( Far - Near ) ) );
}
// sampler2D AdapLumSampler;
// sampler2D BloomSampler;
// float4 ColorCorrect;
// float4 ColorShift;
// float Exposure;
// sampler2D GBufferTextureSampler2;
// sampler2D GBufferTextureSampler3;
// sampler2D HDRSampler;
// sampler2D JitterSampler;
// float PLAYER_MASK;
// sampler2D StencilCopySampler;
// float4 TexelSize;
// float4 ToneMapParams;
// float4 deSatContrastGamma;
// float4 dofBlur;
// float4 dofDist;
// float4 dofProj;
// float gDirectionalMotionBlurLength;
// float4 globalScreenSize;
// row_major float4x4 motionBlurMatrix;
//
//
// Registers:
//
// Name Reg Size
// ---------------------------- ----- ----
// globalScreenSize c44 1
// Exposure c66 1
// motionBlurMatrix c72 4
// TexelSize c76 1
// dofProj c77 1
// dofDist c78 1
// dofBlur c79 1
// gDirectionalMotionBlurLength c80 1
// ToneMapParams c81 1
// deSatContrastGamma c82 1
// ColorCorrect c83 1
// ColorShift c84 1
// PLAYER_MASK c85 1
// GBufferTextureSampler2 s0 1
// GBufferTextureSampler3 s1 1
// HDRSampler s2 1
// BloomSampler s3 1
// AdapLumSampler s4 1
// JitterSampler s5 1
// StencilCopySampler s6 1
//quad
struct VS_OUTPUT_POST
{
float4 vpos : POSITION;
float2 txcoord0 : TEXCOORD0;
};
struct VS_INPUT_POST
{
float3 pos : POSITION;
float2 txcoord0 : TEXCOORD0;
};
//int4 _i0 : register(i0);
/*
float4 _c0 : register(c0);
float4 _c1 : register(c1);
float4 _c2 : register(c2);
float4 _c3 : register(c3);
float4 _c4 : register(c4);
float4 _c5 : register(c5);
float4 _c6 : register(c6);
*/
float4 _c44 : register(c44);
float4 _c66 : register(c66);
float4 _c72 : register(c72);
float4 _c73 : register(c73);
float4 _c74 : register(c74);
float4 _c75 : register(c75);
float4 _c76 : register(c76);
float4 _c77 : register(c77);
float4 _c78 : register(c78);
float4 _c79 : register(c79);
float4 _c80 : register(c80);
float4 _c81 : register(c81);
float4 _c82 : register(c82);
float4 _c83 : register(c83);
float4 _c84 : register(c84);
float4 _c85 : register(c85);
float maxi : register(c86);
float temp : register(c87);
texture2D texs0 : register(s0);
texture2D texs1 : register(s1);
texture2D texs2 : register(s2);
texture2D texs3 : register(s3);
texture2D texs4 : register(s4);
texture2D texs5 : register(s5);
texture2D texs6 : register(s6);
texture2D texs7 : register(s7);
texture2D texs13 : register(s13);//palette
texture2D texs15 : register(s15);
//sampler2D s0=sampler_state { Texture=<texs0>; };
//sampler2D s1=sampler_state { Texture=<texs1>; };
sampler2D s2=sampler_state { Texture=<texs2>; };
//sampler2D s3=sampler_state { Texture=<texs3>; };
sampler2D s4=sampler_state { Texture=<texs4>; };
sampler2D s5=sampler_state { Texture=<texs5>; };
sampler2D s6=sampler_state { Texture=<texs6>; };
sampler2D s7=sampler_state { Texture=<texs7>; };
//sampler2D s13=sampler_state { Texture=<texs13>; };
sampler2D s15=sampler_state { Texture=<texs15>; };
//next samplers states fixing problems on ATI cards
sampler2D s0 = sampler_state
{
Texture = <texs0>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//NONE;//LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D s1 = sampler_state
{
Texture = <texs1>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//NONE;//LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D s3 = sampler_state
{
Texture = <texs3>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//NONE;//LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D s13 = sampler_state
{
Texture = <texs13>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
float4 PS_C215BE6E(VS_OUTPUT_POST IN) : COLOR
{
float4 _oC0=0.0; //output
float4 _c0=float4(0, 0.212500006, 0.715399981, 0.0720999986);
float4 _c1=float4(0.25, 1, 256, 0);
float4 _c2=float4(0, 2, 4, 8);
float4 _c3=float4(58.1640015, 47.1300011, 0, 0);
float4 _c4=float4(-0.5, -1.5, 1.5, 0.5);
float4 _c5=float4(2, -1, 0.125, 0);
float4 _c6=float4(256, 2, 4, 8);
//mine
float4 _c7=float4(1.0, 0.1, 0.8, 1.0);
float4 _c8=float4(0.0, 0.1, 0.8, 0.333);
float4 _c9=float4(0.06, 0.1, 0.8, 0.1);
float4 _c10=float4(0.01, 1.4, 0.0, 0.32);
float4 _c11=float4(0.333333, 1.0, 0.0, 0.0);
//float4 _c12=float4(0.27, 0.67, 0.06, 0.0);
float4 _c12=float4(0.299, 0.587, 0.114, 0.0);
float4 _c13=float4(0.0, 0.0, 0.0, 0.00001);
float4 _c150=float4(0.55, 0.9, 0.85, 0.9);
float4 _c195=float4(0.0, 0.0, 0.0, 0.07);//0.7
float4 r0;
float4 r1;
float4 r2;
float4 r3;
float4 r4;
float4 r5;
float4 r6;
float4 r7;
float4 r8;
float4 r9;
float4 r10;
float4 r11;
float4 _v0=0.0;
_v0.xy=IN.txcoord0.xy;
r1=tex2D(s2, _v0.xy); //HDRSampler
r2=tex2D(s3, _v0.xy); //BloomSampler
//********************
float2 center;
float depth;
float focus;
r0=tex2D(s1, _v0.xy); //GBufferTextureSampler3
r0.y=-_c77.x + _c77.y; //-dofProj.x + dofProj.y
r0.y=1.0/r0.y;
r0.z=r0.y * _c77.y; //dofProj.y
r0.z=r0.z * -_c77.x; //dofProj.x
r0.x=_c77.y * -r0.y + r0.x;
r0.x=1.0/r0.x;
r0.y=r0.z * r0.x;
r0.w=abs(_c79.w);
r3=_c4; //-0.5, -1.5, 1.5, 0.5
depth=r0.z * r0.x - _c78.w; //dofDist.w
depth+=_c78.y * -r3.w; //dofDist.y
depth+=148;//offset
center.x=_v0.x-0.5;
center.y=0.5-_v0.y;
float4 vDofParams = float4(0, 1.5, 1000, 1.0);
//********************
float2 FocusPoint = float2(0.5, 0.5);
r4=tex2D(s1, FocusPoint); //GBufferTextureSampler3
r4.y=-_c77.x + _c77.y; //-dofProj.x + dofProj.y
r4.y=1/r4.y;
r4.z=r4.y * _c77.y; //dofProj.y
r4.z=r4.z * -_c77.x; //dofProj.x
r4.x=_c77.y * -r4.y + r4.x;
r4.x=1/r4.x;
r4.y=r4.z * r4.x;
float cdepth;
cdepth=r4.z * r4.x - _c78.w; //dofDist.w
cdepth+=_c78.y * -r3.w; //dofDist.y
cdepth+=148;//offset
r4.w = tex2D(s0, FocusPoint).w;
if(r4.w > 0)
{
vDofParams.z = cdepth*2.0;
vDofParams.y = cdepth;
}
//********************
depth = max(depth, 0); //fix zoom bug
float dist;
if(depth < vDofParams.y)
dist = (depth - vDofParams.y)/(vDofParams.y - vDofParams.x);
else
{
dist = (depth - vDofParams.y)/(vDofParams.z - vDofParams.y);
dist = clamp(dist, 0, vDofParams.w);
}
dist = dist * 0.5 + 0.5;
static float3 poisson[60] =
{
float3( 0.2165, 0.1250, 1.0000 ),
float3( 0.0000, 0.2500, 1.0000 ),
float3( -0.2165, 0.1250, 1.0000 ),
float3( -0.2165, -0.1250, 1.0000 ),
float3( -0.0000, -0.2500, 1.0000 ),
float3( 0.2165, -0.1250, 1.0000 ),
float3( 0.4330, 0.2500, 1.0000 ),
float3( 0.0000, 0.5000, 1.0000 ),
float3( -0.4330, 0.2500, 1.0000 ),
float3( -0.4330, -0.2500, 1.0000 ),
float3( -0.0000, -0.5000, 1.0000 ),
float3( 0.4330, -0.2500, 1.0000 ),
float3( 0.6495, 0.3750, 1.0000 ),
float3( 0.0000, 0.7500, 1.0000 ),
float3( -0.6495, 0.3750, 1.0000 ),
float3( -0.6495, -0.3750, 1.0000 ),
float3( -0.0000, -0.7500, 1.0000 ),
float3( 0.6495, -0.3750, 1.0000 ),
float3( 0.8660, 0.5000, 1.0000 ),
float3( 0.0000, 1.0000, 1.0000 ),
float3( -0.8660, 0.5000, 1.0000 ),
float3( -0.8660, -0.5000, 1.0000 ),
float3( -0.0000, -1.0000, 1.0000 ),
float3( 0.8660, -0.5000, 1.0000 ),
float3( 0.2163, 0.3754, 0.8670 ),
float3( -0.2170, 0.3750, 0.8670 ),
float3( -0.4333, -0.0004, 0.8670 ),
float3( -0.2163, -0.3754, 0.8670 ),
float3( 0.2170, -0.3750, 0.8670 ),
float3( 0.4333, 0.0004, 0.8670 ),
float3( 0.4328, 0.5004, 0.8847 ),
float3( -0.2170, 0.6250, 0.8847 ),
float3( -0.6498, 0.1246, 0.8847 ),
float3( -0.4328, -0.5004, 0.8847 ),
float3( 0.2170, -0.6250, 0.8847 ),
float3( 0.6498, -0.1246, 0.8847 ),
float3( 0.6493, 0.6254, 0.9065 ),
float3( -0.2170, 0.8750, 0.9065 ),
float3( -0.8663, 0.2496, 0.9065 ),
float3( -0.6493, -0.6254, 0.9065 ),
float3( 0.2170, -0.8750, 0.9065 ),
float3( 0.8663, -0.2496, 0.9065 ),
float3( 0.2160, 0.6259, 0.8851 ),
float3( -0.4340, 0.5000, 0.8851 ),
float3( -0.6500, -0.1259, 0.8851 ),
float3( -0.2160, -0.6259, 0.8851 ),
float3( 0.4340, -0.5000, 0.8851 ),
float3( 0.6500, 0.1259, 0.8851 ),
float3( 0.4325, 0.7509, 0.8670 ),
float3( -0.4340, 0.7500, 0.8670 ),
float3( -0.8665, -0.0009, 0.8670 ),
float3( -0.4325, -0.7509, 0.8670 ),
float3( 0.4340, -0.7500, 0.8670 ),
float3( 0.8665, 0.0009, 0.8670 ),
float3( 0.2158, 0.8763, 0.9070 ),
float3( -0.6510, 0.6250, 0.9070 ),
float3( -0.8668, -0.2513, 0.9070 ),
float3( -0.2158, -0.8763, 0.9070 ),
float3( 0.6510, -0.6250, 0.9070 ),
float3( 0.8668, 0.2513, 0.9070 )
};
float2 pixelSizeHigh;
float2 pixelSizeLow;
pixelSizeHigh.x = 2.0 / _c44.x;
pixelSizeHigh.y = 2.0 / _c44.y;
pixelSizeHigh.xy *= DOFSizeMulti;
pixelSizeLow.xy = pixelSizeHigh.xy;
float2 vMaxCoC = float2(5.0, 10.0);
float radiusScale = DOFAmount;
float discRadius;
float discRadiusLow;
float centerDepth;
float4 tdepth;
float4 tapHigh;
float4 tapLow;
centerDepth = dist;
discRadius = abs(centerDepth * vMaxCoC.y - vMaxCoC.x);
discRadiusLow = discRadius * radiusScale;
r1 = 0.0;
for(int t = 0; t < 60; t++)
{
float2 coordLow = _v0.xy + (pixelSizeLow.xy * poisson[t].xy * discRadiusLow);
float2 coordHigh = _v0.xy + (pixelSizeHigh.xy * poisson[t].xy * discRadius);
tapLow = tex2D(s2, coordLow.xy) * poisson[t].z;
tapHigh = tex2D(s2, coordHigh.xy) * poisson[t].z;
tdepth = tex2D(s1, coordHigh.xy); //GBufferTextureSampler3
tdepth.y = -_c77.x + _c77.y; //-dofProj.x + dofProj.y
tdepth.y = 1.0 / tdepth.y;
tdepth.z = tdepth.y * _c77.y; //dofProj.y
tdepth.z = tdepth.z * -_c77.x; //dofProj.x
tdepth.x = _c77.y * -tdepth.y + tdepth.x;
tdepth.x = 1.0 / tdepth.x;
tdepth.w = tdepth.z * tdepth.x - _c78.w; //dofDist.w
tdepth.w += _c78.y * -r3.w; //dofDist.y
tdepth.w += 148;//offset
tdepth.w = max(tdepth.w, 0); //fix zoom bug
if(tdepth.w < vDofParams.y)
tapHigh.w = (tdepth.w - vDofParams.y)/(vDofParams.y - vDofParams.x);
else
{
tapHigh.w = (tdepth.w - vDofParams.y)/(vDofParams.z - vDofParams.y);
tapHigh.w = clamp(tapHigh.w, 0, vDofParams.w);
}
tapHigh.w = tapHigh.w * 0.5 + 0.5;
tapLow.w = tapHigh.w;
float tapBlur = abs(tapHigh.w * 2.0 - 1.0);
float4 tap = lerp(tapHigh, tapLow, tapBlur);
if(tap.w >= centerDepth) tap.w = 1;
else tap.w = abs(tap.w * 2.0 - 1.0);
r1.xyz += tap.xyz * tap.w;
r1.w += tap.w;
}
r1.xyz /= r1.w;
//float4 dofcolor = r1;
//dofcolor.w = r1.w / DoF_TAPS;
//********************
r1.w=dot(r1.xyz, r1.xyz); //dp3
r1.w=1.0/r1.w;
//if (-r1.w<0.0) r3 = r1;
//else r3 = _c0.x;
r3 = lerp(_c0.x, r1, saturate(r1.w * 10000));
r4 = r3;
r5 = r3;
r6 = r3;
r7 = r3;
r0.x=r0.z * r0.x - _c78.w; //dofDist.w
r0.x=_c78.y * -r3.w + r0.x; //dofDist.y
r1.w=max(r0.x, _c0.x); //0.0
r0.x=1.0/_c78.z; //dofDist.z
r0.x=r1.w * r0.x;
r1.w=lerp(_c79.y, _c79.z, r0.x);//dofBlur
r0.x=min(_c79.z, r1.w); //dofBlur.z
r0.z=dot(r7.xyz, _c0.yzw); //0.212500006, 0.715399981, 0.0720999986
r8.x=dot(r3.xyz, _c0.yzw); //0.212500006, 0.715399981, 0.0720999986
r8.y=dot(r4.xyz, _c0.yzw); //0.212500006, 0.715399981, 0.0720999986
r8.z=dot(r5.xyz, _c0.yzw); //0.212500006, 0.715399981, 0.0720999986
r8.w=dot(r6.xyz, _c0.yzw); //0.212500006, 0.715399981, 0.0720999986
r1.w=dot(r8, _c1.xxxx); //0.25
r8=r8 - r1.w;
r2.w=dot(r8, r8);
r0.z=r0.z - r1.w;
r0.z=r0.z * r0.z - r2.w;
r0.x=r0.x*r0.x;
if (r0.z<0.0)
{
r0.x=r0.x;
} else r0.x=_c1.y; //1.0
r8=tex2D(s0, _v0.xy); //GBufferTextureSampler2
r8.yz=_c1.yz; // 1.0, 256.0
r9=r8.w * -r8.z + _c2; //0, 2, 4, 8
if (r9.w<0.0) //r9<0.0
{
r9=_c1.w; //0.0
} else r9=_c1.y; //1.0
//r9 is filtered sky mask
//r10=r8.w + tempc6;//c6.yzwx; //256, 2, 4, 8
r10=r8.w * -_c6.x + _c6.yzwx; //256, 2, 4, 8
if (r10.x<0.0)
{
r10.x=-_c1.w; //0.0
} else r10.x=-_c1.y; //1.0
if (r10.y<0.0)
{
r10.y=-_c1.w; //0.0
} else r10.y=-_c1.y; //1.0
if (r10.z<0.0)
{
r10.z=-_c1.w; //0.0
} else r10.z=-_c1.y; //1.0
if (r10.w<0.0)
{
r10.w=-_c1.w; //0.0
} else r10.w=-_c1.y; //1.0
r9=r9 + r10;
r9=r9 * _c4.x; //-0.5
r0.z=dot(r9, _c1.yyyy); //1.0
r0.z=r0.z + _c4.w; //0.5
r0.z=1.0/r0.z;
r8.xzw=r3.xyz * r9.x;
r7.xyz=r7 * _c4.w + r8.xzw; //0.5
r7.xyz=r4 * r9.y + r7;
r7.xyz=r5 * r9.z + r7;
r7.xyz=r6 * r9.w + r7;
r7.xyz=r0.z * r7;
r0.z=-r0.x + _c1.y; //1.0
r1.w=r0.x * _c1.x; //0.25
r3.xyz=r3 * r1.w;
r3.xyz=r7 * r0.z + r3;
r3.xyz=r4 * r1.w + r3;
r3.xyz=r5 * r1.w + r3;
r3.xyz=r6 * r1.w + r3;
//r4.xyz=_v0.yxy * _c5.x + _c5.y; //2, -1
r4.x=_v0.y * _c5.x + _c5.y;
r4.y=_v0.x * _c5.x + _c5.y;
r4.z=_v0.y * _c5.x + _c5.y;
r0.z=r4.y * _c77.z; //dofProj.z
r0.z=r0.y * r0.z;
r1.w=-r4.x * _c77.w; //dofProj.w
r1.w=r0.y * r1.w;
r5.xyz=r1.w * _c73; //motionBlurMatrix.2
r5.xyz=r0.z * _c72 + r5; //motionBlurMatrix.1
r5.xyz=-r0.y * _c74 + r5; //motionBlurMatrix.3
r5.xyz=r5 + _c75; //motionBlurMatrix.4
r0.y=-r5.z * _c77.z; //dofProj.z
r0.y=1/r0.y;
r6.x=r5.x * r0.y;
r0.y=r5.z * _c77.w; //dofProj.w
r0.y=1/r0.y;
r6.y=r5.y * r0.y;
//r0.yz=-r4 + r6.xxyw;
r0.yz=-r4.yz + r6.xy;
//r0.yz=r0 * _c80.x; //gDirectionalMotionBlurLength.x
r0.y=r0.y * _c80.x;
r0.z=r0.z * _c80.x;
r4.xy=r0.yz * _c5.z; //0.125
r5=tex2D(s6, _v0.xy); //StencilCopySampler
r1.w=r5.x - _c85.x; //PLAYER_MASK.x
r4.zw=r3.xy * _c2.w; //8.0
r4.zw=_v0.xy * _c3.xy + r4.zw; //58.1640015, 47.1300011
r5=tex2D(s5, r4.zw); //JitterSampler
//r2.w=r5.x - 0.5; //-0.5
r4.zw=r4.xy * (r5.x - 4) + _v0.xy; //0.082 fixed
r5.xyz=r3.xyz;
r2.w=_c1.y; //1.0
r3.w=_c1.y; //1.0
for (int iii=0; iii<8; iii++)
{
r6.x=r4.x * r3.w + r4.z;
r6.y=r4.y * r3.w + r4.w;
r7=tex2D(s6, r6.xy);
r5.w=r7.x - _c85.x;
if (r5.w<-0.3)
{
r5.w=_c1.y; //1.0
} else r5.w=_c1.w; //0.0
r6=tex2D(s2, r6.xy);
r5.xyz=r6.xyz * r5.w + r5.xyz;
r2.w=r2.w + r5.w;
r3.w=r3.w + _c1.y; //1.0
}
r2.w=1.0/r2.w;
//r0.yz=r0 * _c44.xxyw; //globalScreenSize
r0.y=r0.y * _c44.x; //globalScreenSize
r0.z=r0.z * _c44.y; //globalScreenSize
r0.y=dot(r0.yz, r0.yz)+_c0.x;//dp2
//r0.y=sqrt(r0.y);
//r0.y=1.0/r0.y;
r0.y=pow(r0.y, _c4.w); //0.5
r0.y=r0.y * _c4.w; //0.5
r0.x=r0.x + _c1.y; //1.0
r0.x=1.0/r0.x;
//r0.y is wrong
r0.x=saturate(r0.y * r0.x);
r4.xyz=r5 * r2.w - r3;
r0.xyz=r0.x * r4 + r3;
//_oC0.xyz=0.5*r0.xyz;
if (-r1.w<0.0) r0.xyz=r3.xyz;
if (-r0.w<0.0) r0.xyz=r1.xyz;
//for future use
r11=r0;
r1=tex2D(s4, _c0.x); //AdapLumSampler , 0.0
r0.w=1.0/r1.x;
r0.w=r0.w * _c81.y; //ToneMapParams.y
r1.x=1.0/r0.w;
r1.x=r1.x * _c81.x; //ToneMapParams.x
r1.xyz=r2 * _c66.x - r1.x; //Exposure.x
r2.xyz=max(r1, _c0.x); //0.0
r1.xyz=r2 * _c81.z; //ToneMapParams.z
r1.xyz=r1 * _c1.x; //0.25
r0.xyz=r0 * _c66.x + r1; //Exposure.x
r1.xyz=r0.w * r0;
r1.x=dot(r1.xyz, _c0.yzw); //0.2125, 0.7154, 0.0721
r0.xyz=r0 * r0.w - r1.x;
r0.xyz=_c82.x * r0 + r1.x; //deSatContrastGamma.x
r0.w=r1.x * _c84.w; //ColorShift.w
r1.yzw=r0.w * _c84.xxyz; //ColorShift
//darken as DarkeningAmount, but keeps colors
r2.x=saturate(r0.w);
r0.xyz=r0.xyz - _c84.xyz * r0.w; //ColorShift
r0.xyz=r2.x * r0.xyz + r1.yzww;
//coloring (green, brown, ...)
r0.xyz=2.0 * r0.xyz * _c83.xyz; //ColorCorrect
//keeps colors, changes luma
r1.x=saturate(r1.x);//luma
r0.w=_c82.z - _c1.y; //deSatContrastGamma.z - 1.0
r2.x=pow(r1.x, r0.w);
_oC0.xyz=r0.xyz * r2.x; //orig
_oC0.w=_c1.y; //1.0
//********************
float4 color;
//r0=tex2D(s2, _v0.xy);//hdr color
color= r11;
float4 origcolor = tex2D(s2, _v0.xy);
float4 colorbloom=tex2D(s3, _v0.xy);
colorbloom.r*=lerp(0.4, 1.3, saturate(pow(depth/300, 0.5)));
colorbloom.g*=lerp(0.4, 1.3, saturate(pow(depth/300, 0.5)));
colorbloom.b*=lerp(0.4, 1.3, saturate(pow(depth/300, 0.5)));
colorbloom.r*=BloomR;
colorbloom.g*=BloomG;
colorbloom.b*=BloomB;
color=colorbloom * BloomAmount + color;
float cgray=dot(color.xyz, 0.333);//luma
float3 poweredcolor=pow(color.xyz, ISaturation);
float newgray=dot(poweredcolor.xyz, 0.333);
color.xyz=poweredcolor.xyz*cgray/(newgray+0.0001);
r10.x=dot(color.xyz, _c12.xyz);
r10.x*=IBrightness;
color*=r10.x;
color.xyz=lerp(color.xyz, pow(color.xyz*2, IContrast), IWhiteAmount);
r5=tex2D(s4, _c0.x);
//r5=1.0;
//adaptation
r5.w=r5.x;
r5.w=0.725/r5.w;
color.xyz=color.xyz * r5.w;
r3.xy=_c10.xwxw;
r3.xy=r3.xy * r5.w;
color=color * _c7.y; //pre multiply
r1=color * _c7.z; //e multiply
r1=r1 + _c7.w;
color=color / r1;
color=BloomAmountAdd*colorbloom * r3.x + color;
color.xyz=lerp(color.xyz, 1 - pow(2.0, -color.xyz), 0.5);
float middlegray=dot(color.xyz, 0.3333);
float3 diffcolor=color.rgb-middlegray;
color.rgb+=diffcolor*1.0;
color.xyz=saturate(color.xyz);
color.xyz=lerp(color.xyz, sin(color.xyz*1.57079), 0.4);
//********************
#ifdef APPLYGAMECOLORCORRECTION
//apply original corrections (((
r0.w=1.0;//_c81.y/r5.x;//r5 is AdapLumSampler
luma=0.5*color.r + 0.5*color.g + 0.5*color.b;
color.xyz=color.xyz * r0.w - luma;
color.xyz=_c82.x * color.xyz + luma; //deSatContrastGamma.x
r0.w=luma * _c84.w; //ColorShift.w
r1.xyz=r0.w * _c84.xyz; //ColorShift
//darken as DarkeningAmount, but keeps colors
color.xyz=color.xyz - _c84.xyz * r0.w; //ColorShift
color.xyz=saturate(r0.w) * color.xyz + r1.xyz;
//coloring (green, brown, ...)
color.xyz=2.0 * color.xyz * _c83.xyz; //ColorCorrect
//desaturating
luma=saturate(luma);
r0.w=_c82.z - _c1.y; //deSatContrastGamma.z - 1.0
color.xyz=color.xyz * pow(luma, r0.w);
#endif //APPLYGAMECOLORCORRECTION
//********************
//pallete texture (0.082 version feature)
//#ifdef E_CC_PALETTE
color.rgb=saturate(color.rgb);
float3 brightness=0.001;//tex2D(s4, _c0.x);//adaptation luminance
// brightness=brightness/(brightness+1.0);
float3 palette;
float4 uvsrc=0.0;
uvsrc.y=brightness.r;
uvsrc.x=color.r;
palette.r=tex2Dlod(s13, uvsrc).r;
uvsrc.x=color.g;
uvsrc.y=brightness.g;
palette.g=tex2Dlod(s13, uvsrc).g;
uvsrc.x=color.b;
uvsrc.y=brightness.b;
palette.b=tex2Dlod(s13, uvsrc).b;
color.rgb=palette.rgb;
//#endif //E_CC_PALETTE
//********************
focus=length(center.xy)*1.41421;
focus=pow(focus, 5);
color.xyz-=focus*VignetteAmount;
color.xyz = saturate(color.xyz);
////////////////////SSAO///////////////////////////
tdepth = readDepth( _c78.w );
float d;
float pw = 1.0 / ViewportSize.x;
float ph = 1.0 / ViewportSize.y;
float aoCap = 10.0;
float ao = 0.0;
float aoMultiplier=1000.0;
float depthTolerance = 0.0001;
d=readDepth( float2(_c78.x+pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x+pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( float2(_c78.x+pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x+pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( float2(_c78.x+pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x+pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
pw*=2.0;
ph*=2.0;
aoMultiplier/=2.0;
d=readDepth( float2(_c78.x+pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y+ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x+pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
d=readDepth( float2(_c78.x-pw,_c78.y-ph));
ao+=min(aoCap,max(0.0,tdepth-d-depthTolerance) * aoMultiplier);
ao/=16.0;
//////////////////
//********************
_oC0.xyz=color.xyz;
//_oC0.w=1.0;
return _oC0+( 1.0 - ao )*( float4( tex2D( ScnSamp, IN.txcoord0 ).xyz * float3( uvsrc.rgb ), 1.0 ) );
}
//mine temporary post process
technique Shader_C215BE6E
{
pass p0
{
PixelShader = compile ps_3_0 PS_C215BE6E();
}
}
//original shader of post processing
technique Shader_ORIGINALPOSTPROCESS
{
pass p0
{
PixelShader=
asm
{
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.23.949.2378
//
// Parameters:
//
// sampler2D AdapLumSampler;
// sampler2D BloomSampler;
// float4 ColorCorrect;
// float4 ColorShift;
// float Exposure;
// sampler2D GBufferTextureSampler2;
// sampler2D GBufferTextureSampler3;
// sampler2D HDRSampler;
// sampler2D JitterSampler;
// float PLAYER_MASK;
// sampler2D StencilCopySampler;
// float4 TexelSize;
// float4 ToneMapParams;
// float4 deSatContrastGamma;
// float4 dofBlur;
// float4 dofDist;
// float4 dofProj;
// float gDirectionalMotionBlurLength;
// float4 globalScreenSize;
// row_major float4x4 motionBlurMatrix;
//
//
// Registers:
//
// Name Reg Size
// ---------------------------- ----- ----
// globalScreenSize c44 1
// Exposure c66 1
// motionBlurMatrix c72 4
// TexelSize c76 1
// dofProj c77 1
// dofDist c78 1
// dofBlur c79 1
// gDirectionalMotionBlurLength c80 1
// ToneMapParams c81 1
// deSatContrastGamma c82 1
// ColorCorrect c83 1
// ColorShift c84 1
// PLAYER_MASK c85 1
// GBufferTextureSampler2 s0 1
// GBufferTextureSampler3 s1 1
// HDRSampler s2 1
// BloomSampler s3 1
// AdapLumSampler s4 1
// JitterSampler s5 1
// StencilCopySampler s6 1
//
ps_3_0
def c0, 0, 0.212500006, 0.715399981, 0.0720999986
def c1, 0.25, 1, 256, 0
def c2, 0, 2, 4, 8
def c3, 58.1640015, 47.1300011, 0, 0
def c4, -0.5, -1.5, 1.5, 0.5
def c5, 2, -1, 0.125, 0
def c6, 256, 2, 4, 8
def c180, 0.0, 0.0, 0.0, 100.5
def c181, 1.0, 0.0, 0.0, 20.01
def c183, 800.0, 600.0, 0.0, 100.5
defi i0, 7, 0, 0, 0
dcl_texcoord v0.xy
dcl_2d s0
dcl_2d s1
dcl_2d s2
dcl_2d s3
dcl_2d s4
dcl_2d s5
dcl_2d s6
texld r0, v0, s1
add r0.y, -c77.x, c77.y
rcp r0.y, r0.y
mul r0.z, r0.y, c77.y
mul r0.z, r0.z, -c77.x
mad r0.x, c77.y, -r0.y, r0.x
rcp r0.x, r0.x
mul r0.y, r0.z, r0.x
texld r1, v0, s2
texld r2, v0, s3
abs r0.w, c79.w
mov r3, c4
mad r4.xy, c76, r3, v0
texld r4, r4, s2
mad r5.xy, c76, r3.zxzw, v0
texld r5, r5, s2
mad r3.xz, c76.xyyw, r3.wyzw, v0.xyyw
texld r6, r3.xzzw, s2
mad r3.xy, c76, r3.ywzw, v0
texld r7, r3, s2
dp3 r1.w, r4, r4
rcp r1.w, r1.w
cmp r3.xyz, -r1.w, c0.x, r4
dp3 r1.w, r5, r5
rcp r1.w, r1.w
cmp r4.xyz, -r1.w, c0.x, r5
dp3 r1.w, r6, r6
rcp r1.w, r1.w
cmp r5.xyz, -r1.w, c0.x, r6
dp3 r1.w, r7, r7
rcp r1.w, r1.w
cmp r6.xyz, -r1.w, c0.x, r7
dp3 r1.w, r1, r1
rcp r1.w, r1.w
cmp r7.xyz, -r1.w, c0.x, r1
mad r0.x, r0.z, r0.x, -c78.w
mad r0.x, c78.y, -r3.w, r0.x
max r1.w, r0.x, c0.x
rcp r0.x, c78.z
mul r0.x, r1.w, r0.x
lrp r1.w, r0.x, c79.z, c79.y
min r0.x, c79.z, r1.w
dp3 r0.z, r7, c0.yzww
dp3 r8.x, r3, c0.yzww
dp3 r8.y, r4, c0.yzww
dp3 r8.z, r5, c0.yzww
dp3 r8.w, r6, c0.yzww
dp4 r1.w, r8, c1.x
add r8, r8, -r1.w
dp4 r2.w, r8, r8
add r0.z, r0.z, -r1.w
mad r0.z, r0.z, r0.z, -r2.w
mul r0.x, r0.x, r0.x
cmp r0.x, r0.z, c1.y, r0.x
texld r8, v0, s0
mov r8.yz, c1
mad r9, r8.w, -r8.z, c2
cmp r9, r9, c1.y, c1.w
mad r10, r8.w, -c6.x, c6.yzwx
cmp r10, r10, -c1.y, -c1.w
add r9, r9, r10
mul r9, r9, c4.x
dp4 r0.z, r9, c1.y
add r0.z, r0.z, c4.w
rcp r0.z, r0.z
mul r8.xzw, r3.xyyz, r9.x
mad r7.xyz, r7, c4.w, r8.xzww
mad r7.xyz, r4, r9.y, r7
mad r7.xyz, r5, r9.z, r7
mad r7.xyz, r6, r9.w, r7
mul r7.xyz, r0.z, r7
add r0.z, -r0.x, c1.y
mul r1.w, r0.x, c1.x
mul r3.xyz, r3, r1.w
mad r3.xyz, r7, r0.z, r3
mad r3.xyz, r4, r1.w, r3
mad r3.xyz, r5, r1.w, r3
mad r3.xyz, r6, r1.w, r3
mad r4.xyz, v0.yxyw, c5.x, c5.y
mul r0.z, r4.y, c77.z
mul r0.z, r0.y, r0.z
mul r1.w, -r4.x, c77.w
mul r1.w, r0.y, r1.w
mul r5.xyz, r1.w, c73
mad r5.xyz, r0.z, c72, r5
mad r5.xyz, -r0.y, c74, r5
add r5.xyz, r5, c75
mul r0.y, -r5.z, c77.z
rcp r0.y, r0.y
mul r6.x, r5.x, r0.y
mul r0.y, r5.z, c77.w
rcp r0.y, r0.y
mul r6.y, r5.y, r0.y
add r0.yz, -r4, r6.xxyw
mul r0.yz, r0, c80.x
mul r4.xy, r0.yzzw, c5.z
texld r5, v0, s6
add r1.w, r5.x, -c85.x
mul r4.zw, r3.xyxy, c2.w
mad r4.zw, v0.xyxy, c3.xyxy, r4
texld r5, r4.zwzw, s5
add r2.w, r5.x, c4.x
mad r4.zw, r4.xyxy, r2.w, v0.xyxy
mov r5.xyz, r3
mov r2.w, c1.y
mov r3.w, c1.y
rep i0
mad r6.xy, r4, r3.w, r4.zwzw
texld r7, r6, s6
add r5.w, r7.x, -c85.x
cmp r5.w, r5.w, c1.w, c1.y
texld r6, r6, s2
mad r5.xyz, r6, r5.w, r5
add r2.w, r2.w, r5.w
add r3.w, r3.w, c1.y
endrep
rcp r2.w, r2.w
mul r0.yz, r0, c183.xxyw//c44.xxyw
dp2add r0.y, r0.yzzw, r0.yzzw, c0.x
rsq r0.y, r0.y
rcp r0.y, r0.y
mul r0.y, r0.y, c4.w
add r0.x, r0.x, c1.y
rcp r0.x, r0.x
mul_sat r0.x, r0.y, r0.x
mad r4.xyz, r5, r2.w, -r3
mad r0.xyz, r0.x, r4, r3
cmp r0.xyz, r1.w, r3, r0
cmp r0.xyz, -r0.w, r0, r1
texld r1, c0.x, s4
rcp r0.w, r1.x
mul r0.w, r0.w, c81.y
rcp r1.x, r0.w
mul r1.x, r1.x, c81.x
mad r1.xyz, r2, c66.x, -r1.x
max r2.xyz, r1, c0.x
mul r1.xyz, r2, c81.z
mul r1.xyz, r1, c1.x
mad r0.xyz, r0, c66.x, r1
mul r1.xyz, r0.w, r0
dp3 r1.x, r1, c0.yzww
mad r0.xyz, r0, r0.w, -r1.x
mad r0.xyz, c82.x, r0, r1.x
mul r0.w, r1.x, c84.w
mul r1.yzw, r0.w, c84.xxyz
mov_sat r2.x, r0.w
mad r0.xyz, c84, -r0.w, r0
mad r0.xyz, r2.x, r0, r1.yzww
mul r0.xyz, r0, c83
add r0.xyz, r0, r0
mov_sat r1.x, r1.x
add r0.w, -r8.y, c82.z
pow r2.x, r1.x, r0.w
//mul r2.x, r2.x, c181.x
mul oC0.xyz, r0, r2.x
mov oC0.w, c1.y
//texld r1, v0, s2
//mul oC0.xyz, r1, c199.z
};
}
}
and from other config:
#1
[spoiler]
Code: Select all
// Volumetric SSAO
// Implemented by Tomerk
// Optimized by Ethatron
// ---------------------------------------
// TWEAKABLE VARIABLES.
#undef TEST_MODE
// testMode. set to 1, you can see the raw ssao
#define LUMINANCE_CONSIDERATION
float luminosity_threshold = 0.3;
// comment this line to not take pixel brightness into account
#define N_SAMPLES 9
// number of samples, currently do not change.
float aoRadiusMultiplier = 4;
// Linearly multiplies the radius of the AO Sampling
float aoStrengthMultiplier = 1.0;
// Linearly multiplies the strength of the AO
float aoClamp = 0.0;
// The maximum strength of the AO, 0 is max strength, 1 is weakest
float ThicknessModel = 100;
// units in space the AO assumes objects' thicknesses are
// END OF TWEAKABLE VARIABLES.
// ---------------------------------------
texture2D noise;
sampler2D PassSamplerL34 = sampler_state
{
texture = <obge_LastRendertarget0_EFFECTPASS>;
AddressU = CLAMP;
AddressV = CLAMP;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
MIPFILTER = NONE;
};
struct VSOUTb
{
float4 vertPos : POSITION;
float2 UVCoord : TEXCOORD0;
};
struct VSINb
{
float4 vertPos : POSITION0;
float2 UVCoord : TEXCOORD0;
};
VSOUTb FrameVSm(VSIN IN)
{
VSOUT OUT = (VSOUT)0.0f; // initialize to zero, avoid complaints.
OUT.vertPos = IN.vertPos;
OUT.UVCoord = IN.UVCoord;
return OUT;
}
static const float2 sample_offsetm[N_SAMPLES] =
{
//#if N_SAMPLES >= 9
float2(-0.1376476f, 0.2842022f ),
float2(-0.626618f , 0.4594115f ),
float2(-0.8903138f, -0.05865424f),
float2( 0.2871419f, 0.8511679f ),
float2(-0.1525251f, -0.3870117f ),
float2( 0.6978705f, -0.2176773f ),
float2( 0.7343006f, 0.3774331f ),
float2( 0.1408805f, -0.88915f ),
float2(-0.6642616f, -0.543601f )
//#endif
};
static const float sample_radiusm[N_SAMPLES] =
{
//#if N_SAMPLES >= 9
0.948832,
0.629516,
0.451554,
0.439389,
0.909372,
0.682344,
0.5642,
0.4353,
0.5130
//#endif
};
float4 Occlusionb(VSOUTb IN) : COLOR0 {
float3 sample = tex2D(PassSamplerL, IN.UVCoord).rgb;
float depth = (IN.UVCoord);
[branch]
if (depth >= 0.99)
return float4(sample, 1.0);
float3 pos = (IN.UVCoord, depth);
float3 dx = ddx(pos);
float3 dy = ddy(pos);
float3 norm = normalize(cross(dx, dy));
norm.y *= -1;
float sample_depth;
float ao = 0;
float s = 0.0;
float2 rand_vec = (IN.UVCoord);
float2 sample_vec_divisor = g_InvFocalLen * depth * 2.0 / (aoRadiusMultiplier * 5000 * rcpres);
float2 sample_center = IN.UVCoord + norm.xy / sample_vec_divisor * float2(1, aspect);
float sample_center_depth = depth * 1.0 + norm.z * aoRadiusMultiplier * 10;
[unroll]
for (int i = 0; i < N_SAMPLES; i++) {
float2 sample_vec = reflect(sample_offset[i], rand_vec) / sample_vec_divisor;
float2 sample_coords = sample_center + sample_vec * float2(1, aspect);
float curr_sample_radius = sample_radius[i] * aoRadiusMultiplier * 10;
float curr_sample_depth = 3.0 * (sample_coords);
ao += clamp(0, curr_sample_radius + sample_center_depth - curr_sample_depth , 2 * curr_sample_radius);
ao -= clamp(0, curr_sample_radius + sample_center_depth - curr_sample_depth - ThicknessModel, 2 * curr_sample_radius);
s += 2 * curr_sample_radius;
}
ao /= s;
ao *= (depth);
ao = 1.0 - ao * aoStrengthMultiplier;
return float4(sample, ao);
}
float4 BlurNCombine(VSOUT IN) : COLOR0 {
float4 sample = tex2D(PassSamplerL, IN.UVCoord).rgba;
float3 color = sample.rgb;
float ao = sample.a * 4;
ao += tex2D(PassSamplerL, IN.UVCoord + float2( rcpres.x, 0)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(-rcpres.x, 0)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(0, rcpres.y)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(0, -rcpres.y)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + rcpres ).a;
ao += tex2D(PassSamplerL, IN.UVCoord - rcpres ).a;
ao += tex2D(PassSamplerL, IN.UVCoord + rcpres * float2(1, -1)).a;
ao += tex2D(PassSamplerL, IN.UVCoord - rcpres * float2(1, -1)).a;
ao /= 16;
#ifdef LUMINANCE_CONSIDERATION
float luminance = (color);
float white = 1.0;
float black = 0;
luminance = clamp(
max(black, luminance - luminosity_threshold) +
max(black, luminance - luminosity_threshold) +
max(black, luminance - luminosity_threshold), 0.0, 1.0);
ao = lerp(ao, white, luminance);
#endif
#ifdef TEST_MODE
return ao;
#endif
return float4(color * ao, 1);
}
technique t065
<
int group = 1.0;
int fxclass = 2.0;
int conditions = 2.0;
>
{
pass {
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 Occlusion();
}
pass {
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 BlurNCombine();
}
}
#2
Code: Select all
// By Christian Jakobsen
// Ported by Ethatron
// ---------------------------------------
// TWEAKABLE VARIABLES.
#undef TEST_MODE
// testMode. set to 1, you can see the raw ssao
float distance = 0.0025;
// END OF TWEAKABLE VARIABLES.
// ---------------------------------------
// shader codes begin here
texture2D s24;
sampler2D PassSamplerL3 = sampler_state
{
texture = <obge_LastRendertarget0_EFFECTPASS>;
AddressU = CLAMP;
AddressV = CLAMP;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
MIPFILTER = LINEAR;
};
texture2D cust_NoiseTexture < string filename = "Noise.dds"; >;
sampler2D NoiseSampler = sampler_state {
texture = <cust_NoiseTexture>;
AddressU = WRAP;
AddressV = WRAP;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
MIPFILTER = LINEAR;
};
struct VSINv
{
float4 vertPos : POSITION0;
float2 UVCoord : TEXCOORD0;
};
struct VSOUTv
{
float4 vertPos : POSITION;
float2 UVCoord : TEXCOORD0;
};
VSOUT FrameVSb(VSIN IN) {
VSOUT OUT = (VSOUT)0.0f; // initialize to zero, avoid complaints.
OUT.vertPos = IN.vertPos;
OUT.UVCoord = IN.UVCoord;
return OUT;
}
float4 Occlusion(VSOUT IN) : COLOR0 {
float3 sample = tex2D(PassSamplerL, IN.UVCoord).rgb;
#define screenTC IN.UVCoord
#define screenSize (IN.UVCoord)
#define sSceneDepthSampler DpthSampler
#define sRandVectSampler NoiseSampler
//Tile the texture coordinates
float2 rotationTC = screenTC * screenSize / 4.0f;
//Sample a random vector and transform it into [-1, 1] range
float3 vRotation = 2.0f * tex2Dlod(sRandVectSampler, float4(rotationTC, 0, 0)).rgb - 1.0f;
//Create rotation matrix
float3x3 matRotate;
float offsetScale = distance;
float h = 1.0f / (1.0f + vRotation.z);
matRotate._m00 = h * vRotation.y * vRotation.y + vRotation.z;
matRotate._m01 = -h * vRotation.y * vRotation.x;
matRotate._m02 = -vRotation.x;
matRotate._m10 = -h * vRotation.y * vRotation.x;
matRotate._m11 = h * vRotation.x * vRotation.x + vRotation.z;
matRotate._m12 = -vRotation.y;
matRotate._m20 = vRotation.x;
matRotate._m21 = vRotation.y;
matRotate._m22 = vRotation.z;
//Specify number of samples
const int nSamplesNum = 24;
//Sample the depth at the current pixel
float fSceneDepthP = (screenTC);
//Set the offset scale step
float fOffsetScaleStep = 1.0f + 2.4f / nSamplesNum;
//Initialize the accessibility factor to zero
float fAccessibility = 0;
//Sample area around current pixel and accumulate the accessibility factor
[loop]
for (int i = 0 ; i < (nSamplesNum / 8) ; i++)
for (int x = -1 ; x <= 1 ; x += 2)
for (int y = -1 ; y <= 1 ; y += 2)
for (int z = -1 ; z <= 1 ; z += 2) {
//Create offset vector
float3 vOffset = normalize(float3(x, y, z)) * (offsetScale *= fOffsetScaleStep);
//Rotate the offset vector
float3 vRotatedOffset = mul(vOffset, matRotate);
//Center pixel's coordinates in screen space
float3 vSamplePos = float3(screenTC, fSceneDepthP);
//Offset sample point
vSamplePos += float3(vRotatedOffset.xy, vRotatedOffset.z * fSceneDepthP);
//Read sample point depth
float fSceneDepthS = (vSamplePos.xy);
//Discard if depth equals max
if (fSceneDepthS >= 1.0f)
fAccessibility += 1.0f;
else {
//Compute accessibility factor
float fRangeIsInvalid = saturate(fSceneDepthP - fSceneDepthS);
fAccessibility += lerp(fSceneDepthS > vSamplePos.z, 0.5f, fRangeIsInvalid);
}
}
//Compute average accessibility
fAccessibility = fAccessibility / nSamplesNum;
//Amplify and return the ambient occlusion coefficient
return float4(sample, saturate(fAccessibility * fAccessibility + fAccessibility) / (fSceneDepthP));
}
float4 Blur2(VSOUT IN) : COLOR0 {
float4 sample = tex2D(PassSamplerL, IN.UVCoord).rgba;
#if 0
float ao = sample.a * 4;
ao += tex2D(PassSamplerL, IN.UVCoord + float2( rcpres.x, 0)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(-rcpres.x, 0)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(0, rcpres.y)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + float2(0, -rcpres.y)).a * 2;
ao += tex2D(PassSamplerL, IN.UVCoord + rcpres ).a;
ao += tex2D(PassSamplerL, IN.UVCoord - rcpres ).a;
ao += tex2D(PassSamplerL, IN.UVCoord + rcpres * float2(1, -1)).a;
ao += tex2D(PassSamplerL, IN.UVCoord - rcpres * float2(1, -1)).a;
ao /= 16;
#else
float ao = sample.a;
ao += 0.67 * tex2Dlod(PassSamplerL, float4(IN.UVCoord + float2( rcpres.x, rcpres.y), 0, 1)).a;
ao += 0.57 * tex2Dlod(PassSamplerL, float4(IN.UVCoord + float2(-rcpres.x, -rcpres.y), 0, 1)).a;
ao += 0.43 * tex2Dlod(PassSamplerL, float4(IN.UVCoord + float2( rcpres.x, -rcpres.y), 0, 2)).a;
ao += 0.33 * tex2Dlod(PassSamplerL, float4(IN.UVCoord + float2(-rcpres.x, rcpres.y), 0, 2)).a;
ao *= 0.333f;
#endif
ao = saturate(pow(saturate(ao * 1.25 - 0.25), 0.25));
#ifdef TEST_MODE
return ao;
#endif
return float4(sample.rgb * ao, 1);
}
technique t00
<
int group = 1;
int fxclass = 2;
int conditions = 3;
>
{
pass p0 {
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 Occlusion();
}
pass p1 {
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 Blur();
}
}
#3
Code: Select all
/////////
//Configuration
/////////
//These are the falloff parameters. The effect will falloff when depth is
//between these two values. Bear in mind that depth is NOT linear. A value
//of 0.5 is only a few meters away from the player, while a value of 0.75
//is about 100 meters away from the player.
extern float FalloffStart = 99.75f; //0.75f
extern float FalloffEnd = 99.85f; //0.85f
//This variable determines the number of sampling levels.
//Every level includes 8 samples, so 4 * 8 = 32 samples.
extern int ssao_sample_size = 9; //4
//This variable determines how much the sampling area will increase between
//SSAO levels. If you play with ssao_sample_size, you should adjust this.
//If you increase the number of samples, its a good idea to reduce this value.
//On the other hand, decreasing the samples should increase this value.
extern float ssao_sampling_area = 99.7f; //1.7f
//This value determines how much the DarkenAO function should strengthen the
//darker portions of the Ambient Occlusion. If you feel the effect is too
//subtle, try increasing it.
extern float DarkenAO_Intensity = 99.0f; //3.0f
//The DarkenAO function will strengthen the darkness of the ambient occlusion
//for samples lower than this value. To have it darken more of the scene,
//increase this value. To only darken the darkest parts, decrease the value.
//The value's range is from 0.0 to 1.0.
extern float DarkenAO_Threshold = 99.7f; //0.7f
//This value determines the maximum difference between the depth of the pixel
//being blurred and the adjacent pixel being sampled for the blur. Larger
//values can cause the AO of foreground and background objects to blur together.
//Smaller values can introduce artifacting on surfaces at sharp angles to the
//player.
extern float Blur_DropThreshhold = 99.002f; //0.002f
//Uncomment this line to see the raw SSAO shader. The effect will not be combined
//into the scene, allowing you to see what the AO of the scene looks like, and is
//useful when tweaking the above values to fine tune the effect.
//#define RAW_SSAO
//Uncomment this line to prevent the SSAO shader from reducing the effect on
//bright parts of the scene. Taking brightness into consideration reduces
//unappealing darkening of self-illuminating or highly specular objects, but
//it does cause an overall reduction of the effect on everything else,
//especially in well lit scenes.
//#define NO_BRIGHTNESS_CONSIDERATION
texture Depth4;
texture thisframe7;
texture lastpass4;
texture NoiseText
<
string filename="Noise.dds";
>;
float2 rcpres4;
float4x4 m44proj4;
static const float nearZ4 = m44proj._43 / m44proj._33;
static const float farZ4 = (m44proj._33 * nearZ) / (m44proj._33 - 1.0f);
sampler depthSampler4 = sampler_state
{
texture = <Depth>;
AddressU = WRAP;
AddressV = WRAP;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
sampler frameSampler4 = sampler_state
{
texture = <thisframe>;
AddressU = CLAMP;
AddressV = CLAMP;
MINFILTER = POINT;
MAGFILTER = POINT;
};
sampler passSampler4 = sampler_state
{
texture = <lastpass>;
AddressU = WRAP;
AddressV = WRAP;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
sampler noiseSampler = sampler_state
{
texture = <NoiseText>;
AddressU = WRAP;
AddressV = WRAP;
MINFILTER = POINT;
MAGFILTER = POINT;
};
struct VSOUT6
{
float4 vertPos : POSITION;
float2 UVCoord : TEXCOORD0;
};
struct VSIN6
{
float4 vertPos : POSITION0;
float2 UVCoord : TEXCOORD0;
};
VSOUT FrameVS8(VSIN IN)
{
VSOUT OUT = (VSOUT)0.0f; // initialize to zero, avoid complaints.
OUT.vertPos = IN.vertPos;
OUT.UVCoord = IN.UVCoord;
return OUT;
}
//The random texture gives us 3 random numbers.
//We use the first 2, so we can use the third to change things up a bit.
/*float4 randomizeVector(in float4 rnd)
{
float norm = rnd.x + rnd.y + rnd.z;
rnd = rnd + rnd.z;
return (rnd / norm);
}*/
float readDepth2(in float2 coord : TEXCOORD0)
{
float posZ = tex2D(depthSampler, coord).x;
posZ = pow(posZ, 0.05);
return (2.0f * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));
}
float compareDepths(in float depth1, in float depth2, inout int far)
{
float diff = (depth1 - depth2) * 100.0f; //depth difference (0-100)
float gdisplace = 0.2f; //gauss bell center
float garea = 2.0f; //gauss bell width 2
//reduce left bell width to avoid self-shadowing
if (diff < gdisplace)
{
garea = 0.1f;
}
else
{
far = 1.0f;
}
float gauss = pow(2.7182,-2.0f*(diff-gdisplace)*(diff-gdisplace)/(garea*garea));
return gauss;
}
float calAO(in float2 texCoord : TEXCOORD0, in float depth, in float dw, in float dh)
{
float temp = 0.0f;
float temp2 = 0.0f;
float coordw = texCoord.x + dw/depth;
float coordh = texCoord.y + dh/depth;
float coordw2 = texCoord.x - dw/depth;
float coordh2 = texCoord.y - dh/depth;
if (coordw < 1.0 && coordw > 0.0 && coordh < 1.0 && coordh > 0.0)
{
float2 coord = float2(coordw , coordh);
float2 coord2 = float2(coordw2, coordh2);
int far = 0.0f;
temp = compareDepths(depth, readDepth(coord), far);
//DEPTH EXTRAPOLATION:
if (far > 0.0f)
{
temp2 = compareDepths(readDepth(coord2),depth,far);
temp += (1.0f-temp)*temp2;
}
}
return temp;
}
float3 DarkenAO( float3 color )
{
//This is the darkening threshold.
float it = 1/DarkenAO_Threshold;
if (color.x > DarkenAO_Threshold)
return color;
else
return pow((color * it), DarkenAO_Intensity) / it;
}
float4 Ssao(VSOUT IN) : COLOR0
{
float2 fres = (1/rcpres[0]) / 512.0f;
float4 random = tex2D(noiseSampler,IN.UVCoord.xy*fres.xy);
random = (random * 2.0) - float4(1.0f, 1.0f, 1.0f, 0.0f);
float depth = readDepth(IN.UVCoord);
if(depth > FalloffEnd)
return float4(1.0f, 1.0f, 1.0f, 1.0f);
float ao = 0.0f;
float pw = rcpres[0];
float ph = rcpres[1];
for(int i=0; i<ssao_sample_size; ++i)
{
//calculate color bleeding and ao:
ao+=calAO(IN.UVCoord, depth, pw, ph);
ao+=calAO(IN.UVCoord, depth, pw, -ph);
ao+=calAO(IN.UVCoord, depth, -pw, ph);
ao+=calAO(IN.UVCoord, depth, -pw, -ph);
ao+=calAO(IN.UVCoord, depth, pw*1.2f, 0.0f);
ao+=calAO(IN.UVCoord, depth, -pw*1.2f, 0.0f);
ao+=calAO(IN.UVCoord, depth, 0.0f, ph*1.2f);
ao+=calAO(IN.UVCoord, depth, 0.0f, -ph*1.2f);
pw += random.x*0.00035f;
ph += random.y*0.00035f;
pw *= ssao_sampling_area;
ph *= ssao_sampling_area;
}
//Test AO Raw Effect
//-------------------
ao = 1.0f-(ao/(ssao_sample_size*8.0f));
//Perform the falloff if depth gets too deep.
if( depth > FalloffStart)
{
float add = 1 - ao;
ao = ao + (add * ((depth - FalloffStart) / (FalloffEnd - FalloffStart)));
}
float3 calcAO = ao;
calcAO = DarkenAO(calcAO);
return float4(calcAO.rgb,1.0);
//-------------------
}
static const int cKernelSize = 13;
static const float2 OffsetMaskH = float2(1.0f, 0.0f);
static const float2 OffsetMaskV = float2(0.0f, 1.0f);
//Blur Weights
/*static const float BlurWeights[cKernelSize] =
{
1.0f / 4096.0f,
12.0f / 4096.0f,
66.0f / 4096.0f,
220.0f / 4096.0f,
495.0f / 4096.0f,
792.0f / 4096.0f,
924.0f / 4096.0f,
792.0f / 4096.0f,
495.0f / 4096.0f,
220.0f / 4096.0f,
66.0f / 4096.0f,
12.0f / 4096.0f,
1.0f / 4096.0f
};*/
static const float BlurWeights2[cKernelSize] =
{
0.057424882f,
0.058107773f,
0.061460144f,
0.071020611f,
0.088092873f,
0.106530916f,
0.114725602f,
0.106530916f,
0.088092873f,
0.071020611f,
0.061460144f,
0.058107773f,
0.057424882f
};
static const float2 BlurOffsets2[cKernelSize] =
{
float2(-6.0f * rcpres[0], -6.0f * rcpres[1]),
float2(-5.0f * rcpres[0], -5.0f * rcpres[1]),
float2(-4.0f * rcpres[0], -4.0f * rcpres[1]),
float2(-3.0f * rcpres[0], -3.0f * rcpres[1]),
float2(-2.0f * rcpres[0], -2.0f * rcpres[1]),
float2(-1.0f * rcpres[0], -1.0f * rcpres[1]),
float2( 0.0f * rcpres[0], 0.0f * rcpres[1]),
float2( 1.0f * rcpres[0], 1.0f * rcpres[1]),
float2( 2.0f * rcpres[0], 2.0f * rcpres[1]),
float2( 3.0f * rcpres[0], 3.0f * rcpres[1]),
float2( 4.0f * rcpres[0], 4.0f * rcpres[1]),
float2( 5.0f * rcpres[0], 5.0f * rcpres[1]),
float2( 6.0f * rcpres[0], 6.0f * rcpres[1])
};
//Two-Pass Blur
float4 BlurPS(float2 uv : TEXCOORD0, uniform float2 OffsetMask) : COLOR0
{
float4 Color[cKernelSize];
float Weight[cKernelSize];
float WeightSum = 0.0f;
float4 finalColor = float4(0.0f, 0.0f, 0.0f, 0.0f);
float Depth1 = readDepth( uv );
int i = 0;
for (i = 0; i < cKernelSize; i++)
{
//Perform the offset.
float2 uvOff = uv + (BlurOffsets[i] * OffsetMask);
//Sample the depth of the sampled pixel, and compare.
float Depth2 = readDepth( uvOff );
float diff = Depth1 - Depth2;
if(abs(diff) < Blur_DropThreshhold)
{
//Accept this sample.
Color[i] = tex2D( passSampler, uvOff );
Weight[i] = BlurWeights[i];
//Weight[i] = 1 / 13.0f;
}
else
{
//Drop the sample.
Color[i] = float4(0.0f, 0.0f, 0.0f, 0.0f);
Weight[i] = 0.0f;
}
WeightSum += Weight[i];
}
//Renormalize the weights, and combine the colors.
for (i = 0; i < cKernelSize; i++)
{
Weight[i] /= WeightSum;
finalColor += Color[i] * Weight[i];
}
return finalColor;
}
float4 Combine( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 fSample = tex2D(frameSampler, Tex);
float4 pSample = tex2D(passSampler, Tex);
#if !defined( NO_BRIGHTNESS_CONSIDERATION )
float samBrightness = (0.299 * fSample.r) + (0.587 * fSample.g) + (0.114 * fSample.b);
pSample = float4(pow(pSample,(1 - samBrightness)).rgb,1.0);
#endif
return (fSample * pSample);
}
technique t09
{
pass p0
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 Ssao();
CullMode = none;
}
pass p1
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 BlurPS( OffsetMaskH );
}
pass p2
{
VertexShader = compile vs_3_0 FrameVS();
PixelShader = compile ps_3_0 BlurPS( OffsetMaskV );
}
#if !defined( RAW_SSAO )
pass p3
{
VertexShader = compile vs_1_1 FrameVS();
}
#endif
}
sorry for gigantic post but I can't find SPOILER option here :S