hlsl.gs-hs-mix.tesc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. cbuffer UniformBlock0 : register(b0)
  2. {
  3. float4x4 model_view_matrix;
  4. float4x4 proj_matrix;
  5. float4x4 model_view_proj_matrix;
  6. float3x3 normal_matrix;
  7. float3 color;
  8. float3 view_dir;
  9. float3 tess_factor;
  10. };
  11. // =============================================================================
  12. // Hull Shader
  13. // =============================================================================
  14. struct HSInput {
  15. float3 PositionWS : POSITION;
  16. float3 NormalWS : NORMAL;
  17. };
  18. struct HSOutput {
  19. float3 PositionWS : POSITION;
  20. };
  21. struct HSTrianglePatchConstant {
  22. float EdgeTessFactor[3] : SV_TessFactor;
  23. float InsideTessFactor : SV_InsideTessFactor;
  24. float3 NormalWS[3] : NORMAL;
  25. };
  26. HSTrianglePatchConstant HSPatchConstant(InputPatch<HSInput, 3> patch)
  27. {
  28. float3 roundedEdgeTessFactor = tess_factor;
  29. float roundedInsideTessFactor = 3;
  30. float insideTessFactor = 1;
  31. HSTrianglePatchConstant result;
  32. // Edge and inside tessellation factors
  33. result.EdgeTessFactor[0] = roundedEdgeTessFactor.x;
  34. result.EdgeTessFactor[1] = roundedEdgeTessFactor.y;
  35. result.EdgeTessFactor[2] = roundedEdgeTessFactor.z;
  36. result.InsideTessFactor = roundedInsideTessFactor;
  37. // Constant data
  38. result.NormalWS[0] = patch[0].NormalWS;
  39. result.NormalWS[1] = patch[1].NormalWS;
  40. result.NormalWS[2] = patch[2].NormalWS;
  41. return result;
  42. }
  43. [domain("tri")]
  44. [partitioning("fractional_odd")]
  45. [outputtopology("triangle_ccw")]
  46. [outputcontrolpoints(3)]
  47. [patchconstantfunc("HSPatchConstant")]
  48. HSOutput HSMain(
  49. InputPatch<HSInput, 3> patch,
  50. uint id : SV_OutputControlPointID
  51. )
  52. {
  53. HSOutput output;
  54. output.PositionWS = patch[id].PositionWS;
  55. return output;
  56. }
  57. // =============================================================================
  58. // Geometry Shader
  59. // =============================================================================
  60. struct GSVertexInput {
  61. float3 PositionWS : POSITION;
  62. float3 NormalWS : NORMAL;
  63. };
  64. struct GSVertexOutput {
  65. float4 PositionCS : SV_POSITION;
  66. };
  67. [maxvertexcount(6)]
  68. void GSMain(
  69. triangle GSVertexInput input[3],
  70. inout LineStream<GSVertexOutput> output
  71. )
  72. {
  73. float3 P0 = input[0].PositionWS.xyz;
  74. float3 P1 = input[1].PositionWS.xyz;
  75. float3 P2 = input[2].PositionWS.xyz;
  76. GSVertexOutput vertex;
  77. // Totally hacky...
  78. P0.z += 0.001;
  79. P1.z += 0.001;
  80. P2.z += 0.001;
  81. float4 Q0 = mul(proj_matrix, float4(P0, 1.0));
  82. float4 Q1 = mul(proj_matrix, float4(P1, 1.0));
  83. float4 Q2 = mul(proj_matrix, float4(P2, 1.0));
  84. // Edge 0
  85. vertex.PositionCS = Q0;
  86. output.Append(vertex);
  87. vertex.PositionCS = Q1;
  88. output.Append(vertex);
  89. output.RestartStrip();
  90. // Edge 1
  91. vertex.PositionCS = Q1;
  92. output.Append(vertex);
  93. vertex.PositionCS = Q2;
  94. output.Append(vertex);
  95. output.RestartStrip();
  96. // Edge 2
  97. vertex.PositionCS = Q2;
  98. output.Append(vertex);
  99. vertex.PositionCS = Q0;
  100. output.Append(vertex);
  101. output.RestartStrip();
  102. }