D3D12_VertexShader.hlsl 2.9 KB

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