//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
//ENBSeries:
boris-vorontsov@yandex.ru, boris-vorontsov.narod.ru
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
/*
THIS IS HLSL (HIGH LEVEL SHADER LANGUAGE) FILE FOR EXECUTING ADDITIONAL
HARDWARE EFFECTS. MAKE THE COPY BEFORE CHANGING IT!
edited by Dpeasant, credits go to DKT for his hdr-tonemap, to OBGE-shader coder guy(didnt remeber his nickname, and i dont have obge currently) for his crysis-colourmood code and to Boris for his enb and skyrim tonemap shader
*/
//keyboard controled variables
float tempF1;
float tempF2;
float tempF3;
float tempF4;
float tempF5;
float tempF6;
float tempF7;
float tempF8;
float tempF9;
float tempF0;
float EIntensityContrastV2=1.25;//contrast,as it says
float EColorSaturationV2=2.2;//saturation, works in conjunction with contrast. If you want to decrease or increase colours, youd better use next option
float Color1=0.85;//use this to control overall colours
float EAdaptationMinV3=0.086;
float EAdaptationMaxV3=0.28;
float EToneMappingCurveV3=7.0;
float Defog=0.05;//this controls the intensity of colourfilter, fogcolor.
float4 FogColor={0.06, 0.023, 0.086, 0.2}; //Values for blue, green, red and white. Cant remember which goes for what, experiment.
float4 FogColor2={0.09, 0.1, 0.02, 0.0};//not used
float Exposure=0.1;//exposure. Can be negative also. I have very poor contrast ration on my screen(350:1), so maybe it will be too exposed for you. Change it yourself.
float Gamma=1.0;//gamma. Thats it
float BlueShift=0.05;//Blueshift - overall tint of the image.
float fRatio = 0.5; // blend ratio (0-1)
float moodR = 0.75; // mood color red component
float moodG = 0.66; // mood color green component
float moodB = 0.515; // mood color blue component
////////////////////////////////////////////////////////
//global variables, already set before executing this code
float ScreenSize; //width of the display resolution (1024 f.e.)
float ScreenScaleY; //screen proportions (1.333 for 1024/768)
float ScreenBrightnessAdaptation;//(-10..10) for bloom it controls how much to dark in the night or when scene is dark (user defined constant factor)
float bloomPower;//(0..10) actually used for bloom, but may be useful here (user defined constant factor)
float useBloom;//(0 or 1) if bloom enabled by user
//textures
texture2D texColor;
texture2D texs4;//adaptation enb
texture2D texs3;//bloom enb
sampler2D SamplerColor = sampler_state
{
Texture = <texColor>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;//NONE;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
};
sampler2D _s4 = sampler_state
{
Texture = <texs4>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//LINEAR;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D _s3 = sampler_state
{
Texture = <texs3>;
MinFilter = LINEAR;//
MagFilter = LINEAR;//
MipFilter = NONE;//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;
};
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
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;
}
float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
{
/*
float tempF1=5.0;
float tempF2=4.0;
float tempF3=1.0;
float tempF4=1.0;
float tempF5=1.3;
float tempF6=4.35;
float tempF7=1.12;
float tempF8=1.2;
float tempF9=3.17;
float tempF0=1.4;
*/
//START TO MAKE YOUR CHANGES FROM HERE
float4 res;
float4 uvsrc=0;
uvsrc.xy=In.txcoord;
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.41),
float2( 0.0,-1.41),
float2(-1.41, 0.0),
float2( 1.41, 0.0)
};
res=0.2;
float4 coord=1.0;
coord.xy=In.txcoord.xy;
float4 origcolor=tex2D(SamplerColor, coord.xy);
float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
res+=origcolor;
float range=0.0005*tempF1/ScreenSize;
for (int i=0; i<8; i++)
{
coord.xy=In.txcoord+offset[i]*range;
float4 color;
float gray;
color=tex2D(SamplerColor, coord.xy);
float4 colordiff=abs(origcolor-color);
gray=dot(colordiff.rgb,0.333);
float lerpfact=saturate(8.0*abs(gray)*color.a);//saturate
res+=lerp(origcolor, color, lerpfact);
}
res=res*0.142222;
float4 color=res; //tex2Dbias(SamplerColor, uvsrc);
float tf7=tempF7*1.04;
float tf8=tempF8*0.3;
//float3 correctedcolor=saturate((1.0-color*tempF9*0.5)*tempF0*0.11);
//res.rgb=saturate(color.rgb-correctedcolor);
//res.rgb=pow(res.rgb,0.3)*1.04;
float4 colInput = tex2D(SamplerColor, coord.xy);
float4 colMood = 1.0f;
colMood.r = moodR;
colMood.g = moodG;
colMood.b = moodB;
float fLum = ( colInput.r + colInput.g + colInput.b ) / 3;
colMood = lerp(0, colMood, saturate(fLum * 2.0));
colMood = lerp(colMood, 1, saturate(fLum - 0.5) * 2.0);
float4 colOutput = lerp(colInput, colMood, saturate(fLum * fRatio));
res.rgb=max(0, colOutput);
res.rgb = max(0, res.rgb - Defog * FogColor.rgb);
res.rgb *= pow(2.0f, Exposure);
res.rgb = pow(res.rgb, Gamma);
float3 d = res.rgb * float3(1.00f, 1.06f, 1.3f);
res.rgb = lerp(res.rgb, d, BlueShift);
//r7.rgb=max(0, r7.rgb - Defog * FogColor2.rgb);
float luma=dot(res.xyz,0.333);
float cgray=dot(res.xyz, 0.333);//luma
float3 poweredcolor=pow(res.xyz, Color1);
float newgray=dot(poweredcolor.xyz, 0.333);
res.xyz=poweredcolor.xyz*cgray/(newgray+0.0001);
float colours=(res.r+res.g+res.b)*0.333; //dot(res.xyz, 0.333);
float3 diffcolor=res.rgb-colours;
res.rgb+=diffcolor*0.1;
float4 Adaptation=tex2D(_s4, 0.5);
float grayadaptation=max(max(Adaptation.x, Adaptation.y), Adaptation.z);
grayadaptation=max(grayadaptation, 0.0);
grayadaptation=min(grayadaptation, 50.0);
res.xyz=res.xyz/(grayadaptation*EAdaptationMaxV3+EAdaptationMinV3) ;//*tempF1.x
float3 xncol=normalize(res.xyz);
float3 scl=res.xyz/xncol.xyz;
scl=pow(scl, EIntensityContrastV2);
xncol.xyz=pow(xncol.xyz, EColorSaturationV2);
res.xyz=scl*xncol.xyz;
float3 luma2=res.xyz;
float lumamax=33.0;
res.xyz=(res.xyz * (1.0 + res.xyz/lumamax))/(res.xyz + EToneMappingCurveV3);
//res.xyz=res.xyz*0.6+sin(res.xyz*3.14*0.5)*0.4;
float3 correctedcolor=saturate((1-res*0.15)*0.021);
//res.rgb=saturate(res.rgb-correctedcolor)*0.96;
//res.rgb=pow(res.rgb,0.9)*1.07;
res.a=1.0;
return res;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++
technique PostProcess
{
pass P0
{
VertexShader = compile vs_2_0 VS_PostProcess();
PixelShader = compile ps_2_a PS_PostProcess();
FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}