Position.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /******************************************************************************/
  2. #include "!Header.h"
  3. /******************************************************************************/
  4. #define PARAMS \
  5. uniform Bool skin ,\
  6. uniform Int textures ,\
  7. uniform Bool test_blend,\
  8. uniform Int fx ,\
  9. uniform Bool tesselate
  10. /******************************************************************************/
  11. struct VS_PS
  12. {
  13. Vec pos:TEXCOORD0,
  14. nrm:TEXCOORD1;
  15. Vec2 tex:TEXCOORD2;
  16. };
  17. /******************************************************************************/
  18. // VS
  19. /******************************************************************************/
  20. void VS
  21. (
  22. VtxInput vtx,
  23. out VS_PS O,
  24. out Vec4 O_vtx:POSITION,
  25. PARAMS
  26. )
  27. {
  28. Vec pos=vtx.pos();
  29. VecH nrm; if(tesselate)nrm=vtx.nrm();
  30. if(fx==FX_LEAF)
  31. {
  32. if(tesselate)BendLeaf(vtx.hlp(), pos, nrm);
  33. else BendLeaf(vtx.hlp(), pos);
  34. }
  35. if(fx==FX_LEAFS)
  36. {
  37. if(tesselate)BendLeafs(vtx.hlp(), vtx.size(), pos, nrm);
  38. else BendLeafs(vtx.hlp(), vtx.size(), pos);
  39. }
  40. if(!skin)
  41. {
  42. #if MODEL>=SM_4 || MODEL==SM_GL
  43. if(true) // instance
  44. {
  45. O.pos= TransformPos(pos, vtx.instance());
  46. if(tesselate)O.nrm=Normalize(TransformDir(nrm, vtx.instance()));
  47. if(fx==FX_GRASS)BendGrass(pos, O.pos, vtx.instance());
  48. }else
  49. #endif
  50. {
  51. O.pos= TransformPos(pos);
  52. if(tesselate)O.nrm=Normalize(TransformDir(nrm));
  53. if(fx==FX_GRASS)BendGrass(pos, O.pos);
  54. }
  55. }else
  56. {
  57. VecI bone=vtx.bone();
  58. O.pos= TransformPos(pos, bone, vtx.weight());
  59. if(tesselate)O.nrm=Normalize(TransformDir(nrm, bone, vtx.weight()));
  60. }
  61. if(textures)O.tex=vtx.tex();
  62. O_vtx=Project(O.pos);
  63. }
  64. /******************************************************************************/
  65. // PS
  66. /******************************************************************************/
  67. void PS
  68. (
  69. VS_PS I,
  70. #if MODEL==SM_3
  71. out Vec4 ret:COLOR,
  72. #endif
  73. PARAMS
  74. )
  75. {
  76. if(textures==1)clip(Tex(Col, I.tex).a+(test_blend ? (MaterialAlpha()*0.5f-1) : (MaterialAlpha()-1)));else
  77. if(textures==2)clip(Tex(Nrm, I.tex).a+(test_blend ? (MaterialAlpha()*0.5f-1) : (MaterialAlpha()-1))); // #MaterialTextureChannelOrder
  78. #if MODEL==SM_3
  79. ret=0;
  80. #endif
  81. }
  82. /******************************************************************************/
  83. // HULL / DOMAIN
  84. /******************************************************************************/
  85. #if MODEL>=SM_4
  86. HSData HSConstant(InputPatch<VS_PS,3> I) {return GetHSData(I[0].pos, I[1].pos, I[2].pos, I[0].nrm, I[1].nrm, I[2].nrm, true);}
  87. [maxtessfactor(5.0)]
  88. [domain("tri")]
  89. [partitioning("fractional_odd")] // use 'odd' because it supports range from 1.0 ('even' supports range from 2.0)
  90. [outputtopology("triangle_cw")]
  91. [patchconstantfunc("HSConstant")]
  92. [outputcontrolpoints(3)]
  93. VS_PS HS
  94. (
  95. InputPatch<VS_PS,3> I, UInt cp_id:SV_OutputControlPointID,
  96. PARAMS
  97. )
  98. {
  99. VS_PS O;
  100. O.pos=I[cp_id].pos;
  101. O.nrm=I[cp_id].nrm;
  102. if(textures)O.tex=I[cp_id].tex;
  103. return O;
  104. }
  105. /******************************************************************************/
  106. [domain("tri")]
  107. void DS
  108. (
  109. HSData hs_data, const OutputPatch<VS_PS,3> I, Vec B:SV_DomainLocation,
  110. out VS_PS O,
  111. out Vec4 O_vtx:POSITION,
  112. PARAMS
  113. )
  114. {
  115. if(textures)O.tex=I[0].tex*B.z + I[1].tex*B.x + I[2].tex*B.y;
  116. SetDSPosNrm(O.pos, O.nrm, I[0].pos, I[1].pos, I[2].pos, I[0].nrm, I[1].nrm, I[2].nrm, B, hs_data, false, 0);
  117. O_vtx=Project(O.pos);
  118. }
  119. #endif
  120. /******************************************************************************/
  121. // TECHNIQUES
  122. /******************************************************************************/
  123. CUSTOM_TECHNIQUE
  124. /******************************************************************************/