SimpleHs3.hlsl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // RUN: %dxc -E main -T hs_6_0 %s | FileCheck %s
  2. // CHECK: loadInput
  3. // CHECK: loadOutputControlPoint
  4. // CHECK: storePatchConstant
  5. // CHECK: outputControlPointID
  6. //--------------------------------------------------------------------------------------
  7. // SimpleTessellation.hlsl
  8. //
  9. // Advanced Technology Group (ATG)
  10. // Copyright (C) Microsoft Corporation. All rights reserved.
  11. //--------------------------------------------------------------------------------------
  12. struct VSSceneIn
  13. {
  14. float3 pos : POSITION;
  15. float3 norm : NORMAL;
  16. float2 tex : TEXCOORD0;
  17. };
  18. struct PSSceneIn
  19. {
  20. float4 pos : SV_Position;
  21. float2 tex : TEXCOORD0;
  22. float3 norm : NORMAL;
  23. };
  24. cbuffer cb0
  25. {
  26. float4x4 g_mWorldViewProj;
  27. };
  28. Texture2D g_txDiffuse : register( t0 );
  29. SamplerState g_sampler : register( s0 );
  30. //////////////////////////////////////////////////////////////////////////////////////////
  31. // Regular VS/PS rendering
  32. PSSceneIn VSSceneMain( VSSceneIn input )
  33. {
  34. PSSceneIn output;
  35. output.pos = mul( float4( input.pos, 1.0 ), g_mWorldViewProj );
  36. output.tex = input.tex;
  37. output.norm = input.norm;
  38. return output;
  39. }
  40. float4 PSSceneMain( PSSceneIn input ) : SV_Target
  41. {
  42. return g_txDiffuse.Sample( g_sampler, input.tex );
  43. }
  44. //////////////////////////////////////////////////////////////////////////////////////////
  45. // Simple forwarding Tessellation shaders
  46. struct HSPerVertexData
  47. {
  48. // This is just the original vertex verbatim. In many real life cases this would be a
  49. // control point instead
  50. PSSceneIn v;
  51. };
  52. struct HSPerPatchData
  53. {
  54. // We at least have to specify tess factors per patch
  55. // As we're tesselating triangles, there will be 4 tess factors
  56. // In real life case this might contain face normal, for example
  57. float edges[ 3 ] : SV_TessFactor;
  58. float inside : SV_InsideTessFactor;
  59. };
  60. float4 HSPerPatchFunc()
  61. {
  62. return 1.8;
  63. }
  64. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, const OutputPatch< PSSceneIn, 3 > opoints )
  65. {
  66. HSPerPatchData d;
  67. d.edges[ 0 ] = points[0].tex.x;
  68. d.edges[ 1 ] = opoints[1].tex.y;
  69. d.edges[ 2 ] = 1;
  70. d.inside = 1;
  71. return d;
  72. }
  73. // hull per-control point shader
  74. [domain("tri")]
  75. [partitioning("fractional_odd")]
  76. [outputtopology("triangle_cw")]
  77. [patchconstantfunc("HSPerPatchFunc")]
  78. [outputcontrolpoints(3)]
  79. HSPerVertexData main( const uint id : SV_OutputControlPointID,
  80. const InputPatch< PSSceneIn, 3 > points )
  81. {
  82. HSPerVertexData v;
  83. // Just forward the vertex
  84. v.v = points[ id ];
  85. return v;
  86. }