home *** CD-ROM | disk | FTP | other *** search
- //flag wavery in the wind shader
- //2 directional lights applied
-
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //world,view,projection transforms
- float4x4 matWorldViewProj;
- float4x4 matWorld;
-
- //2 directional lights
- float4 l1Direction;
- float4 l1Color;
-
- float4 l2Direction;
- float4 l2Color;
-
- //ambient light
- float4 lAmbient;
-
- //opacity of flag
- float alpha;
-
- //used to flip u tex coord to make flag always appear readable to user
- float tcMod;
-
- //force of wind (from 0 to... something that looks good... around 5-ish)
- float windForce;
-
- //theta of wave in flag
- float waveTheta;
-
- //shader input
- struct VS_INPUT
- {
- float4 Pos : POSITION;
- float4 Normal : NORMAL;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader output
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float4 Color : COLOR;
- float2 Tex0 : TEXCOORD0;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- float4 pos=In.Pos;
- float4 norm=In.Normal;
-
- //make droop in low wind
- float droopAmt=abs(2.1-windForce)*0.35f*In.Pos.y;
- pos.z-=droopAmt;
- pos.y-=sqrt(abs((droopAmt)*0.2f))*In.Pos.y*0.5f;
- norm.y-=droopAmt*0.2f*In.Pos.z;
-
- //waves in x axis
- float waveMag=saturate(windForce*0.3)*3.33333f;
-
- float xMove=(sin(In.Pos.y+waveTheta)+cos(In.Pos.z+waveTheta))*0.3f*(waveMag+0.1f);
- pos.x+=xMove*In.Pos.y*(1.0f/7.0f);
- pos.y-=In.Pos.y*waveMag*0.1f;
- norm.y+=3.5f/xMove;
- norm.z+=xMove*0.11f;
- norm.x-=xMove*0.08f;
-
- //waves in z axis
- float zMove=sin(waveTheta+In.Pos.y*2)*waveMag*0.01f*In.Pos.y;
- pos.z+=zMove;
- norm.x-=zMove;
-
- //waves in y axis
- float yMove=sin(waveTheta*0.75f+In.Pos.z*1.5f+1.0f)*waveMag*0.015f*In.Pos.y;
- pos.y+=yMove;
- norm.z-=yMove;
-
- //calc directional light color
- norm.xyz=mul(matWorld,normalize(norm.xyz)); //rotate normal
-
- float3 l1Contrib=dot(-norm.xyz,l1Direction.xyz)*l1Color.xyz;
- l1Contrib=abs(l1Contrib);
-
- float3 l2Contrib=dot(-norm.xyz,l2Direction.xyz)*l2Color.xyz;
- l2Contrib=abs(l2Contrib);
-
- Out.Color.xyz=l1Contrib + l2Contrib + lAmbient.xyz;
- Out.Color.a=alpha; //see through cloth a little
-
- Out.Color.xyz+=(xMove*yMove*zMove)*2.0f;
-
- //calc transformed position and copy texture coord
- pos.xyz*=1.5f; //scaling here.. temp
- Out.Pos=mul(matWorldViewProj,pos);
- Out.Tex0=float2(In.Tex0.x*tcMod,In.Tex0.y);
-
- //spit out the results
- return Out;
- }
-