motion blur and DOF

Posted By: mocosgames

motion blur and DOF - 06/24/07 05:03

I made 2 shaders based one the blur shader in the wiki, motion blur and depth of field. They work with any gamestudio edition that can use shaders. You can use them in anything for free.

http://img106.imageshack.us/my.php?image=pic1gz7.jpg

http://img106.imageshack.us/my.php?image=pic2tk2.jpg

DOF shader Code:
 float4x4 matWorldViewProj;	
float4x4 matWorld;
float4 vecViewPos;

float4 vecSkill41;

texture entSkin1;

sampler basemap = sampler_state { Texture = <entSkin1>; };

void blur1VS( uniform float exten,
in float4 inNormal : NORMAL0,
in float4 inPosition : POSITION0,
in float4 inTexcoord : TEXCOORD0,
out float4 outPosition : POSITION0,
out float4 outTexcoord : TEXCOORD0)
{
float3 PosWorld = mul(inPosition, matWorld);

float focus_distance=10;

float blurriness=0.3;
float depth = (((distance(PosWorld, vecViewPos))*.01)-focus_distance)*blurriness;

depth*=sign(depth)+2;

inPosition.xyz += abs(depth)*inNormal/exten;
outTexcoord = inTexcoord;
outPosition = mul(inPosition, matWorldViewProj);

}

void blur1PS ( uniform float alpha,
in float4 inTexcoord : TEXCOORD0,
out float4 outColor : COLOR0){
outColor = tex2D(basemap, inTexcoord.xy);
outColor.a=alpha;
}


void mainVS( in float4 inNormal : NORMAL0,
in float4 inPosition : POSITION0,
in float4 inTexcoord : TEXCOORD0,
out float4 outPosition : POSITION0,
out float4 outTexcoord : TEXCOORD0)
{
outTexcoord = inTexcoord;
outPosition = mul(inPosition, matWorldViewProj);
}

void mainPS(in float4 inTexcoord : TEXCOORD0, out float4 outColor : COLOR0) { outColor = tex2D(basemap, inTexcoord.xy); outColor.a=1; }

technique t1 {
pass p0 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_2_0 mainPS();
}

pass p1 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 blur1VS(1.4);
PixelShader = compile ps_2_0 blur1PS(0.5);
}
pass p2 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 blur1VS(0.9);
PixelShader = compile ps_2_0 blur1PS(0.3);
}
}



motion blur action Code:
 
action motionblur{
my.transparent=on;
my.material=mblur;

var cam_pos[3];
var cam_x_change;
var cam_y_change;
var cam_pan_change;
var cam_tilt_change;
var cam_pan;
var cam_tilt;
while(1){
//have all movement code up here
my.skill41=float(-cam_pan_change*2+cam_y_change);
my.skill42=float(-cam_tilt_change*2);
my.skill43=float(cam_x_change);

cam_pan_change=camera.pan-cam_pan;
cam_tilt_change=camera.tilt-cam_tilt;
vec_add(cam_pos,my.pos);

vec_sub(cam_pos,camera.pos);

vec_rotate(cam_pos,vector(-camera.pan,-camera.tilt,-camera.roll));
cam_x_change=cam_pos.x/vec_dist(my.pos,camera.pos)*300;
cam_y_change=cam_pos.y/vec_dist(my.pos,camera.pos)*300;

cam_pan=camera.pan;
cam_tilt=camera.tilt;
vec_set(cam_pos,camera.pos);
vec_sub(cam_pos,my.pos);
wait(1);
}
}


motion blur shader Code:
 float4x4 matWorldViewProj;	
float4x4 matWorld;
float4 vecViewPos;

float4 vecSkill41;

texture entSkin1;

sampler basemap = sampler_state { Texture = <entSkin1>; };

void blur1VS( uniform float exten,
in float4 inNormal : NORMAL0,
in float4 inPosition : POSITION0,
in float4 inTexcoord : TEXCOORD0,
out float4 outPosition : POSITION0,
out float4 outTexcoord : TEXCOORD0)
{
float3 PosWorld = mul(inPosition, matWorld);

float focus_distance=10;

float blurriness=0.3;
float depth = (((distance(PosWorld, vecViewPos))*.01)-focus_distance)*blurriness;

depth*=sign(depth)+2;

inPosition.xyz += abs(depth)*inNormal/exten;
outTexcoord = inTexcoord;
outPosition = mul(inPosition, matWorldViewProj);

}

void blur1PS ( uniform float alpha,
in float4 inTexcoord : TEXCOORD0,
out float4 outColor : COLOR0){
outColor = tex2D(basemap, inTexcoord.xy);
outColor.a=alpha;
}


void mainVS( in float4 inNormal : NORMAL0,
in float4 inPosition : POSITION0,
in float4 inTexcoord : TEXCOORD0,
out float4 outPosition : POSITION0,
out float4 outTexcoord : TEXCOORD0)
{
outTexcoord = inTexcoord;
outPosition = mul(inPosition, matWorldViewProj);
}

void mainPS(in float4 inTexcoord : TEXCOORD0, out float4 outColor : COLOR0) { outColor = tex2D(basemap, inTexcoord.xy); outColor.a=1; }

technique t1 {
pass p0 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_2_0 mainPS();
}

pass p1 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 blur1VS(1.4);
PixelShader = compile ps_2_0 blur1PS(0.5);
}
pass p2 {
ZENABLE = TRUE;
zwriteenable=true;
AlphaBlendEnable = true;
VertexShader = compile vs_1_1 blur1VS(0.9);
PixelShader = compile ps_2_0 blur1PS(0.3);
}
}


Posted By: aztec

Re: motion blur and DOF - 06/24/07 06:37

wow thank you a lot
Posted By: frazzle

Re: motion blur and DOF - 06/24/07 09:22

Nice contribution !!
Great too see the wiki shaders are still in use
Btw, could you host the scripts and make them available for download ?? I ask this for practical reasons because copy and pasting the code can turn out quite annoying sometimes

Thxn in progress

Frazzle
Posted By: aztec

Re: motion blur and DOF - 06/24/07 10:22

Quote:


Btw, could you host the scripts and make them available for download ?? I ask this for practical reasons because copy and pasting the code can turn out quite annoying sometimes





thats true
Posted By: Ghost

Re: motion blur and DOF - 06/24/07 10:26

Very cool contribution, thanks.
Posted By: mpdeveloper_B

Re: motion blur and DOF - 06/24/07 13:36

very nice, you even made the DOF where anyone can modify it, thank you so much
Posted By: mocosgames

Re: motion blur and DOF - 06/24/07 18:18

Heres a link where you can download it: http://putstuff.putfile.com/90581/8860779
That folder also contains the underwater shader I made.
Posted By: Lion_Ts

Re: motion blur and DOF - 06/24/07 21:17

Thank you, Brandon!
I'm going to try your underwater shader...
Posted By: frazzle

Re: motion blur and DOF - 06/24/07 21:43

Quote:

Heres a link where you can download it: http://putstuff.putfile.com/90581/8860779
That folder also contains the underwater shader I made.




Thank you, very appriciated

Cheers

Frazzle
© 2024 lite-C Forums