D3D12_VertexShader.hlsl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma pack_matrix( row_major )
  2. cbuffer VertexShaderConstants : register(b0)
  3. {
  4. matrix model;
  5. matrix projectionAndView;
  6. };
  7. struct VertexShaderInput
  8. {
  9. float3 pos : POSITION;
  10. float2 tex : TEXCOORD0;
  11. float4 color : COLOR0;
  12. };
  13. struct VertexShaderOutput
  14. {
  15. float4 pos : SV_POSITION;
  16. float2 tex : TEXCOORD0;
  17. float4 color : COLOR0;
  18. };
  19. #define ColorRS \
  20. "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
  21. "DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
  22. "DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
  23. "DENY_HULL_SHADER_ROOT_ACCESS )," \
  24. "RootConstants(num32BitConstants=32, b0)," \
  25. "RootConstants(num32BitConstants=20, b1)"\
  26. #define TextureRS \
  27. "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
  28. " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
  29. " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
  30. " DENY_HULL_SHADER_ROOT_ACCESS )," \
  31. "RootConstants(num32BitConstants=32, b0),"\
  32. "RootConstants(num32BitConstants=20, b1),"\
  33. "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
  34. "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
  35. #define YUVRS \
  36. "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
  37. " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
  38. " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
  39. " DENY_HULL_SHADER_ROOT_ACCESS )," \
  40. "RootConstants(num32BitConstants=32, b0),"\
  41. "RootConstants(num32BitConstants=20, b1),"\
  42. "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
  43. "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
  44. "DescriptorTable ( SRV(t2), visibility = SHADER_VISIBILITY_PIXEL ),"\
  45. "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
  46. #define NVRS \
  47. "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
  48. " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
  49. " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
  50. " DENY_HULL_SHADER_ROOT_ACCESS )," \
  51. "RootConstants(num32BitConstants=32, b0),"\
  52. "RootConstants(num32BitConstants=20, b1),"\
  53. "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
  54. "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
  55. "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
  56. [RootSignature(ColorRS)]
  57. VertexShaderOutput mainColor(VertexShaderInput input)
  58. {
  59. VertexShaderOutput output;
  60. float4 pos = float4(input.pos, 1.0f);
  61. // Transform the vertex position into projected space.
  62. pos = mul(pos, model);
  63. pos = mul(pos, projectionAndView);
  64. output.pos = pos;
  65. // Pass through texture coordinates and color values without transformation
  66. output.tex = input.tex;
  67. output.color = input.color;
  68. return output;
  69. }
  70. [RootSignature(TextureRS)]
  71. VertexShaderOutput mainTexture(VertexShaderInput input)
  72. {
  73. return mainColor(input);
  74. }
  75. [RootSignature(YUVRS)]
  76. VertexShaderOutput mainYUV(VertexShaderInput input)
  77. {
  78. return mainColor(input);
  79. }
  80. [RootSignature(NVRS)]
  81. VertexShaderOutput mainNV(VertexShaderInput input)
  82. {
  83. return mainColor(input);
  84. }