home *** CD-ROM | disk | FTP | other *** search
- //extrudes object away from a light, fading out far edge
- //Luke Lenhart
- //(C)2004-2005 Digipen Institute of Technology
-
- //world,view,projection transforms
- float4x4 matWorld, matViewProj;
-
- //light position (in world space)
- float4 lightPos;
-
- //current swipe in position on x axis
- float xSwipePos;
-
- //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;
- float4 Pos2 : TEXCOORD1;
- };
-
- //shader code
- VS_OUTPUT VShader(VS_INPUT In)
- {
- VS_OUTPUT Out;
-
- //copy out source position
- Out.Pos2=In.Pos;
-
- //move us to world space
- float4 pos=mul(matWorld,In.Pos);
- float4 norm=mul(matWorld,In.Normal.xyz);
-
- //calc extrude dist based on x swipe position
- float posMod=saturate((xSwipePos-In.Pos.x));
- posMod=sin(posMod*3.1415926535);
- posMod=pow(posMod,0.33f);
- float extrude_dist=2.05f*posMod;
-
- //calc direction from light to vert
- float3 rayDir=normalize(pos.xyz-lightPos.xyz);
-
- //stuff on the back side should be extruded
- float sideCheck=dot(norm,rayDir);
- if (In.Pos.y>0) //extruded
- {
- //push vert in direction of ray
- pos.xyz+=rayDir*extrude_dist;
- Out.Tex0.y=0.99f;
- }
- else //fixed
- {
- Out.Tex0.y=0.01f;
- }
-
- //alpha based on extrusion amount
- Out.Color=float4(1,1,1,posMod-0.1f);
-
- //calc transformed position
- Out.Pos=mul(matViewProj,pos);
-
- //calc tex coord
- Out.Tex0.x=In.Pos.x+In.Pos.z;
-
- //spit out the results
- return Out;
- }
-