Advertisement
Guest User

tess.ds

a guest
May 24th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #include "common.h"
  2. #include "DX11\tess.h"
  3.  
  4. //if you use ccw then corresponding coefs are w, v, u
  5. //if you use cw then corresponding coefs are u, v, w
  6. [domain("tri")]
  7. v2p_bumped main( HS_CONSTANT_DATA_OUTPUT input,
  8. float3 uvw : SV_DomainLocation,
  9. const OutputPatch<p_bumped, 3> bp )
  10. {
  11. v2p_bumped output;
  12.  
  13. //interpolate in screen space
  14. //uvw = uvw*input.www/dot(uvw,input.www);
  15.  
  16. float minc = min( uvw.x, min( uvw.y, uvw.z ) );
  17. // if the vertex is not on an edge of the original triangle
  18. [flatten]if (minc!=0.0f)
  19. {
  20. // if we are at not the centre of the triangle
  21. [flatten]if( ((1.0f/3.0f)-minc)> 0.01f )
  22. {
  23. // solving for making the smallest uvw component 0.0f as this means the bigger ones sum to 1.0f and
  24. // are on the edge of the triangle
  25. // if vertex gets too close to the edge move it on to the edge to replace to old edge vertex
  26. // otherwise keep fK at 1.0f to restore the old uvw position
  27.  
  28. float fK = (1.0f/3.0f)/((1.0f/3.0f)-minc);
  29. fK = minc < 0.1 ? fK : 1.0f;
  30. // update uvw
  31. uvw = lerp((1.0f/3.0f).xxx, uvw, fK);
  32. }
  33. }
  34.  
  35. float u = uvw.x;
  36. float v = uvw.y;
  37. float w = uvw.z;
  38.  
  39. output.tcdh = bp[0].tcdh*w + bp[1].tcdh*v + bp[2].tcdh*u;
  40. output.position = bp[0].position*w + bp[1].position*v + bp[2].position*u;
  41.  
  42. float3 M1 = bp[0].M1*w + bp[1].M1*v + bp[2].M1*u; output.M1 = M1;
  43. float3 M2 = bp[0].M2*w + bp[1].M2*v + bp[2].M2*u; output.M2 = M2;
  44. float3 M3 = bp[0].M3*w + bp[1].M3*v + bp[2].M3*u; output.M3 = M3;
  45. float3 Normal = normalize(float3(M1.z, M2.z, M3.z));
  46.  
  47. float3 triPos = output.position.xyz;
  48.  
  49. #ifdef USE_TDETAIL
  50. output.tcdbump = bp[0].tcdbump*w + bp[1].tcdbump*v + bp[2].tcdbump*u;
  51. #endif
  52. #ifdef USE_LM_HEMI
  53. output.lmh = bp[0].lmh*w + bp[1].lmh*v + bp[2].lmh*u;
  54. #endif
  55.  
  56. #if TESS_PN
  57. float3 N[3] =
  58. {
  59. float3(bp[0].M1.z, bp[0].M2.z, bp[0].M3.z),
  60. float3(bp[1].M1.z, bp[1].M2.z, bp[1].M3.z),
  61. float3(bp[2].M1.z, bp[2].M2.z, bp[2].M3.z)
  62. };
  63.  
  64. float3 P[3] =
  65. {
  66. bp[0].position.xyz,
  67. bp[1].position.xyz,
  68. bp[2].position.xyz
  69. };
  70.  
  71. ComputePatchVertex(P, N, uvw, input.patch, output.position.xyz, Normal);
  72. #endif
  73.  
  74. #if TESS_HM
  75. # ifdef USE_TDETAIL
  76. ComputeDisplacedVertex(output.position.xyz, Normal, output.tcdh, output.tcdbump);
  77. # else
  78. ComputeDisplacedVertex(output.position.xyz, Normal, output.tcdh, 0);
  79. # endif
  80. #endif
  81.  
  82.  
  83. [flatten]if( minc==0 )
  84. output.position.xyz = triPos;
  85.  
  86.  
  87. //output.M1.z = Normal.x;
  88. //output.M2.z = Normal.y;
  89. //output.M3.z = Normal.z;
  90. output.hpos = mul(m_P, float4(output.position.xyz,1));
  91.  
  92. return output;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement