DX12VertexShader.hlsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. Texture2D shaderTexture : register(t0);
  2. SamplerState SampleType : register(s0);
  3. // Matrizen für die einzelnen Knochen des Modells
  4. struct MatrixBuffer
  5. {
  6. matrix knochenMatrix[128];
  7. };
  8. // The projection and view matrix
  9. struct KameraBuffer
  10. {
  11. matrix view;
  12. matrix projection;
  13. };
  14. // The position of the kamera
  15. struct KameraBuffer2
  16. {
  17. float4 kPosition;
  18. };
  19. // these values should sum up to 1
  20. struct Material
  21. {
  22. float ambientFactor;
  23. float diffusFactor;
  24. float specularFactor;
  25. };
  26. struct LightCount
  27. {
  28. int diffuseLightCount;
  29. int pointLightCount;
  30. };
  31. ConstantBuffer<KameraBuffer> Kamera : register(b0);
  32. ConstantBuffer<MatrixBuffer> Skelett : register(b1);
  33. ConstantBuffer<KameraBuffer2> Kamera2 : register(b2);
  34. ConstantBuffer<Material> Object : register(b3);
  35. ConstantBuffer<LightCount> Light : register(b4);
  36. struct VertexInputType
  37. {
  38. float3 position : POSITION;
  39. float2 tex : TEXCOORD;
  40. float3 normal : NORMAL;
  41. uint knochen : KNOCHEN_ID;
  42. uint id : VERTEX_ID;
  43. };
  44. struct PixelInputType
  45. {
  46. float4 worldPos : POSITION;
  47. float4 position : SV_POSITION;
  48. float2 tex : TEXCOORD;
  49. float3 normal : NORMAL;
  50. };
  51. PixelInputType main(VertexInputType input)
  52. {
  53. //return input;
  54. PixelInputType output;
  55. output.normal = normalize(mul(input.normal, (float3x3)Skelett.knochenMatrix[input.knochen]));
  56. // Change the position vector to be 4 units for proper matrix calculations.
  57. float4 position = float4(input.position.x, input.position.y, input.position.z, 1.f);
  58. // Store the texture coordinates for the pixel shader.
  59. output.tex = input.tex;
  60. // Calculate the position of the vertex against the world, view, and projection matrices.
  61. output.worldPos = mul(position, Skelett.knochenMatrix[input.knochen]);
  62. output.position = mul(output.worldPos, Kamera.view);
  63. output.position = mul(output.position, Kamera.projection);
  64. return output;
  65. }