DX11CustomVertexShader.hlsl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. cbuffer Light : register(b2)
  15. {
  16. int lightLength;
  17. float3 light[24];
  18. }
  19. //////////////
  20. // TYPEDEFS //
  21. //////////////
  22. struct VertexInputType
  23. {
  24. float4 position : POSITION;
  25. float2 tex : TEXCOORD0;
  26. float3 normal : NORMAL;
  27. uint knochen : KNOCHEN_ID0;
  28. half id : VERTEX_ID;
  29. };
  30. struct PixelInputType
  31. {
  32. float4 worldPos : POSITION;
  33. float4 position : SV_POSITION;
  34. float2 tex : TEXCOORD0;
  35. float3 normal : TEXCOORD1;
  36. float4 light : TEXCOORD2;
  37. };
  38. ////////////////////////////////////////////////////////////////////////////////
  39. // Vertex Shader
  40. ////////////////////////////////////////////////////////////////////////////////
  41. PixelInputType TextureVertexShader(VertexInputType input)
  42. {
  43. //return input;
  44. PixelInputType output;
  45. output.normal = normalize(mul(input.normal, (float3x3)knochenMatrix[input.knochen]));
  46. // Change the position vector to be 4 units for proper matrix calculations.
  47. input.position.w = 1.0f;
  48. // Store the texture coordinates for the pixel shader.
  49. output.tex = input.tex;
  50. // Calculate the position of the vertex against the world, view, and projection matrices.
  51. output.worldPos = mul(input.position, knochenMatrix[input.knochen]);
  52. output.position = mul(output.worldPos, view);
  53. output.position = mul(output.position, projection);
  54. output.light = float4(1.0f, 1.0f, 1.0f, 0.f);
  55. if (input.id < lightLength)
  56. {
  57. output.light.xyz = light[input.id];
  58. output.light.w = 1.f;
  59. }
  60. return output;
  61. }