| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603 |
- // M I D H R A S T I C E N B F O R F A L L O U T 3
- //++++++++++++++++++++++++++++++++++++++++++++
- // ENBSeries effect file
- // visit http://enbdev.com for updates
- // Copyright (c) 2007-2011 Boris Vorontsov
- // Tinting and Anamorphic Flare code courtesy of Matso
- //++++++++++++++++++++++++++++++++++++++++++++
- //+++++++++++++++++++++++++++++
- //internal parameters, can be modified
- //+++++++++++++++++++++++++++++
- #define USE_TINTING 1
- #define TINT_COLOR float3(0.77, 0.7, 0.825)
- #define TINT_TEXTURE tex2D(SamplerBloom6, In.txcoord0.xy).rgb
- #define TINT_LEVEL 1.3
- #define USE_ANAMFLARE 1 // comment it to disable anamorphic lens flare
- #if USE_TINTING == 1
- #define TINT TINT_COLOR
- #elseif USE_TINTING == 2
- #define TINT TINT_TEXTURE
- #endif
- //+++++++++++++++++++++++++++++
- //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;
- //additional info for computations
- float4 TempParameters;
- //Lenz reflection intensity, lenz reflection power
- float4 LenzParameters;
- //BloomRadius1, BloomRadius2, BloomBlueShiftAmount, BloomContrast
- float4 BloomParameters;
- // Anamorphic flare parameters
- #define fFlareLuminance 0.333 // bright pass luminance value
- #define fFlareBlur 200.0 // manages the size of the flare //200
- #define fFlareIntensity 0.10 // effect intensity
- // MIDHRAS - Use the settings below to adjust BloomRadius for the consecutive bloom passes.
- //#define BloomRadius0 0.282
- #define BloomRadius1 1.524
- #define BloomRadius2 1.524
- texture2D texBloom1;
- texture2D texBloom2;
- texture2D texBloom3;
- texture2D texBloom4;
- texture2D texBloom5;
- texture2D texBloom6;
- texture2D texBloom7;//additional bloom tex
- texture2D texBloom8;//additional bloom tex
- sampler2D SamplerBloom1 = sampler_state
- {
- Texture = <texBloom1>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom2 = sampler_state
- {
- Texture = <texBloom2>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom3 = sampler_state
- {
- Texture = <texBloom3>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom4 = sampler_state
- {
- Texture = <texBloom4>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom5 = sampler_state
- {
- Texture = <texBloom5>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom6 = sampler_state
- {
- Texture = <texBloom6>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom7 = sampler_state
- {
- Texture = <texBloom7>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerBloom8 = sampler_state
- {
- Texture = <texBloom8>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- struct VS_OUTPUT_POST
- {
- float4 vpos : POSITION;
- float2 txcoord0 : TEXCOORD0;
- };
- struct VS_INPUT_POST
- {
- float3 pos : POSITION;
- float2 txcoord0 : TEXCOORD0;
- };
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- //
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- VS_OUTPUT_POST VS_Bloom(VS_INPUT_POST IN)
- {
- VS_OUTPUT_POST OUT;
- OUT.vpos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
- OUT.txcoord0.xy=IN.txcoord0.xy+TempParameters.xy;//1.0/(bloomtexsize*2.0)
- return OUT;
- }
- /**
- * Bright pass - rescales sampled pixel to emboss bright enough value.
- */
- float3 BrightPass(float2 tex)
- {
- float3 c = tex2D(SamplerBloom2, tex).rgb;
- float3 bC = max(c - float3(fFlareLuminance, fFlareLuminance, fFlareLuminance), 0.0);
- float bright = dot(bC, 1.0);
- bright = smoothstep(0.0f, 0.5, bright);
- return lerp(0.0, c, bright);
- }
- /**
- * Anamorphic sampling function - scales pixel coordinate
- * to stratch the image along one of the axels.
- * (http://en.wikipedia.org/wiki/Anamorphosis)
- */
- float3 AnamorphicSample(int axis, float2 tex, float blur)
- {
- tex = 2.0 * tex - 1.0;
- if (!axis) tex.x /= -blur;
- else tex.y /= -blur;
- tex = 0.5 * tex + 0.5;
- return BrightPass(tex);
- }
- /**
- * Converts pixel color to gray-scale.
- */
- float GrayScale(float3 sample)
- {
- return dot(sample, float3(0.3, 0.59, 0.11));
- }
- // Constants ///////////////////////////////////////////////////////////////
- const float2 bloomOffset[8]=
- {
- float2(0.707, 0.707),
- float2(0.707, -0.707),
- float2(-0.707, 0.707),
- float2(-0.707, -0.707),
- float2(0.0, 1.0),
- float2(0.0, -1.0),
- float2(1.0, 0.0),
- float2(-1.0, 0.0)
- };
- // deepness, curvature, inverse size
- const float3 offset[4]=
- {
- float3(1.6, 4.0, 1.0),
- float3(0.7, 0.25, 2.0),
- float3(0.3, 1.5, 0.5),
- float3(-0.5, 1.0, 1.0)
- };
- // color filter per reflection
- const float3 factors[4]=
- {
- float3(0.3, 0.4, 0.4),
- float3(0.2, 0.4, 0.5),
- float3(0.5, 0.3, 0.7),
- float3(0.1, 0.2, 0.7)
- };
- ////////////////////////////////////////////////////////////////////////////
- // Anamorphic lens flare pixel shader (Matso code)
- float4 PS_ProcessPass_Anamorphic(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
- {
- float4 res;
- float2 coord = IN.txcoord0.xy;
- //MIDHRAS - Anamorphic flare can be used in various ways: if you set all RGB-values to a single identical number, the AF will take on the colour of the light it's triggered by. However, setting only one RGB value, or any combination of the three using different numbers, allows you to set the colour of the flare. The higher the numbers, the more opaque and strong the flares.
- float3 anamFlare = AnamorphicSample(0, coord.xy, fFlareBlur) * float3(0.35, 0.35, 0.35); //trichromatic Anamorphic Flare (adaptive)
- //float3 anamFlare = AnamorphicSample(0, coord.xy, fFlareBlur) * float3(0.75, 0.55, 0.0); //monochromatic Anamorphic Flare RED
- //float3 anamFlare = AnamorphicSample(0, coord.xy, fFlareBlur) * float3(0.0, 0.55, 0.0); //monochromatic Anamorphic Flare GREEN
- //float3 anamFlare = AnamorphicSample(0, coord.xy, fFlareBlur) * float3(0.0, 0.0, 1.0); //monochromatic Anamorphic Flare BLUE
- //MIDHRAS - The RGB values for the float3 values above can be used to set the colour of the AnamFlare. Putting them all at the same values results in an anamFlare that takes on the colour of the light that causes it. Putting two values to 0 will give you a flare in the colour of the parameter that you gave a value above zero. the higher the number, the more opaque the flare.
-
- res.rgb = anamFlare * fFlareIntensity;
- res.a = 1.0;
-
- return res;
- }
- //zero pass HQ, input texture is fullscreen
- //SamplerBloom1 - fullscreen texture
- float4 PS_BloomPrePass(VS_OUTPUT_POST In) : COLOR
- {
- float4 bloomuv;
- float4 bloom=0.05;//MIDHRAS - 0.0 //tex2D(SamplerBloom1, In.txcoord0);
- const float2 offset[4]=
- {
- float2(0.25, 1.25),
- float2(0.25, -0.25),
- float2(-0.25, 0.25),
- float2(-0.25, -0.25)
- };
- //TempParameters.w==1 if first pass, ==2 is second pass
- float2 screenfact=TempParameters.z;
- screenfact.y*=ScreenSize.z;
- float4 srcbloom=bloom;
- for (int i=0; i<4; i++)
- {
- bloomuv.xy=offset[i];
- bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;
- float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
- bloom.xyz+=tempbloom.xyz;
- }
- bloom.xyz*=0.35;
- bloom.xyz=min(bloom.xyz, 32768.0);
- bloom.xyz=max(bloom.xyz, 0.0);
- return bloom;
- }
- //first and second passes draw to every texture
- //twice, after computations of these two passes,
- //result is set as input to next cycle
- //first pass
- //SamplerBloom1 is result of prepass or second pass from cycle
- float4 PS_BloomTexture1(VS_OUTPUT_POST In) : COLOR
- {
- float4 bloomuv;
- float4 bloom=tex2D(SamplerBloom1, In.txcoord0);
- const float2 offset[8]=
- {
- float2(1.0, 1.0),
- float2(1.0, -1.0),
- float2(-1.0, 1.0),
- float2(-1.0, -1.0),
- float2(0.0, 1.0),
- float2(0.0, -1.0),
- float2(1.0, 0.0),
- float2(-1.0, 0.0)
- };
- float2 screenfact=0.0017;
- screenfact.y*=ScreenSize.z;
- float4 srcbloom=bloom;
- //TempParameters.w == (1+passnumber)
- //float step=BloomParameters.x;//*pow(2.0, BloomParameters.x * (TempParameters.w-1.0));//*0.5
- float step = BloomRadius1 * BloomParameters.x; //MIDHRAS - uncomment if bloom radius control is needed (also set BloomRadius1 above).
- // float step=(TempParameters.w-0.25);//
- screenfact.xy*=step;//====================================================
- float4 bloomadd=bloom;
- for (int i=0; i<8; i++)
- {
- bloomuv.xy=offset[i];
- bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;//-(1.0/256.0);//-(1.0/512.0);
- float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
- bloom+=tempbloom;
- }
- bloom*=0.1111111;
- //////////////////////////////////////////////////////////////////////////////////
- #ifdef USE_TINTING
- float3 tint = TINT * TINT_LEVEL;
- float ttt = max(dot(bloom.xyz, 0.333) - dot(srcbloom.xyz, 0.111), 0.0);
- //float ttt = max(dot(bloom.xyz, 0.333) - dot(srcbloom.xyz, 0.333), 0.0);
- float gray = BloomParameters.z * ttt * 10.0;
- float mixfact = (gray / (1.0 + gray));
-
- mixfact *= 1.0 - saturate((TempParameters.w - 1.0) * 0.2);
- tint.xy += saturate((TempParameters.w - 1.0) * 0.3);
- tint.xy = saturate(tint.xy);
-
- bloom.xyz *= lerp(1.0, tint.xyz, mixfact);
- #endif
- //////////////////////////////////////////////////////////////////////////////////
- //MIDHRAS - dpeasant alternative to Matso's tinting code:
- /*
- //float3 violet=float3(0.78, 0.5, 1.0);
- float3 violet=float3(0.6, 0.4, 1.0);//v3
- // float3 violet=float3(0.27, 0.52, 1.0);//v4
- //this applies when white
- //float gray=0.104*dot(srcbloom.xyz, 0.333);//max(srcbloom.x, max(srcbloom.y, srcbloom.z));
- //this applies on dark and when contrast
- float ttt=dot(bloom.xyz, 0.333)-dot(srcbloom.xyz, 0.333);
- ttt=max(ttt, 0.0);
- float gray=BloomParameters.z*ttt*10;//max(srcbloom.x, max(srcbloom.y, srcbloom.z));
- float mixfact=(gray/(1.0+gray));
- mixfact*=1.0-saturate((TempParameters.w-1.0)*0.2);
- violet.xy+=saturate((TempParameters.w-1.0)*0.3);
- violet.xy=saturate(violet.xy);
- bloom.xyz*=lerp(1.0, violet.xyz, mixfact);
- */
-
-
- bloom.w=1.0;
- return bloom;
- }
- //second pass
- //SamplerBloom1 is result of first pass
- float4 PS_BloomTexture2(VS_OUTPUT_POST In) : COLOR
- {
- float4 bloomuv;
- float4 bloom=tex2D(SamplerBloom1, In.txcoord0);
- const float2 offset[8]=
- {
- float2(1.0, 1.0),
- float2(1.0, -1.0),
- float2(-1.0, 1.0),
- float2(-1.0, -1.0),
- float2(0.0, 1.0),
- float2(0.0, -1.0),
- float2(1.0, 0.0),
- float2(-1.0, 0.0)
- };
- float2 screenfact=0.0017;
- screenfact.y*=ScreenSize.z;
- float4 srcbloom=bloom;
- //TempParameters.w == (1+passnumber)
- // float step=(TempParameters.w-0.25);
- //float step=BloomParameters.y;//*pow(2.0, BloomParameters.y * (TempParameters.w-1.0))*2.0;//*0.5
- float step = BloomRadius2 * BloomParameters.y;
- screenfact.xy*=step;//*0.25====================================================
- float4 rotvec=0.0;
- sincos(0.3927, rotvec.x, rotvec.y);
- for (int i=0; i<8; i++)
- {
- bloomuv.xy=offset[i];
- bloomuv.xy=reflect(bloomuv.xy, rotvec.xy);///????????
- bloomuv.xy=(bloomuv.xy*screenfact.xy)+In.txcoord0.xy;
- float4 tempbloom=tex2D(SamplerBloom1, bloomuv.xy);
- bloom+=tempbloom;
- }
- bloom*=0.111111;
- float Saturation=-0.206;//todo modify this, negative or positive, you can move this at the beginning of shader file
- float middlegray=(bloom.r+bloom.g+bloom.b)*0.333;
- float3 diffcolor=bloom.rgb-middlegray;
- //bloom.rgb+=diffcolor*Saturation;
- //bloom.rgb=max(bloom.rgb, 0.0); //output must be never negative, but "saturate" also work here and faster.
- bloom.w=1.0;
- return bloom;
- }
- //last pass, mix several bloom textures
- //SamplerBloom5 is the result of prepass
- //float4 PS_BloomPostPass(float2 vPos : VPOS ) : COLOR
- float4 PS_BloomPostPass(VS_OUTPUT_POST In) : COLOR
- {
- float4 bloom;
- //v1
- bloom =tex2D(SamplerBloom1, In.txcoord0);
- bloom+=tex2D(SamplerBloom2, In.txcoord0);
- bloom+=tex2D(SamplerBloom3, In.txcoord0);
- bloom+=tex2D(SamplerBloom4, In.txcoord0);
- bloom+=tex2D(SamplerBloom7, In.txcoord0);
- bloom+=tex2D(SamplerBloom8, In.txcoord0);
- bloom+=tex2D(SamplerBloom5, In.txcoord0);
- // bloom+=tex2D(SamplerBloom6, In.txcoord0);
- bloom*=0.142857;
- float3 lenz=0;
- float2 lenzuv=0.0;
- //deepness, curvature, inverse size
- const float3 offset[4]=
- {
- float3(1.6, 4.0, 1.0),
- float3(0.7, 0.25, 2.0),
- float3(0.3, 1.5, 0.5),
- float3(-0.5, 1.0, 1.0)
- };
- //color filter per reflection
- const float3 factors[4]=
- {
- float3(0.3, 0.4, 0.4),
- float3(0.2, 0.4, 0.5),
- float3(0.5, 0.3, 0.7),
- float3(0.1, 0.2, 0.7)
- };
- //lenzuv.xy=0.5-lenzuv.xy;
- //distfact=0.5-lenzuv.xy-0.5;
- if (LenzParameters.x>0.00001)
- {
- for (int i=0; i<4; i++)
- {
- float2 distfact=(In.txcoord0.xy-0.5);
- lenzuv.xy=offset[i].x*distfact;
- lenzuv.xy*=pow(2.0*length(float2(distfact.x*ScreenSize.z,distfact.y)), offset[i].y);
- lenzuv.xy*=offset[i].z;
- lenzuv.xy=0.5-lenzuv.xy;//v1
- // lenzuv.xy=In.txcoord0.xy-lenzuv.xy;//v2
- float3 templenz=tex2D(SamplerBloom2, lenzuv.xy);
- templenz=templenz*factors[i];
- distfact=(lenzuv.xy-0.5);
- distfact*=2.0;
- templenz*=saturate(1.0-dot(distfact,distfact));//limit by uv 0..1
- // templenz=factors[i] * (1.0-dot(distfact,distfact));
- float maxlenz=max(templenz.x, max(templenz.y, templenz.z));
- /* float3 tempnor=(templenz.xyz/maxlenz);
- tempnor=pow(tempnor, tempF1.z);
- templenz.xyz=tempnor.xyz*maxlenz;
- */
- float tempnor=(maxlenz/(1.0+maxlenz));
- tempnor=pow(tempnor, LenzParameters.y);
- templenz.xyz*=tempnor;
- // templenz*=maxlenz*maxlenz;
- lenz+=templenz;
- // lenz.xyz=max(lenz.xyz, templenz.xyz*0.99);
- }
- lenz.xyz*=0.25*LenzParameters.x;
- bloom.xyz+=lenz.xyz;
- // bloom.w=dot(lenz.xyz, 0.333);
- bloom.w=max(lenz.xyz, max(lenz.y, lenz.z));
- }
- return bloom;
- }
- //---------------------------------------------------------------------------------
- technique BloomPrePass
- {
- pass p0
- {
- VertexShader = compile vs_3_0 VS_Bloom();
- PixelShader = compile ps_3_0 PS_BloomPrePass();
- ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
- CullMode=NONE;
- AlphaBlendEnable=FALSE;
- AlphaTestEnable=FALSE;
- SEPARATEALPHABLENDENABLE=FALSE;
- FogEnable=FALSE;
- SRGBWRITEENABLE=FALSE;
- }
- }
- technique BloomTexture1
- {
- pass p0
- {
- VertexShader = compile vs_3_0 VS_Bloom();
- PixelShader = compile ps_3_0 PS_BloomTexture1();
- ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
- CullMode=NONE;
- AlphaBlendEnable=FALSE;
- AlphaTestEnable=FALSE;
- SEPARATEALPHABLENDENABLE=FALSE;
- FogEnable=FALSE;
- SRGBWRITEENABLE=FALSE;
- }
- }
- technique BloomTexture2
- {
- pass p0
- {
- VertexShader = compile vs_3_0 VS_Bloom();
- PixelShader = compile ps_3_0 PS_BloomTexture2();
- ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
- CullMode=NONE;
- AlphaBlendEnable=FALSE;
- AlphaTestEnable=FALSE;
- SEPARATEALPHABLENDENABLE=FALSE;
- FogEnable=FALSE;
- SRGBWRITEENABLE=FALSE;
- }
- }
- technique BloomPostPass
- {
- pass p0
- {
- VertexShader = compile vs_3_0 VS_Bloom();
- PixelShader = compile ps_3_0 PS_BloomPostPass();
- ColorWriteEnable=ALPHA|RED|GREEN|BLUE;
- CullMode=NONE;
- AlphaBlendEnable=FALSE;
- AlphaTestEnable=FALSE;
- SEPARATEALPHABLENDENABLE=FALSE;
- FogEnable=FALSE;
- SRGBWRITEENABLE=FALSE;
- }
- #ifdef USE_ANAMFLARE
- pass p1
- {
- AlphaBlendEnable = true;
- SrcBlend = One;
- DestBlend = One;
-
- PixelShader = compile ps_3_0 PS_ProcessPass_Anamorphic();
- }
- #endif
- }
|