DX11VertexShader.hlsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /////////////
  2. // GLOBALS //
  3. /////////////
  4. cbuffer MatrixBuffer : register(b0)
  5. {
  6. matrix knochenMatrix[128];
  7. };
  8. // The projection and view matrix
  9. cbuffer Kamera : register(b1)
  10. {
  11. matrix view;
  12. matrix projection;
  13. }
  14. //////////////
  15. // TYPEDEFS //
  16. //////////////
  17. struct VertexInputType
  18. {
  19. float4 position : POSITION;
  20. float2 tex : TEXCOORD0;
  21. float3 normal : NORMAL;
  22. uint knochen : KNOCHEN_ID0;
  23. uint id : VERTEX_ID0;
  24. };
  25. struct PixelInputType
  26. {
  27. float4 worldPos : POSITION;
  28. float4 position : SV_POSITION;
  29. float2 tex : TEXCOORD0;
  30. float3 normal : TEXCOORD1;
  31. };
  32. ////////////////////////////////////////////////////////////////////////////////
  33. // Vertex Shader
  34. ////////////////////////////////////////////////////////////////////////////////
  35. PixelInputType TextureVertexShader(VertexInputType input)
  36. {
  37. //return input;
  38. PixelInputType output;
  39. output.normal = normalize(mul(input.normal, (float3x3)knochenMatrix[input.knochen]));
  40. // Change the position vector to be 4 units for proper matrix calculations.
  41. input.position.w = 1.0f;
  42. // Store the texture coordinates for the pixel shader.
  43. output.tex = input.tex;
  44. // Calculate the position of the vertex against the world, view, and projection matrices.
  45. output.worldPos = mul(input.position, knochenMatrix[input.knochen]);
  46. output.position = mul(output.worldPos, view);
  47. output.position = mul(output.position, projection);
  48. return output;
  49. }