ModelViewerVS.hlsl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // RUN: %dxc -E main -T vs_6_0 %s | FileCheck %s
  2. // CHECK: bufferLoad
  3. //
  4. // Copyright (c) Microsoft. All rights reserved.
  5. // This code is licensed under the MIT License (MIT).
  6. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
  8. // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
  9. // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
  10. //
  11. // Developed by Minigraph
  12. //
  13. // Author(s): James Stanard
  14. // Alex Nankervis
  15. //
  16. #define USE_VERTEX_BUFFER 0
  17. #include "ModelViewerRS.hlsli"
  18. cbuffer VSConstants : register(b0)
  19. {
  20. float4x4 modelToProjection;
  21. float4x4 modelToShadow;
  22. float3 ViewerPos;
  23. };
  24. #if USE_VERTEX_BUFFER
  25. struct VSInput
  26. {
  27. float3 position : POSITION;
  28. float2 texcoord0 : TEXCOORD;
  29. float3 normal : NORMAL;
  30. float3 tangent : TANGENT;
  31. float3 bitangent : BITANGENT;
  32. };
  33. #else
  34. struct VSInput
  35. {
  36. float3 position;
  37. float2 texcoord0;
  38. float3 normal;
  39. float3 tangent;
  40. float3 bitangent;
  41. };
  42. StructuredBuffer<VSInput> vertexArray : register(t0);
  43. cbuffer StartVertex : register(b1)
  44. {
  45. uint baseVertex;
  46. };
  47. #endif
  48. struct VSOutput
  49. {
  50. float4 position : SV_Position;
  51. float2 texcoord0 : texcoord0;
  52. float3 viewDir : texcoord1;
  53. float3 shadowCoord : texcoord2;
  54. float3 normal : normal;
  55. float3 tangent : tangent;
  56. float3 bitangent : bitangent;
  57. };
  58. [RootSignature(ModelViewer_RootSig)]
  59. #if USE_VERTEX_BUFFER
  60. VSOutput main(VSInput vsInput)
  61. {
  62. #else
  63. VSOutput main(uint vertexID : SV_VertexID)
  64. {
  65. // The baseVertex argument to DrawIndexed is not automatically added to SV_VertexID...
  66. VSInput vsInput = vertexArray[vertexID + baseVertex];
  67. #endif
  68. VSOutput vsOutput;
  69. vsOutput.position = mul(modelToProjection, float4(vsInput.position, 1.0));
  70. vsOutput.texcoord0 = vsInput.texcoord0;
  71. vsOutput.viewDir = vsInput.position - ViewerPos;
  72. vsOutput.shadowCoord = mul(modelToShadow, float4(vsInput.position, 1.0)).xyz;
  73. vsOutput.normal = vsInput.normal;
  74. vsOutput.tangent = vsInput.tangent;
  75. vsOutput.bitangent = vsInput.bitangent;
  76. return vsOutput;
  77. }