SimpleHs2.hlsl 2.5 KB

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