llshadermgr.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. /**
  2. * @file llshadermgr.cpp
  3. * @brief Shader manager implementation.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-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. #include "linden_common.h"
  33. #include "llshadermgr.h"
  34. #include "lldir.h"
  35. #include "llrender.h"
  36. #if LL_DARWIN
  37. # include "OpenGL/OpenGL.h"
  38. #endif
  39. #if LL_DEBUG
  40. # define UNIFORM_ERRS llerrs
  41. #else
  42. # define UNIFORM_ERRS llwarns_once
  43. #endif
  44. // Static member variables
  45. LLShaderMgr* LLShaderMgr::sInstance = NULL;
  46. LLShaderMgr::shaders_map_t LLShaderMgr::sVertexShaderObjects;
  47. LLShaderMgr::shaders_map_t LLShaderMgr::sFragmentShaderObjects;
  48. LLShaderMgr::reserved_strings_t LLShaderMgr::sReservedAttribs;
  49. LLShaderMgr::reserved_strings_t LLShaderMgr::sReservedUniforms;
  50. S32 LLShaderMgr::sIndexedTextureChannels = 0;
  51. bool LLShaderMgr::sMirrorsEnabled = false;
  52. LLShaderMgr::LLShaderMgr()
  53. {
  54. sInstance = this;
  55. }
  56. LLShaderMgr::~LLShaderMgr()
  57. {
  58. sInstance = NULL;
  59. }
  60. //static
  61. LLShaderMgr* LLShaderMgr::getInstance()
  62. {
  63. if (!sInstance)
  64. {
  65. llerrs << "This should already have been instantiated by the application !"
  66. << llendl;
  67. }
  68. return sInstance;
  69. }
  70. bool LLShaderMgr::attachShaderFeatures(LLGLSLShader* shader)
  71. {
  72. if (!shader)
  73. {
  74. llerrs << "NULL shader pointer passed !" << llendl;
  75. }
  76. LLShaderFeatures* features = &shader->mFeatures;
  77. if (features->attachNothing)
  78. {
  79. return true;
  80. }
  81. //////////////////////////////////////
  82. // Attach Vertex Shader Features First
  83. //////////////////////////////////////
  84. // Note: the order of shader object attaching is VERY IMPORTANT !
  85. if (features->calculatesAtmospherics)
  86. {
  87. if (!gUsePBRShaders && features->hasWaterFog)
  88. {
  89. if (!shader->attachVertexObject("windlight/atmosphericsVarsWaterV.glsl"))
  90. {
  91. return false;
  92. }
  93. }
  94. else if (!shader->attachVertexObject("windlight/atmosphericsVarsV.glsl"))
  95. {
  96. return false;
  97. }
  98. }
  99. if (features->calculatesLighting || features->calculatesAtmospherics)
  100. {
  101. if (!shader->attachVertexObject("windlight/atmosphericsHelpersV.glsl"))
  102. {
  103. return false;
  104. }
  105. }
  106. if (features->calculatesLighting)
  107. {
  108. if (features->isSpecular)
  109. {
  110. if (!shader->attachVertexObject("lighting/lightFuncSpecularV.glsl"))
  111. {
  112. return false;
  113. }
  114. if (!features->isAlphaLighting &&
  115. !shader->attachVertexObject("lighting/sumLightsSpecularV.glsl"))
  116. {
  117. return false;
  118. }
  119. if (!shader->attachVertexObject("lighting/lightSpecularV.glsl"))
  120. {
  121. return false;
  122. }
  123. }
  124. else
  125. {
  126. if (!shader->attachVertexObject("lighting/lightFuncV.glsl"))
  127. {
  128. return false;
  129. }
  130. if (!features->isAlphaLighting &&
  131. !shader->attachVertexObject("lighting/sumLightsV.glsl"))
  132. {
  133. return false;
  134. }
  135. if (!shader->attachVertexObject("lighting/lightV.glsl"))
  136. {
  137. return false;
  138. }
  139. }
  140. }
  141. // Note: the order of shader object attaching is VERY IMPORTANT !
  142. if (features->calculatesAtmospherics)
  143. {
  144. if (gUsePBRShaders &&
  145. // Note: "F" suffix is superfluous here, there is nothing fragment
  146. // specific in srgbF.
  147. !shader->attachVertexObject("environment/srgbF.glsl"))
  148. {
  149. return false;
  150. }
  151. if (!shader->attachVertexObject("windlight/atmosphericsFuncs.glsl"))
  152. {
  153. return false;
  154. }
  155. if (!shader->attachVertexObject("windlight/atmosphericsV.glsl"))
  156. {
  157. return false;
  158. }
  159. }
  160. if (features->hasSkinning &&
  161. !shader->attachVertexObject("avatar/avatarSkinV.glsl"))
  162. {
  163. return false;
  164. }
  165. if (features->hasObjectSkinning)
  166. {
  167. shader->mRiggedVariant = shader;
  168. if (!shader->attachVertexObject("avatar/objectSkinV.glsl"))
  169. {
  170. return false;
  171. }
  172. }
  173. if (gUsePBRShaders &&
  174. !shader->attachVertexObject("deferred/textureUtilV.glsl"))
  175. {
  176. return false;
  177. }
  178. ///////////////////////////////////////
  179. // Attach Fragment Shader Features Next
  180. ///////////////////////////////////////
  181. // Note: the order of shader object attaching is VERY IMPORTANT !
  182. if (gUsePBRShaders &&
  183. !shader->attachFragmentObject("deferred/globalF.glsl"))
  184. {
  185. return false;
  186. }
  187. if (gUsePBRShaders &&
  188. (features->hasSrgb || features->hasAtmospherics ||
  189. features->calculatesAtmospherics || features->isDeferred) &&
  190. !shader->attachFragmentObject("environment/srgbF.glsl"))
  191. {
  192. return false;
  193. }
  194. if (gUsePBRShaders)
  195. {
  196. if (features->calculatesAtmospherics || features->hasGamma ||
  197. features->isDeferred)
  198. {
  199. if (!shader->attachFragmentObject("windlight/atmosphericsVarsF.glsl"))
  200. {
  201. return false;
  202. }
  203. }
  204. }
  205. else if (features->calculatesAtmospherics)
  206. {
  207. if (features->hasWaterFog)
  208. {
  209. if (!shader->attachFragmentObject("windlight/atmosphericsVarsWaterF.glsl"))
  210. {
  211. return false;
  212. }
  213. }
  214. else if (!shader->attachFragmentObject("windlight/atmosphericsVarsF.glsl"))
  215. {
  216. return false;
  217. }
  218. }
  219. if (features->calculatesLighting || features->calculatesAtmospherics)
  220. {
  221. if (!shader->attachFragmentObject("windlight/atmosphericsHelpersF.glsl"))
  222. {
  223. return false;
  224. }
  225. }
  226. // We want this BEFORE shadows and AO because those facilities use pos/norm
  227. // access
  228. if ((features->isDeferred || features->hasReflectionProbes) &&
  229. !shader->attachFragmentObject("deferred/deferredUtil.glsl"))
  230. {
  231. return false;
  232. }
  233. if ((features->hasScreenSpaceReflections ||
  234. features->hasReflectionProbes) &&
  235. !shader->attachFragmentObject("deferred/screenSpaceReflUtil.glsl"))
  236. {
  237. return false;
  238. }
  239. if (features->hasShadows &&
  240. !shader->attachFragmentObject("deferred/shadowUtil.glsl"))
  241. {
  242. return false;
  243. }
  244. if (features->hasReflectionProbes &&
  245. !shader->attachFragmentObject("deferred/reflectionProbeF.glsl"))
  246. {
  247. return false;
  248. }
  249. if (features->hasAmbientOcclusion &&
  250. !shader->attachFragmentObject("deferred/aoUtil.glsl"))
  251. {
  252. return false;
  253. }
  254. if ((features->hasGamma || (gUsePBRShaders && features->isDeferred)) &&
  255. !shader->attachFragmentObject("windlight/gammaF.glsl"))
  256. {
  257. return false;
  258. }
  259. if (!gUsePBRShaders && features->hasSrgb &&
  260. !shader->attachFragmentObject("environment/srgbF.glsl"))
  261. {
  262. return false;
  263. }
  264. if (!gUsePBRShaders && features->encodesNormal &&
  265. !shader->attachFragmentObject("environment/encodeNormF.glsl"))
  266. {
  267. return false;
  268. }
  269. if (features->hasAtmospherics || (gUsePBRShaders && features->isDeferred))
  270. {
  271. if (!shader->attachFragmentObject("windlight/atmosphericsFuncs.glsl"))
  272. {
  273. return false;
  274. }
  275. if (!shader->attachFragmentObject("windlight/atmosphericsF.glsl"))
  276. {
  277. return false;
  278. }
  279. }
  280. if (gUsePBRShaders && features->isPBRTerrain &&
  281. !shader->attachFragmentObject("deferred/pbrterrainUtilF.glsl"))
  282. {
  283. return false;
  284. }
  285. if (features->hasTransport && !gUsePBRShaders &&
  286. !shader->attachFragmentObject("windlight/transportF.glsl"))
  287. {
  288. return false;
  289. }
  290. // Note: the order of shader object attaching is VERY IMPORTANT !
  291. if (gUsePBRShaders)
  292. {
  293. if (features->hasAtmospherics &&
  294. !shader->attachFragmentObject("environment/waterFogF.glsl"))
  295. {
  296. return false;
  297. }
  298. }
  299. else if (features->hasWaterFog &&
  300. !shader->attachFragmentObject("environment/waterFogF.glsl"))
  301. {
  302. return false;
  303. }
  304. if (features->hasLighting)
  305. {
  306. if (features->hasWaterFog && !gUsePBRShaders)
  307. {
  308. if (features->disableTextureIndex)
  309. {
  310. if (features->hasAlphaMask)
  311. {
  312. if (!shader->attachFragmentObject("lighting/lightWaterAlphaMaskNonIndexedF.glsl"))
  313. {
  314. return false;
  315. }
  316. }
  317. else if (!shader->attachFragmentObject("lighting/lightWaterNonIndexedF.glsl"))
  318. {
  319. return false;
  320. }
  321. }
  322. else
  323. {
  324. if (features->hasAlphaMask)
  325. {
  326. if (!shader->attachFragmentObject("lighting/lightWaterAlphaMaskF.glsl"))
  327. {
  328. return false;
  329. }
  330. }
  331. else if (!shader->attachFragmentObject("lighting/lightWaterF.glsl"))
  332. {
  333. return false;
  334. }
  335. shader->mFeatures.mIndexedTextureChannels =
  336. llmax(sIndexedTextureChannels - 1, 1);
  337. }
  338. }
  339. else if (features->disableTextureIndex)
  340. {
  341. if (features->hasAlphaMask)
  342. {
  343. if (!shader->attachFragmentObject("lighting/lightAlphaMaskNonIndexedF.glsl"))
  344. {
  345. return false;
  346. }
  347. }
  348. else if (!shader->attachFragmentObject("lighting/lightNonIndexedF.glsl"))
  349. {
  350. return false;
  351. }
  352. }
  353. else
  354. {
  355. if (features->hasAlphaMask)
  356. {
  357. if (!shader->attachFragmentObject("lighting/lightAlphaMaskF.glsl"))
  358. {
  359. return false;
  360. }
  361. }
  362. else if (!shader->attachFragmentObject("lighting/lightF.glsl"))
  363. {
  364. return false;
  365. }
  366. shader->mFeatures.mIndexedTextureChannels =
  367. llmax(sIndexedTextureChannels - 1, 1);
  368. }
  369. }
  370. // Note: the order of shader objects attaching is VERY IMPORTANT !
  371. else if (!gUsePBRShaders && features->isFullbright)
  372. {
  373. if (features->isShiny && features->hasWaterFog)
  374. {
  375. if (features->disableTextureIndex)
  376. {
  377. if (!shader->attachFragmentObject("lighting/lightFullbrightShinyWaterNonIndexedF.glsl"))
  378. {
  379. return false;
  380. }
  381. }
  382. else
  383. {
  384. if (!shader->attachFragmentObject("lighting/lightFullbrightShinyWaterF.glsl"))
  385. {
  386. return false;
  387. }
  388. shader->mFeatures.mIndexedTextureChannels =
  389. llmax(sIndexedTextureChannels - 1, 1);
  390. }
  391. }
  392. else if (features->hasWaterFog)
  393. {
  394. if (features->disableTextureIndex)
  395. {
  396. if (features->hasAlphaMask)
  397. {
  398. if (!shader->attachFragmentObject("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl"))
  399. {
  400. return false;
  401. }
  402. }
  403. else if (!shader->attachFragmentObject("lighting/lightFullbrightWaterNonIndexedF.glsl"))
  404. {
  405. return false;
  406. }
  407. }
  408. else
  409. {
  410. if (features->hasAlphaMask)
  411. {
  412. if (!shader->attachFragmentObject("lighting/lightFullbrightWaterAlphaMaskF.glsl"))
  413. {
  414. return false;
  415. }
  416. }
  417. else if (!shader->attachFragmentObject("lighting/lightFullbrightWaterF.glsl"))
  418. {
  419. return false;
  420. }
  421. shader->mFeatures.mIndexedTextureChannels =
  422. llmax(sIndexedTextureChannels - 1, 1);
  423. }
  424. }
  425. else if (features->isShiny)
  426. {
  427. if (features->disableTextureIndex)
  428. {
  429. if (!shader->attachFragmentObject("lighting/lightFullbrightShinyNonIndexedF.glsl"))
  430. {
  431. return false;
  432. }
  433. }
  434. else
  435. {
  436. if (!shader->attachFragmentObject("lighting/lightFullbrightShinyF.glsl"))
  437. {
  438. return false;
  439. }
  440. shader->mFeatures.mIndexedTextureChannels =
  441. llmax(sIndexedTextureChannels - 1, 1);
  442. }
  443. }
  444. else if (features->disableTextureIndex)
  445. {
  446. if (features->hasAlphaMask)
  447. {
  448. if (!shader->attachFragmentObject("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl"))
  449. {
  450. return false;
  451. }
  452. }
  453. else if (!shader->attachFragmentObject("lighting/lightFullbrightNonIndexedF.glsl"))
  454. {
  455. return false;
  456. }
  457. }
  458. else
  459. {
  460. if (features->hasAlphaMask)
  461. {
  462. if (!shader->attachFragmentObject("lighting/lightFullbrightAlphaMaskF.glsl"))
  463. {
  464. return false;
  465. }
  466. }
  467. else if (!shader->attachFragmentObject("lighting/lightFullbrightF.glsl"))
  468. {
  469. return false;
  470. }
  471. shader->mFeatures.mIndexedTextureChannels =
  472. llmax(sIndexedTextureChannels - 1, 1);
  473. }
  474. }
  475. // Note: the order of shader object attaching is VERY IMPORTANT !
  476. else if (!gUsePBRShaders && features->isShiny)
  477. {
  478. if (features->hasWaterFog)
  479. {
  480. if (features->disableTextureIndex)
  481. {
  482. if (!shader->attachFragmentObject("lighting/lightShinyWaterNonIndexedF.glsl"))
  483. {
  484. return false;
  485. }
  486. }
  487. else
  488. {
  489. if (!shader->attachFragmentObject("lighting/lightShinyWaterF.glsl"))
  490. {
  491. return false;
  492. }
  493. shader->mFeatures.mIndexedTextureChannels =
  494. llmax(sIndexedTextureChannels - 1, 1);
  495. }
  496. }
  497. else if (features->disableTextureIndex)
  498. {
  499. if (!shader->attachFragmentObject("lighting/lightShinyNonIndexedF.glsl"))
  500. {
  501. return false;
  502. }
  503. }
  504. else
  505. {
  506. if (!shader->attachFragmentObject("lighting/lightShinyF.glsl"))
  507. {
  508. return false;
  509. }
  510. shader->mFeatures.mIndexedTextureChannels =
  511. llmax(sIndexedTextureChannels - 1, 1);
  512. }
  513. }
  514. if (features->mIndexedTextureChannels <= 1)
  515. {
  516. if (!shader->attachVertexObject("objects/nonindexedTextureV.glsl"))
  517. {
  518. return false;
  519. }
  520. }
  521. else if (!shader->attachVertexObject("objects/indexedTextureV.glsl"))
  522. {
  523. return false;
  524. }
  525. return true;
  526. }
  527. //============================================================================
  528. // Load Shader
  529. static std::string get_shader_log(GLuint object)
  530. {
  531. std::string res;
  532. // Get log length
  533. GLint length;
  534. glGetShaderiv(object, GL_INFO_LOG_LENGTH, &length);
  535. if (length > 0)
  536. {
  537. // The log could be any size, so allocate appropriately
  538. GLchar* log = new GLchar[length];
  539. glGetShaderInfoLog(object, length, &length, log);
  540. res = std::string((char*)log);
  541. delete[] log;
  542. }
  543. // Intel log spam removal
  544. if (gGLManager.mIsIntel && res.find("No errors") == 0)
  545. {
  546. res.clear();
  547. }
  548. return res;
  549. }
  550. static std::string get_program_log(GLuint object)
  551. {
  552. std::string res;
  553. // Get log length
  554. GLint length;
  555. glGetProgramiv(object, GL_INFO_LOG_LENGTH, &length);
  556. if (length > 0)
  557. {
  558. // The log could be any size, so allocate appropriately
  559. GLchar* log = new GLchar[length];
  560. glGetProgramInfoLog(object, length, &length, log);
  561. res = std::string((char*)log);
  562. delete[] log;
  563. }
  564. // Intel log spam removal
  565. if (gGLManager.mIsIntel && res.find("No errors") == 0)
  566. {
  567. res.clear();
  568. }
  569. return res;
  570. }
  571. void LLShaderMgr::dumpObjectLog(bool is_program, GLuint ret, bool warns)
  572. {
  573. std::string log = is_program ? get_program_log(ret) : get_shader_log(ret);
  574. if (log.length() > 0)
  575. {
  576. if (warns)
  577. {
  578. llwarns << log << llendl;
  579. }
  580. else
  581. {
  582. LL_DEBUGS("ShaderLoading") << log << LL_ENDL;
  583. }
  584. }
  585. }
  586. void LLShaderMgr::dumpShaderSource(U32 shader_count, GLchar** shader_text)
  587. {
  588. llinfos << "\n";
  589. for (U32 i = 0; i < shader_count; ++i)
  590. {
  591. llcont << i << ": " << shader_text[i];
  592. }
  593. llcont << llendl;
  594. }
  595. GLuint LLShaderMgr::loadShaderFile(const std::string& filename,
  596. S32& shader_level, U32 type,
  597. LLGLSLShader::defines_map_t* defines,
  598. S32 texture_index_channels)
  599. {
  600. #if LL_DARWIN
  601. // Ensure work-around for missing GLSL funcs gets propogated to feature
  602. // shader files (e.g. srgbF.glsl)
  603. if (defines)
  604. {
  605. (*defines)["OLD_SELECT"] = "1";
  606. }
  607. #endif
  608. LL_DEBUGS("ShaderLoading") << "Loading shader file: " << filename
  609. << " class " << shader_level << LL_ENDL;
  610. if (filename.empty())
  611. {
  612. return 0;
  613. }
  614. // Read in from file
  615. LLFILE* file = NULL;
  616. S32 try_gpu_class = shader_level;
  617. S32 gpu_class;
  618. // Find the most relevant file
  619. const std::string& prefix = getShaderDirPrefix();
  620. for (gpu_class = try_gpu_class; gpu_class > 0; --gpu_class)
  621. {
  622. // Search from the current GPU class down to class 1 to find the most
  623. // relevant shader
  624. std::string fname = prefix + llformat("%d", gpu_class) +
  625. LL_DIR_DELIM_STR + filename;
  626. file = LLFile::open(fname, "r");
  627. if (file)
  628. {
  629. LL_DEBUGS("ShaderLoading") << "Loading file: " << fname << LL_ENDL;
  630. break; // Done
  631. }
  632. }
  633. if (!file)
  634. {
  635. llwarns << "GLSL Shader file not found: " << filename << llendl;
  636. return 0;
  637. }
  638. bool found_header = false;
  639. std::vector<std::string> header, body;
  640. // We would not accept lines longer than 1024 characters
  641. char line[1024];
  642. while (fgets(line, 1024, file))
  643. {
  644. if (!found_header && strstr((const char*)line, "[EXTRA_CODE_HERE]"))
  645. {
  646. found_header = true;
  647. header.swap(body);
  648. }
  649. else
  650. {
  651. body.emplace_back(line);
  652. }
  653. }
  654. LLFile::close(file);
  655. S32 major_version = gGLManager.mGLSLVersionMajor;
  656. S32 minor_version = gGLManager.mGLSLVersionMinor;
  657. std::string glsl_version;
  658. if (major_version < 2 && minor_version < 30)
  659. {
  660. if (gUsePBRShaders)
  661. {
  662. // We should NEVER get here: OpenGL v3.1 is the minimum requirement
  663. // for PBR.
  664. llwarns << "Unsupported GLSL version for PBR." << llendl;
  665. return false;
  666. }
  667. if (minor_version < 10)
  668. {
  669. // We should NEVER get here: if major version is 1 and minor
  670. // version is less than 10, viewer should never attempt to use
  671. // shaders and continuing would result in undefined behavior.
  672. llerrs << "Unsupported GLSL version." << llendl;
  673. }
  674. if (minor_version <= 19)
  675. {
  676. glsl_version = "#version 110\n";
  677. header.emplace_back("#define ATTRIBUTE attribute\n");
  678. header.emplace_back("#define VARYING varying\n");
  679. header.emplace_back("#define VARYING_FLAT varying\n");
  680. }
  681. else if (minor_version <= 29)
  682. {
  683. // Set version to 1.20
  684. glsl_version = "#version 120\n";
  685. header.emplace_back("#define FXAA_GLSL_120 1\n");
  686. if (gGLManager.mHasGpuShader4)
  687. {
  688. header.emplace_back("#define FXAA_FAST_PIXEL_OFFSET 1\n");
  689. }
  690. else
  691. {
  692. header.emplace_back("#define FXAA_FAST_PIXEL_OFFSET 0\n");
  693. }
  694. header.emplace_back("#define ATTRIBUTE attribute\n");
  695. header.emplace_back("#define VARYING varying\n");
  696. header.emplace_back("#define VARYING_FLAT varying\n");
  697. }
  698. }
  699. else
  700. {
  701. if (major_version >= 4)
  702. {
  703. // Set version to 400 or 420
  704. if (minor_version >= 20)
  705. {
  706. glsl_version = "#version 420\n";
  707. }
  708. else
  709. {
  710. glsl_version = "#version 400\n";
  711. }
  712. header.emplace_back("#define FXAA_GLSL_400 1\n");
  713. }
  714. else if (major_version == 3)
  715. {
  716. if (minor_version < 10)
  717. {
  718. glsl_version = "#version 300\n";
  719. }
  720. else if (minor_version <= 19)
  721. {
  722. glsl_version = "#version 310\n";
  723. }
  724. else if (minor_version <= 29)
  725. {
  726. glsl_version = "#version 320\n";
  727. }
  728. else
  729. {
  730. glsl_version = "#version 330\n";
  731. }
  732. header.emplace_back("#define FXAA_GLSL_130 1\n");
  733. }
  734. else
  735. {
  736. if (minor_version >= 50 && gUsePBRShaders &&
  737. type == GL_GEOMETRY_SHADER)
  738. {
  739. glsl_version = "#version 150\n";
  740. }
  741. else if (minor_version >= 40 || gUsePBRShaders)
  742. {
  743. glsl_version = "#version 140\n";
  744. }
  745. else
  746. {
  747. // Set version to 1.30
  748. glsl_version = "#version 130\n";
  749. }
  750. if (minor_version >= 50 && gGLManager.mHasGpuShader5 &&
  751. !gUsePBRShaders)
  752. {
  753. header.emplace_back("#extension GL_ARB_gpu_shader5 : enable\n");
  754. }
  755. header.emplace_back("#define FXAA_GLSL_130 1\n");
  756. // Some implementations of GLSL 1.30 require integer precision be
  757. // explicitly declared
  758. header.emplace_back("precision mediump int;\n");
  759. header.emplace_back("precision highp float;\n");
  760. }
  761. if (sMirrorsEnabled)
  762. {
  763. header.emplace_back("#define HERO_PROBES 1\n");
  764. }
  765. if (!gUsePBRShaders)
  766. {
  767. header.emplace_back("#define DEFINE_GL_FRAGCOLOR 1\n");
  768. header.emplace_back("#define ATTRIBUTE in\n");
  769. if (type == GL_VERTEX_SHADER)
  770. {
  771. // "varying" state is "out" in a vertex program, "in" in a
  772. // fragment program ("varying" is deprecated after version
  773. // 1.20)
  774. header.emplace_back("#define VARYING out\n");
  775. header.emplace_back("#define VARYING_FLAT flat out\n");
  776. }
  777. else
  778. {
  779. header.emplace_back("#define VARYING in\n");
  780. header.emplace_back("#define VARYING_FLAT flat in\n");
  781. }
  782. // Backwards compatibility with legacy texture lookup syntax
  783. header.emplace_back("#define texture2D texture\n");
  784. header.emplace_back("#define textureCube texture\n");
  785. header.emplace_back("#define texture2DLod textureLod\n");
  786. header.emplace_back("#define shadow2D(a,b) vec2(texture(a,b))\n");
  787. if (major_version > 1 || minor_version >= 40)
  788. {
  789. // GLSL 1.40 replaces texture2DRect et al with texture
  790. header.emplace_back("#define texture2DRect texture\n");
  791. header.emplace_back("#define shadow2DRect(a,b) vec2(texture(a,b))\n");
  792. }
  793. }
  794. }
  795. // Use alpha float to store bit flags. See addDeferredAttachments() in
  796. // llpipeline.cpp, and frag_data[2] in shaders.
  797. if (gUsePBRShaders)
  798. {
  799. // ATMOS kill
  800. header.emplace_back("#define GBUFFER_FLAG_SKIP_ATMOS 0.0 \n");
  801. // Bit 0
  802. header.emplace_back("#define GBUFFER_FLAG_HAS_ATMOS 0.34\n");
  803. // Bit 1
  804. header.emplace_back("#define GBUFFER_FLAG_HAS_PBR 0.67\n");
  805. // Bit 2
  806. header.emplace_back("#define GBUFFER_FLAG_HAS_HDRI 1.0\n");
  807. header.emplace_back("#define GET_GBUFFER_FLAG(flag) (abs(norm.w-flag)<0.1)\n");
  808. }
  809. // Used by the SMAA shader only (this is actually one same shader source
  810. // used in both a fragment and a vertex shader files, with VERTEX_SHADER
  811. // defining what is its actual usage). HB
  812. if (type == GL_VERTEX_SHADER)
  813. {
  814. header.emplace_back("#define VERTEX_SHADER 1\n");
  815. }
  816. // Copy preprocessor definitions into buffer
  817. if (defines)
  818. {
  819. for (LLGLSLShader::defines_map_t::iterator iter = defines->begin(),
  820. end = defines->end();
  821. iter != end; ++iter)
  822. {
  823. header.emplace_back("#define " + iter->first + " " + iter->second +
  824. "\n");
  825. }
  826. }
  827. // #define used to implement workarounds for ATI GLSL compiler bugs
  828. if (gGLManager.mIsAMD)
  829. {
  830. header.emplace_back("#define IS_AMD_CARD 1\n");
  831. }
  832. if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER)
  833. {
  834. // Use specified number of texture channels for indexed texture
  835. // rendering
  836. /* prepend shader code that looks like this:
  837. uniform sampler2D tex0;
  838. uniform sampler2D tex1;
  839. uniform sampler2D tex2;
  840. .
  841. .
  842. .
  843. uniform sampler2D texN;
  844. VARYING_FLAT ivec4 vary_texture_index;
  845. vec4 ret = vec4(1,0,1,1);
  846. vec4 diffuseLookup(vec2 texcoord)
  847. {
  848. switch (vary_texture_index.r))
  849. {
  850. case 0: ret = texture2D(tex0, texcoord); break;
  851. case 1: ret = texture2D(tex1, texcoord); break;
  852. case 2: ret = texture2D(tex2, texcoord); break;
  853. .
  854. .
  855. .
  856. case N: return texture2D(texN, texcoord); break;
  857. }
  858. return ret;
  859. }
  860. NOTE: 'texture2D' is replaced with 'texture' for PBR shaders. HB
  861. */
  862. header.emplace_back("#define HAS_DIFFUSE_LOOKUP\n");
  863. // Uniform declaration
  864. for (S32 i = 0; i < texture_index_channels; ++i)
  865. {
  866. header.emplace_back(llformat("uniform sampler2D tex%d;\n", i));
  867. }
  868. if (texture_index_channels > 1)
  869. {
  870. if (gUsePBRShaders)
  871. {
  872. header.emplace_back("flat in int vary_texture_index;\n");
  873. }
  874. else
  875. {
  876. header.emplace_back("VARYING_FLAT int vary_texture_index;\n");
  877. }
  878. }
  879. header.emplace_back("vec4 diffuseLookup(vec2 texcoord)\n");
  880. header.emplace_back("{\n");
  881. const char* texture_fn = gUsePBRShaders ? "texture" : "texture2D";
  882. if (texture_index_channels == 1)
  883. {
  884. // Do not use flow control, that is silly
  885. header.emplace_back(llformat("\treturn %s(tex0, texcoord);\n",
  886. texture_fn));
  887. header.emplace_back("}\n");
  888. }
  889. else if (major_version < 2 && minor_version < 30)
  890. {
  891. // We should never get here. Indexed texture rendering requires
  892. // GLSL 1.30 or later (for passing integers between vertex and
  893. // fragment shaders)
  894. llerrs << "Indexed texture rendering requires GLSL 1.30 or later."
  895. << llendl;
  896. }
  897. // Switches are unreliable on some NVIDIA drivers.
  898. // *TODO: check to see if that decade-old affirmation is still true
  899. // nowadays... Perhaps via a debug setting ? HB
  900. else if (gGLManager.mIsNVIDIA)
  901. {
  902. static const char* if_line =
  903. "\t%sif (vary_texture_index == %d) { return %s(tex%d, texcoord); }\n";
  904. for (S32 i = 0; i < texture_index_channels; ++i)
  905. {
  906. header.emplace_back(llformat(if_line, i > 0 ? "else " : "", i,
  907. texture_fn, i));
  908. }
  909. header.emplace_back("\treturn vec4(1,0,1,1);\n");
  910. header.emplace_back("}\n");
  911. }
  912. else
  913. {
  914. static const char* case_line =
  915. "\t\tcase %d: return %s(tex%d, texcoord);\n";
  916. header.emplace_back("\tvec4 ret = vec4(1,0,1,1);\n");
  917. header.emplace_back("\tswitch (vary_texture_index)\n");
  918. header.emplace_back("\t{\n");
  919. // Switch body
  920. for (S32 i = 0; i < texture_index_channels; ++i)
  921. {
  922. header.emplace_back(llformat(case_line, i, texture_fn, i));
  923. }
  924. header.emplace_back("\t}\n");
  925. header.emplace_back("\treturn ret;\n");
  926. header.emplace_back("}\n");
  927. }
  928. }
  929. // We cannot have any shaders longer than 4096 lines...
  930. constexpr U32 MAX_SHADER_TEXT_SIZE = 4096;
  931. GLchar* text[MAX_SHADER_TEXT_SIZE];
  932. U32 count = 0;
  933. // #version must come first in the directives...
  934. text[count++] = (GLchar*)strdup(glsl_version.c_str());
  935. // Copy shader header text into memory
  936. for (U32 i = 0, lines = header.size();
  937. i < lines && count < MAX_SHADER_TEXT_SIZE; ++i)
  938. {
  939. text[count++] = (GLchar*)strdup(header[i].c_str());
  940. }
  941. // Copy shader body text into memory
  942. for (U32 i = 0, lines = body.size();
  943. i < lines && count < MAX_SHADER_TEXT_SIZE; ++i)
  944. {
  945. text[count++] = (GLchar*)strdup(body[i].c_str());
  946. }
  947. LL_DEBUGS("ShaderPreprocessing") << filename << " text:\n"
  948. << "----------------------------------\n";
  949. for (U32 i = 0; i < count; ++i)
  950. {
  951. LL_CONT << text[i];
  952. }
  953. LL_CONT << "----------------------------------" << LL_ENDL;
  954. GLenum error = GL_NO_ERROR;
  955. if (count >= MAX_SHADER_TEXT_SIZE)
  956. {
  957. llwarns << "Shader file " << filename
  958. << " is too large (more than 4096 lines): shader loading skipped."
  959. << llendl;
  960. ++error; // Flag an error, we do not care which. HB
  961. }
  962. GLuint ret = 0;
  963. if (error == GL_NO_ERROR)
  964. {
  965. // Create the shader object
  966. clear_glerror();
  967. ret = glCreateShader(type);
  968. error = glGetError();
  969. if (error != GL_NO_ERROR)
  970. {
  971. llwarns << "GL error in glCreateShader: " << error
  972. << " - Shader file: " << filename << llendl;
  973. if (ret)
  974. {
  975. glDeleteShader(ret); // We no longer need that handle
  976. ret = 0;
  977. }
  978. clear_glerror();
  979. }
  980. }
  981. // Load source
  982. if (ret)
  983. {
  984. glShaderSource(ret, count, (const GLchar**)text, NULL);
  985. error = glGetError();
  986. if (error != GL_NO_ERROR)
  987. {
  988. llwarns << "GL error in glShaderSource: " << error
  989. << " - Shader file: " << filename << llendl;
  990. if (ret)
  991. {
  992. glDeleteShader(ret); // We no longer need that handle
  993. ret = 0;
  994. }
  995. clear_glerror();
  996. }
  997. }
  998. // Compile source
  999. if (ret)
  1000. {
  1001. glCompileShader(ret);
  1002. error = glGetError();
  1003. if (error != GL_NO_ERROR)
  1004. {
  1005. llwarns << "GL error in glCompileShader: " << error
  1006. << " - Shader file: " << filename << llendl;
  1007. if (ret)
  1008. {
  1009. glDeleteShader(ret); // We no longer need that handle
  1010. ret = 0;
  1011. }
  1012. clear_glerror();
  1013. }
  1014. }
  1015. if (ret)
  1016. {
  1017. // Check for errors
  1018. GLint success = GL_TRUE;
  1019. glGetShaderiv(ret, GL_COMPILE_STATUS, &success);
  1020. error = glGetError();
  1021. if (error != GL_NO_ERROR || success == GL_FALSE)
  1022. {
  1023. // An error occured, print log
  1024. llwarns << "GLSL compilation error: " << error
  1025. << " - Shader file: " << filename << llendl;
  1026. if (gDebugGL)
  1027. {
  1028. dumpObjectLog(false, ret);
  1029. dumpShaderSource(count, text);
  1030. }
  1031. glDeleteShader(ret); // We no longer need that handle
  1032. ret = 0;
  1033. clear_glerror();
  1034. }
  1035. }
  1036. // Free memory
  1037. for (GLuint i = 0; i < count; i++)
  1038. {
  1039. free(text[i]);
  1040. }
  1041. // Successfully loaded, save results
  1042. if (ret)
  1043. {
  1044. // Add shader file to map
  1045. if (type == GL_VERTEX_SHADER)
  1046. {
  1047. sVertexShaderObjects[filename] = ret;
  1048. }
  1049. else if (type == GL_FRAGMENT_SHADER)
  1050. {
  1051. sFragmentShaderObjects[filename] = ret;
  1052. }
  1053. else if (type != GL_GEOMETRY_SHADER)
  1054. {
  1055. llwarns << "Unmanaged shader type " << type << " for: "
  1056. << filename << llendl;
  1057. }
  1058. shader_level = try_gpu_class;
  1059. return ret;
  1060. }
  1061. if (shader_level <= 1)
  1062. {
  1063. llwarns << "Failed to load " << filename << llendl;
  1064. return ret;
  1065. }
  1066. // Try again at a lower shader level...
  1067. return loadShaderFile(filename, --shader_level, type, defines,
  1068. texture_index_channels);
  1069. }
  1070. bool LLShaderMgr::linkProgramObject(GLuint obj, bool suppress_errors)
  1071. {
  1072. // Check for errors
  1073. glLinkProgram(obj);
  1074. GLint success = GL_TRUE;
  1075. glGetProgramiv(obj, GL_LINK_STATUS, &success);
  1076. if (success == GL_FALSE && !suppress_errors)
  1077. {
  1078. // An error occured, print log
  1079. llwarns << "GLSL linker error:" << llendl;
  1080. }
  1081. #if !LL_DARWIN
  1082. std::string log = get_program_log(obj);
  1083. LLStringUtil::toLower(log);
  1084. if (log.find("software") != std::string::npos)
  1085. {
  1086. llwarns << "GLSL linker: running in software" << llendl;
  1087. success = GL_FALSE;
  1088. suppress_errors = false;
  1089. }
  1090. #endif
  1091. if (!suppress_errors)
  1092. {
  1093. dumpObjectLog(true, obj, !success);
  1094. }
  1095. return success != GL_FALSE;
  1096. }
  1097. #if 0 // Not used
  1098. bool LLShaderMgr::validateProgramObject(GLuint obj)
  1099. {
  1100. // Check program validity against current GL
  1101. glValidateProgram(obj);
  1102. GLint success = GL_TRUE;
  1103. glGetShaderiv(obj, GL_VALIDATE_STATUS, &success);
  1104. if (success == GL_FALSE)
  1105. {
  1106. llwarns << "GLSL program not valid: " << llendl;
  1107. dumpObjectLog(true, obj);
  1108. return false;
  1109. }
  1110. dumpObjectLog(true, obj, false);
  1111. return true;
  1112. }
  1113. #endif
  1114. //virtual
  1115. void LLShaderMgr::initAttribsAndUniforms()
  1116. {
  1117. sReservedAttribs.clear();
  1118. sReservedUniforms.clear();
  1119. // MUST match order of enum in llvertexbuffer.h
  1120. sReservedAttribs.emplace_back("position");
  1121. sReservedAttribs.emplace_back("normal");
  1122. sReservedAttribs.emplace_back("texcoord0");
  1123. sReservedAttribs.emplace_back("texcoord1");
  1124. sReservedAttribs.emplace_back("texcoord2");
  1125. sReservedAttribs.emplace_back("texcoord3");
  1126. sReservedAttribs.emplace_back("diffuse_color");
  1127. sReservedAttribs.emplace_back("emissive");
  1128. sReservedAttribs.emplace_back("tangent");
  1129. sReservedAttribs.emplace_back("weight");
  1130. sReservedAttribs.emplace_back("weight4");
  1131. sReservedAttribs.emplace_back("clothing");
  1132. sReservedAttribs.emplace_back("joint");
  1133. sReservedAttribs.emplace_back("texture_index");
  1134. // Matrix state
  1135. sReservedUniforms.emplace_back("modelview_matrix");
  1136. sReservedUniforms.emplace_back("projection_matrix");
  1137. sReservedUniforms.emplace_back("inv_proj");
  1138. sReservedUniforms.emplace_back("modelview_projection_matrix");
  1139. sReservedUniforms.emplace_back("inv_modelview");
  1140. sReservedUniforms.emplace_back("normal_matrix");
  1141. sReservedUniforms.emplace_back("texture_matrix0");
  1142. // Actually never used by shaders, but currently needed by the C++ code due
  1143. // to NUM_MATRIX_MODES. *TODO: cleanup the code and get rid of this. HB
  1144. sReservedUniforms.emplace_back("texture_matrix1");
  1145. sReservedUniforms.emplace_back("texture_matrix2");
  1146. sReservedUniforms.emplace_back("texture_matrix3");
  1147. sReservedUniforms.emplace_back("object_plane_s");
  1148. sReservedUniforms.emplace_back("object_plane_t");
  1149. llassert(sReservedUniforms.size() == size_t(OBJECT_PLANE_T + 1));
  1150. // For PBR shaders only
  1151. sReservedUniforms.emplace_back("texture_base_color_transform");
  1152. sReservedUniforms.emplace_back("texture_normal_transform");
  1153. sReservedUniforms.emplace_back("texture_metallic_roughness_transform");
  1154. sReservedUniforms.emplace_back("texture_emissive_transform");
  1155. sReservedUniforms.emplace_back("base_color_texcoord");
  1156. sReservedUniforms.emplace_back("emissive_texcoord");
  1157. sReservedUniforms.emplace_back("normal_texcoord");
  1158. sReservedUniforms.emplace_back("metallic_roughness_texcoord");
  1159. sReservedUniforms.emplace_back("occlusion_texcoord");
  1160. sReservedUniforms.emplace_back("gltf_node_id");
  1161. sReservedUniforms.emplace_back("gltf_material_id");
  1162. sReservedUniforms.emplace_back("terrain_texture_transforms");
  1163. llassert(sReservedUniforms.size() ==
  1164. size_t(TERRAIN_TEXTURE_TRANSFORMS + 1));
  1165. sReservedUniforms.emplace_back("viewport");
  1166. sReservedUniforms.emplace_back("light_position");
  1167. sReservedUniforms.emplace_back("light_direction");
  1168. sReservedUniforms.emplace_back("light_attenuation");
  1169. // For PBR shaders only
  1170. sReservedUniforms.emplace_back("light_deferred_attenuation");
  1171. sReservedUniforms.emplace_back("light_diffuse");
  1172. sReservedUniforms.emplace_back("light_ambient");
  1173. sReservedUniforms.emplace_back("light_count");
  1174. sReservedUniforms.emplace_back("light");
  1175. sReservedUniforms.emplace_back("light_col");
  1176. sReservedUniforms.emplace_back("far_z");
  1177. llassert(sReservedUniforms.size() == size_t(MULTI_LIGHT_FAR_Z + 1));
  1178. // MUST match order in eGLSLReservedUniforms
  1179. sReservedUniforms.emplace_back("proj_mat");
  1180. sReservedUniforms.emplace_back("proj_p");
  1181. sReservedUniforms.emplace_back("proj_n");
  1182. sReservedUniforms.emplace_back("proj_origin");
  1183. sReservedUniforms.emplace_back("proj_range");
  1184. sReservedUniforms.emplace_back("proj_ambiance");
  1185. sReservedUniforms.emplace_back("proj_shadow_idx");
  1186. sReservedUniforms.emplace_back("shadow_fade");
  1187. sReservedUniforms.emplace_back("proj_focus");
  1188. sReservedUniforms.emplace_back("proj_lod");
  1189. llassert(sReservedUniforms.size() == size_t(PROJECTOR_LOD + 1));
  1190. sReservedUniforms.emplace_back("color");
  1191. // For PBR shaders only
  1192. sReservedUniforms.emplace_back("emissiveColor");
  1193. sReservedUniforms.emplace_back("metallicFactor");
  1194. sReservedUniforms.emplace_back("roughnessFactor");
  1195. sReservedUniforms.emplace_back("mirror_flag");
  1196. sReservedUniforms.emplace_back("clipPlane");
  1197. sReservedUniforms.emplace_back("diffuseMap");
  1198. sReservedUniforms.emplace_back("altDiffuseMap");
  1199. sReservedUniforms.emplace_back("specularMap");
  1200. sReservedUniforms.emplace_back("emissiveMap"); // For PBR shaders
  1201. sReservedUniforms.emplace_back("bumpMap");
  1202. sReservedUniforms.emplace_back("bumpMap2");
  1203. sReservedUniforms.emplace_back("environmentMap");
  1204. // For PBR shaders only
  1205. sReservedUniforms.emplace_back("sceneMap");
  1206. sReservedUniforms.emplace_back("sceneDepth");
  1207. sReservedUniforms.emplace_back("reflectionProbes");
  1208. sReservedUniforms.emplace_back("irradianceProbes");
  1209. sReservedUniforms.emplace_back("heroProbes");
  1210. sReservedUniforms.emplace_back("cloud_noise_texture");
  1211. sReservedUniforms.emplace_back("cloud_noise_texture_next");
  1212. sReservedUniforms.emplace_back("fullbright"); // For EE shaders
  1213. sReservedUniforms.emplace_back("lightnorm");
  1214. sReservedUniforms.emplace_back("sunlight_color");
  1215. sReservedUniforms.emplace_back("ambient_color");
  1216. sReservedUniforms.emplace_back("sky_hdr_scale"); // For PBR shaders
  1217. sReservedUniforms.emplace_back("sky_sunlight_scale"); // For PBR shaders
  1218. sReservedUniforms.emplace_back("sky_ambient_scale"); // For PBR shaders
  1219. sReservedUniforms.emplace_back("blue_horizon");
  1220. sReservedUniforms.emplace_back("blue_density");
  1221. sReservedUniforms.emplace_back("haze_horizon");
  1222. sReservedUniforms.emplace_back("haze_density");
  1223. sReservedUniforms.emplace_back("cloud_shadow");
  1224. sReservedUniforms.emplace_back("density_multiplier");
  1225. sReservedUniforms.emplace_back("distance_multiplier");
  1226. sReservedUniforms.emplace_back("max_y");
  1227. sReservedUniforms.emplace_back("glow");
  1228. sReservedUniforms.emplace_back("cloud_color");
  1229. sReservedUniforms.emplace_back("cloud_pos_density1");
  1230. sReservedUniforms.emplace_back("cloud_pos_density2");
  1231. sReservedUniforms.emplace_back("cloud_scale");
  1232. sReservedUniforms.emplace_back("gamma");
  1233. sReservedUniforms.emplace_back("scene_light_strength");
  1234. llassert(sReservedUniforms.size() == size_t(SCENE_LIGHT_STRENGTH + 1));
  1235. sReservedUniforms.emplace_back("center");
  1236. sReservedUniforms.emplace_back("size");
  1237. sReservedUniforms.emplace_back("falloff");
  1238. sReservedUniforms.emplace_back("box_center");
  1239. sReservedUniforms.emplace_back("box_size");
  1240. sReservedUniforms.emplace_back("minLuminance");
  1241. sReservedUniforms.emplace_back("maxExtractAlpha");
  1242. sReservedUniforms.emplace_back("lumWeights");
  1243. sReservedUniforms.emplace_back("warmthWeights");
  1244. sReservedUniforms.emplace_back("warmthAmount");
  1245. sReservedUniforms.emplace_back("glowStrength");
  1246. sReservedUniforms.emplace_back("glowDelta");
  1247. sReservedUniforms.emplace_back("glowNoiseMap"); // For PBR shaders
  1248. llassert(sReservedUniforms.size() == size_t(GLOW_NOISE_MAP + 1));
  1249. sReservedUniforms.emplace_back("minimum_alpha");
  1250. sReservedUniforms.emplace_back("emissive_brightness");
  1251. sReservedUniforms.emplace_back("shadow_matrix");
  1252. sReservedUniforms.emplace_back("env_mat");
  1253. sReservedUniforms.emplace_back("shadow_clip");
  1254. sReservedUniforms.emplace_back("sun_wash");
  1255. sReservedUniforms.emplace_back("shadow_noise");
  1256. sReservedUniforms.emplace_back("blur_size");
  1257. sReservedUniforms.emplace_back("ssao_radius");
  1258. sReservedUniforms.emplace_back("ssao_max_radius");
  1259. sReservedUniforms.emplace_back("ssao_factor");
  1260. sReservedUniforms.emplace_back("ssao_effect_mat");
  1261. sReservedUniforms.emplace_back("screen_res");
  1262. sReservedUniforms.emplace_back("near_clip");
  1263. sReservedUniforms.emplace_back("shadow_offset");
  1264. sReservedUniforms.emplace_back("shadow_bias");
  1265. sReservedUniforms.emplace_back("spot_shadow_bias");
  1266. sReservedUniforms.emplace_back("spot_shadow_offset");
  1267. sReservedUniforms.emplace_back("sun_dir");
  1268. sReservedUniforms.emplace_back("moon_dir");
  1269. sReservedUniforms.emplace_back("shadow_res");
  1270. sReservedUniforms.emplace_back("proj_shadow_res");
  1271. sReservedUniforms.emplace_back("shadow_target_width");
  1272. // For PBR shaders only
  1273. sReservedUniforms.emplace_back("iterationCount");
  1274. sReservedUniforms.emplace_back("rayStep");
  1275. sReservedUniforms.emplace_back("distanceBias");
  1276. sReservedUniforms.emplace_back("depthRejectBias");
  1277. sReservedUniforms.emplace_back("glossySampleCount");
  1278. sReservedUniforms.emplace_back("noiseSine");
  1279. sReservedUniforms.emplace_back("adaptiveStepMultiplier");
  1280. llassert(sReservedUniforms.size() ==
  1281. size_t(DEFERRED_SSR_NOISE_SINE + 1));
  1282. // For PBR shaders only
  1283. sReservedUniforms.emplace_back("modelview_delta");
  1284. sReservedUniforms.emplace_back("inv_modelview_delta");
  1285. sReservedUniforms.emplace_back("cube_snapshot");
  1286. sReservedUniforms.emplace_back("tc_scale");
  1287. sReservedUniforms.emplace_back("rcp_screen_res");
  1288. sReservedUniforms.emplace_back("rcp_frame_opt");
  1289. sReservedUniforms.emplace_back("rcp_frame_opt2");
  1290. sReservedUniforms.emplace_back("focal_distance");
  1291. sReservedUniforms.emplace_back("blur_constant");
  1292. sReservedUniforms.emplace_back("tan_pixel_angle");
  1293. sReservedUniforms.emplace_back("magnification");
  1294. sReservedUniforms.emplace_back("max_cof");
  1295. sReservedUniforms.emplace_back("res_scale");
  1296. sReservedUniforms.emplace_back("dof_width");
  1297. sReservedUniforms.emplace_back("dof_height");
  1298. sReservedUniforms.emplace_back("depthMap");
  1299. sReservedUniforms.emplace_back("shadowMap0");
  1300. sReservedUniforms.emplace_back("shadowMap1");
  1301. sReservedUniforms.emplace_back("shadowMap2");
  1302. sReservedUniforms.emplace_back("shadowMap3");
  1303. sReservedUniforms.emplace_back("shadowMap4");
  1304. sReservedUniforms.emplace_back("shadowMap5");
  1305. llassert(sReservedUniforms.size() == size_t(DEFERRED_SHADOW5 + 1));
  1306. sReservedUniforms.emplace_back("normalMap");
  1307. sReservedUniforms.emplace_back("positionMap");
  1308. sReservedUniforms.emplace_back("diffuseRect");
  1309. sReservedUniforms.emplace_back("specularRect");
  1310. sReservedUniforms.emplace_back("emissiveRect"); // For PBR shaders only
  1311. sReservedUniforms.emplace_back("exposureMap"); // For PBR shaders only
  1312. sReservedUniforms.emplace_back("brdfLut"); // For PBR shaders only
  1313. sReservedUniforms.emplace_back("noiseMap");
  1314. sReservedUniforms.emplace_back("lightFunc");
  1315. sReservedUniforms.emplace_back("lightMap");
  1316. sReservedUniforms.emplace_back("bloomMap"); // For EE shaders only
  1317. sReservedUniforms.emplace_back("projectionMap");
  1318. sReservedUniforms.emplace_back("norm_mat");
  1319. sReservedUniforms.emplace_back("texture_gamma"); // For EE shaders only
  1320. sReservedUniforms.emplace_back("specular_color");
  1321. sReservedUniforms.emplace_back("env_intensity");
  1322. sReservedUniforms.emplace_back("matrixPalette");
  1323. sReservedUniforms.emplace_back("screenTex");
  1324. sReservedUniforms.emplace_back("screenDepth"); // For PBR shaders only
  1325. sReservedUniforms.emplace_back("refTex");
  1326. sReservedUniforms.emplace_back("eyeVec");
  1327. sReservedUniforms.emplace_back("time");
  1328. sReservedUniforms.emplace_back("waveDir1");
  1329. sReservedUniforms.emplace_back("waveDir2");
  1330. sReservedUniforms.emplace_back("lightDir");
  1331. sReservedUniforms.emplace_back("specular");
  1332. sReservedUniforms.emplace_back("waterFogColor");
  1333. sReservedUniforms.emplace_back("waterFogColorLinear"); // For PBR shaders
  1334. sReservedUniforms.emplace_back("waterFogDensity");
  1335. sReservedUniforms.emplace_back("waterFogKS");
  1336. sReservedUniforms.emplace_back("refScale");
  1337. sReservedUniforms.emplace_back("waterHeight");
  1338. sReservedUniforms.emplace_back("waterPlane");
  1339. sReservedUniforms.emplace_back("normScale");
  1340. sReservedUniforms.emplace_back("fresnelScale");
  1341. sReservedUniforms.emplace_back("fresnelOffset");
  1342. sReservedUniforms.emplace_back("blurMultiplier");
  1343. sReservedUniforms.emplace_back("sunAngle");
  1344. sReservedUniforms.emplace_back("camPosLocal");
  1345. sReservedUniforms.emplace_back("gWindDir");
  1346. sReservedUniforms.emplace_back("gSinWaveParams");
  1347. sReservedUniforms.emplace_back("gGravity");
  1348. sReservedUniforms.emplace_back("detail_0");
  1349. sReservedUniforms.emplace_back("detail_1");
  1350. sReservedUniforms.emplace_back("detail_2");
  1351. sReservedUniforms.emplace_back("detail_3");
  1352. sReservedUniforms.emplace_back("alpha_ramp");
  1353. // For PBR shaders only (PBR terrain)
  1354. sReservedUniforms.emplace_back("detail_0_base_color");
  1355. sReservedUniforms.emplace_back("detail_1_base_color");
  1356. sReservedUniforms.emplace_back("detail_2_base_color");
  1357. sReservedUniforms.emplace_back("detail_3_base_color");
  1358. sReservedUniforms.emplace_back("detail_0_normal");
  1359. sReservedUniforms.emplace_back("detail_1_normal");
  1360. sReservedUniforms.emplace_back("detail_2_normal");
  1361. sReservedUniforms.emplace_back("detail_3_normal");
  1362. sReservedUniforms.emplace_back("detail_0_metallic_roughness");
  1363. sReservedUniforms.emplace_back("detail_1_metallic_roughness");
  1364. sReservedUniforms.emplace_back("detail_2_metallic_roughness");
  1365. sReservedUniforms.emplace_back("detail_3_metallic_roughness");
  1366. sReservedUniforms.emplace_back("detail_0_emissive");
  1367. sReservedUniforms.emplace_back("detail_1_emissive");
  1368. sReservedUniforms.emplace_back("detail_2_emissive");
  1369. sReservedUniforms.emplace_back("detail_3_emissive");
  1370. sReservedUniforms.emplace_back("baseColorFactors");
  1371. sReservedUniforms.emplace_back("metallicFactors");
  1372. sReservedUniforms.emplace_back("roughnessFactors");
  1373. sReservedUniforms.emplace_back("emissiveColors");
  1374. sReservedUniforms.emplace_back("minimum_alphas");
  1375. sReservedUniforms.emplace_back("origin");
  1376. sReservedUniforms.emplace_back("display_gamma");
  1377. sReservedUniforms.emplace_back("sun_size");
  1378. sReservedUniforms.emplace_back("fog_color");
  1379. sReservedUniforms.emplace_back("blend_factor");
  1380. sReservedUniforms.emplace_back("no_atmo"); // For EE shaders only
  1381. sReservedUniforms.emplace_back("moisture_level");
  1382. sReservedUniforms.emplace_back("droplet_radius");
  1383. sReservedUniforms.emplace_back("ice_level");
  1384. sReservedUniforms.emplace_back("rainbow_map");
  1385. sReservedUniforms.emplace_back("halo_map");
  1386. sReservedUniforms.emplace_back("moon_brightness");
  1387. sReservedUniforms.emplace_back("cloud_variance");
  1388. // For PBR shaders only
  1389. sReservedUniforms.emplace_back("reflection_probe_ambiance");
  1390. sReservedUniforms.emplace_back("max_probe_lod");
  1391. sReservedUniforms.emplace_back("probe_strength");
  1392. // Used only by the EE shaders, but not in the C++ renderer code.
  1393. // *TODO: check for a possible bug or eliminate if actually useless. HB
  1394. sReservedUniforms.emplace_back("sh_input_r");
  1395. sReservedUniforms.emplace_back("sh_input_g");
  1396. sReservedUniforms.emplace_back("sh_input_b");
  1397. sReservedUniforms.emplace_back("sun_moon_glow_factor");
  1398. sReservedUniforms.emplace_back("sun_up_factor");
  1399. sReservedUniforms.emplace_back("moonlight_color");
  1400. // For PBR shaders only
  1401. sReservedUniforms.emplace_back("debug_normal_draw_length");
  1402. llassert_always(sReservedUniforms.size() == (size_t)END_RESERVED_UNIFORMS);
  1403. LL_DEBUGS("ShaderLoading") << "Checking duplicates in reserved uniforms: ";
  1404. std::set<std::string> dupe_check;
  1405. for (U32 i = 0, count = sReservedUniforms.size(); i < count; ++i)
  1406. {
  1407. if (dupe_check.find(sReservedUniforms[i]) != dupe_check.end())
  1408. {
  1409. LL_CONT << "Duplicate reserved uniform name found: "
  1410. << sReservedUniforms[i];
  1411. llassert(false);
  1412. }
  1413. else
  1414. {
  1415. dupe_check.emplace(sReservedUniforms[i]);
  1416. }
  1417. }
  1418. LL_CONT << "Done." << LL_ENDL;
  1419. }