DX11CustomVertexShader.hlsl 2.3 KB

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