Blend.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /******************************************************************************/
  2. #include "!Header.h"
  3. #include "Sky.h"
  4. /******************************************************************************/
  5. #define PARAMS \
  6. uniform Bool skin ,\
  7. uniform Bool color ,\
  8. uniform Bool rflct ,\
  9. uniform Int textures ,\
  10. uniform Bool light_map
  11. /******************************************************************************/
  12. void VS
  13. (
  14. VtxInput vtx,
  15. out Vec2 outTex :TEXCOORD0,
  16. out Vec2 outTexL :TEXCOORD1,
  17. out Vec outRfl :TEXCOORD2,
  18. out VecH4 outColor:COLOR ,
  19. out Vec4 outVtx :POSITION ,
  20. PARAMS
  21. )
  22. {
  23. if(textures )outTex =vtx.tex ();
  24. if(light_map)outTexL =vtx.tex1();
  25. outColor =MaterialColor();
  26. if(color )outColor*=vtx.color();
  27. Vec pos; VecH nrm;
  28. if(!skin)
  29. {
  30. #if MODEL>=SM_4 || MODEL==SM_GL
  31. if(true) // instance
  32. {
  33. pos=TransformPos(vtx.pos(), vtx.instance());
  34. if(rflct)nrm=TransformDir(vtx.nrm(), vtx.instance());
  35. }else
  36. #endif
  37. {
  38. pos=TransformPos(vtx.pos());
  39. if(rflct)nrm=TransformDir(vtx.nrm());
  40. }
  41. }else
  42. {
  43. VecI bone=vtx.bone();
  44. pos=TransformPos(vtx.pos(), bone, vtx.weight());
  45. if(rflct)nrm=TransformDir(vtx.nrm(), bone, vtx.weight());
  46. }
  47. if(rflct)outRfl=Transform3(reflect(Normalize(pos), Normalize(nrm)), CamMatrix);
  48. outVtx=Project(pos);
  49. outColor.a*=Sat(Length(pos)*SkyFracMulAdd.x + SkyFracMulAdd.y);
  50. }
  51. /******************************************************************************/
  52. Vec4 PS
  53. (
  54. Vec2 inTex :TEXCOORD0,
  55. Vec2 inTexL :TEXCOORD1,
  56. Vec inRfl :TEXCOORD2,
  57. VecH4 inColor:COLOR ,
  58. PARAMS
  59. ):COLOR
  60. {
  61. VecH4 tex_nrm; // #MaterialTextureChannelOrder
  62. if(textures==1) inColor *=Tex(Col, inTex);else // alpha in 'Col' texture
  63. if(textures==2){inColor.rgb*=Tex(Col, inTex).rgb; tex_nrm=Tex(Nrm, inTex); inColor.a*=tex_nrm.a;} // alpha in 'Nrm' texture
  64. if(light_map)inColor.rgb*=Tex(Lum, inTexL).rgb;
  65. inColor.rgb+=Highlight.rgb;
  66. // reflection
  67. if(rflct)inColor.rgb+=TexCube(Rfl, inRfl).rgb*((textures==2) ? MaterialReflect()*tex_nrm.z : MaterialReflect());
  68. return inColor;
  69. }
  70. /******************************************************************************/
  71. CUSTOM_TECHNIQUE // this is defined in C++ as a macro
  72. /******************************************************************************/
  73. #if 0
  74. @GROUP "Main"
  75. @SHARED
  76. #include "Glsl.h"
  77. #include "Glsl Material.h"
  78. #include "Glsl Light.h"
  79. VAR LP Vec4 IO_col;
  80. #if textures>0
  81. VAR HP Vec2 IO_tex;
  82. #endif
  83. #if light_map!=0
  84. VAR HP Vec2 IO_tex_l;
  85. #endif
  86. #if rflct!=0
  87. VAR MP Vec IO_rfl;
  88. #endif
  89. @SHARED_END
  90. @VS
  91. #include "Glsl VS.h"
  92. #include "Glsl VS 3D.h"
  93. void main()
  94. {
  95. HP Vec pos=vtx_pos();
  96. #if textures>0
  97. IO_tex=vtx_tex();
  98. #endif
  99. #if light_map!=0
  100. IO_tex_l=vtx_tex1();
  101. #endif
  102. IO_col=MaterialColor();
  103. #if COLOR!=0
  104. IO_col*=vtx_color();
  105. #endif
  106. #if skin==0
  107. pos= TransformPos(pos , gl_InstanceID) ;
  108. #if rflct!=0
  109. MP Vec nrm=Normalize(TransformDir(vtx_nrm(), gl_InstanceID));
  110. #endif
  111. O_vtx= Project (pos);
  112. #else
  113. MP VecI bone =vtx_bone ();
  114. MP Vec weight=vtx_weight();
  115. pos= TransformPos(pos , bone, weight) ;
  116. #if rflct!=0
  117. MP Vec nrm=Normalize(TransformDir(vtx_nrm(), bone, weight));
  118. #endif
  119. O_vtx= Project (pos);
  120. #endif
  121. MP Vec mp_pos =pos;
  122. MP Flt d =Length(mp_pos);
  123. LP Flt opacity=Sat(d*SkyFracMulAdd.x + SkyFracMulAdd.y);
  124. IO_col.a*=opacity;
  125. #if rflct!=0
  126. IO_rfl=Normalize(pos); // convert to MP
  127. IO_rfl=Transform3(reflect(IO_rfl, nrm), CamMatrix);
  128. #endif
  129. }
  130. @VS_END
  131. @PS
  132. #include "Glsl PS.h"
  133. void main()
  134. {
  135. LP Vec4 col=IO_col;
  136. #if textures==1
  137. col*=Tex(Col, IO_tex);
  138. #elif textures==2
  139. LP Vec4 tex_nrm=Tex(Nrm, IO_tex); // #MaterialTextureChannelOrder
  140. LP Vec4 tex_col=Tex(Col, IO_tex); tex_col.a=tex_nrm.a; col*=tex_col;
  141. #endif
  142. #if light_map!=0
  143. col.rgb*=Tex(Lum, IO_tex_l).rgb;
  144. #endif
  145. col.rgb+=Highlight.rgb;
  146. #if rflct!=0
  147. #if textures==2
  148. col.rgb+=TexCube(Rfl, IO_rfl).rgb*(MaterialReflect()*tex_nrm.z);
  149. #else
  150. col.rgb+=TexCube(Rfl, IO_rfl).rgb*MaterialReflect();
  151. #endif
  152. #endif
  153. gl_FragColor=col; // set 'gl_FragColor' at end since it's MP
  154. }
  155. @PS_END
  156. @GROUP_END
  157. #endif
  158. /******************************************************************************/