home *** CD-ROM | disk | FTP | other *** search
- //blurs objects along the direction they are moving
- //handles 2 directional lights and ambient
- //must be used with clipZ_lit.psh
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //world,view,projection transform
- float4x4 matWorld;
- float4x4 matViewProj;
-
- //2 directional lights
- float4 l1Direction;
- float4 l1Color;
-
- float4 l2Direction;
- float4 l2Color;
-
- //ambient light
- float4 lAmbient;
-
- //direction of movement (normalized)
- float4 moveDir;
-
- //speed of movement (should cap it to like 10)
- float speed;
-
- //time step (in seconds) (clamp it from 0.05 to 0.25)
- float timeStep;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Normal : NORMAL;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float2 Tex0 : TEXCOORD0;
- float4 Color : COLOR;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //trans to world
- float4 pos=mul(matWorld,In.Pos);
- float3 norm=mul(matWorld,In.Normal.xyz);
-
- //calc colors from directional lights
- float4 l1Contrib=dot(-norm.xyz,l1Direction.xyz)*l1Color;
- l1Contrib=saturate(l1Contrib);
-
- float4 l2Contrib=dot(-norm.xyz,l2Direction.xyz)*l2Color;
- l2Contrib=saturate(l2Contrib);
-
- Out.Color=l1Contrib + l2Contrib + lAmbient;
-
- //stuff on the back side should blur, front side should go away
- float blurMod=dot(norm.xyz,moveDir.xyz);
- if (blurMod>0) //back side
- {
- //blur back stuff the most
- Out.Color.a=1.0f - blurMod;
- Out.Color.a*=Out.Color.a; //pow2 curve
-
- //push backside warp along direction of movement
- pos.xyz+=-moveDir.xyz*blurMod*speed*timeStep;
- }
- else //front side
- {
- Out.Color.a=0;
-
- //pos.xyz-=norm.xyz*0.5f;
- }
-
- //calc transformed position
- Out.Pos=mul(matViewProj,pos);
-
- //copy tex coord
- Out.Tex0=In.Tex0;
-
- //spit out the results
- return Out;
- }
-