Effect
Effect
//textures
texture2D texColor;
texture2D texBloom;
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;
}
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;
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.7*tempF9/ScreenSize;
for (int i=0; i<4; 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(4.0*abs(gray)*color.a);//saturate
res+=lerp(origcolor, color, lerpfact);
}
res=res*0.2;
//res=origcolor;
coord.xy=In.txcoord.xy;
coord.w=2.5*tempF1;
float4 envcol1=tex2Dbias(SamplerColor, coord);
coord.w=3.5*tempF2;
float4 envcol2=tex2Dbias(SamplerColor, coord);
float4 envcol3=tex2D(SamplerBloom, coord.xy);
float4 bloom=envcol3;
float4 envcol=(envcol1+envcol2+envcol3)*0.777;
//envcol=tempF5*pow(envcol,tempF4);
//envcol=envcol*tempF7/(1.0+envcol*tempF8);
//envcol=dot(envcol.xyz,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);
//tempcol.xyz=saturate(res.xyz-envcol.xyz);
//float diff=dot(tempcol.xyz, 0.333);
//float srcgray=dot(res.xyz,0.333);
//envcol.xyz=res.xyz-(tempF7*envcol.xyz)*(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=res.rgb-middlegray;
res.rgb-=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;
coord.xy=In.txcoord.xy;
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++)
{
coord.xy=In.txcoord+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;
}
}