// data from application to vertex program struct vertexIn { float3 Position : POSITION; // pre-defined registers float4 UV : TEXCOORD0; float4 Normal : NORMAL; }; // vertex shader to pixel shader struct vertexOut { float4 HPosition : POSITION; float4 TexCoord : TEXCOORD0; float3 LightVec : TEXCOORD1; float3 WorldNormal : TEXCOORD2; float3 WorldPos : TEXCOORD3; float3 WorldView : TEXCOORD4; }; // vertex shader vertexOut mainVS(vertexIn IN, // vertex input from app uniform float4x4 WorldViewProj,// constant parameters uniform float4x4 WorldIT, // from app: various uniform float4x4 World, // transformation uniform float4x4 ViewIT, // matrices and a uniform float3 LightPos // point-light source ) { vertexOut OUT; // output of the vertex shader OUT.WorldNormal = mul(WorldIT, IN.Normal).xyz; // position in object coords: float4 Po = float4(IN.Position.x,IN.Position.y, IN.Position.z,1.0); float3 Pw = mul(World, Po).xyz; // pos in world coord OUT.WorldPos = Pw; // pos in world coords OUT.LightVec = LightPos - Pw; // light vector OUT.TexCoord = IN.UV; // original tex coords // view vector in world coords: OUT.WorldView = normalize(ViewIT[3].xyz - Pw); // pos in clip coords: OUT.HPosition = mul(WorldViewProj, Po); return OUT; // output of vertex shader }