Full Screen Effect - Compilation
by Siddartha · 11/08/2008 (2:48 am) · 12 comments
*** All 5 blogs containing sample shaders were compiled and moved into a resource: Sample Fullscreen Shaders ***
Hi all,
I am here by giving you the full screen radial blur effect using pixel shader 2.0
use this link given below to set full screen shaders to work.
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9104
once setting full screen shader support is set
then create a new shaderdata in gameTSCtrl class and create a new shader using these hlsl data.
step 1: create a "Radialblur_vs.hlsl" file using default text editor and add the following code:
///////////////////////////////////////////////////////////////////////////////////////////////
struct VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
};
VS_OUTPUT main(float4 Pos: POSITION){
VS_OUTPUT Out;
// Clean up inaccuracies
Pos.xy = sign(Pos.xy);
Out.Pos = float4(Pos.xy, 0, 1);
// Image-space
Out.texCoord.x = 0.5 * (1 + Pos.x);
Out.texCoord.y = 0.5 * (1 - Pos.y);
return Out;
}
//////////////////////////////////////////////////////////////////////////////////////////////
step 2: create a "Radialblur_ps2.hlsl" file using default text editor and add the code given below
///////////////////////////////////////////////////////////////////////////////////////////////
uniform sampler tex: register(s0);
static const float samples[10] =
{
-0.08,
-0.05,
-0.03,
-0.02,
-0.01,
0.01,
0.02,
0.03,
0.05,
0.08
};
float4 main(float2 texCoord: TEXCOORD0,
uniform float sampleDist,
uniform float sampleStrength
) : COLOR
{
//Vector from pixel to the center of the screen
float2 dir = 0.5 - texCoord;
//Distance from pixel to the center (distant pixels have stronger effect)
//float dist = distance( float2( 0.5, 0.5 ), texCoord );
float dist = sqrt( dir.x*dir.x + dir.y*dir.y );
//Now that we have dist, we can normlize vector
dir = normalize( dir );
//Save the color to be used later
float4 color = tex2D( tex, texCoord );
//Average the pixels going along the vector
float4 sum = color;
for (int i = 0; i < 10; i++)
{
sum += tex2D( tex, texCoord + dir * samples[i] * 1.0);
}
sum /= 11;
//Calculate amount of blur based on
//distance and a strength parameter
float t = dist * 2.2;
t = saturate( t );//We need 0 <= t <= 1
//Blend the original color with the averaged pixels
return lerp( color, sum, t );
}
////////////////////////////////////////////////////////////////////////////////////////
step 3: save these two files in shaders folder .
step 4: open shaders.cs file and added the folowing code in the last
new ShaderData(Radialblur)
{
DXVertexShaderFile = "shaders/Radialblur_vs.hlsl";
DXPixelShaderFile = "shaders/Radialblur_ps2.hlsl";
pixVersion = 2.0;
};
step 5: using this shader data you can now generate full screen radial blur effect like the other full screen shaders
nightvision,heatvision etc...
Hi all,
I am here by giving you the full screen radial blur effect using pixel shader 2.0
use this link given below to set full screen shaders to work.
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9104
once setting full screen shader support is set
then create a new shaderdata in gameTSCtrl class and create a new shader using these hlsl data.
step 1: create a "Radialblur_vs.hlsl" file using default text editor and add the following code:
///////////////////////////////////////////////////////////////////////////////////////////////
struct VS_OUTPUT {
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
};
VS_OUTPUT main(float4 Pos: POSITION){
VS_OUTPUT Out;
// Clean up inaccuracies
Pos.xy = sign(Pos.xy);
Out.Pos = float4(Pos.xy, 0, 1);
// Image-space
Out.texCoord.x = 0.5 * (1 + Pos.x);
Out.texCoord.y = 0.5 * (1 - Pos.y);
return Out;
}
//////////////////////////////////////////////////////////////////////////////////////////////
step 2: create a "Radialblur_ps2.hlsl" file using default text editor and add the code given below
///////////////////////////////////////////////////////////////////////////////////////////////
uniform sampler tex: register(s0);
static const float samples[10] =
{
-0.08,
-0.05,
-0.03,
-0.02,
-0.01,
0.01,
0.02,
0.03,
0.05,
0.08
};
float4 main(float2 texCoord: TEXCOORD0,
uniform float sampleDist,
uniform float sampleStrength
) : COLOR
{
//Vector from pixel to the center of the screen
float2 dir = 0.5 - texCoord;
//Distance from pixel to the center (distant pixels have stronger effect)
//float dist = distance( float2( 0.5, 0.5 ), texCoord );
float dist = sqrt( dir.x*dir.x + dir.y*dir.y );
//Now that we have dist, we can normlize vector
dir = normalize( dir );
//Save the color to be used later
float4 color = tex2D( tex, texCoord );
//Average the pixels going along the vector
float4 sum = color;
for (int i = 0; i < 10; i++)
{
sum += tex2D( tex, texCoord + dir * samples[i] * 1.0);
}
sum /= 11;
//Calculate amount of blur based on
//distance and a strength parameter
float t = dist * 2.2;
t = saturate( t );//We need 0 <= t <= 1
//Blend the original color with the averaged pixels
return lerp( color, sum, t );
}
////////////////////////////////////////////////////////////////////////////////////////
step 3: save these two files in shaders folder .
step 4: open shaders.cs file and added the folowing code in the last
new ShaderData(Radialblur)
{
DXVertexShaderFile = "shaders/Radialblur_vs.hlsl";
DXPixelShaderFile = "shaders/Radialblur_ps2.hlsl";
pixVersion = 2.0;
};
step 5: using this shader data you can now generate full screen radial blur effect like the other full screen shaders
nightvision,heatvision etc...
About the author
WebSites: www.siddartha.info Myblogs: http://schoolofgaming.blogspot.com http://techtoolsreviewer.blogspot.com http://coolgamescreens.blogspot.com
#2
11/08/2008 (8:48 am)
These are all useful for TGEA users. Hes not spamming on purpose, but they probably could have all gone in 1 blog post.
#3
11/08/2008 (9:22 am)
These should go in as a code resource. On the other hand these are already somewhere amongst the resources. So I agree with you Jondo, this is 21st century spam.
#4
11/08/2008 (10:03 am)
I like the idea of shader collections but it would be nice to have a library in the TGEA docs similar to NVIDIA's shader library.
#5
Our site admin will be back soon, but until then we are running on a skeleton crew.
11/08/2008 (3:42 pm)
I'm going to go ahead and combine all of these into one resource and blog, just to cut down on the spamming. It seems are .plan section of the site has been getting some heavy abuse lately, so I'll try to keep it clean and e-mail when necessary.Our site admin will be back soon, but until then we are running on a skeleton crew.
#7
11/08/2008 (4:59 pm)
Great Stuff! Thank you for your hard work!
#8
11/08/2008 (8:04 pm)
I just got in before the formal dinner here on my cruise, so I was about to do just want Michael did! These are good resources that should have been organized into a single plan.
#9
1. I beat you to it
2. I won't blame your wife for beating the crap out of you if you get caught posting here.
3. Though you should be completely focused on the cruise and the many fun hours of shuffle boarding (wah wah), for the love of all that is merciful please hurry back when can.
This place is insane...O_o
11/08/2008 (8:14 pm)
@David - Ha!1. I beat you to it
2. I won't blame your wife for beating the crap out of you if you get caught posting here.
3. Though you should be completely focused on the cruise and the many fun hours of shuffle boarding (wah wah), for the love of all that is merciful please hurry back when can.
This place is insane...O_o
#10
11/09/2008 (9:46 am)
The one line nonsensical blogs are actually starting to get old. (I used to get a kick out of them . . .) At least this dude has a good heart and is posting useful stuff! ;)
#11
We are not cold hearted, though. We'll send out e-mails to blog posters letting them know about the deletion and why, along with suggestions on how to improve their original .plan.
Siddartha's .plan is also a good example. The content is very useful, so I took a little extra time to help create a resource that consolidates his work.
I can guarantee I will not put that much effort in every time, but hopefully the enforced .plan policy will start to catch on.
11/09/2008 (11:17 am)
@Kevin - Agreed. We are starting to crack down on one liner blogs, as well as ones that ask questions that should be in the forums.We are not cold hearted, though. We'll send out e-mails to blog posters letting them know about the deletion and why, along with suggestions on how to improve their original .plan.
Siddartha's .plan is also a good example. The content is very useful, so I took a little extra time to help create a resource that consolidates his work.
I can guarantee I will not put that much effort in every time, but hopefully the enforced .plan policy will start to catch on.
#12
its been long time going under work pressures.could not see this blog back.
wonderfull work ..next time I do it my own ..definitly not putting you in stress.
thanks ;)
11/21/2008 (5:44 am)
thankyou Michael. for consolidating the shader stuff..its been long time going under work pressures.could not see this blog back.
wonderfull work ..next time I do it my own ..definitly not putting you in stress.
thanks ;)
Jondo
BrokeAss Games