Squadron Z HD Textured Vertex Shader

Textured Vertex Shader Code:

  • This is my main vertex shader, used on the models and terrain in the first pass. This function includes my vertex shader code for the laser effect, which is highlighted in red. I chose to use flags to trigger certain effects, rather than split them into separate shaders.
VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
{
VertexToPixel Output = (VertexToPixel)0;
float4x4 preViewProjection = mul (xView, xProjection);
float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
/*Begin Laser Graphics*/
float4 inposition = inPos;
Output.colormod = 0;
float4 temp, temp2 = inPos;
temp.x=laserpos.x;
temp.yw = 1;
temp.z = -laserpos.y;
temp = mul(temp, preViewProjection);
temp2 = mul(temp2, preWorldViewProjection);
if(laser && temp.y < temp2.y)
{
float relposx = abs(inposition.x – laserpos.x);
Output.colormod = sin(max(1-(relposx/(laserwidth)),0))/random;
if(relposx < laserwidth*2*3.1415926535)
{
inposition.z += 2.5*(cos(relposx / (laserwidth*2)));
}
}
/*End Laser Graphics*/
Output.Position = mul(inposition, preWorldViewProjection);
Output.TextureCoords = inTexCoords;
Output.Normal = normalize(mul(normalize(inNormal), (float3x3)xWorld));
Output.direction = mul(inposition,xWorld) – xLightPosition;
Output.LightingFactor = 1;
Output.Position3D = mul(inposition, xWorld);
if(inposition.y < -5.75)
Output.specularity = .5f;
else
Output.specularity = 0;
if(specularity > 0)
Output.specularity = specularity;
return Output;
}
Advertisements
%d bloggers like this: