TriangleVertexShader.hlsl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "VertexConstants.h"
  2. struct VS_INPUT
  3. {
  4. // Per vertex data
  5. float3 vPos : POSITION;
  6. float3 vNorm : NORMAL;
  7. float2 vTex : TEXCOORD0;
  8. float4 vCol : COLOR;
  9. // Per instance data
  10. matrix iModel : INSTANCE_TRANSFORM; // model matrix
  11. matrix iModelInvTrans : INSTANCE_INV_TRANSFORM; // (model matrix^-1)^T
  12. float4 iCol : INSTANCE_COLOR; // color of the model
  13. };
  14. struct VS_OUTPUT
  15. {
  16. float4 Position : SV_POSITION;
  17. float3 Normal : TEXCOORD0;
  18. float3 WorldPos : TEXCOORD1;
  19. float2 Tex : TEXCOORD2;
  20. float4 PositionL : TEXCOORD3;
  21. float4 Color : COLOR0;
  22. };
  23. VS_OUTPUT main(VS_INPUT input)
  24. {
  25. VS_OUTPUT output;
  26. // Get world position
  27. float4 pos = float4(input.vPos, 1.0f);
  28. float4 world_pos = mul(input.iModel, pos);
  29. // Transform the position from world space to homogeneous projection space
  30. float4 proj_pos = mul(View, world_pos);
  31. proj_pos = mul(Projection, proj_pos);
  32. output.Position = proj_pos;
  33. // Transform the position from world space to projection space of the light
  34. float4 proj_lpos = mul(LightView, world_pos);
  35. proj_lpos = mul(LightProjection, proj_lpos);
  36. output.PositionL = proj_lpos;
  37. // output normal
  38. float4 norm = float4(input.vNorm, 0.0f);
  39. output.Normal = normalize(mul(input.iModelInvTrans, norm).xyz);
  40. // output world position of the vertex
  41. output.WorldPos = world_pos.xyz;
  42. // output texture coordinates
  43. output.Tex = input.vTex;
  44. // output color
  45. output.Color = input.vCol * input.iCol;
  46. return output;
  47. }