DX12VertexShader.hlsl 1.9 KB

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