// Gaussian Blur PixelShader 3.0
// By Torsten Simon - © 2010
// Accepts incomming:
// skill1 - strength (0 ... 10)
// mat_name.skill1=floatv(0...10);
#define USE_STATIC_VALUES true
// Remove/Comment this line to use material.Skill2...Skill5 for the values below
#define WIDTH 8
// WIDTH in Pixels to distribute the blur, lower values -> faster rendering
#define WIDTH_SKIP 2
// "Jump" Pixels when blurring, higher values -> faster rendering
#define RADIUS 7
// Radius when blurring, higher values -> faster rendering
#define GLOW 0
// Min: 0, Max: 100, Applying a glowing blur effect
// Please Read:
// This shader uses PS_3_0, but if you use the fast, simple blur-parameters
// you can also use PS_2_0. Therefore, change line 123 to
// PixelShader = compile ps_2_0 postprocessing_gaussian();
/* Some Examples to try
// Default (Small, Smooth)
#define WIDTH 8
#define WIDTH_SKIP 2
#define RADIUS 7
// Fast, Simple Blur (Works with PS_2_0 as well!)
#define WIDTH 8
#define WIDTH_SKIP 4
#define RADIUS 45
// Wide Range
#define WIDTH 30
#define WIDTH_SKIP 8
#define RADIUS 10
// Medium Range
#define WIDTH 20
#define WIDTH_SKIP 8
#define RADIUS 15
*/
#include <define>
float4 vecSkill1;
// Min: 0, Max:10
float4 vecSkill5;
Texture TargetMap;
sampler2D g_samSrcColor = sampler_state { texture = <TargetMap>; MipFilter = Linear; };
float4 vecViewPort;
#define RENDER vecSkill1.x>0
float4 postprocessing_gaussian(float2 Tex : TEXCOORD0) : COLOR0
{
float4 ret=tex2D(g_samSrcColor, Tex.xy);
#ifdef RENDER
int width,width_skip,radius,glow;
#ifdef USE_STATIC_VALUES
width=WIDTH;
width_skip=WIDTH_SKIP;
radius=RADIUS;
glow=GLOW;
#else
width=vecSkill1.y;
width_skip=max(vecSkill1.z,1);
if(width<width_skip) width=width_skip;
else width+=width%width_skip;
radius=max(vecSkill1.w,1);
glow=vecSkill5.x;
#endif
// Real sample
float4 sampleM = tex2D(g_samSrcColor, Tex.xy);
// Brightness calculation script
float fac=(vecSkill1.x)*float(float(((float)width_skip/(float)width)/float(360/radius))/10)*((glow+50)/50.f);
float s=(10-vecSkill1.x)*.1+fac;
ret=s*sampleM; // return variable
int i=0;
int dist=width_skip;
while(dist<=width)
{
float4 pos1;
float round=radians(i);
pos1.x=Tex.x+sin(round)*vecViewPort.z*dist;
pos1.y=Tex.y+cos(round)*vecViewPort.w*dist;
pos1.z=0;
pos1.w=0;
float4 S1=tex2Dlod(g_samSrcColor,pos1);
ret+=fac*(S1);
i+=radius;
if(i>=360) {
dist+=width_skip;
i=0;
}
}
#endif
return ret;
}
technique PostProcess
{
pass p1
{
AlphaBlendEnable = false;
VertexShader = null;
PixelShader = compile ps_3_0 postprocessing_gaussian();
}
}