World Editor.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /******************************************************************************/
  2. #include "!Header.h"
  3. /******************************************************************************/
  4. // COLOR
  5. /******************************************************************************/
  6. void Color_VS
  7. (
  8. VtxInput vtx,
  9. out VecH4 outCol:COLOR ,
  10. out VecH outNrm:TEXCOORD0,
  11. out Vec outPos:TEXCOORD1,
  12. out Vec4 outVtx:POSITION ,
  13. uniform Bool vtx_col=false
  14. )
  15. {
  16. if(vtx_col)outCol=vtx.color();
  17. outNrm=Normalize(TransformDir(vtx.nrm()));
  18. outPos= TransformPos(vtx.pos()) ;
  19. outVtx= Project ( outPos ) ;
  20. }
  21. /******************************************************************************/
  22. void Color_PS
  23. (
  24. VecH4 inCol:COLOR ,
  25. VecH inNrm:TEXCOORD0,
  26. Vec inPos:TEXCOORD1,
  27. out DeferredSolidOutput output,
  28. uniform VecH color ,
  29. uniform Bool vtx_col=false
  30. )
  31. {
  32. output.color ((vtx_col ? color*inCol.rgb : color)+Highlight.rgb);
  33. output.glow (0);
  34. output.normal (Normalize(inNrm));
  35. output.specular(0);
  36. output.velocity(0, inPos);
  37. }
  38. /******************************************************************************/
  39. // CIRCLE / SQUARE / GRID
  40. /******************************************************************************/
  41. BUFFER(WorldEditor)
  42. Flt XZImageUse,
  43. XZPattern;
  44. Flt XZRange,
  45. XZSoft,
  46. XZAngle,
  47. XZPatternScale;
  48. Vec2 XZPos;
  49. VecH XZCol;
  50. BUFFER_END
  51. Image XZImage;
  52. /******************************************************************************/
  53. struct VS_PS
  54. {
  55. Vec pos :TEXCOORD0,
  56. nrm :TEXCOORD1;
  57. Vec2 pos2D:TEXCOORD2;
  58. Vec4 vtx :POSITION ;
  59. };
  60. struct VS_PS_NOVTX
  61. {
  62. Vec pos :TEXCOORD0,
  63. nrm :TEXCOORD1;
  64. Vec2 pos2D:TEXCOORD2;
  65. };
  66. /******************************************************************************/
  67. VS_PS FX_VS
  68. (
  69. VtxInput vtx
  70. )
  71. {
  72. VS_PS O;
  73. O.pos= TransformPos(vtx.pos()) ; O.pos2D=Transform(O.pos, CamMatrix).xz;
  74. O.nrm=Normalize(TransformDir(vtx.nrm()));
  75. O.vtx= Project ( O.pos ) ;
  76. return O;
  77. }
  78. /******************************************************************************/
  79. Vec4 Circle_PS
  80. (
  81. VS_PS I
  82. ):COLOR
  83. {
  84. Vec2 cos_sin; CosSin(cos_sin.x, cos_sin.y, XZAngle);
  85. Vec2 d=I.pos2D-XZPos; d=Rotate(d, cos_sin); d/=XZRange;
  86. Flt b;
  87. b=Length(d);
  88. b=Sat ((b-(1-XZSoft))/XZSoft);
  89. b=BlendSmoothCube(b);
  90. if(XZImageUse)b*=Tex(XZImage, (XZPattern ? I.pos2D*XZPatternScale : d*0.5f+0.5f)*Vec2(1,-1)).r;
  91. return Vec4(XZCol*b, 0);
  92. }
  93. /******************************************************************************/
  94. Vec4 Square_PS
  95. (
  96. VS_PS I
  97. ):COLOR
  98. {
  99. Vec2 cos_sin; CosSin(cos_sin.x, cos_sin.y, XZAngle);
  100. Vec2 d=I.pos2D-XZPos; d=Rotate(d, cos_sin); d/=XZRange;
  101. Flt b;
  102. b=Max(Abs(d));
  103. b=Sat((b-(1-XZSoft))/XZSoft);
  104. b=BlendSmoothCube(b);
  105. if(XZImageUse)b*=Tex(XZImage, (XZPattern ? I.pos2D*XZPatternScale : d*0.5f+0.5f)*Vec2(1, -1)).r;
  106. return Vec4(XZCol*b, 0);
  107. }
  108. /******************************************************************************/
  109. Vec4 Grid_PS
  110. (
  111. VS_PS_NOVTX I
  112. ):COLOR
  113. {
  114. Vec2 pos =I.pos2D/XZRange;
  115. Vec2 xz =Sat((Abs(Frac(pos)-0.5f)-0.5f)/XZSoft+1);
  116. Flt alpha=Max(xz);
  117. Flt dd=Max(Vec4(Abs(ddx(pos)), Abs(ddy(pos)))); alpha*=LerpRS(0.2f, 0.1f, dd);
  118. return Vec4(XZCol*alpha, 0);
  119. }
  120. /******************************************************************************/
  121. // HULL / DOMAIN
  122. /******************************************************************************/
  123. #if MODEL>=SM_4
  124. HSData HSConstant(InputPatch<VS_PS_NOVTX,3> I) {return GetHSData(I[0].pos, I[1].pos, I[2].pos, I[0].nrm, I[1].nrm, I[2].nrm);}
  125. [maxtessfactor(5.0)]
  126. [domain("tri")]
  127. [partitioning("fractional_odd")] // use 'odd' because it supports range from 1.0 ('even' supports range from 2.0)
  128. [outputtopology("triangle_cw")]
  129. [patchconstantfunc("HSConstant")]
  130. [outputcontrolpoints(3)]
  131. VS_PS_NOVTX HS
  132. (
  133. InputPatch<VS_PS_NOVTX,3> I, UInt cp_id:SV_OutputControlPointID
  134. )
  135. {
  136. VS_PS_NOVTX O;
  137. O.pos =I[cp_id].pos;
  138. O.nrm =I[cp_id].nrm;
  139. O.pos2D=I[cp_id].pos2D;
  140. return O;
  141. }
  142. /******************************************************************************/
  143. [domain("tri")]
  144. VS_PS DS
  145. (
  146. HSData hs_data, const OutputPatch<VS_PS_NOVTX,3> I, Vec B:SV_DomainLocation
  147. )
  148. {
  149. VS_PS O;
  150. O.pos2D=I[0].pos2D*B.z + I[1].pos2D*B.x + I[2].pos2D*B.y;
  151. 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);
  152. O.vtx=Project(O.pos);
  153. return O;
  154. }
  155. #endif
  156. /******************************************************************************/
  157. TECHNIQUE(WhiteVtx, Color_VS(true), Color_PS(Vec(1, 1, 1), true ));
  158. TECHNIQUE(White , Color_VS( ), Color_PS(Vec(1, 1, 1), false));
  159. TECHNIQUE(Green , Color_VS( ), Color_PS(Vec(0, 1, 0), false));
  160. TECHNIQUE(Yellow , Color_VS( ), Color_PS(Vec(1, 1, 0), false));
  161. TECHNIQUE(Red , Color_VS( ), Color_PS(Vec(1, 0, 0), false));
  162. TECHNIQUE (Circle <bool ForceHP=true;>, FX_VS(), Circle_PS());
  163. TECHNIQUE (Square <bool ForceHP=true;>, FX_VS(), Square_PS());
  164. TECHNIQUE (Grid <bool ForceHP=true;>, FX_VS(), Grid_PS());
  165. TECHNIQUE_TESSELATION(CircleT , FX_VS(), Circle_PS(), HS(), DS());
  166. TECHNIQUE_TESSELATION(SquareT , FX_VS(), Square_PS(), HS(), DS());
  167. TECHNIQUE_TESSELATION(GridT , FX_VS(), Grid_PS(), HS(), DS());
  168. /******************************************************************************/
  169. #if 0
  170. @GROUP "Circle"
  171. @SHARED
  172. #include "Glsl.h"
  173. VAR HP Vec2 IO_pos2D;
  174. @SHARED_END
  175. @VS
  176. #include "Glsl VS.h"
  177. #include "Glsl VS 3D.h"
  178. void main()
  179. {
  180. HP Vec pos=TransformPos(vtx_pos());
  181. IO_pos2D=Transform(pos, CamMatrix).xz;
  182. O_vtx=Project(pos);
  183. }
  184. @VS_END
  185. @PS
  186. #include "Glsl PS.h"
  187. void main()
  188. {
  189. Vec2 cos_sin; CosSin(cos_sin.x, cos_sin.y, XZAngle);
  190. Vec2 d=I.pos2D-XZPos; d=Rotate(d, cos_sin); d/=XZRange;
  191. Flt b;
  192. b=Length(d);
  193. b=Sat ((b-(1-XZSoft))/XZSoft);
  194. b=BlendSmoothCube(b);
  195. if(XZImageUse)b*=Tex(XZImage, (XZPattern ? I.pos2D*XZPatternScale : d*0.5f+0.5f)*Vec2(1,-1)).r;
  196. return Vec4(XZCol*b, 0);
  197. gl_FragColor.rgb=col; // set 'gl_FragColor' at end since it's MP
  198. gl_FragColor.a =((per_pixel!=0) ? glow : 0.0);
  199. }
  200. @PS_END
  201. @GROUP_END
  202. #endif
  203. /******************************************************************************/