llviewershadermgr.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /**
  2. * @file llviewershadermgr.h
  3. * @brief Viewer Shader Manager
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_VIEWER_SHADER_MGR_H
  33. #define LL_VIEWER_SHADER_MGR_H
  34. #include "llmaterial.h"
  35. #include "llshadermgr.h"
  36. #define LL_DEFERRED_MULTI_LIGHT_COUNT 16
  37. class LLViewerShaderMgr : public LLShaderMgr
  38. {
  39. protected:
  40. LOG_CLASS(LLViewerShaderMgr);
  41. private:
  42. // Use createInstance() and releaseInstance()
  43. LLViewerShaderMgr();
  44. ~LLViewerShaderMgr() override;
  45. void init();
  46. public:
  47. static void createInstance();
  48. static void releaseInstance();
  49. void initAttribsAndUniforms() override;
  50. void setShaders();
  51. void unloadShaders();
  52. bool loadBasicShaders();
  53. bool loadShadersEffects();
  54. bool loadShadersDeferred();
  55. bool loadShadersObject();
  56. bool loadShadersAvatar();
  57. bool loadShadersEnvironment();
  58. bool loadShadersWater();
  59. bool loadShadersInterface();
  60. bool loadShadersWindLight();
  61. enum EShaderClass
  62. {
  63. SHADER_LIGHTING,
  64. SHADER_OBJECT,
  65. SHADER_AVATAR,
  66. SHADER_ENVIRONMENT,
  67. SHADER_INTERFACE,
  68. SHADER_EFFECT,
  69. SHADER_WINDLIGHT,
  70. SHADER_WATER,
  71. SHADER_DEFERRED,
  72. SHADER_COUNT
  73. };
  74. LL_INLINE S32 getShaderLevel(S32 type) const
  75. {
  76. return mShaderLevel[type];
  77. }
  78. // Simple model of forward iterator
  79. // http://www.sgi.com/tech/stl/ForwardIterator.html
  80. class shader_iter
  81. {
  82. private:
  83. friend bool operator==(shader_iter const& a, shader_iter const& b);
  84. friend bool operator!=(shader_iter const& a, shader_iter const& b);
  85. typedef std::vector<LLGLSLShader*>::const_iterator base_iter_t;
  86. public:
  87. shader_iter() = default;
  88. LL_INLINE shader_iter(base_iter_t iter)
  89. : mIter(iter)
  90. {
  91. }
  92. LL_INLINE LLGLSLShader& operator*() const
  93. {
  94. return **mIter;
  95. }
  96. LL_INLINE LLGLSLShader* operator->() const
  97. {
  98. return *mIter;
  99. }
  100. LL_INLINE shader_iter& operator++()
  101. {
  102. ++mIter;
  103. return *this;
  104. }
  105. LL_INLINE shader_iter operator++(int)
  106. {
  107. return mIter++;
  108. }
  109. private:
  110. base_iter_t mIter;
  111. };
  112. typedef std::vector<LLGLSLShader*> shaders_list_t;
  113. LL_INLINE const shaders_list_t& getEnvShadersList() const
  114. {
  115. return mShaderList;
  116. }
  117. LL_INLINE const std::string& getShaderDirPrefix() const override
  118. {
  119. return mShaderDirPrefix;
  120. }
  121. void updateShaderUniforms(LLGLSLShader* shader) override;
  122. private:
  123. std::string mShaderDirPrefix;
  124. // The list of shaders we need to propagate parameters to.
  125. std::vector<LLGLSLShader*> mShaderList;
  126. public:
  127. S32 mMaxAvatarShaderLevel;
  128. std::vector<S32> mShaderLevel;
  129. static bool sInitialized;
  130. static bool sSkipReload;
  131. static bool sHasFXAA;
  132. static bool sHasSMAA;
  133. static bool sHasCAS;
  134. static bool sHasIrrandiance;
  135. // Set when PBR shaders are loaded, depending on GL capability. HB
  136. static bool sCanDoRP;
  137. // Set when PBR shaders are loaded, depending on GL capability and
  138. // settings. HB
  139. static bool sHasRP;
  140. };
  141. LL_INLINE bool operator==(LLViewerShaderMgr::shader_iter const& a,
  142. LLViewerShaderMgr::shader_iter const& b)
  143. {
  144. return a.mIter == b.mIter;
  145. }
  146. LL_INLINE bool operator!=(LLViewerShaderMgr::shader_iter const& a,
  147. LLViewerShaderMgr::shader_iter const& b)
  148. {
  149. return a.mIter != b.mIter;
  150. }
  151. extern LLViewerShaderMgr* gViewerShaderMgrp;
  152. extern LLVector4 gShinyOrigin;
  153. // Utility shaders
  154. extern LLGLSLShader gOcclusionProgram;
  155. extern LLGLSLShader gOcclusionCubeProgram;
  156. extern LLGLSLShader gGlowCombineProgram;
  157. extern LLGLSLShader gReflectionMipProgram; // PBR only
  158. extern LLGLSLShader gGaussianProgram; // PBR only
  159. extern LLGLSLShader gRadianceGenProgram; // PBR only
  160. extern LLGLSLShader gHeroRadianceGenProgram; // PBR only
  161. extern LLGLSLShader gIrradianceGenProgram; // PBR only
  162. extern LLGLSLShader gSplatTextureRectProgram; // EE/WL only
  163. extern LLGLSLShader gGlowCombineFXAAProgram;
  164. extern LLGLSLShader gDebugProgram;
  165. enum NormalDebugShaderVariant : S32
  166. {
  167. NORMAL_DEBUG_SHADER_DEFAULT,
  168. NORMAL_DEBUG_SHADER_WITH_TANGENTS,
  169. NORMAL_DEBUG_SHADER_COUNT
  170. };
  171. extern LLGLSLShader gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT]; // PBR only
  172. extern LLGLSLShader gDebugProgram;
  173. extern LLGLSLShader gClipProgram;
  174. extern LLGLSLShader gDownsampleDepthProgram; // EE/WL only
  175. extern LLGLSLShader gDownsampleDepthRectProgram; // EE/WL only
  176. extern LLGLSLShader gAlphaMaskProgram;
  177. extern LLGLSLShader gBenchmarkProgram;
  178. extern LLGLSLShader gOneTextureNoColorProgram;
  179. extern LLGLSLShader gReflectionProbeDisplayProgram; // PBR only
  180. extern LLGLSLShader gCopyProgram; // PBR only
  181. extern LLGLSLShader gCopyDepthProgram; // PBR only
  182. // Object shaders
  183. extern LLGLSLShader gObjectSimpleProgram; // EE/WL only
  184. extern LLGLSLShader gObjectSimpleImpostorProgram; // EE/WL only
  185. extern LLGLSLShader gObjectPreviewProgram;
  186. extern LLGLSLShader gPhysicsPreviewProgram; // PBR only
  187. extern LLGLSLShader gObjectSimpleAlphaMaskProgram; // EE/WL only
  188. extern LLGLSLShader gObjectSimpleWaterProgram; // EE/WL only
  189. extern LLGLSLShader gObjectSimpleWaterAlphaMaskProgram; // EE/WL only
  190. extern LLGLSLShader gObjectSimpleNonIndexedTexGenProgram; // EE/WL only
  191. extern LLGLSLShader gObjectSimpleNonIndexedTexGenWaterProgram; // EE/WL only
  192. extern LLGLSLShader gObjectAlphaMaskNonIndexedProgram; // EE/WL only
  193. extern LLGLSLShader gObjectAlphaMaskNonIndexedWaterProgram; // EE/WL only
  194. extern LLGLSLShader gObjectAlphaMaskNoColorProgram;
  195. extern LLGLSLShader gObjectAlphaMaskNoColorWaterProgram; // EE/WL only
  196. extern LLGLSLShader gObjectFullbrightProgram; // EE/WL only
  197. extern LLGLSLShader gObjectFullbrightWaterProgram; // EE/WL only
  198. extern LLGLSLShader gObjectFullbrightNoColorWaterProgram; // EE/WL only
  199. extern LLGLSLShader gObjectEmissiveProgram; // EE/WL only
  200. extern LLGLSLShader gObjectEmissiveWaterProgram; // EE/WL only
  201. extern LLGLSLShader gObjectFullbrightAlphaMaskProgram; // EE/WL only
  202. extern LLGLSLShader gObjectFullbrightWaterAlphaMaskProgram; // EE/WL only
  203. extern LLGLSLShader gObjectBumpProgram;
  204. extern LLGLSLShader gTreeProgram; // EE/WL only
  205. extern LLGLSLShader gTreeWaterProgram; // EE/WL only
  206. extern LLGLSLShader gObjectFullbrightShinyProgram; // EE/WL only
  207. extern LLGLSLShader gObjectFullbrightShinyWaterProgram; // EE/WL only
  208. extern LLGLSLShader gObjectShinyProgram; // EE/WL only
  209. extern LLGLSLShader gObjectShinyWaterProgram; // EE/WL only
  210. // Environment shaders
  211. extern LLGLSLShader gMoonProgram; // EE/WL only
  212. extern LLGLSLShader gStarsProgram; // EE/WL only
  213. extern LLGLSLShader gTerrainProgram; // EE/WL only
  214. extern LLGLSLShader gTerrainWaterProgram; // EE/WL only
  215. extern LLGLSLShader gWaterProgram;
  216. extern LLGLSLShader gWaterEdgeProgram;
  217. extern LLGLSLShader gUnderWaterProgram;
  218. // Effects Shaders
  219. extern LLGLSLShader gGlowProgram;
  220. extern LLGLSLShader gGlowExtractProgram;
  221. extern LLGLSLShader gPostScreenSpaceReflectionProgram; // PBR only
  222. // Interface shaders
  223. extern LLGLSLShader gHighlightProgram;
  224. extern LLGLSLShader gHighlightNormalProgram;
  225. extern LLGLSLShader gHighlightSpecularProgram;
  226. // Avatar shader handles
  227. extern LLGLSLShader gAvatarProgram;
  228. extern LLGLSLShader gAvatarWaterProgram; // EE/WL only
  229. extern LLGLSLShader gAvatarEyeballProgram;
  230. extern LLGLSLShader gImpostorProgram;
  231. // WindLight shader handles (EE/WL only)
  232. extern LLGLSLShader gWLSkyProgram;
  233. extern LLGLSLShader gWLCloudProgram;
  234. extern LLGLSLShader gWLSunProgram;
  235. extern LLGLSLShader gWLMoonProgram;
  236. // Post processing shader handles
  237. extern LLGLSLShader gPostSMAAEdgeDetect[4];
  238. extern LLGLSLShader gPostSMAABlendWeights[4];
  239. extern LLGLSLShader gPostSMAANeighborhoodBlend[4];
  240. extern LLGLSLShader gPostCASProgram;
  241. // Deferred rendering shaders
  242. extern LLGLSLShader gDeferredImpostorProgram;
  243. extern LLGLSLShader gDeferredWaterProgram; // EE/WL only
  244. extern LLGLSLShader gDeferredUnderWaterProgram; // EE/WL only
  245. extern LLGLSLShader gDeferredHighlightProgram; // PBR only
  246. extern LLGLSLShader gDeferredDiffuseProgram;
  247. extern LLGLSLShader gDeferredDiffuseAlphaMaskProgram;
  248. extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram;
  249. extern LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
  250. extern LLGLSLShader gDeferredBumpProgram;
  251. extern LLGLSLShader gDeferredTerrainProgram;
  252. extern LLGLSLShader gDeferredTerrainWaterProgram; // EE/WL only
  253. extern LLGLSLShader gDeferredTreeProgram;
  254. extern LLGLSLShader gDeferredTreeShadowProgram;
  255. extern LLGLSLShader gDeferredLightProgram;
  256. extern LLGLSLShader gDeferredMultiLightProgram[LL_DEFERRED_MULTI_LIGHT_COUNT];
  257. extern LLGLSLShader gDeferredSpotLightProgram;
  258. extern LLGLSLShader gDeferredMultiSpotLightProgram;
  259. extern LLGLSLShader gDeferredSunProgram;
  260. extern LLGLSLShader gHazeProgram; // PBR only
  261. extern LLGLSLShader gHazeWaterProgram; // PBR only
  262. extern LLGLSLShader gDeferredBlurLightProgram;
  263. extern LLGLSLShader gDeferredAvatarProgram;
  264. extern LLGLSLShader gDeferredSoftenProgram;
  265. extern LLGLSLShader gDeferredSoftenWaterProgram; // EE/WL only
  266. extern LLGLSLShader gDeferredShadowProgram;
  267. extern LLGLSLShader gDeferredShadowCubeProgram;
  268. extern LLGLSLShader gDeferredShadowAlphaMaskProgram;
  269. extern LLGLSLShader gDeferredShadowGLTFAlphaMaskProgram; // PBR only
  270. extern LLGLSLShader gDeferredShadowGLTFAlphaBlendProgram; // PBR only
  271. extern LLGLSLShader gDeferredShadowFullbrightAlphaMaskProgram;
  272. extern LLGLSLShader gDeferredPostProgram;
  273. extern LLGLSLShader gDeferredCoFProgram;
  274. extern LLGLSLShader gDeferredDoFCombineProgram;
  275. extern LLGLSLShader gFXAAProgram[4];
  276. extern LLGLSLShader gDeferredPostNoDoFProgram;
  277. extern LLGLSLShader gDeferredPostGammaCorrectProgram;
  278. extern LLGLSLShader gNoPostGammaCorrectProgram; // PBR only
  279. extern LLGLSLShader gLegacyPostGammaCorrectProgram; // PBR only
  280. extern LLGLSLShader gExposureProgram; // PBR only
  281. extern LLGLSLShader gExposureProgramNoFade; // PBR only
  282. extern LLGLSLShader gLuminanceProgram; // PBR only
  283. extern LLGLSLShader gDeferredAvatarShadowProgram;
  284. extern LLGLSLShader gDeferredAvatarAlphaShadowProgram;
  285. extern LLGLSLShader gDeferredAvatarAlphaMaskShadowProgram;
  286. extern LLGLSLShader gDeferredAlphaProgram;
  287. extern LLGLSLShader gHUDAlphaProgram; // PBR only
  288. extern LLGLSLShader gDeferredAlphaImpostorProgram;
  289. extern LLGLSLShader gDeferredFullbrightProgram;
  290. extern LLGLSLShader gDeferredFullbrightAlphaMaskProgram;
  291. extern LLGLSLShader gDeferredFullbrightAlphaMaskAlphaProgram; // PBR only
  292. extern LLGLSLShader gHUDFullbrightProgram; // PBR only
  293. extern LLGLSLShader gHUDFullbrightAlphaMaskProgram; // PBR only
  294. extern LLGLSLShader gHUDFullbrightAlphaMaskAlphaProgram; // PBR only
  295. extern LLGLSLShader gDeferredAlphaWaterProgram; // EE/WL only
  296. extern LLGLSLShader gDeferredFullbrightWaterProgram; // EE/WL only
  297. extern LLGLSLShader gDeferredFullbrightAlphaMaskWaterProgram; // EE/WL only
  298. extern LLGLSLShader gDeferredEmissiveProgram;
  299. extern LLGLSLShader gDeferredAvatarEyesProgram;
  300. extern LLGLSLShader gDeferredAvatarAlphaProgram;
  301. extern LLGLSLShader gEnvironmentMapProgram; // PBR only
  302. extern LLGLSLShader gDeferredWLSkyProgram;
  303. extern LLGLSLShader gDeferredWLCloudProgram;
  304. extern LLGLSLShader gDeferredWLSunProgram;
  305. extern LLGLSLShader gDeferredWLMoonProgram;
  306. extern LLGLSLShader gDeferredStarProgram;
  307. extern LLGLSLShader gDeferredFullbrightShinyProgram;
  308. extern LLGLSLShader gHUDFullbrightShinyProgram; // PBR only
  309. extern LLGLSLShader gNormalMapGenProgram;
  310. extern LLGLSLShader gDeferredGenBrdfLutProgram; // PBR only
  311. extern LLGLSLShader gDeferredBufferVisualProgram; // PBR only
  312. // Deferred materials shaders
  313. extern LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT * 2];
  314. extern LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT * 2]; // EE/WL only
  315. extern LLGLSLShader gHUDPBROpaqueProgram; // PBR only
  316. extern LLGLSLShader gPBRGlowProgram; // PBR only
  317. extern LLGLSLShader gDeferredPBROpaqueProgram; // PBR only
  318. extern LLGLSLShader gDeferredPBRAlphaProgram; // PBR only
  319. extern LLGLSLShader gHUDPBRAlphaProgram; // PBR only
  320. extern LLGLSLShader gDeferredPBRTerrainProgram; // PBR only
  321. // Encodes detail level for dropping textures, in accordance with the GLTF spec
  322. // where possible. 0 is highest detail, -1 drops emissive, etc. Dropping
  323. // metallic roughness is off-spec - Reserve for potato machines as needed.
  324. // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#additional-textures
  325. enum TerrainPBRDetail : S32
  326. {
  327. TERRAIN_PBR_DETAIL_EMISSIVE = 0,
  328. TERRAIN_PBR_DETAIL_OCCLUSION = -1,
  329. TERRAIN_PBR_DETAIL_NORMAL = -2,
  330. TERRAIN_PBR_DETAIL_METALLIC_ROUGHNESS = -3,
  331. TERRAIN_PBR_DETAIL_BASE_COLOR = -4,
  332. };
  333. #endif // LL_VIEWER_SHADER_MGR_H