0% found this document useful (0 votes)
10 views4 pages

HLSL Post-Processing Shader Code

Uploaded by

fvalenciaucho
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

HLSL Post-Processing Shader Code

Uploaded by

fvalenciaucho
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//ENBSeries: boris-vorontsov@[Link], [Link]


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/*
THIS IS HLSL (HIGH LEVEL SHADER LANGUAGE) FILE FOR EXECUTING ADDITIONAL
HARDWARE EFFECTS. MAKE THE COPY BEFORE CHANGING IT!
*/

//keyboard controled variables


float tempF1;
float tempF2;
float tempF3;
float tempF4;
float tempF5;
float tempF6;
float tempF7;
float tempF8;
float tempF9;
float tempF0;

//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)
float4 ScreenBrightness;//rgba(0..1) color of the screen with time dependent
inertia
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 texBloom;

sampler2D SamplerColor = sampler_state


{
Texture = <texColor>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;//NONE;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
};

sampler2D SamplerBloom = sampler_state


{
Texture = <texBloom>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;//NONE;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
};

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([Link].x,[Link].y,[Link].z,1.0);

[Link]=pos;
[Link]=[Link];

return OUT;
}

float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR


{

float2 offset[4]=
{
float2(-1.0,-1.0),
float2(-1.0, 1.0),
float2( 1.0, 1.0),
float2( 1.0,-1.0)

};
float4 res=0.0;
float4 coord=0.0;
[Link]=[Link];
float4 origcolor=tex2D(SamplerColor, [Link]);
float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
res+=origcolor;
float range=0.7*tempF9/ScreenSize;
for (int i=0; i<4; i++)
{

[Link]=[Link]+offset[i]*range;
float4 color;
float gray;
color=tex2D(SamplerColor, [Link]);
float4 colordiff=abs(origcolor-color);
gray=dot([Link],0.333);
float lerpfact=saturate(4.0*abs(gray)*color.a);//saturate
res+=lerp(origcolor, color, lerpfact);
}
res=res*0.2;

//res=origcolor;

[Link]=[Link];
coord.w=2.5*tempF1;
float4 envcol1=tex2Dbias(SamplerColor, coord);
coord.w=3.5*tempF2;
float4 envcol2=tex2Dbias(SamplerColor, coord);
float4 envcol3=tex2D(SamplerBloom, [Link]);
float4 bloom=envcol3;

float4 envcol=(envcol1+envcol2+envcol3)*0.777;

//envcol=tempF5*pow(envcol,tempF4);

//envcol=envcol*tempF7/(1.0+envcol*tempF8);

//envcol=dot([Link],0.333);
//envcol=max(envcol.x, max(envcol.y, envcol.z));
float4 tempcol;//=max(envcol.x, max(envcol.y, envcol.z));
//envcol=lerp(tempcol, envcol, tempF3);

//[Link]=saturate([Link]);
//float diff=dot([Link], 0.333);

//float srcgray=dot([Link],0.333);
//[Link]=[Link]-(tempF7*[Link])*(1.0-saturate(srcgray));

envcol=tempF5*pow(envcol,tempF4);
res=lerp(res, res*envcol, tempF6);
//res=res*tempF7/(1.0+res*tempF8);
//res+=tempF7*pow(bloom,4.0*tempF8);

//desaturate
float middlegray=(res.r+res.g+res.b)*0.333;
float3 diffcolor=[Link]-middlegray;
[Link]-=diffcolor*0.4*tempF0;

if (tempF3>1.1) res=origcolor;

res.a=1.0;
return res;
}

/*
float4 PS_PostProcess(VS_OUTPUT_POST In) : COLOR
{

float2 offset[4]=
{
float2(-1.0,-1.0),
float2(-1.0, 1.0),
float2( 1.0, 1.0),
float2( 1.0,-1.0)
};
float4 res=0.0;
float4 coord=0.0;
[Link]=[Link];
float4 origcolor=tex2Dlod(SamplerColor, coord);
float origgray=max(origcolor.r, max(origcolor.g, origcolor.b));
res+=origcolor;
float range=tempF5*0.001;// /ScreenSize.x
for (int i=0; i<4; i++)
{
[Link]=[Link]+offset[i]*range;
float4 color;
float gray;
color=tex2Dlod(SamplerColor, coord);
float4 colordiff=abs(origcolor-color);
gray=max(colordiff.r, max(colordiff.g, colordiff.b));
float lerpfact=saturate(tempF6*abs(gray));//saturate
res+=lerp(origcolor, color, lerpfact);
}
res=res/5.0;

res.a=1.0;
return res;
}
*/

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
technique PostProcess
{
pass P0
{
VertexShader = compile vs_2_0 VS_PostProcess();
PixelShader = compile ps_2_0 PS_PostProcess();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

You might also like