Shader Main.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. struct MainShaderClass
  4. {
  5. Str path;
  6. ShaderFile *shader;
  7. // get
  8. Shader* find(C Str8 &name); // find shader, null on fail
  9. Shader* get(C Str8 &name); // get shader, Exit on fail
  10. // effects
  11. static void clear( C Vec4 &color, C Rect *rect=null);
  12. static void draw (C Image &image, C Rect *rect=null);
  13. static void draw (C Image &image, C Color &color, C Color &color_add=TRANSPARENT, C Rect *rect=null);
  14. static void draw (C Image &image, C Vec4 &color, C Vec4 &color_add=Vec4Zero , C Rect *rect=null);
  15. // private
  16. void del ();
  17. void createSamplers();
  18. void create ();
  19. void compile ();
  20. void getTechniques ();
  21. void connectRT ();
  22. ShaderImage
  23. *h_ImageCol[4], *h_ImageColMS,
  24. *h_ImageNrm[4], *h_ImageNrmMS,
  25. *h_ImageDet[4],
  26. *h_ImageMac[4],
  27. *h_ImageRfl[4],
  28. *h_ImageDepth, *h_ImageDepthMS,
  29. *h_ImageLum , *h_ImageLumMS ,
  30. *h_ImageShdMap[2],
  31. *h_ImageCub,
  32. *h_ImageVol[2];
  33. ShaderParam
  34. *h_ColSize ,
  35. *h_ColClamp ,
  36. *h_RTSizeI ,
  37. *h_PixelOffset,
  38. *h_Coords ,
  39. *h_Viewport ,
  40. *h_DepthWeightScale,
  41. *h_CamAngVel ,
  42. *h_ObjAngVel ,
  43. *h_ObjVel ,
  44. *h_ViewMatrix,
  45. *h_CamMatrix ,
  46. *h_ProjMatrix,
  47. *h_FurVel ,
  48. *h_ClipPlane ,
  49. *h_Material ,
  50. *h_MultiMaterial[4],
  51. *h_Light_dir ,
  52. *h_Light_pnt ,
  53. *h_Light_sqr ,
  54. *h_Light_cone,
  55. *h_Step ,
  56. *h_Color[2] ,
  57. *h_BehindBias ,
  58. *h_AllowBackFlip,
  59. *h_VtxSkinning ,
  60. *h_VtxHeightmap,
  61. *h_VtxNrmMulAdd,
  62. *h_FontShadow ,
  63. *h_FontContrast,
  64. *h_FontShade ,
  65. *h_FontDepth ,
  66. *h_LightMapScale ,
  67. *h_LightMapColAdd ,
  68. *h_LightMapSpecular,
  69. *h_GrassRangeMulAdd,
  70. *h_BendFactor,
  71. *h_Volume,
  72. *h_RippleParams,
  73. *h_AmbientMaterial,
  74. *h_AmbientContrast,
  75. *h_AmbientRange ,
  76. *h_AmbientScale ,
  77. *h_AmbientBias ,
  78. *h_NightShadeColor,
  79. *h_HdrBrightness,
  80. *h_HdrMaxDark,
  81. *h_HdrMaxBright,
  82. *h_HdrWeight,
  83. *h_TesselationDensity,
  84. *h_Sun ,
  85. *h_SkyFracMulAdd ,
  86. *h_SkyDnsMulAdd ,
  87. *h_SkyDnsExp ,
  88. *h_SkyHorExp ,
  89. *h_SkyBoxBlend ,
  90. *h_SkyHorCol ,
  91. *h_SkySkyCol ,
  92. *h_SkyStarOrn ,
  93. *h_SkySunHighlight,
  94. *h_SkySunPos ,
  95. *h_FogColor_Density ,
  96. *h_LocalFogColor_Density,
  97. *h_LocalFogInside ,
  98. *h_VertexFogMulAdd,
  99. *h_VertexFogColor ,
  100. *h_ShdJitter ,
  101. *h_ShdRange ,
  102. *h_ShdRangeMulAdd,
  103. *h_ShdOpacity ,
  104. *h_ShdStep[6] ,
  105. *h_ShdMatrix ,
  106. *h_ShdMatrix4[6] ,
  107. *h_ParticleFrames,
  108. *h_DecalParams,
  109. *h_OverlayParams,
  110. *h_SMAAThreshold;
  111. // SHADERS
  112. Shader
  113. *h_Draw2DFlat ,
  114. *h_Draw3DFlat ,
  115. *h_Draw2DCol ,
  116. *h_Draw3DCol ,
  117. *h_Draw2DTex ,
  118. *h_Draw2DTexC ,
  119. *h_Draw2DTexCol ,
  120. *h_Draw3DTex [2][2], // [AlphaTest] [Fog]
  121. *h_Draw3DTexCol[2][2], // [AlphaTest] [Fog]
  122. *h_DrawTexX ,
  123. //*h_DrawTexZ ,
  124. *h_DrawTexW ,
  125. *h_DrawTexXC ,
  126. *h_DrawTexWC ,
  127. *h_DrawTexXCD ,
  128. *h_DrawTexWCD ,
  129. //*h_DrawTexNrm ,
  130. *h_Simple ,
  131. *h_DrawMask,
  132. *h_DrawCubeFace,
  133. *h_Font ,
  134. *h_FontD,
  135. *h_Laser[2],
  136. *h_PaletteDraw,
  137. // BASIC 2D
  138. *h_SetCol ,
  139. *h_Draw ,
  140. *h_DrawC ,
  141. *h_DrawA ,
  142. *h_DrawMs1,
  143. *h_DrawMsN,
  144. *h_DrawMsM,
  145. // BLUR
  146. #define SHADER_BLUR_RANGE 5 // 5 pixel range in both directions
  147. *h_BlurX[2], // [High]
  148. *h_BlurY[2], // [High]
  149. /**h_BlurX_X,
  150. *h_BlurX_W,
  151. *h_BlurY_X,
  152. *h_BlurY_W,*/
  153. // MAX
  154. *h_MaxX,
  155. *h_MaxY,
  156. // VIDEO
  157. *h_YUV,
  158. *h_YUVA,
  159. // 2D FX
  160. *h_ColTrans ,
  161. *h_ColTransHB ,
  162. *h_ColTransHSB ,
  163. *h_Ripple ,
  164. *h_Titles ,
  165. *h_Fade ,
  166. *h_Wave ,
  167. *h_RadialBlur ,
  168. *h_Outline ,
  169. *h_OutlineDS ,
  170. *h_OutlineClip ,
  171. *h_OutlineApply ,
  172. *h_EdgeDetect ,
  173. *h_EdgeDetectApply,
  174. *h_DetectMSCol ,
  175. //*h_DetectMSNrm ,
  176. #if DX9
  177. *h_LinearizeDepthRAWZ[2], // [Perspective]
  178. #endif
  179. *h_LinearizeDepth[2][3], // [Perspective] [MultiSample]
  180. *h_ResolveDepth,
  181. *h_SetDepth,
  182. *h_Dither,
  183. *h_Combine,
  184. *h_CombineMS,
  185. *h_CombineSS,
  186. *h_CombineSSAlpha,
  187. // FOG
  188. *h_Fog[3] , // [MultiSample]
  189. *h_FogBox ,
  190. *h_FogBox0 ,
  191. *h_FogBox1 ,
  192. *h_FogHgt ,
  193. *h_FogHgt0 ,
  194. *h_FogHgt1 ,
  195. *h_FogBall ,
  196. *h_FogBall0,
  197. *h_FogBall1;
  198. void initFogBoxShaders (); INLINE void loadFogBoxShaders () {if(SLOW_SHADER_LOAD)initFogBoxShaders ();}
  199. void initFogHgtShaders (); INLINE void loadFogHgtShaders () {if(SLOW_SHADER_LOAD)initFogHgtShaders ();}
  200. void initFogBallShaders(); INLINE void loadFogBallShaders() {if(SLOW_SHADER_LOAD)initFogBallShaders();}
  201. Shader
  202. // VOLUME
  203. *h_Volume0[2], // [RedGreen as LumAlpha]
  204. *h_Volume1[2], // [RedGreen as LumAlpha]
  205. *h_Volume2[2], // [RedGreen as LumAlpha]
  206. // EDGE SOFTEN
  207. *h_FXAA ,
  208. #if SUPPORT_MLAA
  209. *h_MLAAEdge ,
  210. *h_MLAABlend,
  211. *h_MLAA ,
  212. #endif
  213. *h_SMAAEdge ,
  214. *h_SMAABlend,
  215. *h_SMAA ,
  216. // PARTICLE
  217. *h_Bilb ,
  218. *h_Particle[2][2][3][2], // [Palette] [Soft] [Anim] [Motion stretch affects opacity]
  219. // POINT
  220. *h_DrawTexPoint ,
  221. *h_DrawTexPointC,
  222. // CUBIC
  223. *h_DrawTexCubicFast ,
  224. *h_DrawTexCubicFastC ,
  225. *h_DrawTexCubicFast1 ,
  226. *h_DrawTexCubicFastD ,
  227. *h_DrawTexCubicFastRGB ,
  228. *h_DrawTexCubicFastRGBD,
  229. *h_DrawTexCubic ,
  230. *h_DrawTexCubicC ,
  231. *h_DrawTexCubic1 ,
  232. *h_DrawTexCubicD ,
  233. *h_DrawTexCubicRGB ,
  234. *h_DrawTexCubicRGBD ;
  235. void initCubicShaders(); INLINE void loadCubicShaders() {if(SLOW_SHADER_LOAD)initCubicShaders();}
  236. // SHADOWS
  237. Shader
  238. *h_ShdDir[6][2][2], // [NumberOfMaps] [Clouds] [MultiSample]
  239. *h_ShdPnt [2], // [MultiSample]
  240. *h_ShdCone [2], // [MultiSample]
  241. *h_ShdBlur [4], // [Quality]
  242. *h_ShdBlurX ,
  243. *h_ShdBlurY ;
  244. Shader* getShdDir (Int map_num, Bool clouds, Bool multi_sample);
  245. Shader* getShdPnt ( Bool multi_sample);
  246. Shader* getShdCone( Bool multi_sample);
  247. // LIGHT
  248. Shader
  249. *h_LightDir [2] [2][2], // [Shadow] [MultiSample] [QualityUnpack]
  250. *h_LightPnt [2] [2][2], // [Shadow] [MultiSample] [QualityUnpack]
  251. *h_LightSqr [2] [2][2], // [Shadow] [MultiSample] [QualityUnpack]
  252. *h_LightCone[2][2][2][2]; // [Shadow] [Image] [MultiSample] [QualityUnpack]
  253. Shader* getLightDir (Bool shadow, Bool multi_sample, Bool quality);
  254. Shader* getLightPnt (Bool shadow, Bool multi_sample, Bool quality);
  255. Shader* getLightSqr (Bool shadow, Bool multi_sample, Bool quality);
  256. Shader* getLightCone(Bool shadow, Bool image, Bool multi_sample, Bool quality);
  257. // COL LIGHT
  258. Shader
  259. *h_ColLight[3][2][2][2]; // [Multisample] [AmbientOcclusion] [CelShade] [NightShade]
  260. Shader* getColLight(Int multi_sample, Bool ao, Bool cel_shade, Bool night_shade);
  261. // BLOOM
  262. ShaderParam
  263. *h_BloomParams;
  264. Shader
  265. *h_BloomDS[2][2][2][2], // [Glow] [UVClamp] [HalfRes] [Saturate]
  266. *h_Bloom [2] ; // [Dither]
  267. Shader* getBloomDS(Bool glow, Bool viewport_clamp, Bool half, Bool saturate);
  268. Shader* getBloom (Bool dither);
  269. // SKY
  270. Shader
  271. *h_SunRaysMask[2] , // [Mask]
  272. *h_SunRays [2][2] , // [High] [Jitter]
  273. *h_SkyTF[2] [2] [2], // [Textures(0->1, 1->2)] [Cloud ] [Dither] (Textures +Flat)
  274. *h_SkyT [2] [3][2], // [Textures(0->1, 1->2)] [MultiSample] [Dither] (Textures )
  275. *h_SkyAF[2][2][2] [2], // [PerVertex ] [Stars] [Cloud ] [Dither] (Atmospheric+Flat)
  276. *h_SkyA [2][2][2][3][2]; // [PerVertex ] [Stars] [Density] [MultiSample] [Dither] (Atmospheric )
  277. Shader* getSunRaysMask(Bool mask);
  278. Shader* getSunRays (Bool high, Bool jitter);
  279. Shader* getSkyTF(Int textures, Bool cloud , Bool dither);
  280. Shader* getSkyT (Int textures, Int multi_sample, Bool dither);
  281. Shader* getSkyAF(Bool per_vertex, Bool stars, Bool cloud , Bool dither);
  282. Shader* getSkyA (Bool per_vertex, Bool stars, Bool density, Int multi_sample, Bool dither);
  283. }extern
  284. Sh;
  285. struct AmbientOcclusion
  286. {
  287. ShaderFile *shader;
  288. Shader *h_AO[4][2][2]; // [Quality] [Jitter] [Normal]
  289. Shader* get(Int quality, Bool jitter, Bool normal);
  290. }extern
  291. AO;
  292. struct LayeredCloudsFx
  293. {
  294. ShaderFile *shader;
  295. ShaderParam *h_CL[4], *range;
  296. Shader *h_Clouds[4][2][2]; // [#Layers] [Blend] [Draw Mask to 2nd RT]
  297. void load();
  298. Shader* get(Int layers, Bool blend, Bool mask);
  299. }extern
  300. LC;
  301. struct VolumetricCloudsFx
  302. {
  303. ShaderFile *shader;
  304. ShaderParam *h_Cloud, *h_CloudMap;
  305. Shader *h_Clouds, *h_CloudsDraw, *h_CloudsMap;
  306. void load();
  307. }extern
  308. VolCloud;
  309. struct VolumetricLights
  310. {
  311. ShaderFile *shader;
  312. ShaderParam *h_Light_point_range;
  313. Shader *h_VolDir[6][2], // [ShdMapNum] [Clouds]
  314. *h_VolPnt ,
  315. *h_VolSqr ,
  316. *h_VolCone ,
  317. *h_Volumetric ,
  318. *h_VolumetricA ;
  319. void load();
  320. }extern
  321. VL;
  322. struct HDR
  323. {
  324. ShaderFile *shader;
  325. Shader *h_HdrDS[2] , // [Step]
  326. *h_HdrUpdate,
  327. *h_Hdr ;
  328. void load();
  329. }extern
  330. Hdr;
  331. struct MotionBlur
  332. {
  333. ShaderFile *shader;
  334. ShaderParam *h_MotionUVMulAdd ,
  335. *h_MotionVelScaleLimit,
  336. *h_MotionPixelSize ;
  337. Shader *h_Explosion ,
  338. *h_ClearSkyVel ,
  339. *h_Convert [2][2], // [High][Clamp]
  340. *h_Dilate ,
  341. *h_SetDirs [2] , // [Clamp]
  342. *h_Blur [2] ; // [Dither]
  343. struct Pixel
  344. {
  345. Int pixels;
  346. Shader *h_DilateX[2], // [Diagonal]
  347. *h_DilateY[2]; // [Diagonal]
  348. }pixels[9];
  349. void load();
  350. C Pixel* pixel(Int pixel, Bool diagonal);
  351. }extern
  352. Mtn;
  353. struct DepthOfField
  354. {
  355. ShaderFile *shader;
  356. ShaderParam *h_DofParams;
  357. Shader *h_DofDS[2][2][2], // [Clamp ][Realistic][Half]
  358. *h_Dof [2][2] ; // [Dither][Realistic]
  359. struct Pixel
  360. {
  361. Int pixels;
  362. Shader *h_BlurX,
  363. *h_BlurY;
  364. }pixels[11];
  365. void load();
  366. Shader* getDS(Bool clamp , Bool realistic, Bool half);
  367. Shader* get (Bool dither, Bool realistic);
  368. C Pixel& pixel(Int pixel);
  369. }extern
  370. Dof;
  371. struct WaterShader
  372. {
  373. ShaderFile *shader;
  374. Shader *h_Ocean [2] , // [FakeReflect]
  375. *h_Lake [2] , // [FakeReflect]
  376. *h_River [2] , // [FakeReflect]
  377. *h_OceanL[2][7][2], // [FakeReflect] [Shadows] [Soft]
  378. *h_LakeL [2][7][2], // [FakeReflect] [Shadows] [Soft]
  379. *h_RiverL[2][7][2], // [FakeReflect] [Shadows] [Soft]
  380. *h_Apply [2][2] , // [Refract] [Depth]
  381. *h_Under [2] ; // [Refract]
  382. void load();
  383. }extern
  384. WS;
  385. extern ShaderImage::Sampler SamplerPoint, SamplerLinearWrap, SamplerLinearWCC, SamplerLinearCWC, SamplerLinearCWW, SamplerLinearClamp, SamplerFont, SamplerAnisotropic, SamplerShadowMap;
  386. void CreateAnisotropicSampler();
  387. void CreateFontSampler ();
  388. Str8 TechNameSimple (Int skin, Int materials, Int textures, Int bump_mode, Int alpha_test, Int light_map, Int rflct, Int color, Int mtrl_blend, Int heightmap, Int fx, Int per_pixel, Int tess);
  389. Str8 TechNameDeferred (Int skin, Int materials, Int textures, Int bump_mode, Int alpha_test, Int light_map, Int detail, Int macro, Int rflct, Int color, Int mtrl_blend, Int heightmap, Int fx, Int tess);
  390. Str8 TechNameForward (Int skin, Int materials, Int textures, Int bump_mode, Int alpha_test, Int light_map, Int detail, Int rflct, Int color, Int mtrl_blend, Int heightmap, Int fx, Int light_dir, Int light_dir_shd, Int light_dir_shd_num, Int light_point, Int light_point_shd, Int light_sqr, Int light_sqr_shd, Int light_cone, Int light_cone_shd, Int tess);
  391. Str8 TechNameBlendLight(Int skin, Int color , Int textures, Int bump_mode, Int alpha_test, Int alpha, Int light_map, Int rflct, Int fx, Int per_pixel, Int shadow_maps);
  392. Str8 TechNamePosition (Int skin, Int textures, Int test_blend, Int fx, Int tess);
  393. Str8 TechNameBlend (Int skin, Int color, Int rflct, Int textures, Int light_map);
  394. Str8 TechNameSetColor (Int skin, Int textures, Int tess);
  395. Str8 TechNameBehind (Int skin, Int textures);
  396. Str8 TechNameEarlyZ (Int skin);
  397. Str8 TechNameAmbient (Int skin, Int alpha_test);
  398. Str8 TechNameOverlay (Int skin, Int normal);
  399. Str8 TechNameFurBase (Int skin, Int size, Int diffuse);
  400. Str8 TechNameFurSoft (Int skin, Int size, Int diffuse);
  401. Str8 TechNameTattoo (Int skin, Int tess);
  402. struct DefaultShaders
  403. {
  404. Bool valid,
  405. detail, macro, reflect, light_map,
  406. mtrl_blend,
  407. heightmap,
  408. normal, color, size,
  409. fur, blend, grass, leaf, ambient,
  410. alpha, alpha_test, alpha_blend, alpha_blend_light,
  411. skin,
  412. tess;
  413. Byte materials, textures, bump, fx;
  414. void init(C Material *material[4], UInt mesh_base_flag, Int lod_index, Bool heightmap);
  415. DefaultShaders(C Material *material[4], UInt mesh_base_flag, Int lod_index, Bool heightmap) {init(material, mesh_base_flag, lod_index, heightmap);}
  416. DefaultShaders(C Material *material , UInt mesh_base_flag, Int lod_index, Bool heightmap);
  417. Shader* EarlyZ ()C;
  418. Shader* Simple ()C;
  419. Shader* Solid (Bool mirror=false)C;
  420. Shader* Ambient()C;
  421. Shader* Outline()C;
  422. Shader* Behind ()C;
  423. Shader* Fur ()C;
  424. Shader* Shadow ()C;
  425. Shader* Blend ()C;
  426. Shader* Overlay()C;
  427. Shader* get (RENDER_MODE mode)C;
  428. FRST * Frst ()C;
  429. BLST * Blst ()C;
  430. void set(Shader *shader[RM_SHADER_NUM], FRST **frst, BLST **blst);
  431. };
  432. #endif
  433. /******************************************************************************/