// 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 main(vertexIn IN, // vertex input from app uniform float4x4 WorldViewProj, uniform float4x4 WorldProj //uniform float3 LightPos ) { vertexOut OUT; // output of the vertex shader OUT.WorldNormal = mul(WorldProj, IN.Normal).xyz; // position in object coords: float4 Po = float4(IN.Position.x,IN.Position.y, IN.Position.z,1.0); float3 Pw = mul(WorldViewProj, Po).xyz; // pos in world coord float3 LightPos = { 0, 0, 0}; 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 (WorldViewProj[3].xyz - Pw); // pos in clip coords: OUT.HPosition = mul(WorldViewProj, Po); return OUT; // output of vertex shader }