1 |
// data from application to vertex program |
2 |
struct vertexIn { |
3 |
float3 Position : POSITION; // pre-defined registers |
4 |
float4 UV : TEXCOORD0; |
5 |
float4 Normal : NORMAL; |
6 |
}; |
7 |
// vertex shader to pixel shader |
8 |
struct vertexOut { |
9 |
float4 HPosition : POSITION; |
10 |
float4 TexCoord : TEXCOORD0; |
11 |
float3 LightVec : TEXCOORD1; |
12 |
float3 WorldNormal : TEXCOORD2; |
13 |
float3 WorldPos : TEXCOORD3; |
14 |
float3 WorldView : TEXCOORD4; |
15 |
}; |
16 |
|
17 |
// vertex shader |
18 |
vertexOut main(vertexIn IN) |
19 |
{ |
20 |
vertexOut OUT; // output of the vertex shader |
21 |
|
22 |
OUT.WorldNormal = mul(glstate.matrix.modelview[0], IN.Normal).xyz; |
23 |
// position in object coords: |
24 |
float4 Po = float4(IN.Position.x,IN.Position.y, IN.Position.z,1.0); |
25 |
float3 Pw = mul(glstate.matrix.mvp, Po).xyz; // pos in world coord |
26 |
|
27 |
float3 LightPos = { 0, 0, 0}; |
28 |
OUT.WorldPos = Pw; // pos in world coords |
29 |
OUT.LightVec = LightPos - Pw; // light vector |
30 |
OUT.TexCoord = IN.UV; // original tex coords |
31 |
// view vector in world coords: |
32 |
OUT.WorldView = normalize (glstate.matrix.mvp[3].xyz - Pw); |
33 |
// pos in clip coords: |
34 |
OUT.HPosition = mul(glstate.matrix.mvp, Po); |
35 |
return OUT; // output of vertex shader |
36 |
} |
37 |
|