DX12VertexShader.hlsl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. };
  43. struct PixelInputType
  44. {
  45. float4 worldPos : POSITION;
  46. float4 position : SV_POSITION;
  47. float2 tex : TEXCOORD;
  48. float3 normal : NORMAL;
  49. };
  50. PixelInputType main( VertexInputType input )
  51. {
  52. //return input;
  53. PixelInputType output;
  54. output.normal = normalize( mul( input.normal, ( float3x3 )Skelett.knochenMatrix[ input.knochen ] ) );
  55. // Change the position vector to be 4 units for proper matrix calculations.
  56. float4 position = float4( input.position.x, input.position.y, input.position.z, 1.f );
  57. // Store the texture coordinates for the pixel shader.
  58. output.tex = input.tex;
  59. // Calculate the position of the vertex against the world, view, and projection matrices.
  60. output.worldPos = mul( position, Skelett.knochenMatrix[ input.knochen ] );
  61. output.position = mul( output.worldPos, Kamera.view );
  62. output.position = mul( output.position, Kamera.projection );
  63. return output;
  64. }