llviewershadermgr.cpp 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223
  1. /**
  2. * @file llviewershadermgr.cpp
  3. * @brief Viewer 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 "llviewerprecompiledheaders.h"
  33. #if LL_LINUX
  34. # include <stdlib.h> // For getenv()
  35. #endif
  36. #include "llviewershadermgr.h"
  37. #include "lldir.h"
  38. #include "llfeaturemanager.h"
  39. #include "lljoint.h"
  40. #include "llrender.h"
  41. #include "hbtracy.h"
  42. #include "llenvironment.h"
  43. #include "llpipeline.h"
  44. #include "llsky.h"
  45. #include "llviewercontrol.h"
  46. #include "llviewerwindow.h"
  47. #include "llworld.h"
  48. static LLStaticHashedString sTexture0("texture0");
  49. static LLStaticHashedString sTexture1("texture1");
  50. static LLStaticHashedString sTex0("tex0");
  51. static LLStaticHashedString sTex1("tex1");
  52. static LLStaticHashedString sTex2("tex2");
  53. static LLStaticHashedString sGlowMap("glowMap");
  54. static LLStaticHashedString sScreenMap("screenMap");
  55. LLViewerShaderMgr* gViewerShaderMgrp;
  56. bool LLViewerShaderMgr::sInitialized = false;
  57. bool LLViewerShaderMgr::sSkipReload = false;
  58. bool LLViewerShaderMgr::sHasFXAA = false;
  59. bool LLViewerShaderMgr::sHasSMAA = false;
  60. bool LLViewerShaderMgr::sHasCAS = false;
  61. bool LLViewerShaderMgr::sHasIrrandiance = false;
  62. bool LLViewerShaderMgr::sCanDoRP = false;
  63. bool LLViewerShaderMgr::sHasRP = false;
  64. LLVector4 gShinyOrigin;
  65. // Utility shaders
  66. LLGLSLShader gOcclusionProgram;
  67. LLGLSLShader gSkinnedOcclusionProgram;
  68. LLGLSLShader gOcclusionCubeProgram;
  69. LLGLSLShader gGlowCombineProgram;
  70. LLGLSLShader gReflectionMipProgram; // PBR only
  71. LLGLSLShader gGaussianProgram; // PBR only
  72. LLGLSLShader gRadianceGenProgram; // PBR only
  73. LLGLSLShader gHeroRadianceGenProgram; // PBR only
  74. LLGLSLShader gIrradianceGenProgram; // PBR only
  75. LLGLSLShader gSplatTextureRectProgram; // EE/WL only
  76. LLGLSLShader gGlowCombineFXAAProgram;
  77. LLGLSLShader gOneTextureNoColorProgram; // EE/WL only
  78. LLGLSLShader gDebugProgram;
  79. LLGLSLShader gSkinnedDebugProgram;
  80. LLGLSLShader gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT]; // PBR only
  81. LLGLSLShader gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT]; // PBR only
  82. LLGLSLShader gClipProgram;
  83. LLGLSLShader gDownsampleDepthProgram; // EE/WL only
  84. LLGLSLShader gDownsampleDepthRectProgram; // EE/WL only
  85. LLGLSLShader gAlphaMaskProgram;
  86. LLGLSLShader gBenchmarkProgram;
  87. LLGLSLShader gReflectionProbeDisplayProgram; // PBR only
  88. LLGLSLShader gCopyProgram; // PBR only
  89. LLGLSLShader gCopyDepthProgram; // PBR only
  90. // Object shaders
  91. LLGLSLShader gObjectSimpleProgram; // EE/WL only
  92. LLGLSLShader gSkinnedObjectSimpleProgram; // EE/WL only
  93. LLGLSLShader gObjectSimpleImpostorProgram; // EE/WL only
  94. LLGLSLShader gSkinnedObjectSimpleImpostorProgram; // EE/WL only
  95. LLGLSLShader gObjectPreviewProgram;
  96. LLGLSLShader gSkinnedObjectPreviewProgram; // PBR only
  97. LLGLSLShader gPhysicsPreviewProgram; // PBR only
  98. LLGLSLShader gObjectSimpleAlphaMaskProgram; // EE/WL only
  99. LLGLSLShader gSkinnedObjectSimpleAlphaMaskProgram; // EE/WL only
  100. LLGLSLShader gObjectSimpleWaterProgram; // EE/WL only
  101. LLGLSLShader gSkinnedObjectSimpleWaterProgram; // EE/WL only
  102. LLGLSLShader gObjectSimpleWaterAlphaMaskProgram; // EE/WL only
  103. LLGLSLShader gSkinnedObjectSimpleWaterAlphaMaskProgram; // EE/WL only
  104. LLGLSLShader gObjectFullbrightProgram; // EE/WL only
  105. LLGLSLShader gSkinnedObjectFullbrightProgram; // EE/WL only
  106. LLGLSLShader gObjectFullbrightWaterProgram; // EE/WL only
  107. LLGLSLShader gSkinnedObjectFullbrightWaterProgram; // EE/WL only
  108. LLGLSLShader gObjectEmissiveProgram; // EE/WL only
  109. LLGLSLShader gSkinnedObjectEmissiveProgram; // EE/WL only
  110. LLGLSLShader gObjectEmissiveWaterProgram; // EE/WL only
  111. LLGLSLShader gSkinnedObjectEmissiveWaterProgram; // EE/WL only
  112. LLGLSLShader gObjectFullbrightAlphaMaskProgram; // EE/WL only
  113. LLGLSLShader gSkinnedObjectFullbrightAlphaMaskProgram; // EE/WL only
  114. LLGLSLShader gObjectFullbrightWaterAlphaMaskProgram; // EE/WL only
  115. LLGLSLShader gSkinnedObjectFullbrightWaterAlphaMaskProgram; // EE/WL only
  116. LLGLSLShader gObjectFullbrightShinyProgram; // EE/WL only
  117. LLGLSLShader gSkinnedObjectFullbrightShinyProgram; // EE/WL only
  118. LLGLSLShader gObjectFullbrightShinyWaterProgram; // EE/WL only
  119. LLGLSLShader gSkinnedObjectFullbrightShinyWaterProgram; // EE/WL only
  120. LLGLSLShader gObjectShinyProgram; // EE/WL only
  121. LLGLSLShader gSkinnedObjectShinyProgram; // EE/WL only
  122. LLGLSLShader gObjectShinyWaterProgram; // EE/WL only
  123. LLGLSLShader gSkinnedObjectShinyWaterProgram; // EE/WL only
  124. LLGLSLShader gObjectBumpProgram;
  125. LLGLSLShader gSkinnedObjectBumpProgram;
  126. LLGLSLShader gTreeProgram; // EE/WL only
  127. LLGLSLShader gTreeWaterProgram; // EE/WL only
  128. LLGLSLShader gObjectFullbrightNoColorWaterProgram; // EE/WL only
  129. LLGLSLShader gObjectSimpleNonIndexedTexGenProgram; // EE/WL only
  130. LLGLSLShader gObjectSimpleNonIndexedTexGenWaterProgram; // EE/WL only
  131. LLGLSLShader gObjectAlphaMaskNonIndexedProgram; // EE/WL only
  132. LLGLSLShader gObjectAlphaMaskNonIndexedWaterProgram; // EE/WL only
  133. LLGLSLShader gObjectAlphaMaskNoColorProgram;
  134. LLGLSLShader gObjectAlphaMaskNoColorWaterProgram; // EE/WL only
  135. // Environment shaders
  136. LLGLSLShader gMoonProgram; // EE/WL only
  137. LLGLSLShader gStarsProgram; // EE/WL only
  138. LLGLSLShader gTerrainProgram; // EE/WL only
  139. LLGLSLShader gTerrainWaterProgram; // EE/WL only
  140. LLGLSLShader gWaterProgram;
  141. LLGLSLShader gUnderWaterProgram;
  142. LLGLSLShader gWaterEdgeProgram;
  143. // Interface shaders
  144. LLGLSLShader gHighlightProgram;
  145. LLGLSLShader gSkinnedHighlightProgram;
  146. LLGLSLShader gHighlightNormalProgram;
  147. LLGLSLShader gHighlightSpecularProgram;
  148. // Avatar shader handles
  149. LLGLSLShader gAvatarProgram;
  150. LLGLSLShader gAvatarWaterProgram; // EE/WL only
  151. LLGLSLShader gAvatarEyeballProgram;
  152. LLGLSLShader gImpostorProgram;
  153. // WindLight shader handles
  154. LLGLSLShader gWLSkyProgram; // EE/WL only
  155. LLGLSLShader gWLCloudProgram; // EE/WL only
  156. LLGLSLShader gWLSunProgram; // EE/WL only
  157. LLGLSLShader gWLMoonProgram; // EE/WL only
  158. // Effects Shaders
  159. LLGLSLShader gGlowProgram;
  160. LLGLSLShader gGlowExtractProgram;
  161. LLGLSLShader gPostScreenSpaceReflectionProgram;
  162. // Deferred rendering shaders
  163. LLGLSLShader gDeferredImpostorProgram;
  164. LLGLSLShader gDeferredWaterProgram; // EE/WL only
  165. LLGLSLShader gDeferredUnderWaterProgram; // EE/WL only
  166. LLGLSLShader gDeferredHighlightProgram; // PBR only
  167. LLGLSLShader gDeferredDiffuseProgram;
  168. LLGLSLShader gDeferredDiffuseAlphaMaskProgram;
  169. LLGLSLShader gDeferredSkinnedDiffuseAlphaMaskProgram;
  170. LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskProgram;
  171. LLGLSLShader gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
  172. LLGLSLShader gDeferredSkinnedDiffuseProgram;
  173. LLGLSLShader gDeferredSkinnedBumpProgram;
  174. LLGLSLShader gDeferredBumpProgram;
  175. LLGLSLShader gDeferredTerrainProgram;
  176. LLGLSLShader gDeferredTerrainWaterProgram; // EE/WL only
  177. LLGLSLShader gDeferredTreeProgram;
  178. LLGLSLShader gDeferredTreeShadowProgram;
  179. LLGLSLShader gDeferredSkinnedTreeShadowProgram;
  180. LLGLSLShader gDeferredAvatarProgram;
  181. LLGLSLShader gDeferredAvatarAlphaProgram;
  182. LLGLSLShader gDeferredLightProgram;
  183. LLGLSLShader gDeferredMultiLightProgram[LL_DEFERRED_MULTI_LIGHT_COUNT];
  184. LLGLSLShader gDeferredSpotLightProgram;
  185. LLGLSLShader gDeferredMultiSpotLightProgram;
  186. LLGLSLShader gDeferredSunProgram;
  187. LLGLSLShader gHazeProgram; // PBR only
  188. LLGLSLShader gHazeWaterProgram; // PBR only
  189. LLGLSLShader gDeferredBlurLightProgram;
  190. LLGLSLShader gDeferredSoftenProgram;
  191. LLGLSLShader gDeferredSoftenWaterProgram; // EE/WL only
  192. LLGLSLShader gDeferredShadowProgram;
  193. LLGLSLShader gDeferredSkinnedShadowProgram;
  194. LLGLSLShader gDeferredShadowCubeProgram;
  195. LLGLSLShader gDeferredShadowAlphaMaskProgram;
  196. LLGLSLShader gDeferredSkinnedShadowAlphaMaskProgram;
  197. LLGLSLShader gDeferredShadowGLTFAlphaMaskProgram; // PBR only
  198. LLGLSLShader gDeferredSkinnedShadowGLTFAlphaMaskProgram; // PBR only
  199. LLGLSLShader gDeferredShadowGLTFAlphaBlendProgram; // PBR only
  200. LLGLSLShader gDeferredSkinnedShadowGLTFAlphaBlendProgram; // PBR only
  201. LLGLSLShader gDeferredShadowFullbrightAlphaMaskProgram;
  202. LLGLSLShader gDeferredSkinnedShadowFullbrightAlphaMaskProgram;
  203. LLGLSLShader gDeferredAvatarShadowProgram;
  204. LLGLSLShader gDeferredAvatarAlphaShadowProgram;
  205. LLGLSLShader gDeferredAvatarAlphaMaskShadowProgram;
  206. LLGLSLShader gDeferredAlphaProgram;
  207. LLGLSLShader gHUDAlphaProgram; // PBR only
  208. LLGLSLShader gDeferredSkinnedAlphaProgram;
  209. LLGLSLShader gDeferredAlphaImpostorProgram;
  210. LLGLSLShader gDeferredSkinnedAlphaImpostorProgram;
  211. LLGLSLShader gDeferredAlphaWaterProgram; // EE/WL only
  212. LLGLSLShader gDeferredSkinnedAlphaWaterProgram; // EE/WL only
  213. LLGLSLShader gDeferredAvatarEyesProgram;
  214. LLGLSLShader gDeferredFullbrightProgram;
  215. LLGLSLShader gDeferredFullbrightAlphaMaskProgram;
  216. LLGLSLShader gDeferredFullbrightAlphaMaskAlphaProgram; // PBR only
  217. LLGLSLShader gHUDFullbrightProgram; // PBR only
  218. LLGLSLShader gHUDFullbrightAlphaMaskProgram; // PBR only
  219. LLGLSLShader gHUDFullbrightAlphaMaskAlphaProgram; // PBR only
  220. LLGLSLShader gDeferredFullbrightWaterProgram; // EE/WL only
  221. LLGLSLShader gDeferredSkinnedFullbrightWaterProgram; // EE/WL only
  222. LLGLSLShader gDeferredFullbrightAlphaMaskWaterProgram; // EE/WL only
  223. LLGLSLShader gDeferredSkinnedFullbrightAlphaMaskWaterProgram; // EE/WL only
  224. LLGLSLShader gDeferredEmissiveProgram;
  225. LLGLSLShader gDeferredSkinnedEmissiveProgram;
  226. LLGLSLShader gDeferredPostProgram;
  227. LLGLSLShader gDeferredCoFProgram;
  228. LLGLSLShader gDeferredDoFCombineProgram;
  229. LLGLSLShader gDeferredPostGammaCorrectProgram;
  230. LLGLSLShader gNoPostGammaCorrectProgram; // PBR only
  231. LLGLSLShader gLegacyPostGammaCorrectProgram; // PBR only
  232. LLGLSLShader gExposureProgram; // PBR only
  233. LLGLSLShader gExposureProgramNoFade; // PBR only
  234. LLGLSLShader gLuminanceProgram; // PBR only
  235. LLGLSLShader gFXAAProgram[4];
  236. LLGLSLShader gPostSMAAEdgeDetect[4];
  237. LLGLSLShader gPostSMAABlendWeights[4];
  238. LLGLSLShader gPostSMAANeighborhoodBlend[4];
  239. LLGLSLShader gPostCASProgram;
  240. LLGLSLShader gDeferredPostNoDoFProgram;
  241. LLGLSLShader gEnvironmentMapProgram; // PBR only
  242. LLGLSLShader gDeferredWLSkyProgram;
  243. LLGLSLShader gDeferredWLCloudProgram;
  244. LLGLSLShader gDeferredWLSunProgram;
  245. LLGLSLShader gDeferredWLMoonProgram;
  246. LLGLSLShader gDeferredStarProgram;
  247. LLGLSLShader gDeferredFullbrightShinyProgram;
  248. LLGLSLShader gHUDFullbrightShinyProgram;
  249. LLGLSLShader gDeferredSkinnedFullbrightShinyProgram;
  250. LLGLSLShader gDeferredSkinnedFullbrightProgram;
  251. LLGLSLShader gDeferredSkinnedFullbrightAlphaMaskProgram;
  252. LLGLSLShader gDeferredSkinnedFullbrightAlphaMaskAlphaProgram; // PBR only
  253. LLGLSLShader gNormalMapGenProgram;
  254. LLGLSLShader gDeferredGenBrdfLutProgram; // PBR only
  255. LLGLSLShader gDeferredBufferVisualProgram; // PBR only
  256. // Deferred materials shaders
  257. LLGLSLShader gDeferredMaterialProgram[LLMaterial::SHADER_COUNT * 2];
  258. LLGLSLShader gDeferredMaterialWaterProgram[LLMaterial::SHADER_COUNT * 2]; // EE/WL only
  259. LLGLSLShader gHUDPBROpaqueProgram; // PBR only
  260. LLGLSLShader gPBRGlowProgram; // PBR only
  261. LLGLSLShader gPBRGlowSkinnedProgram; // PBR only
  262. LLGLSLShader gDeferredPBROpaqueProgram; // PBR only
  263. LLGLSLShader gDeferredSkinnedPBROpaqueProgram; // PBR only
  264. LLGLSLShader gHUDPBRAlphaProgram; // PBR only
  265. LLGLSLShader gDeferredPBRAlphaProgram; // PBR only
  266. LLGLSLShader gDeferredSkinnedPBRAlphaProgram; // PBR only
  267. LLGLSLShader gDeferredPBRTerrainProgram; // PBR only
  268. // Helper for creating a rigged variant *together* with a given shader. HB
  269. static bool create_with_rigged(LLGLSLShader& shader,
  270. LLGLSLShader& rigged_shader)
  271. {
  272. shader.mRiggedVariant = &rigged_shader;
  273. std::string name = shader.mName;
  274. LLStringUtil::toLower(name);
  275. rigged_shader.mName = "Skinned " + name;
  276. rigged_shader.mShaderFiles = shader.mShaderFiles;
  277. rigged_shader.mShaderLevel = shader.mShaderLevel;
  278. rigged_shader.mShaderGroup = shader.mShaderGroup;
  279. rigged_shader.mFeatures = shader.mFeatures;
  280. rigged_shader.mFeatures.hasObjectSkinning = true;
  281. // Note: must come before addPermutation()
  282. rigged_shader.mDefines = shader.mDefines;
  283. rigged_shader.addPermutation("HAS_SKIN", "1");
  284. return rigged_shader.createShader() && shader.createShader();
  285. }
  286. LLViewerShaderMgr::LLViewerShaderMgr()
  287. : mShaderLevel(SHADER_COUNT, 0),
  288. mMaxAvatarShaderLevel(0)
  289. {
  290. sInitialized = true;
  291. init();
  292. }
  293. LLViewerShaderMgr::~LLViewerShaderMgr()
  294. {
  295. mShaderLevel.clear();
  296. mShaderList.clear();
  297. }
  298. void LLViewerShaderMgr::init()
  299. {
  300. sVertexShaderObjects.clear();
  301. sFragmentShaderObjects.clear();
  302. mShaderList.clear();
  303. std::string subdir = gUsePBRShaders ? "pbr" : "ee";
  304. mShaderDirPrefix = gDirUtil.getFullPath(LL_PATH_APP_SETTINGS, "shaders",
  305. subdir, "class");
  306. if (!gGLManager.mHasRequirements)
  307. {
  308. llwarns << "Failed to pass minimum requirements for shaders."
  309. << llendl;
  310. sInitialized = false;
  311. return;
  312. }
  313. // Make sure WL Sky is the first program. ONLY shaders that need WL param
  314. // management should be added here.
  315. if (!gUsePBRShaders)
  316. {
  317. mShaderList.push_back(&gWLSkyProgram);
  318. mShaderList.push_back(&gWLCloudProgram);
  319. mShaderList.push_back(&gWLSunProgram);
  320. mShaderList.push_back(&gWLMoonProgram);
  321. }
  322. mShaderList.push_back(&gAvatarProgram);
  323. if (!gUsePBRShaders)
  324. {
  325. mShaderList.push_back(&gObjectShinyProgram);
  326. mShaderList.push_back(&gSkinnedObjectShinyProgram);
  327. }
  328. mShaderList.push_back(&gWaterProgram);
  329. mShaderList.push_back(&gWaterEdgeProgram);
  330. mShaderList.push_back(&gAvatarEyeballProgram);
  331. if (!gUsePBRShaders)
  332. {
  333. mShaderList.push_back(&gObjectSimpleProgram);
  334. mShaderList.push_back(&gSkinnedObjectSimpleProgram);
  335. mShaderList.push_back(&gObjectSimpleImpostorProgram);
  336. mShaderList.push_back(&gSkinnedObjectSimpleImpostorProgram);
  337. }
  338. mShaderList.push_back(&gImpostorProgram);
  339. if (!gUsePBRShaders)
  340. {
  341. mShaderList.push_back(&gObjectFullbrightNoColorWaterProgram);
  342. mShaderList.push_back(&gObjectSimpleAlphaMaskProgram);
  343. mShaderList.push_back(&gSkinnedObjectSimpleAlphaMaskProgram);
  344. }
  345. mShaderList.push_back(&gObjectBumpProgram);
  346. if (!gUsePBRShaders)
  347. {
  348. mShaderList.push_back(&gSkinnedObjectBumpProgram);
  349. mShaderList.push_back(&gObjectEmissiveProgram);
  350. mShaderList.push_back(&gSkinnedObjectEmissiveProgram);
  351. mShaderList.push_back(&gObjectEmissiveWaterProgram);
  352. mShaderList.push_back(&gSkinnedObjectEmissiveWaterProgram);
  353. mShaderList.push_back(&gObjectFullbrightProgram);
  354. mShaderList.push_back(&gSkinnedObjectFullbrightProgram);
  355. }
  356. mShaderList.push_back(&gObjectFullbrightAlphaMaskProgram);
  357. mShaderList.push_back(&gSkinnedObjectFullbrightAlphaMaskProgram);
  358. if (!gUsePBRShaders)
  359. {
  360. mShaderList.push_back(&gObjectFullbrightShinyProgram);
  361. mShaderList.push_back(&gSkinnedObjectFullbrightShinyProgram);
  362. mShaderList.push_back(&gObjectFullbrightShinyWaterProgram);
  363. mShaderList.push_back(&gSkinnedObjectFullbrightShinyWaterProgram);
  364. mShaderList.push_back(&gObjectSimpleNonIndexedTexGenProgram);
  365. mShaderList.push_back(&gObjectSimpleNonIndexedTexGenWaterProgram);
  366. mShaderList.push_back(&gObjectAlphaMaskNonIndexedProgram);
  367. mShaderList.push_back(&gObjectAlphaMaskNonIndexedWaterProgram);
  368. }
  369. mShaderList.push_back(&gObjectAlphaMaskNoColorProgram);
  370. if (!gUsePBRShaders)
  371. {
  372. mShaderList.push_back(&gObjectAlphaMaskNoColorWaterProgram);
  373. mShaderList.push_back(&gTreeProgram);
  374. mShaderList.push_back(&gTreeWaterProgram);
  375. mShaderList.push_back(&gMoonProgram);
  376. mShaderList.push_back(&gStarsProgram);
  377. mShaderList.push_back(&gTerrainProgram);
  378. mShaderList.push_back(&gTerrainWaterProgram);
  379. mShaderList.push_back(&gObjectSimpleWaterProgram);
  380. mShaderList.push_back(&gSkinnedObjectSimpleWaterProgram);
  381. mShaderList.push_back(&gObjectFullbrightWaterProgram);
  382. mShaderList.push_back(&gSkinnedObjectFullbrightWaterProgram);
  383. mShaderList.push_back(&gObjectSimpleWaterAlphaMaskProgram);
  384. mShaderList.push_back(&gSkinnedObjectSimpleWaterAlphaMaskProgram);
  385. mShaderList.push_back(&gObjectFullbrightWaterAlphaMaskProgram);
  386. mShaderList.push_back(&gSkinnedObjectFullbrightWaterAlphaMaskProgram);
  387. mShaderList.push_back(&gAvatarWaterProgram);
  388. mShaderList.push_back(&gObjectShinyWaterProgram);
  389. mShaderList.push_back(&gSkinnedObjectShinyWaterProgram);
  390. }
  391. mShaderList.push_back(&gUnderWaterProgram);
  392. mShaderList.push_back(&gDeferredSunProgram);
  393. if (gUsePBRShaders)
  394. {
  395. mShaderList.push_back(&gHazeProgram);
  396. mShaderList.push_back(&gHazeWaterProgram);
  397. }
  398. mShaderList.push_back(&gDeferredSoftenProgram);
  399. if (!gUsePBRShaders)
  400. {
  401. mShaderList.push_back(&gDeferredSoftenWaterProgram);
  402. }
  403. mShaderList.push_back(&gDeferredAlphaProgram);
  404. if (gUsePBRShaders)
  405. {
  406. mShaderList.push_back(&gHUDAlphaProgram);
  407. }
  408. else
  409. {
  410. mShaderList.push_back(&gDeferredSkinnedAlphaProgram);
  411. }
  412. mShaderList.push_back(&gDeferredAlphaImpostorProgram);
  413. if (!gUsePBRShaders)
  414. {
  415. mShaderList.push_back(&gDeferredSkinnedAlphaImpostorProgram);
  416. mShaderList.push_back(&gDeferredAlphaWaterProgram);
  417. mShaderList.push_back(&gDeferredSkinnedAlphaWaterProgram);
  418. }
  419. mShaderList.push_back(&gDeferredFullbrightProgram);
  420. if (gUsePBRShaders)
  421. {
  422. mShaderList.push_back(&gHUDFullbrightProgram);
  423. }
  424. mShaderList.push_back(&gDeferredFullbrightAlphaMaskProgram);
  425. if (gUsePBRShaders)
  426. {
  427. mShaderList.push_back(&gHUDFullbrightAlphaMaskProgram);
  428. mShaderList.push_back(&gDeferredFullbrightAlphaMaskAlphaProgram);
  429. mShaderList.push_back(&gHUDFullbrightAlphaMaskAlphaProgram);
  430. }
  431. else
  432. {
  433. mShaderList.push_back(&gDeferredFullbrightWaterProgram);
  434. mShaderList.push_back(&gDeferredSkinnedFullbrightWaterProgram);
  435. mShaderList.push_back(&gDeferredFullbrightAlphaMaskWaterProgram);
  436. mShaderList.push_back(&gDeferredSkinnedFullbrightAlphaMaskWaterProgram);
  437. }
  438. mShaderList.push_back(&gDeferredFullbrightShinyProgram);
  439. if (gUsePBRShaders)
  440. {
  441. mShaderList.push_back(&gHUDFullbrightShinyProgram);
  442. }
  443. else
  444. {
  445. mShaderList.push_back(&gDeferredSkinnedFullbrightShinyProgram);
  446. mShaderList.push_back(&gDeferredSkinnedFullbrightProgram);
  447. mShaderList.push_back(&gDeferredSkinnedFullbrightAlphaMaskProgram);
  448. }
  449. mShaderList.push_back(&gDeferredEmissiveProgram);
  450. if (!gUsePBRShaders)
  451. {
  452. mShaderList.push_back(&gDeferredSkinnedEmissiveProgram);
  453. }
  454. mShaderList.push_back(&gDeferredAvatarEyesProgram);
  455. if (!gUsePBRShaders)
  456. {
  457. mShaderList.push_back(&gDeferredWaterProgram);
  458. mShaderList.push_back(&gDeferredUnderWaterProgram);
  459. mShaderList.push_back(&gDeferredTerrainWaterProgram);
  460. }
  461. mShaderList.push_back(&gDeferredAvatarAlphaProgram);
  462. if (gUsePBRShaders)
  463. {
  464. mShaderList.push_back(&gEnvironmentMapProgram);
  465. }
  466. mShaderList.push_back(&gDeferredWLSkyProgram);
  467. mShaderList.push_back(&gDeferredWLCloudProgram);
  468. mShaderList.push_back(&gDeferredWLMoonProgram);
  469. mShaderList.push_back(&gDeferredWLSunProgram);
  470. if (gUsePBRShaders)
  471. {
  472. mShaderList.push_back(&gDeferredPBRAlphaProgram);
  473. mShaderList.push_back(&gHUDPBRAlphaProgram);
  474. // The three following shaders need the sky "gamma" value.
  475. mShaderList.push_back(&gDeferredPostGammaCorrectProgram);
  476. mShaderList.push_back(&gNoPostGammaCorrectProgram);
  477. mShaderList.push_back(&gLegacyPostGammaCorrectProgram);
  478. mShaderList.push_back(&gDeferredDiffuseProgram);
  479. mShaderList.push_back(&gDeferredBumpProgram);
  480. mShaderList.push_back(&gDeferredPBROpaqueProgram);
  481. mShaderList.push_back(&gDeferredAvatarProgram);
  482. mShaderList.push_back(&gDeferredPBRTerrainProgram);
  483. mShaderList.push_back(&gDeferredDiffuseAlphaMaskProgram);
  484. mShaderList.push_back(&gDeferredNonIndexedDiffuseAlphaMaskProgram);
  485. mShaderList.push_back(&gDeferredTreeProgram);
  486. }
  487. }
  488. //static
  489. void LLViewerShaderMgr::createInstance()
  490. {
  491. if (gViewerShaderMgrp)
  492. {
  493. llwarns << "Instance already exists !" << llendl;
  494. llassert(false);
  495. return;
  496. }
  497. gViewerShaderMgrp = new LLViewerShaderMgr();
  498. }
  499. //static
  500. void LLViewerShaderMgr::releaseInstance()
  501. {
  502. sInitialized = false;
  503. if (gViewerShaderMgrp)
  504. {
  505. delete gViewerShaderMgrp;
  506. gViewerShaderMgrp = NULL;
  507. }
  508. }
  509. void LLViewerShaderMgr::initAttribsAndUniforms()
  510. {
  511. if (sReservedUniforms.empty())
  512. {
  513. LLShaderMgr::initAttribsAndUniforms();
  514. }
  515. }
  516. // Note: macOS does not have a splash screen, and Windows cannot reuse its
  517. // splash screen after the main viewer window has been created. HB
  518. #if LL_LINUX
  519. class HBUpdateSplashScreen
  520. {
  521. public:
  522. HBUpdateSplashScreen(const std::string& message)
  523. : mSplashScreenExists(LLSplashScreen::isVisible())
  524. {
  525. if (!mSplashScreenExists)
  526. {
  527. // Allow to disable the splash screen on shaders re-compilation
  528. // after viewer startup, just in case it would cause issues on some
  529. // systems (unlikely, but better safe than sorry). HB
  530. if (getenv("LL_DISABLE_SHADER_COMPILING_SPLASH"))
  531. {
  532. mSplashScreenExists = true; // Nothing to do in the destructor.
  533. return;
  534. }
  535. LLSplashScreen::show();
  536. }
  537. LLSplashScreen::update(message);
  538. }
  539. ~HBUpdateSplashScreen()
  540. {
  541. if (!mSplashScreenExists)
  542. {
  543. LLSplashScreen::hide();
  544. }
  545. }
  546. private:
  547. bool mSplashScreenExists;
  548. };
  549. #endif
  550. // Shader Management
  551. void LLViewerShaderMgr::setShaders()
  552. {
  553. // We get called recursively by gSavedSettings callbacks, so return on
  554. // reentrance
  555. static bool reentrance = false;
  556. if (reentrance)
  557. {
  558. // Always refresh cached settings however
  559. LLPipeline::refreshCachedSettings();
  560. return;
  561. }
  562. if (!gPipeline.isInit() || !sInitialized || sSkipReload ||
  563. !gGLManager.mHasRequirements)
  564. {
  565. return;
  566. }
  567. reentrance = true;
  568. // Try and temporarily change the window title. Note that depending on how
  569. // and how fast (compared with the shaders compilation dusration) the
  570. // window manager propagates this change, it might not result in a visible
  571. // change of the window title... HB
  572. HBTempWindowTitle temp_title("Compiling shaders");
  573. #if LL_LINUX
  574. // Note: for Windows, LLSplashScreen::update("Compiling shaders...")
  575. // happens in LLAppViewer::initWindow() on viewer launch, because the
  576. // splash screen cannot be (re)used once the viewer main window created. As
  577. // for macOS, it does not even have a splash screen... HB
  578. HBUpdateSplashScreen splash("Compiling shaders...");
  579. #endif
  580. bool can_do_reflections = false;
  581. S32 reserved_units = 0;
  582. if (gGLManager.mGLSLVersionMajor < 2 && gGLManager.mGLSLVersionMinor <= 20)
  583. {
  584. // NEVER use indexed texture rendering when GLSL version is 1.20 or
  585. // earlier
  586. sIndexedTextureChannels = 1;
  587. }
  588. else
  589. {
  590. S32 max_units = gGLManager.mNumTextureImageUnits;
  591. if (gUsePBRShaders)
  592. {
  593. // Image units needed for PBR with reflection maps.
  594. constexpr S32 MIN_PBR_UNITS = 8;
  595. reserved_units = MIN_PBR_UNITS;
  596. if (max_units > reserved_units)
  597. {
  598. max_units -= reserved_units;
  599. can_do_reflections = true;
  600. }
  601. else
  602. {
  603. max_units = 1;
  604. llwarns << "Not enough available tex units for PBR reflection maps."
  605. << llendl;
  606. }
  607. }
  608. // 1 texture unit at the minimum...
  609. S32 max_tex = llmax(1, gSavedSettings.getU32("RenderMaxTextureIndex"));
  610. sIndexedTextureChannels = llmin(max_tex, max_units);
  611. }
  612. llinfos << "Using up to " << sIndexedTextureChannels + reserved_units
  613. << " image units for shaders";
  614. if (gUsePBRShaders)
  615. {
  616. llcont << " (" << reserved_units
  617. << " reserved units for PBR shadows and reflections plus up to "
  618. << sIndexedTextureChannels << " indexed texture channels)";
  619. }
  620. llcont << "." << llendl;
  621. // Make sure the compiled shader maps are cleared before we recompile
  622. // shaders, and set the shaders directory prefix depending whether we are
  623. // going to use the legacy EE/WL renderer or the PBR one. HB
  624. init();
  625. initAttribsAndUniforms();
  626. gPipeline.releaseGLBuffers();
  627. // *HACK: to reset buffers that change behavior with shaders
  628. gPipeline.resetVertexBuffers();
  629. unloadShaders();
  630. sCanDoRP = can_do_reflections && gGLManager.mGLVersion >= 4.f &&
  631. gFeatureManager.isFeatureAvailable("RenderReflectionProbes");
  632. sHasRP = sCanDoRP && gSavedSettings.getU32("RenderReflectionProbes");
  633. LLPipeline::refreshCachedSettings();
  634. LLShaderMgr::sMirrorsEnabled = LLPipeline::sRenderMirrors;
  635. if (gViewerWindowp)
  636. {
  637. gViewerWindowp->setCursor(UI_CURSOR_WAIT);
  638. }
  639. // Shaders
  640. llinfos << "\n~~~~~~~~~~~~~~~~~~\n Loading Shaders:\n~~~~~~~~~~~~~~~~~~"
  641. << llendl;
  642. llinfos << llformat("Using GLSL %d.%d", gGLManager.mGLSLVersionMajor,
  643. gGLManager.mGLSLVersionMinor) << llendl;
  644. for (S32 i = 0; i < SHADER_COUNT; ++i)
  645. {
  646. mShaderLevel[i] = 0;
  647. }
  648. mMaxAvatarShaderLevel = 0;
  649. LLVertexBuffer::unbind();
  650. // GL_ARB_depth_clamp was so far always disabled because of an issue with
  651. // projectors... Let's use it when available depending on a debug setting,
  652. // to see how it fares... HB
  653. gGLManager.mUseDepthClamp = gGLManager.mHasDepthClamp &&
  654. gSavedSettings.getBool("RenderUseDepthClamp");
  655. if (!gGLManager.mHasDepthClamp)
  656. {
  657. llinfos << "Missing feature GL_ARB_depth_clamp. Void water might disappear in rare cases."
  658. << llendl;
  659. }
  660. else if (gGLManager.mUseDepthClamp)
  661. {
  662. llinfos << "Depth clamping usage is enabled for shaders, which may possibly cause issues with projectors. Change RenderDepthClampShadows and/or RenderUseDepthClamp to FALSE (in this order of preference) if you wish to disable it, and please report successful combination(s) of those settings on the Cool VL Viewer support forum."
  663. << llendl;
  664. }
  665. bool use_deferred = gUsePBRShaders ||
  666. (gFeatureManager.isFeatureAvailable("RenderDeferred") &&
  667. gSavedSettings.getBool("RenderDeferred"));
  668. S32 interface_class, env_class, obj_class, effect_class, water_class,
  669. deferred_class;
  670. interface_class = env_class = obj_class = effect_class = water_class = 2;
  671. if (gUsePBRShaders)
  672. {
  673. deferred_class = water_class = 3;
  674. }
  675. else if (!use_deferred)
  676. {
  677. deferred_class = 0;
  678. }
  679. else if (gSavedSettings.getU32("RenderShadowDetail"))
  680. {
  681. // Shadows on
  682. deferred_class = 2;
  683. }
  684. else
  685. {
  686. // No shadows
  687. deferred_class = 1;
  688. }
  689. // Load lighting shaders
  690. mShaderLevel[SHADER_LIGHTING] = 3;
  691. mShaderLevel[SHADER_INTERFACE] = interface_class;
  692. mShaderLevel[SHADER_ENVIRONMENT] = env_class;
  693. mShaderLevel[SHADER_WATER] = water_class;
  694. mShaderLevel[SHADER_OBJECT] = obj_class;
  695. mShaderLevel[SHADER_EFFECT] = effect_class;
  696. mShaderLevel[SHADER_WINDLIGHT] = 2;
  697. mShaderLevel[SHADER_DEFERRED] = deferred_class;
  698. bool loaded = loadBasicShaders();
  699. if (!loaded)
  700. {
  701. sInitialized = false;
  702. reentrance = false;
  703. mShaderLevel[SHADER_LIGHTING] = 0;
  704. mShaderLevel[SHADER_INTERFACE] = 0;
  705. mShaderLevel[SHADER_ENVIRONMENT] = 0;
  706. mShaderLevel[SHADER_WATER] = 0;
  707. mShaderLevel[SHADER_OBJECT] = 0;
  708. mShaderLevel[SHADER_EFFECT] = 0;
  709. mShaderLevel[SHADER_WINDLIGHT] = 0;
  710. mShaderLevel[SHADER_DEFERRED] = 0;
  711. gPipeline.mVertexShadersLoaded = -1;
  712. llwarns << "Failed to load the basic shaders !" << llendl;
  713. return;
  714. }
  715. gPipeline.mVertexShadersLoaded = 1;
  716. // Load all shaders to set max levels
  717. loaded = loadShadersEnvironment();
  718. if (loaded)
  719. {
  720. loaded = loadShadersWater();
  721. }
  722. if (loaded)
  723. {
  724. loaded = loadShadersWindLight();
  725. }
  726. if (loaded)
  727. {
  728. loaded = loadShadersEffects();
  729. }
  730. if (loaded)
  731. {
  732. loaded = loadShadersInterface();
  733. }
  734. if (loaded)
  735. {
  736. // Load max avatar shaders to set the max level
  737. mShaderLevel[SHADER_AVATAR] = 3;
  738. mMaxAvatarShaderLevel = 3;
  739. if (loadShadersObject())
  740. {
  741. // Skinning shader is enabled and rigged attachment shaders loaded
  742. // correctly
  743. bool avatar_cloth = gSavedSettings.getBool("RenderAvatarCloth");
  744. // Cloth is a class3 shader
  745. S32 avatar_class = avatar_cloth && !gUsePBRShaders ? 3 : 1;
  746. // Set the actual level
  747. mShaderLevel[SHADER_AVATAR] = avatar_class;
  748. loaded = loadShadersAvatar();
  749. if (!gUsePBRShaders && mShaderLevel[SHADER_AVATAR] != avatar_class)
  750. {
  751. if (llmax(mShaderLevel[SHADER_AVATAR] - 1, 0) >= 3)
  752. {
  753. avatar_cloth = true;
  754. }
  755. else
  756. {
  757. avatar_cloth = false;
  758. }
  759. gSavedSettings.setBool("RenderAvatarCloth", avatar_cloth);
  760. }
  761. }
  762. else if (!gUsePBRShaders)
  763. {
  764. // Skinning shader not possible, neither is deferred rendering
  765. mShaderLevel[SHADER_AVATAR] = 0;
  766. mShaderLevel[SHADER_DEFERRED] = 0;
  767. gSavedSettings.setBool("RenderDeferred", false);
  768. gSavedSettings.setBool("RenderAvatarCloth", false);
  769. loadShadersAvatar(); // unloads
  770. loaded = loadShadersObject();
  771. }
  772. }
  773. // Some required shader could not load.
  774. if (!loaded &&
  775. (gUsePBRShaders || !gSavedSettings.getBool("RenderDeferred")))
  776. {
  777. sInitialized = false;
  778. reentrance = false;
  779. // In the PBR case, do not even bother trying to load deferred shaders
  780. // at this point. HB
  781. mShaderLevel[SHADER_DEFERRED] = 0;
  782. llwarns << "Failed to load required shaders !" << llendl;
  783. return;
  784. }
  785. if (loaded && !loadShadersDeferred())
  786. {
  787. if (gUsePBRShaders)
  788. {
  789. // PBR needs deferred shaders, so... HB
  790. sInitialized = false;
  791. reentrance = false;
  792. mShaderLevel[SHADER_DEFERRED] = 0;
  793. llwarns << "Failed to load the deferred shaders !" << llendl;
  794. return;
  795. }
  796. // Everything else succeeded but deferred failed, disable deferred and
  797. // try again.
  798. gSavedSettings.setBool("RenderDeferred", false);
  799. reentrance = false;
  800. setShaders();
  801. return;
  802. }
  803. if (gViewerWindowp)
  804. {
  805. gViewerWindowp->setCursor(UI_CURSOR_ARROW);
  806. }
  807. LLPipeline::refreshCachedSettings();
  808. gPipeline.createGLBuffers();
  809. reentrance = false;
  810. }
  811. void LLViewerShaderMgr::unloadShaders()
  812. {
  813. while (!LLGLSLShader::sInstances.empty())
  814. {
  815. LLGLSLShader* shaderp = *(LLGLSLShader::sInstances.begin());
  816. shaderp->unload();
  817. }
  818. mShaderLevel[SHADER_LIGHTING] = 0;
  819. mShaderLevel[SHADER_OBJECT] = 0;
  820. mShaderLevel[SHADER_AVATAR] = 0;
  821. mShaderLevel[SHADER_ENVIRONMENT] = 0;
  822. mShaderLevel[SHADER_WATER] = 0;
  823. mShaderLevel[SHADER_INTERFACE] = 0;
  824. mShaderLevel[SHADER_EFFECT] = 0;
  825. mShaderLevel[SHADER_WINDLIGHT] = 0;
  826. gPipeline.mVertexShadersLoaded = -1;
  827. }
  828. // Loads basic dependency shaders first. All of these have to load for any
  829. // shaders to function.
  830. bool LLViewerShaderMgr::loadBasicShaders()
  831. {
  832. // Use the feature table to mask out the max light level to use. Also make
  833. // sure it is at least 1.
  834. S32 max_class = gSavedSettings.getU32("RenderShaderLightingMaxLevel");
  835. S32 sum_lights_class = llclamp(max_class, 1, 3);
  836. // Load the Basic Vertex Shaders at the appropriate level (in order of
  837. // shader function call depth for reference purposes, deepest level first).
  838. S32 wl_level = mShaderLevel[SHADER_WINDLIGHT];
  839. S32 light_level = mShaderLevel[SHADER_LIGHTING];
  840. std::vector<std::pair<std::string, S32> > shaders;
  841. shaders.emplace_back("windlight/atmosphericsVarsV.glsl", wl_level);
  842. if (!gUsePBRShaders)
  843. {
  844. shaders.emplace_back("windlight/atmosphericsVarsWaterV.glsl",
  845. wl_level);
  846. }
  847. shaders.emplace_back("windlight/atmosphericsHelpersV.glsl", wl_level);
  848. shaders.emplace_back("lighting/lightFuncV.glsl", light_level);
  849. shaders.emplace_back("lighting/sumLightsV.glsl", sum_lights_class);
  850. shaders.emplace_back("lighting/lightV.glsl", light_level);
  851. shaders.emplace_back("lighting/lightFuncSpecularV.glsl", light_level);
  852. shaders.emplace_back("lighting/sumLightsSpecularV.glsl", sum_lights_class);
  853. shaders.emplace_back("lighting/lightSpecularV.glsl", light_level);
  854. shaders.emplace_back("windlight/atmosphericsFuncs.glsl", wl_level);
  855. shaders.emplace_back("windlight/atmosphericsV.glsl", wl_level);
  856. if (gUsePBRShaders)
  857. {
  858. shaders.emplace_back("environment/srgbF.glsl", 1);
  859. }
  860. shaders.emplace_back("avatar/avatarSkinV.glsl", 1);
  861. shaders.emplace_back("avatar/objectSkinV.glsl", 1);
  862. if (gUsePBRShaders)
  863. {
  864. shaders.emplace_back("deferred/textureUtilV.glsl", 1);
  865. }
  866. if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30)
  867. {
  868. shaders.emplace_back("objects/indexedTextureV.glsl", 1);
  869. }
  870. shaders.emplace_back("objects/nonindexedTextureV.glsl", 1);
  871. LLGLSLShader::defines_map_t attribs;
  872. attribs["MAX_JOINTS_PER_MESH_OBJECT"] =
  873. llformat("%d", LL_MAX_JOINTS_PER_MESH_OBJECT);
  874. bool has_ssr = false;
  875. if (gUsePBRShaders)
  876. {
  877. U32 shadow_detail = gSavedSettings.getU32("RenderShadowDetail");
  878. if (shadow_detail >= 1)
  879. {
  880. attribs["SUN_SHADOW"] = "1";
  881. if (shadow_detail >= 2)
  882. {
  883. attribs["SPOT_SHADOW"] = "1";
  884. }
  885. }
  886. if (sHasRP && gSavedSettings.getBool("RenderScreenSpaceReflections"))
  887. {
  888. has_ssr = true;
  889. attribs["SSR"] = "1";
  890. }
  891. llinfos << "Screen space reflections "
  892. << (has_ssr ? "enabled" : "disabled") << llendl;
  893. if (sHasRP)
  894. {
  895. U32 probe_level =
  896. llmin(3, gSavedSettings.getU32("RenderReflectionProbeLevel"));
  897. llinfos << "Reflection probe level: " << probe_level << llendl;
  898. attribs["REFMAP_LEVEL"] = llformat("%u", probe_level);
  899. attribs["REF_SAMPLE_COUNT"] = "32";
  900. }
  901. else
  902. {
  903. llinfos << "Reflection probes disabled." << llendl;
  904. }
  905. // PBR terrain
  906. S32 d = -4;
  907. S32 s = 1;
  908. F32 f = gSavedSettings.getF32("RenderTerrainPBRBlendFactor");
  909. if (LLPipeline::sRenderPBRTerrain)
  910. {
  911. d = LLPipeline::sRenderPBRTerrainDetail;
  912. s = gSavedSettings.getBool("RenderTerrainPBRTriplanar") ? 3 : 1;
  913. }
  914. attribs["TERRAIN_PBR_DETAIL"] = llformat("%d", d);
  915. attribs["TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT"] = llformat("%d", s);
  916. attribs["TERRAIN_TRIPLANAR_BLEND_FACTOR"] =
  917. llformat("%.2f", llclamp(f, 1.f, 32.f));
  918. }
  919. stop_glerror();
  920. // We no longer have to bind the shaders to global GLhandles, they are
  921. // automatically added to a map now.
  922. for (U32 i = 0, count = shaders.size(); i < count; ++i)
  923. {
  924. // Note usage of GL_VERTEX_SHADER
  925. if (loadShaderFile(shaders[i].first, shaders[i].second,
  926. GL_VERTEX_SHADER, &attribs) == 0)
  927. {
  928. return false;
  929. }
  930. }
  931. // Load the Basic Fragment Shaders at the appropriate level (in order of
  932. // shader function call depth for reference purposes, deepest level first).
  933. shaders.clear();
  934. S32 ch = 1;
  935. if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30)
  936. {
  937. // Use indexed texture rendering for GLSL >= 1.30
  938. if (gUsePBRShaders)
  939. {
  940. ch = llmax(sIndexedTextureChannels, 1);
  941. }
  942. else
  943. {
  944. ch = llmax(sIndexedTextureChannels - 1, 1);
  945. }
  946. }
  947. std::vector<S32> index_channels;
  948. index_channels.push_back(-1);
  949. shaders.emplace_back("windlight/atmosphericsVarsF.glsl", wl_level);
  950. if (!gUsePBRShaders)
  951. {
  952. index_channels.push_back(-1);
  953. shaders.emplace_back("windlight/atmosphericsVarsWaterF.glsl",
  954. wl_level);
  955. }
  956. index_channels.push_back(-1);
  957. shaders.emplace_back("windlight/atmosphericsHelpersF.glsl", wl_level);
  958. index_channels.push_back(-1);
  959. shaders.emplace_back("windlight/gammaF.glsl", wl_level);
  960. index_channels.push_back(-1);
  961. shaders.emplace_back("windlight/atmosphericsFuncs.glsl", wl_level);
  962. index_channels.push_back(-1);
  963. shaders.emplace_back("windlight/atmosphericsF.glsl", wl_level);
  964. if (!gUsePBRShaders)
  965. {
  966. index_channels.push_back(-1);
  967. shaders.emplace_back("windlight/transportF.glsl", wl_level);
  968. }
  969. index_channels.push_back(-1);
  970. shaders.emplace_back("environment/waterFogF.glsl",
  971. mShaderLevel[SHADER_WATER]);
  972. S32 env_level = mShaderLevel[SHADER_ENVIRONMENT];
  973. if (!gUsePBRShaders)
  974. {
  975. index_channels.push_back(-1);
  976. shaders.emplace_back("environment/encodeNormF.glsl", env_level);
  977. }
  978. index_channels.push_back(-1);
  979. shaders.emplace_back("environment/srgbF.glsl", env_level);
  980. index_channels.push_back(-1);
  981. shaders.emplace_back("deferred/deferredUtil.glsl", 1);
  982. if (gUsePBRShaders)
  983. {
  984. index_channels.push_back(-1);
  985. shaders.emplace_back("deferred/globalF.glsl", 1);
  986. }
  987. index_channels.push_back(-1);
  988. shaders.emplace_back("deferred/shadowUtil.glsl", 1);
  989. index_channels.push_back(-1);
  990. shaders.emplace_back("deferred/aoUtil.glsl", 1);
  991. if (gUsePBRShaders)
  992. {
  993. index_channels.push_back(-1);
  994. shaders.emplace_back("deferred/pbrterrainUtilF.glsl", 1);
  995. index_channels.push_back(-1);
  996. shaders.emplace_back("deferred/reflectionProbeF.glsl", sHasRP ? 3 : 2);
  997. index_channels.push_back(-1);
  998. shaders.emplace_back("deferred/screenSpaceReflUtil.glsl",
  999. has_ssr ? 3 : 1);
  1000. }
  1001. index_channels.push_back(-1);
  1002. shaders.emplace_back("lighting/lightNonIndexedF.glsl", light_level);
  1003. index_channels.push_back(-1);
  1004. shaders.emplace_back("lighting/lightAlphaMaskNonIndexedF.glsl",
  1005. light_level);
  1006. if (!gUsePBRShaders)
  1007. {
  1008. index_channels.push_back(-1);
  1009. shaders.emplace_back("lighting/lightFullbrightNonIndexedF.glsl",
  1010. light_level);
  1011. index_channels.push_back(-1);
  1012. shaders.emplace_back("lighting/lightFullbrightNonIndexedAlphaMaskF.glsl",
  1013. light_level);
  1014. index_channels.push_back(-1);
  1015. shaders.emplace_back("lighting/lightWaterNonIndexedF.glsl",
  1016. light_level);
  1017. index_channels.push_back(-1);
  1018. shaders.emplace_back("lighting/lightWaterAlphaMaskNonIndexedF.glsl",
  1019. light_level);
  1020. index_channels.push_back(-1);
  1021. shaders.emplace_back("lighting/lightFullbrightWaterNonIndexedF.glsl",
  1022. light_level);
  1023. index_channels.push_back(-1);
  1024. shaders.emplace_back("lighting/lightFullbrightWaterNonIndexedAlphaMaskF.glsl",
  1025. light_level);
  1026. index_channels.push_back(-1);
  1027. shaders.emplace_back("lighting/lightShinyNonIndexedF.glsl",
  1028. light_level);
  1029. index_channels.push_back(-1);
  1030. shaders.emplace_back("lighting/lightFullbrightShinyNonIndexedF.glsl",
  1031. light_level);
  1032. index_channels.push_back(-1);
  1033. shaders.emplace_back("lighting/lightShinyWaterNonIndexedF.glsl",
  1034. light_level);
  1035. index_channels.push_back(-1);
  1036. shaders.emplace_back("lighting/lightFullbrightShinyWaterNonIndexedF.glsl",
  1037. light_level);
  1038. }
  1039. index_channels.push_back(ch);
  1040. shaders.emplace_back("lighting/lightF.glsl", light_level);
  1041. index_channels.push_back(ch);
  1042. shaders.emplace_back("lighting/lightAlphaMaskF.glsl", light_level);
  1043. if (!gUsePBRShaders)
  1044. {
  1045. index_channels.push_back(ch);
  1046. shaders.emplace_back("lighting/lightFullbrightF.glsl", light_level);
  1047. index_channels.push_back(ch);
  1048. shaders.emplace_back("lighting/lightFullbrightAlphaMaskF.glsl",
  1049. light_level);
  1050. index_channels.push_back(ch);
  1051. shaders.emplace_back("lighting/lightWaterF.glsl", light_level);
  1052. index_channels.push_back(ch);
  1053. shaders.emplace_back("lighting/lightWaterAlphaMaskF.glsl",
  1054. light_level);
  1055. index_channels.push_back(ch);
  1056. shaders.emplace_back("lighting/lightFullbrightWaterF.glsl",
  1057. light_level);
  1058. index_channels.push_back(ch);
  1059. shaders.emplace_back("lighting/lightFullbrightWaterAlphaMaskF.glsl",
  1060. light_level);
  1061. index_channels.push_back(ch);
  1062. shaders.emplace_back("lighting/lightShinyF.glsl", light_level);
  1063. index_channels.push_back(ch);
  1064. shaders.emplace_back("lighting/lightFullbrightShinyF.glsl",
  1065. light_level);
  1066. index_channels.push_back(ch);
  1067. shaders.emplace_back("lighting/lightShinyWaterF.glsl", light_level);
  1068. index_channels.push_back(ch);
  1069. shaders.emplace_back("lighting/lightFullbrightShinyWaterF.glsl",
  1070. light_level);
  1071. }
  1072. for (U32 i = 0; i < shaders.size(); ++i)
  1073. {
  1074. // Note usage of GL_FRAGMENT_SHADER
  1075. if (loadShaderFile(shaders[i].first, shaders[i].second,
  1076. GL_FRAGMENT_SHADER, &attribs,
  1077. index_channels[i]) == 0)
  1078. {
  1079. return false;
  1080. }
  1081. }
  1082. llinfos << "Basic shaders loaded." << llendl;
  1083. return true;
  1084. }
  1085. bool LLViewerShaderMgr::loadShadersEnvironment()
  1086. {
  1087. S32 shader_level = mShaderLevel[SHADER_ENVIRONMENT];
  1088. if (shader_level == 0 || gUsePBRShaders)
  1089. {
  1090. gTerrainProgram.unload();
  1091. gMoonProgram.unload();
  1092. gStarsProgram.unload();
  1093. return true;
  1094. }
  1095. gTerrainProgram.setup("Terrain shader", shader_level,
  1096. "environment/terrainV.glsl",
  1097. "environment/terrainF.glsl");
  1098. gTerrainProgram.mFeatures.mIndexedTextureChannels = 0;
  1099. gTerrainProgram.mFeatures.calculatesLighting = true;
  1100. gTerrainProgram.mFeatures.calculatesAtmospherics = true;
  1101. gTerrainProgram.mFeatures.hasAtmospherics = true;
  1102. gTerrainProgram.mFeatures.disableTextureIndex = true;
  1103. gTerrainProgram.mFeatures.hasGamma = true;
  1104. gTerrainProgram.mFeatures.hasTransport = true;
  1105. gTerrainProgram.mFeatures.hasSrgb = true;
  1106. bool success = gTerrainProgram.createShader();
  1107. if (success)
  1108. {
  1109. gStarsProgram.setup("Environment stars shader", shader_level,
  1110. "environment/starsV.glsl",
  1111. "environment/starsF.glsl");
  1112. gStarsProgram.addConstant(LLGLSLShader::CONST_STAR_DEPTH);
  1113. success = gStarsProgram.createShader();
  1114. }
  1115. if (success)
  1116. {
  1117. gMoonProgram.setup("Environment Moon shader", shader_level,
  1118. "environment/moonV.glsl", "environment/moonF.glsl");
  1119. gMoonProgram.addConstant(LLGLSLShader::CONST_CLOUD_MOON_DEPTH);
  1120. success = gMoonProgram.createShader();
  1121. if (success)
  1122. {
  1123. gMoonProgram.bind();
  1124. gMoonProgram.uniform1i(sTex0, 0);
  1125. gMoonProgram.unbind();
  1126. }
  1127. }
  1128. if (success)
  1129. {
  1130. gWorld.updateWaterObjects();
  1131. llinfos << "Environment shaders loaded at level: " << shader_level
  1132. << llendl;
  1133. return true;
  1134. }
  1135. mShaderLevel[SHADER_ENVIRONMENT] = 0;
  1136. return false;
  1137. }
  1138. bool LLViewerShaderMgr::loadShadersWater()
  1139. {
  1140. S32 shader_level = mShaderLevel[SHADER_WATER];
  1141. if (shader_level == 0)
  1142. {
  1143. gWaterProgram.unload();
  1144. gWaterEdgeProgram.unload();
  1145. gUnderWaterProgram.unload();
  1146. gTerrainWaterProgram.unload();
  1147. return true;
  1148. }
  1149. bool use_sun_shadow = false;
  1150. if (gUsePBRShaders)
  1151. {
  1152. use_sun_shadow = mShaderLevel[SHADER_DEFERRED] > 1 &&
  1153. gSavedSettings.getU32("RenderShadowDetail");
  1154. }
  1155. // Load water shader
  1156. gWaterProgram.setup("Water shader", shader_level,
  1157. "environment/waterV.glsl",
  1158. "environment/waterF.glsl");
  1159. gWaterProgram.mFeatures.calculatesAtmospherics = true;
  1160. gWaterProgram.mFeatures.hasGamma = true;
  1161. gWaterProgram.mFeatures.hasSrgb = true;
  1162. if (gUsePBRShaders)
  1163. {
  1164. gWaterProgram.mFeatures.hasAtmospherics = true;
  1165. gWaterProgram.mFeatures.hasReflectionProbes = true;
  1166. gWaterProgram.mFeatures.hasShadows = use_sun_shadow;
  1167. if (use_sun_shadow)
  1168. {
  1169. gWaterProgram.addPermutation("HAS_SUN_SHADOW", "1");
  1170. }
  1171. if (LLPipeline::RenderTransparentWater)
  1172. {
  1173. gWaterProgram.addPermutation("TRANSPARENT_WATER", "1");
  1174. }
  1175. }
  1176. else
  1177. {
  1178. gWaterProgram.mFeatures.hasTransport = true;
  1179. }
  1180. gWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1181. bool success = gWaterProgram.createShader();
  1182. if (success)
  1183. {
  1184. // Load under water edge shader
  1185. gWaterEdgeProgram.setup("Water edge shader", shader_level,
  1186. "environment/waterV.glsl",
  1187. "environment/waterF.glsl");
  1188. gWaterEdgeProgram.mFeatures.calculatesAtmospherics = true;
  1189. gWaterEdgeProgram.mFeatures.hasGamma = true;
  1190. gWaterEdgeProgram.mFeatures.hasSrgb = true;
  1191. if (gUsePBRShaders)
  1192. {
  1193. gWaterEdgeProgram.mFeatures.hasAtmospherics = true;
  1194. gWaterEdgeProgram.mFeatures.hasReflectionProbes = true;
  1195. gWaterEdgeProgram.mFeatures.hasShadows = use_sun_shadow;
  1196. if (use_sun_shadow)
  1197. {
  1198. gWaterEdgeProgram.addPermutation("HAS_SUN_SHADOW", "1");
  1199. }
  1200. if (LLPipeline::RenderTransparentWater)
  1201. {
  1202. gWaterEdgeProgram.addPermutation("TRANSPARENT_WATER", "1");
  1203. }
  1204. }
  1205. else
  1206. {
  1207. gWaterEdgeProgram.mFeatures.hasTransport = true;
  1208. }
  1209. gWaterEdgeProgram.addPermutation("WATER_EDGE", "1");
  1210. gWaterEdgeProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1211. success = gWaterEdgeProgram.createShader();
  1212. }
  1213. if (success)
  1214. {
  1215. // Load under water vertex shader
  1216. gUnderWaterProgram.setup("Underwater shader", shader_level,
  1217. "environment/waterV.glsl",
  1218. "environment/underWaterF.glsl");
  1219. gUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1220. gUnderWaterProgram.mFeatures.calculatesAtmospherics = true;
  1221. if (gUsePBRShaders)
  1222. {
  1223. gUnderWaterProgram.mFeatures.hasAtmospherics = true;
  1224. }
  1225. else
  1226. {
  1227. gUnderWaterProgram.mFeatures.hasWaterFog = true;
  1228. }
  1229. if (gUsePBRShaders && LLPipeline::RenderTransparentWater)
  1230. {
  1231. gUnderWaterProgram.addPermutation("TRANSPARENT_WATER", "1");
  1232. }
  1233. success = gUnderWaterProgram.createShader();
  1234. }
  1235. bool terrain_water_success = true;
  1236. if (success && !gUsePBRShaders)
  1237. {
  1238. // Load terrain water shader
  1239. gTerrainWaterProgram.setup("Terrain water shader",
  1240. mShaderLevel[SHADER_ENVIRONMENT],
  1241. "environment/terrainWaterV.glsl",
  1242. "environment/terrainWaterF.glsl");
  1243. gTerrainWaterProgram.mFeatures.calculatesLighting = true;
  1244. gTerrainWaterProgram.mFeatures.calculatesAtmospherics = true;
  1245. gTerrainWaterProgram.mFeatures.hasAtmospherics = true;
  1246. gTerrainWaterProgram.mFeatures.hasWaterFog = true;
  1247. gTerrainWaterProgram.mFeatures.mIndexedTextureChannels = 0;
  1248. gTerrainWaterProgram.mFeatures.disableTextureIndex = true;
  1249. gTerrainWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  1250. if (LLPipeline::sRenderDeferred)
  1251. {
  1252. gTerrainWaterProgram.addPermutation("ALM", "1");
  1253. }
  1254. terrain_water_success = gTerrainWaterProgram.createShader();
  1255. }
  1256. // Keep track of water shader levels
  1257. if (gWaterProgram.mShaderLevel != shader_level ||
  1258. gUnderWaterProgram.mShaderLevel != shader_level)
  1259. {
  1260. mShaderLevel[SHADER_WATER] =
  1261. llmin(gWaterProgram.mShaderLevel, gUnderWaterProgram.mShaderLevel);
  1262. }
  1263. if (!success)
  1264. {
  1265. mShaderLevel[SHADER_WATER] = 0;
  1266. return false;
  1267. }
  1268. // If we failed to load the terrain water shaders and we need them (using
  1269. // class2 water), then drop down to class1 water.
  1270. if (mShaderLevel[SHADER_WATER] > 1 && !terrain_water_success)
  1271. {
  1272. --mShaderLevel[SHADER_WATER];
  1273. return loadShadersWater();
  1274. }
  1275. gWorld.updateWaterObjects();
  1276. llinfos << "Water shaders loaded at level: " << mShaderLevel[SHADER_WATER]
  1277. << llendl;
  1278. return true;
  1279. }
  1280. bool LLViewerShaderMgr::loadShadersEffects()
  1281. {
  1282. S32 shader_level = mShaderLevel[SHADER_EFFECT];
  1283. if (shader_level == 0)
  1284. {
  1285. gGlowProgram.unload();
  1286. gGlowExtractProgram.unload();
  1287. return true;
  1288. }
  1289. gGlowProgram.setup("Glow shader (post)", shader_level,
  1290. "effects/glowV.glsl", "effects/glowF.glsl");
  1291. bool success = gGlowProgram.createShader();
  1292. if (success)
  1293. {
  1294. gGlowExtractProgram.setup("Glow extract shader (post)", shader_level,
  1295. "effects/glowExtractV.glsl",
  1296. "effects/glowExtractF.glsl");
  1297. if (gUsePBRShaders && gSavedSettings.getBool("RenderGlowNoise"))
  1298. {
  1299. gGlowExtractProgram.addPermutation("HAS_NOISE", "1");
  1300. }
  1301. success = gGlowExtractProgram.createShader();
  1302. }
  1303. LLPipeline::sCanRenderGlow = success;
  1304. if (success)
  1305. {
  1306. llinfos << "Effects shaders loaded at level: " << shader_level
  1307. << llendl;
  1308. }
  1309. return success;
  1310. }
  1311. bool LLViewerShaderMgr::loadShadersDeferred()
  1312. {
  1313. sHasFXAA = sHasSMAA = sHasCAS = false;
  1314. S32 shader_level = mShaderLevel[SHADER_DEFERRED];
  1315. bool use_sun_shadow = shader_level > 1;
  1316. if (gUsePBRShaders)
  1317. {
  1318. use_sun_shadow &= gSavedSettings.getU32("RenderShadowDetail") > 0;
  1319. }
  1320. if (shader_level == 0)
  1321. {
  1322. gDeferredTreeProgram.unload();
  1323. gDeferredTreeShadowProgram.unload();
  1324. gDeferredSkinnedTreeShadowProgram.unload();
  1325. gDeferredHighlightProgram.unload();
  1326. gDeferredDiffuseProgram.unload();
  1327. gDeferredSkinnedDiffuseProgram.unload();
  1328. gDeferredDiffuseAlphaMaskProgram.unload();
  1329. gDeferredSkinnedDiffuseAlphaMaskProgram.unload();
  1330. gDeferredNonIndexedDiffuseAlphaMaskProgram.unload();
  1331. gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.unload();
  1332. gDeferredBumpProgram.unload();
  1333. gDeferredSkinnedBumpProgram.unload();
  1334. gDeferredImpostorProgram.unload();
  1335. gDeferredTerrainProgram.unload();
  1336. gDeferredTerrainWaterProgram.unload();
  1337. gDeferredLightProgram.unload();
  1338. for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; ++i)
  1339. {
  1340. gDeferredMultiLightProgram[i].unload();
  1341. }
  1342. gDeferredSpotLightProgram.unload();
  1343. gDeferredMultiSpotLightProgram.unload();
  1344. gDeferredSunProgram.unload();
  1345. gDeferredBlurLightProgram.unload();
  1346. gHazeProgram.unload();
  1347. gHazeWaterProgram.unload();
  1348. gDeferredSoftenProgram.unload();
  1349. gDeferredSoftenWaterProgram.unload();
  1350. gDeferredShadowProgram.unload();
  1351. gDeferredSkinnedShadowProgram.unload();
  1352. gDeferredShadowCubeProgram.unload();
  1353. gDeferredShadowAlphaMaskProgram.unload();
  1354. gDeferredSkinnedShadowAlphaMaskProgram.unload();
  1355. gDeferredShadowGLTFAlphaMaskProgram.unload();
  1356. gDeferredSkinnedShadowGLTFAlphaMaskProgram.unload();
  1357. gDeferredShadowGLTFAlphaBlendProgram.unload();
  1358. gDeferredSkinnedShadowGLTFAlphaBlendProgram.unload();
  1359. gDeferredShadowFullbrightAlphaMaskProgram.unload();
  1360. gDeferredSkinnedShadowFullbrightAlphaMaskProgram.unload();
  1361. gDeferredAvatarShadowProgram.unload();
  1362. gDeferredAvatarAlphaShadowProgram.unload();
  1363. gDeferredAvatarAlphaMaskShadowProgram.unload();
  1364. gDeferredAvatarProgram.unload();
  1365. gDeferredAvatarAlphaProgram.unload();
  1366. gDeferredAlphaProgram.unload();
  1367. gHUDAlphaProgram.unload();
  1368. gDeferredSkinnedAlphaProgram.unload();
  1369. gDeferredAlphaWaterProgram.unload();
  1370. gDeferredSkinnedAlphaWaterProgram.unload();
  1371. gDeferredFullbrightProgram.unload();
  1372. gDeferredFullbrightAlphaMaskProgram.unload();
  1373. gDeferredFullbrightAlphaMaskAlphaProgram.unload();
  1374. gHUDFullbrightProgram.unload();
  1375. gHUDFullbrightAlphaMaskProgram.unload();
  1376. gHUDFullbrightAlphaMaskAlphaProgram.unload();
  1377. gDeferredFullbrightWaterProgram.unload();
  1378. gDeferredSkinnedFullbrightWaterProgram.unload();
  1379. gDeferredFullbrightAlphaMaskWaterProgram.unload();
  1380. gDeferredSkinnedFullbrightAlphaMaskWaterProgram.unload();
  1381. gDeferredEmissiveProgram.unload();
  1382. gDeferredSkinnedEmissiveProgram.unload();
  1383. gDeferredAvatarEyesProgram.unload();
  1384. gDeferredPostProgram.unload();
  1385. gDeferredCoFProgram.unload();
  1386. gDeferredDoFCombineProgram.unload();
  1387. gDeferredPostGammaCorrectProgram.unload();
  1388. gExposureProgram.unload();
  1389. gExposureProgramNoFade.unload();
  1390. gLuminanceProgram.unload();
  1391. gNoPostGammaCorrectProgram.unload();
  1392. gLegacyPostGammaCorrectProgram.unload();
  1393. for (U32 i = 0; i < 4; ++i)
  1394. {
  1395. gFXAAProgram[i].unload();
  1396. gPostSMAAEdgeDetect[i].unload();
  1397. gPostSMAABlendWeights[i].unload();
  1398. gPostSMAANeighborhoodBlend[i].unload();
  1399. }
  1400. gPostCASProgram.unload();
  1401. gDeferredWaterProgram.unload();
  1402. gDeferredUnderWaterProgram.unload();
  1403. gEnvironmentMapProgram.unload();
  1404. gDeferredWLSkyProgram.unload();
  1405. gDeferredWLCloudProgram.unload();
  1406. gDeferredWLSunProgram.unload();
  1407. gDeferredWLMoonProgram.unload();
  1408. gDeferredStarProgram.unload();
  1409. gDeferredFullbrightShinyProgram.unload();
  1410. gHUDFullbrightShinyProgram.unload();
  1411. gDeferredSkinnedFullbrightShinyProgram.unload();
  1412. gDeferredSkinnedFullbrightProgram.unload();
  1413. gDeferredSkinnedFullbrightAlphaMaskProgram.unload();
  1414. gDeferredSkinnedFullbrightAlphaMaskAlphaProgram.unload();
  1415. gNormalMapGenProgram.unload();
  1416. gDeferredGenBrdfLutProgram.unload();
  1417. gPostScreenSpaceReflectionProgram.unload();
  1418. gDeferredBufferVisualProgram.unload();
  1419. for (U32 i = 0; i < LLMaterial::SHADER_COUNT * 2; ++i)
  1420. {
  1421. gDeferredMaterialProgram[i].unload();
  1422. gDeferredMaterialWaterProgram[i].unload();
  1423. }
  1424. gHUDPBROpaqueProgram.unload();
  1425. gPBRGlowProgram.unload();
  1426. gPBRGlowSkinnedProgram.unload();
  1427. gDeferredPBROpaqueProgram.unload();
  1428. gDeferredSkinnedPBROpaqueProgram.unload();
  1429. gDeferredPBRAlphaProgram.unload();
  1430. gDeferredSkinnedPBRAlphaProgram.unload();
  1431. gDeferredPBRTerrainProgram.unload();
  1432. return true;
  1433. }
  1434. LLGLSLShader* shaderp = &gDeferredDiffuseProgram;
  1435. shaderp->setup("Deferred diffuse shader", shader_level,
  1436. "deferred/diffuseV.glsl", "deferred/diffuseIndexedF.glsl");
  1437. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  1438. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1439. shaderp->mFeatures.hasSrgb = true;
  1440. bool success = create_with_rigged(*shaderp,
  1441. gDeferredSkinnedDiffuseProgram);
  1442. if (success && gUsePBRShaders)
  1443. {
  1444. gDeferredHighlightProgram.setup("Deferred highlight shader",
  1445. mShaderLevel[SHADER_INTERFACE],
  1446. "interface/highlightV.glsl",
  1447. "deferred/highlightF.glsl");
  1448. success = gDeferredHighlightProgram.createShader();
  1449. }
  1450. if (success)
  1451. {
  1452. shaderp = &gDeferredDiffuseAlphaMaskProgram;
  1453. shaderp->setup("Deferred diffuse alpha mask shader", shader_level,
  1454. "deferred/diffuseV.glsl",
  1455. "deferred/diffuseAlphaMaskIndexedF.glsl");
  1456. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  1457. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1458. success = create_with_rigged(*shaderp,
  1459. gDeferredSkinnedDiffuseAlphaMaskProgram);
  1460. }
  1461. if (success)
  1462. {
  1463. shaderp = &gDeferredNonIndexedDiffuseAlphaMaskProgram;
  1464. shaderp->setup("Deferred diffuse non-indexed alpha mask shader",
  1465. shader_level, "deferred/diffuseV.glsl",
  1466. "deferred/diffuseAlphaMaskF.glsl");
  1467. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1468. success = shaderp->createShader();
  1469. }
  1470. if (success)
  1471. {
  1472. shaderp = &gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
  1473. shaderp->setup("Deferred diffuse non-indexed alpha mask no color shader",
  1474. shader_level, "deferred/diffuseNoColorV.glsl",
  1475. "deferred/diffuseAlphaMaskNoColorF.glsl");
  1476. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1477. success = shaderp->createShader();
  1478. }
  1479. if (success)
  1480. {
  1481. gDeferredBumpProgram.setup("Deferred bump shader", shader_level,
  1482. "deferred/bumpV.glsl",
  1483. "deferred/bumpF.glsl");
  1484. // Note: ignored by PBR
  1485. gDeferredBumpProgram.mFeatures.encodesNormal = true;
  1486. success = create_with_rigged(gDeferredBumpProgram,
  1487. gDeferredSkinnedBumpProgram);
  1488. }
  1489. std::string name;
  1490. for (U32 i = 0; success && i < LLMaterial::SHADER_COUNT * 2; ++i)
  1491. {
  1492. U32 alpha_mode = i & 0x3;
  1493. std::string alpha_mode_str = llformat("%d", alpha_mode);
  1494. bool has_specular_map = i & 0x4;
  1495. bool has_normal_map = i & 0x8;
  1496. bool has_skin = i & 0x10;
  1497. shaderp = &gDeferredMaterialProgram[i];
  1498. name = llformat("Deferred material shader %d", i);
  1499. shaderp->setup(name.c_str(), shader_level, "deferred/materialV.glsl",
  1500. "deferred/materialF.glsl");
  1501. shaderp->addPermutation("DIFFUSE_ALPHA_MODE", alpha_mode_str);
  1502. if (alpha_mode)
  1503. {
  1504. shaderp->mFeatures.hasAlphaMask = true;
  1505. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  1506. }
  1507. shaderp->mFeatures.hasShadows = use_sun_shadow;
  1508. if (use_sun_shadow)
  1509. {
  1510. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  1511. }
  1512. if (has_normal_map)
  1513. {
  1514. shaderp->addPermutation("HAS_NORMAL_MAP", "1");
  1515. }
  1516. if (has_specular_map)
  1517. {
  1518. shaderp->addPermutation("HAS_SPECULAR_MAP", "1");
  1519. }
  1520. shaderp->mFeatures.hasSrgb = true;
  1521. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1522. if (alpha_mode == 1 || gUsePBRShaders)
  1523. {
  1524. if (gUsePBRShaders)
  1525. {
  1526. shaderp->mFeatures.hasReflectionProbes = true;
  1527. }
  1528. else
  1529. {
  1530. shaderp->mFeatures.hasTransport = true;
  1531. }
  1532. // *TODO: verify this is needed for PBR when alpha_mode != 1. HB
  1533. shaderp->mFeatures.calculatesAtmospherics = true;
  1534. shaderp->mFeatures.hasAtmospherics = true;
  1535. shaderp->mFeatures.hasGamma = true;
  1536. }
  1537. if (has_skin)
  1538. {
  1539. shaderp->addPermutation("HAS_SKIN", "1");
  1540. shaderp->mFeatures.hasObjectSkinning = true;
  1541. }
  1542. else
  1543. {
  1544. shaderp->mRiggedVariant = &gDeferredMaterialProgram[i + 0x10];
  1545. }
  1546. success = shaderp->createShader();
  1547. if (!success) break;
  1548. if (!has_skin || !gUsePBRShaders)
  1549. {
  1550. mShaderList.push_back(shaderp);
  1551. }
  1552. if (gUsePBRShaders)
  1553. {
  1554. continue; // No water shader needed any more for PBR
  1555. }
  1556. shaderp = &gDeferredMaterialWaterProgram[i];
  1557. name = llformat("Deferred underwater material shader %d", i);
  1558. shaderp->setup(name.c_str(), shader_level, "deferred/materialV.glsl",
  1559. "deferred/materialF.glsl");
  1560. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  1561. shaderp->addPermutation("WATER_FOG", "1");
  1562. shaderp->addPermutation("DIFFUSE_ALPHA_MODE", alpha_mode_str);
  1563. if (alpha_mode)
  1564. {
  1565. shaderp->mFeatures.hasAlphaMask = true;
  1566. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  1567. }
  1568. shaderp->mFeatures.hasShadows = use_sun_shadow;
  1569. if (use_sun_shadow)
  1570. {
  1571. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  1572. }
  1573. if (has_normal_map)
  1574. {
  1575. shaderp->addPermutation("HAS_NORMAL_MAP", "1");
  1576. }
  1577. if (has_specular_map)
  1578. {
  1579. shaderp->addPermutation("HAS_SPECULAR_MAP", "1");
  1580. }
  1581. shaderp->mFeatures.hasSrgb = true;
  1582. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1583. if (alpha_mode == 1)
  1584. {
  1585. shaderp->mFeatures.hasTransport = true;
  1586. shaderp->mFeatures.hasWaterFog = true;
  1587. shaderp->mFeatures.calculatesAtmospherics = true;
  1588. shaderp->mFeatures.hasAtmospherics = true;
  1589. shaderp->mFeatures.hasGamma = true;
  1590. }
  1591. if (has_skin)
  1592. {
  1593. shaderp->addPermutation("HAS_SKIN", "1");
  1594. shaderp->mFeatures.hasObjectSkinning = true;
  1595. }
  1596. else
  1597. {
  1598. shaderp->mRiggedVariant = &gDeferredMaterialWaterProgram[i + 0x10];
  1599. }
  1600. success = shaderp->createShader();
  1601. if (success)
  1602. {
  1603. mShaderList.push_back(shaderp);
  1604. }
  1605. }
  1606. gDeferredMaterialProgram[1].mFeatures.hasLighting = true;
  1607. gDeferredMaterialProgram[5].mFeatures.hasLighting = true;
  1608. gDeferredMaterialProgram[9].mFeatures.hasLighting = true;
  1609. gDeferredMaterialProgram[13].mFeatures.hasLighting = true;
  1610. gDeferredMaterialProgram[1 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1611. gDeferredMaterialProgram[5 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1612. gDeferredMaterialProgram[9 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1613. gDeferredMaterialProgram[13 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1614. if (!gUsePBRShaders)
  1615. {
  1616. gDeferredMaterialWaterProgram[1].mFeatures.hasLighting = true;
  1617. gDeferredMaterialWaterProgram[5].mFeatures.hasLighting = true;
  1618. gDeferredMaterialWaterProgram[9].mFeatures.hasLighting = true;
  1619. gDeferredMaterialWaterProgram[13].mFeatures.hasLighting = true;
  1620. gDeferredMaterialWaterProgram[1 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1621. gDeferredMaterialWaterProgram[5 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1622. gDeferredMaterialWaterProgram[9 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1623. gDeferredMaterialWaterProgram[13 + LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
  1624. }
  1625. if (success && gUsePBRShaders)
  1626. {
  1627. gDeferredPBROpaqueProgram.setup("Deferred PBR opaque shader",
  1628. shader_level,
  1629. "deferred/pbropaqueV.glsl",
  1630. "deferred/pbropaqueF.glsl");
  1631. gDeferredPBROpaqueProgram.mFeatures.hasSrgb = true;
  1632. success = create_with_rigged(gDeferredPBROpaqueProgram,
  1633. gDeferredSkinnedPBROpaqueProgram);
  1634. }
  1635. if (success && gUsePBRShaders)
  1636. {
  1637. gHUDPBROpaqueProgram.setup("Deferred HUD PBR opaque shader",
  1638. shader_level, "deferred/pbropaqueV.glsl",
  1639. "deferred/pbropaqueF.glsl");
  1640. gHUDPBROpaqueProgram.mFeatures.hasSrgb = true;
  1641. gHUDPBROpaqueProgram.addPermutation("IS_HUD", "1");
  1642. success = gHUDPBROpaqueProgram.createShader();
  1643. }
  1644. if (success && gUsePBRShaders)
  1645. {
  1646. gPBRGlowProgram.setup("Deferred PBR glow shader", shader_level,
  1647. "deferred/pbrglowV.glsl",
  1648. "deferred/pbrglowF.glsl");
  1649. gPBRGlowProgram.mFeatures.hasSrgb = true;
  1650. success = create_with_rigged(gPBRGlowProgram, gPBRGlowSkinnedProgram);
  1651. }
  1652. std::string dam;
  1653. if (success && gUsePBRShaders)
  1654. {
  1655. shaderp = &gDeferredPBRAlphaProgram;
  1656. shaderp->setup("Deferred PBR alpha shader", shader_level,
  1657. "deferred/pbralphaV.glsl", "deferred/pbralphaF.glsl");
  1658. shaderp->mFeatures.isAlphaLighting = true;
  1659. shaderp->mFeatures.hasSrgb = true;
  1660. shaderp->mFeatures.calculatesAtmospherics = true;
  1661. shaderp->mFeatures.hasAtmospherics = true;
  1662. shaderp->mFeatures.hasGamma = true;
  1663. // Includes deferredUtils:
  1664. shaderp->mFeatures.isDeferred = true;
  1665. shaderp->mFeatures.hasReflectionProbes = shader_level;
  1666. if (use_sun_shadow)
  1667. {
  1668. shaderp->mFeatures.hasShadows = true;
  1669. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  1670. }
  1671. dam = llformat("%d", LLMaterial::DIFFUSE_ALPHA_MODE_BLEND);
  1672. shaderp->addPermutation("DIFFUSE_ALPHA_MODE", dam);
  1673. shaderp->addPermutation("HAS_NORMAL_MAP", "1");
  1674. // Note: SPECULAR_MAP = packed vector (Occlusion, Metal, Roughness).
  1675. shaderp->addPermutation("HAS_SPECULAR_MAP", "1");
  1676. shaderp->addPermutation("HAS_EMISSIVE_MAP", "1");
  1677. shaderp->addPermutation("USE_VERTEX_COLOR", "1");
  1678. success = create_with_rigged(*shaderp,
  1679. gDeferredSkinnedPBRAlphaProgram);
  1680. // *HACK: set after creation to disable auto-setup of texture channels
  1681. shaderp->mFeatures.calculatesLighting = true;
  1682. shaderp->mFeatures.hasLighting = true;
  1683. shaderp->mRiggedVariant->mFeatures.calculatesLighting = true;
  1684. shaderp->mRiggedVariant->mFeatures.hasLighting = true;
  1685. }
  1686. if (success && gUsePBRShaders)
  1687. {
  1688. gHUDPBRAlphaProgram.setup("Deferred HUD PBR alpha shader",
  1689. shader_level, "deferred/pbralphaV.glsl",
  1690. "deferred/pbralphaF.glsl");
  1691. gHUDPBRAlphaProgram.mFeatures.hasSrgb = true;
  1692. gHUDPBRAlphaProgram.addPermutation("IS_HUD", "1");
  1693. success = gHUDPBRAlphaProgram.createShader();
  1694. }
  1695. if (success && gUsePBRShaders)
  1696. {
  1697. shaderp = &gDeferredPBRTerrainProgram;
  1698. S32 d = -4;
  1699. S32 s = 1;
  1700. if (LLPipeline::sRenderPBRTerrain)
  1701. {
  1702. d = LLPipeline::sRenderPBRTerrainDetail;
  1703. s = gSavedSettings.getBool("RenderTerrainPBRTriplanar") ? 3 : 1;
  1704. }
  1705. std::string name = llformat("Deferred PBR terrain shader %d %s", d,
  1706. (s == 1 ? "flat" : "trilinear"));
  1707. shaderp->setup(name.c_str(), shader_level, "deferred/pbrterrainV.glsl",
  1708. "deferred/pbrterrainF.glsl");
  1709. shaderp->mFeatures.hasSrgb = true;
  1710. shaderp->mFeatures.isAlphaLighting = true;
  1711. shaderp->mFeatures.calculatesAtmospherics = true;
  1712. shaderp->mFeatures.hasAtmospherics = true;
  1713. shaderp->mFeatures.hasGamma = true;
  1714. shaderp->mFeatures.hasTransport = true;
  1715. shaderp->mFeatures.isPBRTerrain = true;
  1716. // *HACK: to disable auto-setup of texture channels
  1717. shaderp->mFeatures.disableTextureIndex = true;
  1718. shaderp->addPermutation("TERRAIN_PBR_DETAIL", llformat("%d", d));
  1719. shaderp->addPermutation("TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT",
  1720. llformat("%d", s));
  1721. success = shaderp->createShader();
  1722. }
  1723. if (success)
  1724. {
  1725. gDeferredTreeProgram.setup("Deferred tree shader", shader_level,
  1726. "deferred/treeV.glsl",
  1727. "deferred/treeF.glsl");
  1728. // Note: ignored by PBR
  1729. gDeferredTreeProgram.mFeatures.encodesNormal = true;
  1730. success = gDeferredTreeProgram.createShader();
  1731. }
  1732. if (success)
  1733. {
  1734. gDeferredTreeShadowProgram.setup("Deferred tree shadow shader",
  1735. shader_level,
  1736. "deferred/treeShadowV.glsl",
  1737. "deferred/treeShadowF.glsl");
  1738. if (!gUsePBRShaders)
  1739. {
  1740. gDeferredTreeShadowProgram.mFeatures.hasShadows = true;
  1741. gDeferredTreeShadowProgram.mFeatures.isDeferred = true;
  1742. }
  1743. gDeferredTreeShadowProgram.mRiggedVariant =
  1744. &gDeferredSkinnedTreeShadowProgram;
  1745. success = gDeferredTreeShadowProgram.createShader();
  1746. }
  1747. if (success)
  1748. {
  1749. shaderp = &gDeferredSkinnedTreeShadowProgram;
  1750. shaderp->setup("Skinned deferred tree shadow shader", shader_level,
  1751. "deferred/treeShadowSkinnedV.glsl",
  1752. "deferred/treeShadowF.glsl");
  1753. if (!gUsePBRShaders)
  1754. {
  1755. shaderp->mFeatures.hasShadows = true;
  1756. shaderp->mFeatures.isDeferred = true;
  1757. }
  1758. shaderp->mFeatures.hasObjectSkinning = true;
  1759. success = shaderp->createShader();
  1760. }
  1761. if (success)
  1762. {
  1763. gDeferredImpostorProgram.setup("Deferred impostor shader",
  1764. shader_level, "deferred/impostorV.glsl",
  1765. "deferred/impostorF.glsl");
  1766. gDeferredImpostorProgram.mFeatures.hasSrgb = true;
  1767. // Note: ignored by PBR
  1768. gDeferredImpostorProgram.mFeatures.encodesNormal = true;
  1769. success = gDeferredImpostorProgram.createShader();
  1770. }
  1771. if (success)
  1772. {
  1773. gDeferredLightProgram.setup("Deferred light shader", shader_level,
  1774. "deferred/pointLightV.glsl",
  1775. "deferred/pointLightF.glsl");
  1776. gDeferredLightProgram.mFeatures.hasShadows = true;
  1777. gDeferredLightProgram.mFeatures.isDeferred = true;
  1778. gDeferredLightProgram.mFeatures.hasSrgb = true;
  1779. success = gDeferredLightProgram.createShader();
  1780. }
  1781. for (U32 i = 0; success && i < LL_DEFERRED_MULTI_LIGHT_COUNT; ++i)
  1782. {
  1783. shaderp = &gDeferredMultiLightProgram[i];
  1784. name = llformat("Deferred multilight shader %d", i);
  1785. shaderp->setup(name.c_str(), shader_level,
  1786. "deferred/multiPointLightV.glsl",
  1787. "deferred/multiPointLightF.glsl");
  1788. shaderp->mFeatures.hasShadows = true;
  1789. shaderp->mFeatures.isDeferred = true;
  1790. shaderp->mFeatures.hasSrgb = true;
  1791. shaderp->addPermutation("LIGHT_COUNT", llformat("%d", i + 1));
  1792. success = shaderp->createShader();
  1793. }
  1794. if (success)
  1795. {
  1796. gDeferredSpotLightProgram.setup("Deferred spotlight shader",
  1797. shader_level,
  1798. "deferred/pointLightV.glsl",
  1799. "deferred/spotLightF.glsl");
  1800. gDeferredSpotLightProgram.mFeatures.hasShadows = true;
  1801. gDeferredSpotLightProgram.mFeatures.hasSrgb = true;
  1802. gDeferredSpotLightProgram.mFeatures.isDeferred = true;
  1803. success = gDeferredSpotLightProgram.createShader();
  1804. }
  1805. if (success)
  1806. {
  1807. shaderp = &gDeferredMultiSpotLightProgram;
  1808. if (gUsePBRShaders)
  1809. {
  1810. shaderp->setup("Deferred multispotlight shader", shader_level,
  1811. "deferred/multiPointLightV.glsl",
  1812. "deferred/spotLightF.glsl");
  1813. shaderp->addPermutation("MULTI_SPOTLIGHT", "1");
  1814. }
  1815. else
  1816. {
  1817. shaderp->setup("Deferred multispotlight shader", shader_level,
  1818. "deferred/multiPointLightV.glsl",
  1819. "deferred/multiSpotLightF.glsl");
  1820. }
  1821. shaderp->mFeatures.hasShadows = true;
  1822. shaderp->mFeatures.hasSrgb = true;
  1823. shaderp->mFeatures.isDeferred = true;
  1824. success = shaderp->createShader();
  1825. }
  1826. U32 ssao = gSavedSettings.getU32("RenderDeferredSSAO");
  1827. bool use_ao = ssao > 1 ||
  1828. (ssao == 1 && gSavedSettings.getU32("RenderShadowDetail"));
  1829. if (success)
  1830. {
  1831. const char* fragment;
  1832. const char* vertex = "deferred/sunLightV.glsl";
  1833. if (use_ao)
  1834. {
  1835. fragment = "deferred/sunLightSSAOF.glsl";
  1836. }
  1837. else
  1838. {
  1839. fragment = "deferred/sunLightF.glsl";
  1840. if (shader_level == 1)
  1841. {
  1842. // No shadows, no SSAO, no frag coord
  1843. vertex = "deferred/sunLightNoFragCoordV.glsl";
  1844. }
  1845. }
  1846. gDeferredSunProgram.setup("Deferred Sun shader", shader_level,
  1847. vertex, fragment);
  1848. gDeferredSunProgram.mFeatures.hasAmbientOcclusion = use_ao;
  1849. gDeferredSunProgram.mFeatures.hasShadows = true;
  1850. gDeferredSunProgram.mFeatures.isDeferred = true;
  1851. success = gDeferredSunProgram.createShader();
  1852. }
  1853. if (success)
  1854. {
  1855. gDeferredBlurLightProgram.setup("Deferred blur light shader",
  1856. shader_level,
  1857. "deferred/blurLightV.glsl",
  1858. "deferred/blurLightF.glsl");
  1859. gDeferredBlurLightProgram.mFeatures.isDeferred = true;
  1860. success = gDeferredBlurLightProgram.createShader();
  1861. }
  1862. if (success)
  1863. {
  1864. std::string name;
  1865. // type 0 is simple deferred alpha, 1 is skinned, 2 is HUD. HB
  1866. U32 max_type = gUsePBRShaders ? 2 : 1;
  1867. for (U32 type = 0; type <= max_type; ++type)
  1868. {
  1869. if (type == 0)
  1870. {
  1871. name = "Deferred alpha shader";
  1872. shaderp = &gDeferredAlphaProgram;
  1873. shaderp->mRiggedVariant = &gDeferredSkinnedAlphaProgram;
  1874. }
  1875. else if (type == 1)
  1876. {
  1877. name = "Skinned deferred alpha shader";
  1878. shaderp = &gDeferredSkinnedAlphaProgram;
  1879. }
  1880. else
  1881. {
  1882. name = "Deferred HUD alpha shader";
  1883. shaderp = &gHUDAlphaProgram;
  1884. }
  1885. shaderp->setup(name.c_str(), shader_level, "deferred/alphaV.glsl",
  1886. "deferred/alphaF.glsl");
  1887. if (shader_level < 1 || gUsePBRShaders)
  1888. {
  1889. shaderp->mFeatures.mIndexedTextureChannels =
  1890. sIndexedTextureChannels;
  1891. }
  1892. else
  1893. {
  1894. // Shave off some texture units for shadow maps
  1895. shaderp->mFeatures.mIndexedTextureChannels =
  1896. llmax(sIndexedTextureChannels - 6, 1);
  1897. }
  1898. shaderp->mFeatures.isAlphaLighting = true;
  1899. // *HACK: to disable auto-setup of texture channels
  1900. shaderp->mFeatures.disableTextureIndex = true;
  1901. shaderp->mFeatures.hasShadows = use_sun_shadow;
  1902. shaderp->mFeatures.hasSrgb = true;
  1903. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1904. shaderp->mFeatures.calculatesAtmospherics = true;
  1905. shaderp->mFeatures.hasAtmospherics = true;
  1906. shaderp->mFeatures.hasGamma = true;
  1907. if (gUsePBRShaders)
  1908. {
  1909. shaderp->mFeatures.hasReflectionProbes = true;
  1910. }
  1911. else
  1912. {
  1913. shaderp->mFeatures.hasTransport = true;
  1914. }
  1915. if (use_sun_shadow)
  1916. {
  1917. if (gUsePBRShaders)
  1918. {
  1919. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  1920. }
  1921. else
  1922. {
  1923. shaderp->addPermutation("HAS_SHADOW", "1");
  1924. }
  1925. }
  1926. if (type == 1)
  1927. {
  1928. shaderp->mFeatures.hasObjectSkinning = true;
  1929. shaderp->addPermutation("HAS_SKIN", "1");
  1930. }
  1931. else if (type == 2)
  1932. {
  1933. shaderp->addPermutation("IS_HUD", "1");
  1934. }
  1935. shaderp->addPermutation("USE_INDEXED_TEX", "1");
  1936. shaderp->addPermutation("USE_VERTEX_COLOR", "1");
  1937. if (gUsePBRShaders)
  1938. {
  1939. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  1940. }
  1941. success = shaderp->createShader();
  1942. // *HACK: set after creation to disable auto-setup of texture
  1943. // channels
  1944. shaderp->mFeatures.calculatesLighting = true;
  1945. shaderp->mFeatures.hasLighting = true;
  1946. }
  1947. }
  1948. if (success)
  1949. {
  1950. LLGLSLShader* shaders[] = { &gDeferredAlphaImpostorProgram,
  1951. &gDeferredSkinnedAlphaImpostorProgram };
  1952. std::string name;
  1953. for (U32 rigged = 0; success && rigged < 2; ++rigged)
  1954. {
  1955. shaderp = shaders[rigged];
  1956. if (rigged)
  1957. {
  1958. name = "Skinned deferred alpha impostor shader";
  1959. }
  1960. else
  1961. {
  1962. name = "Deferred alpha impostor shader";
  1963. }
  1964. shaderp->setup(name.c_str(), shader_level, "deferred/alphaV.glsl",
  1965. "deferred/alphaF.glsl");
  1966. if (shader_level < 1 || gUsePBRShaders)
  1967. {
  1968. shaderp->mFeatures.mIndexedTextureChannels =
  1969. sIndexedTextureChannels;
  1970. }
  1971. else
  1972. {
  1973. // Shave off some texture units for shadow maps
  1974. shaderp->mFeatures.mIndexedTextureChannels =
  1975. llmax(sIndexedTextureChannels - 6, 1);
  1976. }
  1977. shaderp->mFeatures.isAlphaLighting = true;
  1978. shaderp->mFeatures.hasSrgb = true;
  1979. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  1980. if (gUsePBRShaders)
  1981. {
  1982. shaderp->mFeatures.hasReflectionProbes = true;
  1983. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  1984. }
  1985. if (use_sun_shadow)
  1986. {
  1987. shaderp->mFeatures.hasShadows = true;
  1988. if (gUsePBRShaders)
  1989. {
  1990. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  1991. }
  1992. else
  1993. {
  1994. shaderp->addPermutation("HAS_SHADOW", "1");
  1995. }
  1996. }
  1997. shaderp->addPermutation("USE_INDEXED_TEX", "1");
  1998. shaderp->addPermutation("USE_VERTEX_COLOR", "1");
  1999. shaderp->addPermutation("FOR_IMPOSTOR", "1");
  2000. if (gUsePBRShaders)
  2001. {
  2002. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2003. }
  2004. if (rigged)
  2005. {
  2006. shaderp->mFeatures.hasObjectSkinning = true;
  2007. shaderp->addPermutation("HAS_SKIN", "1");
  2008. }
  2009. else
  2010. {
  2011. shaderp->mRiggedVariant = shaders[1];
  2012. }
  2013. success = shaderp->createShader();
  2014. // *HACK: set after creation to disable auto-setup of texture channels
  2015. shaderp->mFeatures.calculatesLighting = true;
  2016. shaderp->mFeatures.hasLighting = true;
  2017. }
  2018. }
  2019. if (success && !gUsePBRShaders)
  2020. {
  2021. LLGLSLShader* shaders[] = { &gDeferredAlphaWaterProgram,
  2022. &gDeferredSkinnedAlphaWaterProgram };
  2023. std::string name;
  2024. for (U32 rigged = 0; success && rigged < 2; ++rigged)
  2025. {
  2026. shaderp = shaders[rigged];
  2027. if (rigged)
  2028. {
  2029. name = "Skinned deferred alpha underwater shader";
  2030. }
  2031. else
  2032. {
  2033. name = "Deferred alpha underwater shader";
  2034. }
  2035. shaderp->setup(name.c_str(), shader_level, "deferred/alphaV.glsl",
  2036. "deferred/alphaF.glsl");
  2037. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  2038. if (shader_level < 1 || gUsePBRShaders)
  2039. {
  2040. shaderp->mFeatures.mIndexedTextureChannels =
  2041. sIndexedTextureChannels;
  2042. }
  2043. else
  2044. {
  2045. // Shave off some texture units for shadow maps
  2046. shaderp->mFeatures.mIndexedTextureChannels =
  2047. llmax(sIndexedTextureChannels - 6, 1);
  2048. }
  2049. shaderp->mFeatures.isAlphaLighting = true;
  2050. // *HACK: to disable auto-setup of texture channels
  2051. shaderp->mFeatures.disableTextureIndex = true;
  2052. shaderp->mFeatures.hasWaterFog = true;
  2053. shaderp->mFeatures.hasSrgb = true;
  2054. shaderp->mFeatures.encodesNormal = true;
  2055. shaderp->mFeatures.calculatesAtmospherics = true;
  2056. shaderp->mFeatures.hasAtmospherics = true;
  2057. shaderp->mFeatures.hasGamma = true;
  2058. if (gUsePBRShaders)
  2059. {
  2060. shaderp->mFeatures.hasReflectionProbes = true;
  2061. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2062. }
  2063. else
  2064. {
  2065. shaderp->mFeatures.hasTransport = true;
  2066. }
  2067. if (use_sun_shadow)
  2068. {
  2069. shaderp->mFeatures.hasShadows = true;
  2070. if (gUsePBRShaders)
  2071. {
  2072. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  2073. }
  2074. else
  2075. {
  2076. shaderp->addPermutation("HAS_SHADOW", "1");
  2077. }
  2078. }
  2079. shaderp->addPermutation("USE_INDEXED_TEX", "1");
  2080. shaderp->addPermutation("WATER_FOG", "1");
  2081. shaderp->addPermutation("USE_VERTEX_COLOR", "1");
  2082. if (rigged)
  2083. {
  2084. shaderp->mFeatures.hasObjectSkinning = true;
  2085. shaderp->addPermutation("HAS_SKIN", "1");
  2086. }
  2087. else
  2088. {
  2089. shaderp->mRiggedVariant = shaders[1];
  2090. }
  2091. success = shaderp->createShader();
  2092. // *HACK: set after creation to disable auto-setup of texture channels
  2093. shaderp->mFeatures.calculatesLighting = true;
  2094. shaderp->mFeatures.hasLighting = true;
  2095. }
  2096. }
  2097. if (success)
  2098. {
  2099. gDeferredAvatarEyesProgram.setup("Deferred alpha eyes shader",
  2100. shader_level,
  2101. "deferred/avatarEyesV.glsl",
  2102. "deferred/diffuseF.glsl");
  2103. gDeferredAvatarEyesProgram.mFeatures.calculatesAtmospherics = true;
  2104. gDeferredAvatarEyesProgram.mFeatures.hasGamma = true;
  2105. if (gUsePBRShaders)
  2106. {
  2107. // *TODO: verify PBR really needs this. HB
  2108. gDeferredAvatarEyesProgram.mFeatures.hasAtmospherics = true;
  2109. }
  2110. else
  2111. {
  2112. gDeferredAvatarEyesProgram.mFeatures.hasTransport = true;
  2113. }
  2114. gDeferredAvatarEyesProgram.mFeatures.disableTextureIndex = true;
  2115. gDeferredAvatarEyesProgram.mFeatures.hasSrgb = true;
  2116. // Note: ignored by PBR
  2117. gDeferredAvatarEyesProgram.mFeatures.encodesNormal = true;
  2118. gDeferredAvatarEyesProgram.mFeatures.hasShadows = true;
  2119. success = gDeferredAvatarEyesProgram.createShader();
  2120. }
  2121. if (success)
  2122. {
  2123. shaderp = &gDeferredFullbrightProgram;
  2124. shaderp->setup("Deferred full bright shader", shader_level,
  2125. "deferred/fullbrightV.glsl",
  2126. "deferred/fullbrightF.glsl");
  2127. shaderp->mFeatures.calculatesAtmospherics = true;
  2128. shaderp->mFeatures.hasGamma = true;
  2129. if (gUsePBRShaders)
  2130. {
  2131. shaderp->mFeatures.hasAtmospherics = true;
  2132. }
  2133. else
  2134. {
  2135. shaderp->mFeatures.hasTransport = true;
  2136. }
  2137. shaderp->mFeatures.hasSrgb = true;
  2138. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2139. success = create_with_rigged(*shaderp,
  2140. gDeferredSkinnedFullbrightProgram);
  2141. }
  2142. if (success && gUsePBRShaders)
  2143. {
  2144. shaderp = &gHUDFullbrightProgram;
  2145. shaderp->setup("Deferred HUD full bright shader", shader_level,
  2146. "deferred/fullbrightV.glsl",
  2147. "deferred/fullbrightF.glsl");
  2148. shaderp->mFeatures.calculatesAtmospherics = true;
  2149. shaderp->mFeatures.hasGamma = true;
  2150. shaderp->mFeatures.hasAtmospherics = true;
  2151. shaderp->mFeatures.hasSrgb = true;
  2152. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2153. shaderp->addPermutation("IS_HUD", "1");
  2154. success = shaderp->createShader();
  2155. }
  2156. if (success)
  2157. {
  2158. shaderp = &gDeferredFullbrightAlphaMaskProgram;
  2159. shaderp->setup("Deferred full bright alpha masking shader",
  2160. shader_level, "deferred/fullbrightV.glsl",
  2161. "deferred/fullbrightF.glsl");
  2162. shaderp->mFeatures.calculatesAtmospherics = true;
  2163. shaderp->mFeatures.hasGamma = true;
  2164. if (gUsePBRShaders)
  2165. {
  2166. shaderp->mFeatures.hasAtmospherics = true;
  2167. }
  2168. else
  2169. {
  2170. shaderp->mFeatures.hasTransport = true;
  2171. }
  2172. shaderp->mFeatures.hasSrgb = true;
  2173. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2174. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2175. success = create_with_rigged(*shaderp,
  2176. gDeferredSkinnedFullbrightAlphaMaskProgram);
  2177. }
  2178. if (success && gUsePBRShaders)
  2179. {
  2180. shaderp = &gHUDFullbrightAlphaMaskProgram;
  2181. shaderp->setup("Deferred HUD full bright alpha masking shader",
  2182. shader_level, "deferred/fullbrightV.glsl",
  2183. "deferred/fullbrightF.glsl");
  2184. shaderp->mFeatures.calculatesAtmospherics = true;
  2185. shaderp->mFeatures.hasGamma = true;
  2186. shaderp->mFeatures.hasAtmospherics = true;
  2187. shaderp->mFeatures.hasSrgb = true;
  2188. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2189. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2190. shaderp->addPermutation("IS_HUD", "1");
  2191. success = shaderp->createShader();
  2192. }
  2193. if (success && gUsePBRShaders)
  2194. {
  2195. shaderp = &gDeferredFullbrightAlphaMaskAlphaProgram;
  2196. shaderp->setup("Deferred full bright alpha masking alpha shader",
  2197. shader_level, "deferred/fullbrightV.glsl",
  2198. "deferred/fullbrightF.glsl");
  2199. shaderp->mFeatures.calculatesAtmospherics = true;
  2200. shaderp->mFeatures.hasGamma = true;
  2201. shaderp->mFeatures.hasAtmospherics = true;
  2202. shaderp->mFeatures.hasSrgb = true;
  2203. shaderp->mFeatures.isDeferred = true;
  2204. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2205. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2206. shaderp->addPermutation("IS_ALPHA", "1");
  2207. success = create_with_rigged(*shaderp,
  2208. gDeferredSkinnedFullbrightAlphaMaskAlphaProgram);
  2209. }
  2210. if (success && gUsePBRShaders)
  2211. {
  2212. shaderp = &gHUDFullbrightAlphaMaskAlphaProgram;
  2213. shaderp->setup("Deferred HUD full bright alpha masking alpha shader",
  2214. shader_level, "deferred/fullbrightV.glsl",
  2215. "deferred/fullbrightF.glsl");
  2216. shaderp->mFeatures.calculatesAtmospherics = true;
  2217. shaderp->mFeatures.hasGamma = true;
  2218. shaderp->mFeatures.hasAtmospherics = true;
  2219. shaderp->mFeatures.hasSrgb = true;
  2220. shaderp->mFeatures.isDeferred = true;
  2221. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2222. shaderp->addPermutation("HAS_ALPHA_MASK", "1");
  2223. shaderp->addPermutation("IS_ALPHA", "1");
  2224. shaderp->addPermutation("IS_HUD", "1");
  2225. success = shaderp->createShader();
  2226. }
  2227. if (success && !gUsePBRShaders)
  2228. {
  2229. shaderp = &gDeferredFullbrightWaterProgram;
  2230. shaderp->setup("Deferred full bright underwater shader", shader_level,
  2231. "deferred/fullbrightV.glsl",
  2232. "deferred/fullbrightF.glsl");
  2233. shaderp->mFeatures.calculatesAtmospherics = true;
  2234. shaderp->mFeatures.hasGamma = true;
  2235. shaderp->mFeatures.hasTransport = true;
  2236. shaderp->mFeatures.hasWaterFog = true;
  2237. shaderp->mFeatures.hasSrgb = true;
  2238. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2239. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  2240. shaderp->addPermutation("WATER_FOG", "1");
  2241. success = create_with_rigged(*shaderp,
  2242. gDeferredSkinnedFullbrightWaterProgram);
  2243. }
  2244. if (success && !gUsePBRShaders)
  2245. {
  2246. shaderp = &gDeferredFullbrightAlphaMaskWaterProgram;
  2247. shaderp->setup("Deferred full bright underwater alpha masking shader",
  2248. shader_level, "deferred/fullbrightV.glsl",
  2249. "deferred/fullbrightF.glsl");
  2250. shaderp->mFeatures.calculatesAtmospherics = true;
  2251. shaderp->mFeatures.hasGamma = true;
  2252. shaderp->mFeatures.hasTransport = true;
  2253. shaderp->mFeatures.hasWaterFog = true;
  2254. shaderp->mFeatures.hasSrgb = true;
  2255. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2256. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  2257. shaderp->addPermutation("HAS_ALPHA_MASK","1");
  2258. shaderp->addPermutation("WATER_FOG","1");
  2259. success =
  2260. create_with_rigged(*shaderp,
  2261. gDeferredSkinnedFullbrightAlphaMaskWaterProgram);
  2262. }
  2263. if (success)
  2264. {
  2265. shaderp = &gDeferredFullbrightShinyProgram;
  2266. shaderp->setup("Deferred fullbrightshiny shader", shader_level,
  2267. "deferred/fullbrightShinyV.glsl",
  2268. "deferred/fullbrightShinyF.glsl");
  2269. shaderp->mFeatures.calculatesAtmospherics = true;
  2270. shaderp->mFeatures.hasAtmospherics = true;
  2271. shaderp->mFeatures.hasGamma = true;
  2272. shaderp->mFeatures.hasSrgb = true;
  2273. if (gUsePBRShaders)
  2274. {
  2275. shaderp->mFeatures.hasReflectionProbes = true;
  2276. shaderp->mFeatures.mIndexedTextureChannels =
  2277. sIndexedTextureChannels;
  2278. }
  2279. else
  2280. {
  2281. shaderp->mFeatures.hasTransport = true;
  2282. shaderp->mFeatures.mIndexedTextureChannels =
  2283. sIndexedTextureChannels - 1;
  2284. }
  2285. success = create_with_rigged(*shaderp,
  2286. gDeferredSkinnedFullbrightShinyProgram);
  2287. }
  2288. if (success && gUsePBRShaders)
  2289. {
  2290. shaderp = &gHUDFullbrightShinyProgram;
  2291. shaderp->setup("Deferred HUD full bright shiny shader", shader_level,
  2292. "deferred/fullbrightShinyV.glsl",
  2293. "deferred/fullbrightShinyF.glsl");
  2294. shaderp->mFeatures.calculatesAtmospherics = true;
  2295. // *TODO: verify PBR really needs this. HB
  2296. shaderp->mFeatures.hasAtmospherics = true;
  2297. shaderp->mFeatures.hasGamma = true;
  2298. shaderp->mFeatures.hasSrgb = true;
  2299. shaderp->mFeatures.hasReflectionProbes = true;
  2300. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2301. shaderp->addPermutation("IS_HUD", "1");
  2302. success = shaderp->createShader();
  2303. }
  2304. if (success)
  2305. {
  2306. shaderp = &gDeferredEmissiveProgram;
  2307. shaderp->setup("Deferred emissive shader", shader_level,
  2308. "deferred/emissiveV.glsl", "deferred/emissiveF.glsl");
  2309. shaderp->mFeatures.calculatesAtmospherics = true;
  2310. shaderp->mFeatures.hasGamma = true;
  2311. if (gUsePBRShaders)
  2312. {
  2313. // *TODO: verify PBR really needs this. HB
  2314. shaderp->mFeatures.hasAtmospherics = true;
  2315. }
  2316. else
  2317. {
  2318. shaderp->mFeatures.hasTransport = true;
  2319. }
  2320. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2321. success = create_with_rigged(*shaderp,
  2322. gDeferredSkinnedEmissiveProgram);
  2323. }
  2324. if (success && !gUsePBRShaders)
  2325. {
  2326. gDeferredWaterProgram.setup("Deferred water shader", shader_level,
  2327. "deferred/waterV.glsl",
  2328. "deferred/waterF.glsl");
  2329. gDeferredWaterProgram.mFeatures.calculatesAtmospherics = true;
  2330. gDeferredWaterProgram.mFeatures.hasGamma = true;
  2331. gDeferredWaterProgram.mFeatures.hasTransport = true;
  2332. gDeferredWaterProgram.mFeatures.encodesNormal = true;
  2333. gDeferredWaterProgram.mFeatures.hasSrgb = true;
  2334. gDeferredWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  2335. success = gDeferredWaterProgram.createShader();
  2336. }
  2337. if (success && !gUsePBRShaders)
  2338. {
  2339. gDeferredUnderWaterProgram.setup("Deferred under water shader",
  2340. shader_level,
  2341. "deferred/waterV.glsl",
  2342. "deferred/underWaterF.glsl");
  2343. gDeferredUnderWaterProgram.mFeatures.calculatesAtmospherics = true;
  2344. gDeferredUnderWaterProgram.mFeatures.hasGamma = true;
  2345. gDeferredUnderWaterProgram.mFeatures.hasTransport = true;
  2346. gDeferredUnderWaterProgram.mFeatures.hasWaterFog = true;
  2347. gDeferredUnderWaterProgram.mFeatures.hasSrgb = true;
  2348. gDeferredUnderWaterProgram.mFeatures.encodesNormal = true;
  2349. gDeferredUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  2350. success = gDeferredUnderWaterProgram.createShader();
  2351. }
  2352. if (success && gUsePBRShaders)
  2353. {
  2354. gHazeProgram.setup("Deferred haze shader", shader_level,
  2355. "deferred/softenLightV.glsl",
  2356. "deferred/hazeF.glsl");
  2357. gHazeProgram.mFeatures.hasSrgb = true;
  2358. gHazeProgram.mFeatures.calculatesAtmospherics = true;
  2359. gHazeProgram.mFeatures.hasAtmospherics = true;
  2360. gHazeProgram.mFeatures.hasGamma = true;
  2361. gHazeProgram.mFeatures.isDeferred = true;
  2362. gHazeProgram.mFeatures.hasShadows = use_sun_shadow;
  2363. gHazeProgram.mFeatures.hasReflectionProbes = shader_level > 2;
  2364. success = gHazeProgram.createShader();
  2365. }
  2366. if (success && gUsePBRShaders)
  2367. {
  2368. gHazeWaterProgram.setup("Deferred water haze shader", shader_level,
  2369. "deferred/waterHazeV.glsl",
  2370. "deferred/waterHazeF.glsl");
  2371. gHazeWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  2372. gHazeWaterProgram.mFeatures.hasSrgb = true;
  2373. gHazeWaterProgram.mFeatures.calculatesAtmospherics = true;
  2374. gHazeWaterProgram.mFeatures.hasAtmospherics = true;
  2375. gHazeWaterProgram.mFeatures.hasGamma = true;
  2376. gHazeWaterProgram.mFeatures.isDeferred = true;
  2377. gHazeWaterProgram.mFeatures.hasShadows = use_sun_shadow;
  2378. gHazeWaterProgram.mFeatures.hasReflectionProbes = shader_level > 2;
  2379. success = gHazeWaterProgram.createShader();
  2380. }
  2381. S32 soften_level = shader_level;
  2382. if (use_ao)
  2383. {
  2384. // When using SSAO, take screen space light map into account as if
  2385. // shadows are enabled
  2386. soften_level = llmax(soften_level, 2);
  2387. }
  2388. if (success)
  2389. {
  2390. shaderp = &gDeferredSoftenProgram;
  2391. shaderp->setup("Deferred soften shader", soften_level,
  2392. "deferred/softenLightV.glsl",
  2393. "deferred/softenLightF.glsl");
  2394. shaderp->mFeatures.hasSrgb = true;
  2395. shaderp->mFeatures.calculatesAtmospherics = true;
  2396. shaderp->mFeatures.hasAtmospherics = true;
  2397. shaderp->mFeatures.hasGamma = true;
  2398. shaderp->mFeatures.isDeferred = true;
  2399. shaderp->mFeatures.hasShadows = use_sun_shadow;
  2400. if (gUsePBRShaders)
  2401. {
  2402. shaderp->mFeatures.hasReflectionProbes = shader_level > 2;
  2403. if (use_sun_shadow)
  2404. {
  2405. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  2406. }
  2407. if (use_ao)
  2408. {
  2409. shaderp->addPermutation("HAS_SSAO", "1");
  2410. }
  2411. }
  2412. else
  2413. {
  2414. shaderp->mFeatures.hasTransport = true;
  2415. }
  2416. success = shaderp->createShader();
  2417. }
  2418. if (success && !gUsePBRShaders)
  2419. {
  2420. shaderp = &gDeferredSoftenWaterProgram;
  2421. shaderp->setup("Deferred soften underwater shader", soften_level,
  2422. "deferred/softenLightV.glsl",
  2423. "deferred/softenLightF.glsl");
  2424. shaderp->addPermutation("WATER_FOG", "1");
  2425. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  2426. shaderp->mFeatures.hasWaterFog = true;
  2427. shaderp->mFeatures.hasSrgb = true;
  2428. shaderp->mFeatures.calculatesAtmospherics = true;
  2429. shaderp->mFeatures.hasAtmospherics = true;
  2430. shaderp->mFeatures.hasTransport = true;
  2431. shaderp->mFeatures.hasGamma = true;
  2432. shaderp->mFeatures.isDeferred = true;
  2433. shaderp->mFeatures.hasShadows = use_sun_shadow;
  2434. success = shaderp->createShader();
  2435. }
  2436. std::string depth_clamp = gGLManager.mUseDepthClamp ? "1" : "0";
  2437. if (success)
  2438. {
  2439. gDeferredShadowProgram.setup("Deferred shadow shader", shader_level,
  2440. "deferred/shadowV.glsl",
  2441. "deferred/shadowF.glsl");
  2442. if (!gUsePBRShaders)
  2443. {
  2444. gDeferredShadowProgram.mFeatures.isDeferred = true;
  2445. gDeferredShadowProgram.mFeatures.hasShadows = true;
  2446. if (gGLManager.mUseDepthClamp)
  2447. {
  2448. gDeferredShadowProgram.addPermutation("DEPTH_CLAMP", "1");
  2449. }
  2450. }
  2451. gDeferredShadowProgram.mRiggedVariant = &gDeferredSkinnedShadowProgram;
  2452. success = gDeferredShadowProgram.createShader();
  2453. }
  2454. if (success)
  2455. {
  2456. gDeferredSkinnedShadowProgram.setup("Skinned deferred shadow shader",
  2457. shader_level,
  2458. "deferred/shadowSkinnedV.glsl",
  2459. "deferred/shadowF.glsl");
  2460. gDeferredSkinnedShadowProgram.mFeatures.isDeferred = true;
  2461. gDeferredSkinnedShadowProgram.mFeatures.hasShadows = true;
  2462. gDeferredSkinnedShadowProgram.mFeatures.hasObjectSkinning = true;
  2463. if (gGLManager.mUseDepthClamp && !gUsePBRShaders)
  2464. {
  2465. gDeferredSkinnedShadowProgram.addPermutation("DEPTH_CLAMP", "1");
  2466. }
  2467. success = gDeferredSkinnedShadowProgram.createShader();
  2468. }
  2469. if (success)
  2470. {
  2471. gDeferredShadowCubeProgram.setup("Deferred shadow cube shader",
  2472. shader_level,
  2473. "deferred/shadowCubeV.glsl",
  2474. "deferred/shadowF.glsl");
  2475. gDeferredShadowCubeProgram.mFeatures.isDeferred = true;
  2476. gDeferredShadowCubeProgram.mFeatures.hasShadows = true;
  2477. if (gGLManager.mUseDepthClamp && !gUsePBRShaders)
  2478. {
  2479. gDeferredShadowCubeProgram.addPermutation("DEPTH_CLAMP", "1");
  2480. }
  2481. success = gDeferredShadowCubeProgram.createShader();
  2482. }
  2483. if (success)
  2484. {
  2485. shaderp = &gDeferredShadowFullbrightAlphaMaskProgram;
  2486. shaderp->setup("Deferred shadow full bright alpha mask shader",
  2487. shader_level, "deferred/shadowAlphaMaskV.glsl",
  2488. "deferred/shadowAlphaMaskF.glsl");
  2489. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2490. if (gGLManager.mUseDepthClamp || gUsePBRShaders)
  2491. {
  2492. shaderp->addPermutation("DEPTH_CLAMP", "1");
  2493. }
  2494. shaderp->addPermutation("IS_FULLBRIGHT", "1");
  2495. if (gUsePBRShaders)
  2496. {
  2497. success =
  2498. create_with_rigged(*shaderp,
  2499. gDeferredSkinnedShadowFullbrightAlphaMaskProgram);
  2500. }
  2501. else
  2502. {
  2503. shaderp->mRiggedVariant =
  2504. &gDeferredSkinnedShadowFullbrightAlphaMaskProgram;
  2505. success = shaderp->createShader();
  2506. }
  2507. }
  2508. if (success && !gUsePBRShaders)
  2509. {
  2510. shaderp = &gDeferredSkinnedShadowFullbrightAlphaMaskProgram;
  2511. shaderp->setup("Skinned deferred shadow full bright alpha mask shader",
  2512. shader_level, "deferred/shadowAlphaMaskSkinnedV.glsl",
  2513. "deferred/shadowAlphaMaskF.glsl");
  2514. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2515. shaderp->mFeatures.hasObjectSkinning = true;
  2516. if (gGLManager.mUseDepthClamp)
  2517. {
  2518. shaderp->addPermutation("DEPTH_CLAMP", "1");
  2519. }
  2520. shaderp->addPermutation("IS_FULLBRIGHT", "1");
  2521. success = shaderp->createShader();
  2522. }
  2523. if (success)
  2524. {
  2525. shaderp = &gDeferredShadowAlphaMaskProgram;
  2526. shaderp->setup("Deferred shadow alpha mask shader", shader_level,
  2527. "deferred/shadowAlphaMaskV.glsl",
  2528. "deferred/shadowAlphaMaskF.glsl");
  2529. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2530. if (gGLManager.mUseDepthClamp && !gUsePBRShaders)
  2531. {
  2532. shaderp->addPermutation("DEPTH_CLAMP", "1");
  2533. }
  2534. success = create_with_rigged(*shaderp,
  2535. gDeferredSkinnedShadowAlphaMaskProgram);
  2536. }
  2537. if (success && gUsePBRShaders)
  2538. {
  2539. shaderp = &gDeferredShadowGLTFAlphaMaskProgram;
  2540. shaderp->setup("Deferred GLTF shadow alpha mask shader", shader_level,
  2541. "deferred/pbrShadowAlphaMaskV.glsl",
  2542. "deferred/pbrShadowAlphaMaskF.glsl");
  2543. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2544. success = create_with_rigged(*shaderp,
  2545. gDeferredSkinnedShadowGLTFAlphaMaskProgram);
  2546. }
  2547. if (success && gUsePBRShaders)
  2548. {
  2549. shaderp = &gDeferredShadowGLTFAlphaBlendProgram;
  2550. shaderp->setup("Deferred GLTF shadow alpha blend shader", shader_level,
  2551. "deferred/pbrShadowAlphaMaskV.glsl",
  2552. "deferred/pbrShadowAlphaBlendF.glsl");
  2553. shaderp->mFeatures.mIndexedTextureChannels = sIndexedTextureChannels;
  2554. success = create_with_rigged(*shaderp,
  2555. gDeferredSkinnedShadowGLTFAlphaBlendProgram);
  2556. }
  2557. if (success)
  2558. {
  2559. gDeferredAvatarShadowProgram.setup("Deferred avatar shadow shader",
  2560. shader_level,
  2561. "deferred/avatarShadowV.glsl",
  2562. "deferred/avatarShadowF.glsl");
  2563. gDeferredAvatarShadowProgram.mFeatures.hasSkinning = true;
  2564. if (gGLManager.mUseDepthClamp && !gUsePBRShaders)
  2565. {
  2566. gDeferredAvatarShadowProgram.addPermutation("DEPTH_CLAMP", "1");
  2567. }
  2568. success = gDeferredAvatarShadowProgram.createShader();
  2569. }
  2570. if (success)
  2571. {
  2572. shaderp = &gDeferredAvatarAlphaShadowProgram;
  2573. shaderp->setup("Deferred avatar alpha shadow shader", shader_level,
  2574. "deferred/avatarAlphaShadowV.glsl",
  2575. "deferred/avatarAlphaShadowF.glsl");
  2576. shaderp->mFeatures.hasSkinning = true;
  2577. if (!gUsePBRShaders)
  2578. {
  2579. shaderp->addPermutation("DEPTH_CLAMP", depth_clamp);
  2580. }
  2581. success = shaderp->createShader();
  2582. }
  2583. if (success)
  2584. {
  2585. shaderp = &gDeferredAvatarAlphaMaskShadowProgram;
  2586. shaderp->setup("Deferred avatar alpha mask shadow shader",
  2587. shader_level, "deferred/avatarAlphaShadowV.glsl",
  2588. "deferred/avatarAlphaMaskShadowF.glsl");
  2589. shaderp->mFeatures.hasSkinning = true;
  2590. if (!gUsePBRShaders)
  2591. {
  2592. shaderp->addPermutation("DEPTH_CLAMP", depth_clamp);
  2593. }
  2594. success = shaderp->createShader();
  2595. }
  2596. if (success)
  2597. {
  2598. gDeferredTerrainProgram.setup("Deferred terrain shader", shader_level,
  2599. "deferred/terrainV.glsl",
  2600. "deferred/terrainF.glsl");
  2601. // Note: ignored by PBR
  2602. gDeferredTerrainProgram.mFeatures.encodesNormal = true;
  2603. gDeferredTerrainProgram.mFeatures.hasSrgb = true;
  2604. if (gUsePBRShaders)
  2605. {
  2606. // *TODO: verify if all or any of this is really needed. HB
  2607. gDeferredTerrainProgram.mFeatures.isAlphaLighting = true;
  2608. gDeferredTerrainProgram.mFeatures.calculatesAtmospherics = true;
  2609. gDeferredTerrainProgram.mFeatures.hasAtmospherics = true;
  2610. gDeferredTerrainProgram.mFeatures.hasGamma = true;
  2611. }
  2612. // *HACK: to disable auto-setup of texture channels
  2613. gDeferredTerrainProgram.mFeatures.disableTextureIndex = true;
  2614. success = gDeferredTerrainProgram.createShader();
  2615. }
  2616. if (success && !gUsePBRShaders)
  2617. {
  2618. shaderp = &gDeferredTerrainWaterProgram;
  2619. shaderp->setup("Deferred terrain underwater shader", shader_level,
  2620. "deferred/terrainV.glsl", "deferred/terrainF.glsl");
  2621. shaderp->mFeatures.encodesNormal = true;
  2622. shaderp->mFeatures.hasSrgb = true;
  2623. shaderp->mFeatures.hasWaterFog = true;
  2624. // *HACK: to disable auto-setup of texture channels
  2625. shaderp->mFeatures.disableTextureIndex = true;
  2626. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  2627. shaderp->addPermutation("WATER_FOG", "1");
  2628. success = shaderp->createShader();
  2629. }
  2630. if (success)
  2631. {
  2632. shaderp = &gDeferredAvatarProgram;
  2633. shaderp->setup("Deferred avatar shader", shader_level,
  2634. "deferred/avatarV.glsl", "deferred/avatarF.glsl");
  2635. shaderp->mFeatures.hasSkinning = true;
  2636. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  2637. if (!gUsePBRShaders)
  2638. {
  2639. shaderp->addPermutation("AVATAR_CLOTH",
  2640. mShaderLevel[SHADER_AVATAR] == 3 ? "1"
  2641. : "0");
  2642. }
  2643. success = shaderp->createShader();
  2644. }
  2645. if (success)
  2646. {
  2647. shaderp = &gDeferredAvatarAlphaProgram;
  2648. shaderp->setup("Deferred avatar alpha shader", shader_level,
  2649. "deferred/alphaV.glsl", "deferred/alphaF.glsl");
  2650. shaderp->mFeatures.hasSkinning = true;
  2651. shaderp->mFeatures.isAlphaLighting = true;
  2652. shaderp->mFeatures.disableTextureIndex = true;
  2653. shaderp->mFeatures.hasSrgb = true;
  2654. shaderp->mFeatures.encodesNormal = true; // Note: ignored by PBR
  2655. shaderp->mFeatures.calculatesAtmospherics = true;
  2656. shaderp->mFeatures.hasAtmospherics = true;
  2657. if (gUsePBRShaders)
  2658. {
  2659. shaderp->mFeatures.hasReflectionProbes = true;
  2660. }
  2661. else
  2662. {
  2663. shaderp->mFeatures.hasTransport = true;
  2664. }
  2665. shaderp->mFeatures.hasGamma = true;
  2666. shaderp->mFeatures.isDeferred = true;
  2667. shaderp->mFeatures.hasShadows = true;
  2668. if (use_sun_shadow)
  2669. {
  2670. if (gUsePBRShaders)
  2671. {
  2672. shaderp->addPermutation("HAS_SUN_SHADOW", "1");
  2673. }
  2674. else
  2675. {
  2676. shaderp->addPermutation("HAS_SHADOW", "1");
  2677. }
  2678. }
  2679. shaderp->addPermutation("USE_DIFFUSE_TEX", "1");
  2680. shaderp->addPermutation("IS_AVATAR_SKIN", "1");
  2681. success = shaderp->createShader();
  2682. // *HACK: set after creation to disable auto-setup of texture channels
  2683. shaderp->mFeatures.calculatesLighting = true;
  2684. shaderp->mFeatures.hasLighting = true;
  2685. }
  2686. if (success && gUsePBRShaders)
  2687. {
  2688. gExposureProgram.setup("Deferred exposure shader", shader_level,
  2689. "deferred/postDeferredNoTCV.glsl",
  2690. "deferred/exposureF.glsl");
  2691. gExposureProgram.mFeatures.hasSrgb = true;
  2692. gExposureProgram.mFeatures.isDeferred = true;
  2693. gExposureProgram.addPermutation("USE_LAST_EXPOSURE", "1");
  2694. success = gExposureProgram.createShader();
  2695. }
  2696. if (success && gUsePBRShaders)
  2697. {
  2698. gExposureProgramNoFade.setup("Deferred exposure (no fade) shader",
  2699. shader_level,
  2700. "deferred/postDeferredNoTCV.glsl",
  2701. "deferred/exposureF.glsl");
  2702. gExposureProgramNoFade.mFeatures.hasSrgb = true;
  2703. gExposureProgramNoFade.mFeatures.isDeferred = true;
  2704. success = gExposureProgramNoFade.createShader();
  2705. }
  2706. if (success && gUsePBRShaders)
  2707. {
  2708. gLuminanceProgram.setup("Deferred luminance shader", shader_level,
  2709. "deferred/postDeferredNoTCV.glsl",
  2710. "deferred/luminanceF.glsl");
  2711. success = gLuminanceProgram.createShader();
  2712. }
  2713. if (success)
  2714. {
  2715. shaderp = &gDeferredPostGammaCorrectProgram;
  2716. shaderp->setup("Deferred gamma correction post process", shader_level,
  2717. "deferred/postDeferredNoTCV.glsl",
  2718. "deferred/postDeferredGammaCorrect.glsl");
  2719. shaderp->mFeatures.hasSrgb = true;
  2720. shaderp->mFeatures.isDeferred = true;
  2721. shaderp->mFeatures.hasGamma = true;
  2722. success = shaderp->createShader();
  2723. }
  2724. if (success && gUsePBRShaders)
  2725. {
  2726. shaderp = &gNoPostGammaCorrectProgram;
  2727. shaderp->setup("Deferred no post gamma correction post process",
  2728. shader_level, "deferred/postDeferredNoTCV.glsl",
  2729. "deferred/postDeferredGammaCorrect.glsl");
  2730. shaderp->mFeatures.hasSrgb = true;
  2731. shaderp->mFeatures.isDeferred = true;
  2732. shaderp->addPermutation("NO_POST", "1");
  2733. success = shaderp->createShader();
  2734. }
  2735. if (success && gUsePBRShaders)
  2736. {
  2737. shaderp = &gLegacyPostGammaCorrectProgram;
  2738. shaderp->setup("Deferred legacy gamma correction post process",
  2739. shader_level, "deferred/postDeferredNoTCV.glsl",
  2740. "deferred/postDeferredGammaCorrect.glsl");
  2741. shaderp->mFeatures.hasSrgb = true;
  2742. shaderp->mFeatures.isDeferred = true;
  2743. shaderp->addPermutation("LEGACY_GAMMA", "1");
  2744. success = shaderp->createShader();
  2745. }
  2746. static const char* levels[4] = { " low quality shader",
  2747. " medium quality shader",
  2748. " high quality shader",
  2749. " ultra quality shader" };
  2750. if (success)
  2751. {
  2752. static const char* qualities[4] = { "12", "23", "29", "39" };
  2753. for (U32 i = 0; success && i < 4; ++i)
  2754. {
  2755. shaderp = &gFXAAProgram[i];
  2756. shaderp->setup(llformat("FXAA%s", levels[i]).c_str(), shader_level,
  2757. "deferred/postDeferredV.glsl",
  2758. "deferred/fxaaF.glsl");
  2759. shaderp->mFeatures.isDeferred = true;
  2760. shaderp->addPermutation("FXAA_QUALITY__PRESET", qualities[i]);
  2761. success = shaderp->createShader();
  2762. }
  2763. sHasFXAA = success; // Remember the result of FXAA shaders compilation.
  2764. success = true; // Do not give up when only FXAA shaders fail. HB
  2765. }
  2766. if (success)
  2767. {
  2768. static const char* qualities[4] = { "SMAA_PRESET_LOW",
  2769. "SMAA_PRESET_MEDIUM",
  2770. "SMAA_PRESET_HIGH",
  2771. "SMAA_PRESET_ULTRA" };
  2772. LLGLSLShader::defines_map_t defines;
  2773. if (gGLManager.mGLVersion >= 4.f)
  2774. {
  2775. defines.emplace("SMAA_GLSL_4", "1");
  2776. }
  2777. else if (gGLManager.mGLVersion >= 3.1f)
  2778. {
  2779. defines.emplace("SMAA_GLSL_3", "1");
  2780. }
  2781. else
  2782. {
  2783. defines.emplace("SMAA_GLSL_2", "1");
  2784. }
  2785. defines.emplace("SMAA_PREDICATION", "0");
  2786. defines.emplace("SMAA_REPROJECTION", "0");
  2787. for (U32 i = 0; success && i < 4; ++i)
  2788. {
  2789. shaderp = &gPostSMAAEdgeDetect[i];
  2790. shaderp->setup(llformat("SMAA edge detection%s", levels[i]).c_str(),
  2791. shader_level, "deferred/SMAAEdgeDetectV.glsl",
  2792. "deferred/SMAAEdgeDetectF.glsl");
  2793. shaderp->mShaderFiles.emplace_back("deferred/SMAAV.glsl",
  2794. GL_VERTEX_SHADER);
  2795. shaderp->mShaderFiles.emplace_back("deferred/SMAAF.glsl",
  2796. GL_FRAGMENT_SHADER);
  2797. shaderp->mFeatures.isDeferred = true;
  2798. shaderp->addPermutation(qualities[i], "1");
  2799. shaderp->addPermutations(defines);
  2800. success = shaderp->createShader();
  2801. if (success)
  2802. {
  2803. shaderp->bind();
  2804. shaderp->uniform1i(sTex0, 0);
  2805. shaderp->uniform1i(sTex1, 1);
  2806. shaderp->unbind();
  2807. }
  2808. }
  2809. for (U32 i = 0; success && i < 4; ++i)
  2810. {
  2811. shaderp = &gPostSMAABlendWeights[i];
  2812. shaderp->setup(llformat("SMAA weights blending%s",
  2813. levels[i]).c_str(),
  2814. shader_level, "deferred/SMAABlendWeightsV.glsl",
  2815. "deferred/SMAABlendWeightsF.glsl");
  2816. shaderp->mShaderFiles.emplace_back("deferred/SMAAV.glsl",
  2817. GL_VERTEX_SHADER);
  2818. shaderp->mShaderFiles.emplace_back("deferred/SMAAF.glsl",
  2819. GL_FRAGMENT_SHADER);
  2820. shaderp->mFeatures.isDeferred = true;
  2821. shaderp->addPermutation(qualities[i], "1");
  2822. shaderp->addPermutations(defines);
  2823. success = shaderp->createShader();
  2824. if (success)
  2825. {
  2826. shaderp->bind();
  2827. shaderp->uniform1i(sTex0, 0);
  2828. shaderp->uniform1i(sTex1, 1);
  2829. shaderp->uniform1i(sTex2, 2);
  2830. shaderp->unbind();
  2831. }
  2832. }
  2833. for (U32 i = 0; success && i < 4; ++i)
  2834. {
  2835. shaderp = &gPostSMAANeighborhoodBlend[i];
  2836. shaderp->setup(llformat("SMAA neighborhood blending%s",
  2837. levels[i]).c_str(),
  2838. shader_level,
  2839. "deferred/SMAANeighborhoodBlendV.glsl",
  2840. "deferred/SMAANeighborhoodBlendF.glsl");
  2841. shaderp->mShaderFiles.emplace_back("deferred/SMAAV.glsl",
  2842. GL_VERTEX_SHADER);
  2843. shaderp->mShaderFiles.emplace_back("deferred/SMAAF.glsl",
  2844. GL_FRAGMENT_SHADER);
  2845. shaderp->mFeatures.isDeferred = true;
  2846. shaderp->addPermutation(qualities[i], "1");
  2847. shaderp->addPermutations(defines);
  2848. success = shaderp->createShader();
  2849. if (success)
  2850. {
  2851. shaderp->bind();
  2852. shaderp->uniform1i(sTex0, 0);
  2853. shaderp->uniform1i(sTex1, 1);
  2854. shaderp->uniform1i(sTex2, 2);
  2855. shaderp->unbind();
  2856. }
  2857. }
  2858. sHasSMAA = success; // Remember the result of SMAA shaders compilation.
  2859. success = true; // Do not give up when only SMAA shaders fail. HB
  2860. }
  2861. if (success)
  2862. {
  2863. gPostCASProgram.setup("Contrast adaptive sharpen shader", shader_level,
  2864. "deferred/postNoTCV.glsl",
  2865. "deferred/CASF.glsl");
  2866. success = gPostCASProgram.createShader();
  2867. sHasCAS = success; // Remember the result of CAS shader compilation.
  2868. success = true; // Do not give up when only CAS shader fails. HB
  2869. }
  2870. if (success)
  2871. {
  2872. gDeferredPostProgram.setup("Deferred post shader", shader_level,
  2873. "deferred/postDeferredNoTCV.glsl",
  2874. "deferred/postDeferredF.glsl");
  2875. gDeferredPostProgram.mFeatures.isDeferred = true;
  2876. success = gDeferredPostProgram.createShader();
  2877. }
  2878. if (success)
  2879. {
  2880. gDeferredCoFProgram.setup("Deferred CoF shader", shader_level,
  2881. "deferred/postDeferredNoTCV.glsl",
  2882. "deferred/cofF.glsl");
  2883. gDeferredCoFProgram.mFeatures.isDeferred = true;
  2884. success = gDeferredCoFProgram.createShader();
  2885. }
  2886. if (success)
  2887. {
  2888. gDeferredDoFCombineProgram.setup("Deferred DoF combine shader",
  2889. shader_level,
  2890. "deferred/postDeferredNoTCV.glsl",
  2891. "deferred/dofCombineF.glsl");
  2892. gDeferredDoFCombineProgram.mFeatures.isDeferred = true;
  2893. success = gDeferredDoFCombineProgram.createShader();
  2894. }
  2895. if (success)
  2896. {
  2897. gDeferredPostNoDoFProgram.setup("Deferred post no DoF shader",
  2898. shader_level,
  2899. "deferred/postDeferredNoTCV.glsl",
  2900. "deferred/postDeferredNoDoFF.glsl");
  2901. gDeferredPostNoDoFProgram.mFeatures.isDeferred = true;
  2902. success = gDeferredPostNoDoFProgram.createShader();
  2903. }
  2904. if (success && gUsePBRShaders)
  2905. {
  2906. gEnvironmentMapProgram.setup("Deferred environment map shader",
  2907. shader_level,
  2908. "deferred/skyV.glsl",
  2909. "deferred/skyF.glsl");
  2910. gEnvironmentMapProgram.mFeatures.calculatesAtmospherics = true;
  2911. gEnvironmentMapProgram.mFeatures.hasAtmospherics = true;
  2912. gEnvironmentMapProgram.mFeatures.hasGamma = true;
  2913. gEnvironmentMapProgram.mFeatures.hasSrgb = true;
  2914. gEnvironmentMapProgram.addPermutation("HAS_HDRI", "1");
  2915. gEnvironmentMapProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  2916. success = gEnvironmentMapProgram.createShader();
  2917. }
  2918. if (success)
  2919. {
  2920. gDeferredWLSkyProgram.setup("Deferred Windlight sky shader",
  2921. shader_level,
  2922. "deferred/skyV.glsl",
  2923. "deferred/skyF.glsl");
  2924. gDeferredWLSkyProgram.mFeatures.calculatesAtmospherics = true;
  2925. if (gUsePBRShaders)
  2926. {
  2927. gDeferredWLSkyProgram.mFeatures.hasAtmospherics = true;
  2928. }
  2929. else
  2930. {
  2931. gDeferredWLSkyProgram.mFeatures.hasTransport = true;
  2932. }
  2933. gDeferredWLSkyProgram.mFeatures.hasGamma = true;
  2934. gDeferredWLSkyProgram.mFeatures.hasSrgb = true;
  2935. gDeferredWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  2936. success = gDeferredWLSkyProgram.createShader();
  2937. }
  2938. if (success)
  2939. {
  2940. shaderp = &gDeferredWLCloudProgram;
  2941. shaderp->setup("Deferred Windlight cloud shader", shader_level,
  2942. "deferred/cloudsV.glsl", "deferred/cloudsF.glsl");
  2943. shaderp->mFeatures.calculatesAtmospherics = true;
  2944. shaderp->mFeatures.hasGamma = true;
  2945. shaderp->mFeatures.hasSrgb = true;
  2946. if (gUsePBRShaders)
  2947. {
  2948. shaderp->mFeatures.hasAtmospherics = true;
  2949. }
  2950. else
  2951. {
  2952. shaderp->mFeatures.hasTransport = true;
  2953. }
  2954. shaderp->addConstant(LLGLSLShader::CONST_CLOUD_MOON_DEPTH);
  2955. shaderp->mShaderGroup = LLGLSLShader::SG_SKY;
  2956. success = shaderp->createShader();
  2957. }
  2958. if (success)
  2959. {
  2960. gDeferredWLSunProgram.setup("Deferred Windlight Sun program",
  2961. shader_level,
  2962. "deferred/sunDiscV.glsl",
  2963. "deferred/sunDiscF.glsl");
  2964. gDeferredWLSunProgram.mFeatures.calculatesAtmospherics = true;
  2965. gDeferredWLSunProgram.mFeatures.hasAtmospherics = true;
  2966. gDeferredWLSunProgram.mFeatures.hasGamma = true;
  2967. gDeferredWLSunProgram.mFeatures.disableTextureIndex = true;
  2968. gDeferredWLSunProgram.mFeatures.hasSrgb = true;
  2969. if (!gUsePBRShaders)
  2970. {
  2971. gDeferredWLSunProgram.mFeatures.hasTransport = true;
  2972. gDeferredWLSunProgram.mFeatures.isFullbright = true;
  2973. }
  2974. gDeferredWLSunProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  2975. success = gDeferredWLSunProgram.createShader();
  2976. }
  2977. if (success)
  2978. {
  2979. shaderp = &gDeferredWLMoonProgram;
  2980. shaderp->setup("Deferred Windlight Moon program", shader_level,
  2981. "deferred/moonV.glsl", "deferred/moonF.glsl");
  2982. shaderp->mFeatures.calculatesAtmospherics = true;
  2983. shaderp->mFeatures.hasGamma = true;
  2984. shaderp->mFeatures.hasAtmospherics = true;
  2985. shaderp->mFeatures.hasSrgb = true;
  2986. shaderp->mFeatures.disableTextureIndex = true;
  2987. if (!gUsePBRShaders)
  2988. {
  2989. shaderp->mFeatures.hasTransport = true;
  2990. shaderp->mFeatures.isFullbright = true;
  2991. }
  2992. shaderp->mShaderGroup = LLGLSLShader::SG_SKY;
  2993. shaderp->addConstant(LLGLSLShader::CONST_CLOUD_MOON_DEPTH);
  2994. success = shaderp->createShader();
  2995. }
  2996. if (success)
  2997. {
  2998. gDeferredStarProgram.setup("Deferred star program", shader_level,
  2999. "deferred/starsV.glsl",
  3000. "deferred/starsF.glsl");
  3001. gDeferredStarProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3002. gDeferredStarProgram.addConstant(LLGLSLShader::CONST_STAR_DEPTH);
  3003. success = gDeferredStarProgram.createShader();
  3004. }
  3005. if (success)
  3006. {
  3007. gNormalMapGenProgram.setup("Normal map generation program",
  3008. shader_level, "deferred/normgenV.glsl",
  3009. "deferred/normgenF.glsl");
  3010. gNormalMapGenProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3011. success = gNormalMapGenProgram.createShader();
  3012. }
  3013. if (success && gUsePBRShaders)
  3014. {
  3015. gDeferredGenBrdfLutProgram.setup("Brdf generation program",
  3016. shader_level, "deferred/genbrdflutV.glsl",
  3017. "deferred/genbrdflutF.glsl");
  3018. success = gDeferredGenBrdfLutProgram.createShader();
  3019. }
  3020. if (success && gUsePBRShaders)
  3021. {
  3022. shaderp = &gPostScreenSpaceReflectionProgram;
  3023. shaderp->setup("Screen space reflection post program", 3,
  3024. "deferred/screenSpaceReflPostV.glsl",
  3025. "deferred/screenSpaceReflPostF.glsl");
  3026. shaderp->mFeatures.hasScreenSpaceReflections = true;
  3027. shaderp->mFeatures.isDeferred = true;
  3028. success = shaderp->createShader();
  3029. }
  3030. if (success && gUsePBRShaders)
  3031. {
  3032. shaderp = &gDeferredBufferVisualProgram;
  3033. shaderp->setup("Deferred buffer visualization shader", shader_level,
  3034. "deferred/postDeferredNoTCV.glsl",
  3035. "deferred/postDeferredVisualizeBuffers.glsl");
  3036. success = shaderp->createShader();
  3037. }
  3038. if (success)
  3039. {
  3040. llinfos << "Deferred shaders loaded at level: " << shader_level
  3041. << llendl;
  3042. }
  3043. return success;
  3044. }
  3045. bool LLViewerShaderMgr::loadShadersObject()
  3046. {
  3047. S32 shader_level = mShaderLevel[SHADER_OBJECT];
  3048. LLGLSLShader* shaderp;
  3049. bool success = true;
  3050. if (!gUsePBRShaders)
  3051. {
  3052. shaderp = &gObjectSimpleNonIndexedTexGenProgram;
  3053. shaderp->setup("Non indexed tex-gen shader", shader_level,
  3054. "objects/simpleTexGenV.glsl", "objects/simpleF.glsl");
  3055. shaderp->mFeatures.calculatesLighting = true;
  3056. shaderp->mFeatures.calculatesAtmospherics = true;
  3057. shaderp->mFeatures.hasGamma = true;
  3058. shaderp->mFeatures.hasAtmospherics = true;
  3059. shaderp->mFeatures.hasLighting = true;
  3060. shaderp->mFeatures.disableTextureIndex = true;
  3061. success = shaderp->createShader();
  3062. }
  3063. if (success && !gUsePBRShaders)
  3064. {
  3065. shaderp = &gObjectSimpleNonIndexedTexGenWaterProgram;
  3066. shaderp->setup("Non indexed tex-gen water shader", shader_level,
  3067. "objects/simpleTexGenV.glsl",
  3068. "objects/simpleWaterF.glsl");
  3069. shaderp->mFeatures.calculatesLighting = true;
  3070. shaderp->mFeatures.calculatesAtmospherics = true;
  3071. shaderp->mFeatures.hasWaterFog = true;
  3072. shaderp->mFeatures.hasAtmospherics = true;
  3073. shaderp->mFeatures.hasLighting = true;
  3074. shaderp->mFeatures.disableTextureIndex = true;
  3075. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3076. success = shaderp->createShader();
  3077. }
  3078. if (success && !gUsePBRShaders)
  3079. {
  3080. shaderp = &gObjectAlphaMaskNonIndexedProgram;
  3081. shaderp->setup("Non indexed alpha mask shader", shader_level,
  3082. "objects/simpleNonIndexedV.glsl",
  3083. "objects/simpleF.glsl");
  3084. shaderp->mFeatures.calculatesLighting = true;
  3085. shaderp->mFeatures.calculatesAtmospherics = true;
  3086. shaderp->mFeatures.hasGamma = true;
  3087. shaderp->mFeatures.hasAtmospherics = true;
  3088. shaderp->mFeatures.hasLighting = true;
  3089. shaderp->mFeatures.disableTextureIndex = true;
  3090. shaderp->mFeatures.hasAlphaMask = true;
  3091. success = shaderp->createShader();
  3092. }
  3093. if (success && !gUsePBRShaders)
  3094. {
  3095. shaderp = &gObjectAlphaMaskNonIndexedWaterProgram;
  3096. shaderp->setup("Non indexed alpha mask water shader", shader_level,
  3097. "objects/simpleNonIndexedV.glsl",
  3098. "objects/simpleWaterF.glsl");
  3099. shaderp->mFeatures.calculatesLighting = true;
  3100. shaderp->mFeatures.calculatesAtmospherics = true;
  3101. shaderp->mFeatures.hasWaterFog = true;
  3102. shaderp->mFeatures.hasAtmospherics = true;
  3103. shaderp->mFeatures.hasLighting = true;
  3104. shaderp->mFeatures.disableTextureIndex = true;
  3105. shaderp->mFeatures.hasAlphaMask = true;
  3106. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3107. success = shaderp->createShader();
  3108. }
  3109. if (success)
  3110. {
  3111. gObjectAlphaMaskNoColorProgram.setup("No color alpha mask shader",
  3112. shader_level,
  3113. "objects/simpleNoColorV.glsl",
  3114. "objects/simpleF.glsl");
  3115. gObjectAlphaMaskNoColorProgram.mFeatures.calculatesLighting = true;
  3116. gObjectAlphaMaskNoColorProgram.mFeatures.calculatesAtmospherics = true;
  3117. gObjectAlphaMaskNoColorProgram.mFeatures.hasGamma = true;
  3118. gObjectAlphaMaskNoColorProgram.mFeatures.hasAtmospherics = true;
  3119. gObjectAlphaMaskNoColorProgram.mFeatures.hasLighting = true;
  3120. gObjectAlphaMaskNoColorProgram.mFeatures.disableTextureIndex = true;
  3121. gObjectAlphaMaskNoColorProgram.mFeatures.hasAlphaMask = true;
  3122. success = gObjectAlphaMaskNoColorProgram.createShader();
  3123. }
  3124. if (success && !gUsePBRShaders)
  3125. {
  3126. shaderp = &gObjectAlphaMaskNoColorWaterProgram;
  3127. shaderp->setup("No color alpha mask water shader", shader_level,
  3128. "objects/simpleNoColorV.glsl",
  3129. "objects/simpleWaterF.glsl");
  3130. shaderp->mFeatures.calculatesLighting = true;
  3131. shaderp->mFeatures.calculatesAtmospherics = true;
  3132. shaderp->mFeatures.hasWaterFog = true;
  3133. shaderp->mFeatures.hasAtmospherics = true;
  3134. shaderp->mFeatures.hasLighting = true;
  3135. shaderp->mFeatures.disableTextureIndex = true;
  3136. shaderp->mFeatures.hasAlphaMask = true;
  3137. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3138. success = shaderp->createShader();
  3139. }
  3140. if (success && !gUsePBRShaders)
  3141. {
  3142. gTreeProgram.setup("Tree shader", shader_level,
  3143. "objects/treeV.glsl", "objects/simpleF.glsl");
  3144. gTreeProgram.mFeatures.calculatesLighting = true;
  3145. gTreeProgram.mFeatures.calculatesAtmospherics = true;
  3146. gTreeProgram.mFeatures.hasGamma = true;
  3147. gTreeProgram.mFeatures.hasAtmospherics = true;
  3148. gTreeProgram.mFeatures.hasLighting = true;
  3149. gTreeProgram.mFeatures.disableTextureIndex = true;
  3150. gTreeProgram.mFeatures.hasAlphaMask = true;
  3151. success = gTreeProgram.createShader();
  3152. }
  3153. if (success && !gUsePBRShaders)
  3154. {
  3155. gTreeWaterProgram.setup("Tree water shader", shader_level,
  3156. "objects/treeV.glsl",
  3157. "objects/simpleWaterF.glsl");
  3158. gTreeWaterProgram.mFeatures.calculatesLighting = true;
  3159. gTreeWaterProgram.mFeatures.calculatesAtmospherics = true;
  3160. gTreeWaterProgram.mFeatures.hasWaterFog = true;
  3161. gTreeWaterProgram.mFeatures.hasAtmospherics = true;
  3162. gTreeWaterProgram.mFeatures.hasLighting = true;
  3163. gTreeWaterProgram.mFeatures.disableTextureIndex = true;
  3164. gTreeWaterProgram.mFeatures.hasAlphaMask = true;
  3165. gTreeWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3166. success = gTreeWaterProgram.createShader();
  3167. }
  3168. if (success && !gUsePBRShaders)
  3169. {
  3170. shaderp = &gObjectFullbrightNoColorWaterProgram;
  3171. shaderp->setup("Non indexed no color full bright water shader",
  3172. shader_level, "objects/fullbrightNoColorV.glsl",
  3173. "objects/fullbrightWaterF.glsl");
  3174. shaderp->mFeatures.calculatesAtmospherics = true;
  3175. shaderp->mFeatures.isFullbright = true;
  3176. shaderp->mFeatures.hasWaterFog = true;
  3177. shaderp->mFeatures.hasTransport = true;
  3178. shaderp->mFeatures.disableTextureIndex = true;
  3179. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3180. success = shaderp->createShader();
  3181. }
  3182. if (success)
  3183. {
  3184. gImpostorProgram.setup("Impostor shader", shader_level,
  3185. "objects/impostorV.glsl",
  3186. "objects/impostorF.glsl");
  3187. gImpostorProgram.mFeatures.disableTextureIndex = true;
  3188. gImpostorProgram.mFeatures.hasSrgb = true;
  3189. success = gImpostorProgram.createShader();
  3190. }
  3191. if (success)
  3192. {
  3193. gObjectPreviewProgram.setup("Preview shader", shader_level,
  3194. "objects/previewV.glsl",
  3195. "objects/previewF.glsl");
  3196. gObjectPreviewProgram.mFeatures.mIndexedTextureChannels = 0;
  3197. gObjectPreviewProgram.mFeatures.disableTextureIndex = true;
  3198. if (gUsePBRShaders)
  3199. {
  3200. success = create_with_rigged(gObjectPreviewProgram,
  3201. gSkinnedObjectPreviewProgram);
  3202. gSkinnedObjectPreviewProgram.mFeatures.hasLighting = true;
  3203. }
  3204. else
  3205. {
  3206. success = gObjectPreviewProgram.createShader();
  3207. }
  3208. // *HACK: set after creation to disable auto-setup of texture channels
  3209. gObjectPreviewProgram.mFeatures.hasLighting = true;
  3210. }
  3211. if (success && gUsePBRShaders)
  3212. {
  3213. gPhysicsPreviewProgram.setup("Preview physics shader", shader_level,
  3214. "objects/previewPhysicsV.glsl",
  3215. "objects/previewPhysicsF.glsl");
  3216. gPhysicsPreviewProgram.mFeatures.disableTextureIndex = true;
  3217. gPhysicsPreviewProgram.mFeatures.mIndexedTextureChannels = 0;
  3218. success = gPhysicsPreviewProgram.createShader();
  3219. }
  3220. if (success && !gUsePBRShaders)
  3221. {
  3222. gObjectSimpleProgram.setup("Simple shader", shader_level,
  3223. "objects/simpleV.glsl",
  3224. "objects/simpleF.glsl");
  3225. gObjectSimpleProgram.mFeatures.calculatesLighting = true;
  3226. gObjectSimpleProgram.mFeatures.calculatesAtmospherics = true;
  3227. gObjectSimpleProgram.mFeatures.hasGamma = true;
  3228. gObjectSimpleProgram.mFeatures.hasAtmospherics = true;
  3229. gObjectSimpleProgram.mFeatures.hasLighting = true;
  3230. gObjectSimpleProgram.mFeatures.mIndexedTextureChannels = 0;
  3231. success = create_with_rigged(gObjectSimpleProgram,
  3232. gSkinnedObjectSimpleProgram);
  3233. }
  3234. if (success && !gUsePBRShaders)
  3235. {
  3236. gObjectSimpleImpostorProgram.setup("Simple impostor shader",
  3237. shader_level,
  3238. "objects/simpleV.glsl",
  3239. "objects/simpleF.glsl");
  3240. gObjectSimpleImpostorProgram.mFeatures.calculatesLighting = true;
  3241. gObjectSimpleImpostorProgram.mFeatures.calculatesAtmospherics = true;
  3242. gObjectSimpleImpostorProgram.mFeatures.hasGamma = true;
  3243. gObjectSimpleImpostorProgram.mFeatures.hasAtmospherics = true;
  3244. gObjectSimpleImpostorProgram.mFeatures.hasLighting = true;
  3245. gObjectSimpleImpostorProgram.mFeatures.mIndexedTextureChannels = 0;
  3246. // Force alpha mask version of lighting so we can weed out transparent
  3247. // pixels from impostor temp buffer:
  3248. gObjectSimpleImpostorProgram.mFeatures.hasAlphaMask = true;
  3249. success = create_with_rigged(gObjectSimpleImpostorProgram,
  3250. gSkinnedObjectSimpleImpostorProgram);
  3251. }
  3252. if (success && !gUsePBRShaders)
  3253. {
  3254. gObjectSimpleWaterProgram.setup("Simple water shader", shader_level,
  3255. "objects/simpleV.glsl",
  3256. "objects/simpleWaterF.glsl");
  3257. gObjectSimpleWaterProgram.mFeatures.calculatesLighting = true;
  3258. gObjectSimpleWaterProgram.mFeatures.calculatesAtmospherics = true;
  3259. gObjectSimpleWaterProgram.mFeatures.hasWaterFog = true;
  3260. gObjectSimpleWaterProgram.mFeatures.hasAtmospherics = true;
  3261. gObjectSimpleWaterProgram.mFeatures.hasLighting = true;
  3262. gObjectSimpleWaterProgram.mFeatures.mIndexedTextureChannels = 0;
  3263. gObjectSimpleWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3264. success = create_with_rigged(gObjectSimpleWaterProgram,
  3265. gSkinnedObjectSimpleWaterProgram);
  3266. }
  3267. if (success)
  3268. {
  3269. gObjectBumpProgram.setup("Bump shader", shader_level,
  3270. "objects/bumpV.glsl", "objects/bumpF.glsl");
  3271. // Note: ignored by PBR
  3272. gObjectBumpProgram.mFeatures.encodesNormal = true;
  3273. success = create_with_rigged(gObjectBumpProgram,
  3274. gSkinnedObjectBumpProgram);
  3275. // LLDrawpoolBump assumes "texture0" has channel 0 and "texture1" has
  3276. // channel 1
  3277. LLGLSLShader* shader[] = { &gObjectBumpProgram,
  3278. &gSkinnedObjectBumpProgram };
  3279. for (U32 rigged = 0; success && rigged < 2; ++rigged)
  3280. {
  3281. shader[rigged]->bind();
  3282. shader[rigged]->uniform1i(sTexture0, 0);
  3283. shader[rigged]->uniform1i(sTexture1, 1);
  3284. shader[rigged]->unbind();
  3285. }
  3286. }
  3287. if (success && !gUsePBRShaders)
  3288. {
  3289. gObjectSimpleAlphaMaskProgram.setup("Simple alpha mask shader",
  3290. shader_level,
  3291. "objects/simpleV.glsl",
  3292. "objects/simpleF.glsl");
  3293. gObjectSimpleAlphaMaskProgram.mFeatures.calculatesLighting = true;
  3294. gObjectSimpleAlphaMaskProgram.mFeatures.calculatesAtmospherics = true;
  3295. gObjectSimpleAlphaMaskProgram.mFeatures.hasGamma = true;
  3296. gObjectSimpleAlphaMaskProgram.mFeatures.hasAtmospherics = true;
  3297. gObjectSimpleAlphaMaskProgram.mFeatures.hasLighting = true;
  3298. gObjectSimpleAlphaMaskProgram.mFeatures.hasAlphaMask = true;
  3299. gObjectSimpleAlphaMaskProgram.mFeatures.mIndexedTextureChannels = 0;
  3300. success = create_with_rigged(gObjectSimpleAlphaMaskProgram,
  3301. gSkinnedObjectSimpleAlphaMaskProgram);
  3302. }
  3303. if (success && !gUsePBRShaders)
  3304. {
  3305. shaderp = &gObjectSimpleWaterAlphaMaskProgram;
  3306. shaderp->setup("Simple water alpha mask shader", shader_level,
  3307. "objects/simpleV.glsl", "objects/simpleWaterF.glsl");
  3308. shaderp->mFeatures.calculatesLighting = true;
  3309. shaderp->mFeatures.calculatesAtmospherics = true;
  3310. shaderp->mFeatures.hasWaterFog = true;
  3311. shaderp->mFeatures.hasAtmospherics = true;
  3312. shaderp->mFeatures.hasLighting = true;
  3313. shaderp->mFeatures.hasAlphaMask = true;
  3314. shaderp->mFeatures.mIndexedTextureChannels = 0;
  3315. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3316. success =
  3317. create_with_rigged(*shaderp,
  3318. gSkinnedObjectSimpleWaterAlphaMaskProgram);
  3319. }
  3320. if (success && !gUsePBRShaders)
  3321. {
  3322. gObjectFullbrightProgram.setup("Fullbright shader", shader_level,
  3323. "objects/fullbrightV.glsl",
  3324. "objects/fullbrightF.glsl");
  3325. gObjectFullbrightProgram.mFeatures.calculatesAtmospherics = true;
  3326. gObjectFullbrightProgram.mFeatures.hasGamma = true;
  3327. gObjectFullbrightProgram.mFeatures.hasTransport = true;
  3328. gObjectFullbrightProgram.mFeatures.isFullbright = true;
  3329. gObjectFullbrightProgram.mFeatures.hasSrgb = true;
  3330. gObjectFullbrightProgram.mFeatures.mIndexedTextureChannels = 0;
  3331. success = create_with_rigged(gObjectFullbrightProgram,
  3332. gSkinnedObjectFullbrightProgram);
  3333. }
  3334. if (success && !gUsePBRShaders)
  3335. {
  3336. gObjectFullbrightWaterProgram.setup("Fullbright water shader",
  3337. shader_level,
  3338. "objects/fullbrightV.glsl",
  3339. "objects/fullbrightWaterF.glsl");
  3340. gObjectFullbrightWaterProgram.mFeatures.calculatesAtmospherics = true;
  3341. gObjectFullbrightWaterProgram.mFeatures.isFullbright = true;
  3342. gObjectFullbrightWaterProgram.mFeatures.hasWaterFog = true;
  3343. gObjectFullbrightWaterProgram.mFeatures.hasTransport = true;
  3344. gObjectFullbrightWaterProgram.mFeatures.mIndexedTextureChannels = 0;
  3345. gObjectFullbrightWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3346. success = create_with_rigged(gObjectFullbrightWaterProgram,
  3347. gSkinnedObjectFullbrightWaterProgram);
  3348. }
  3349. if (success && !gUsePBRShaders)
  3350. {
  3351. gObjectEmissiveProgram.setup("Emissive shader", shader_level,
  3352. "objects/emissiveV.glsl",
  3353. "objects/fullbrightF.glsl");
  3354. gObjectEmissiveProgram.mFeatures.calculatesAtmospherics = true;
  3355. gObjectEmissiveProgram.mFeatures.hasGamma = true;
  3356. gObjectEmissiveProgram.mFeatures.hasTransport = true;
  3357. gObjectEmissiveProgram.mFeatures.isFullbright = true;
  3358. gObjectEmissiveProgram.mFeatures.hasSrgb = true;
  3359. gObjectEmissiveProgram.mFeatures.mIndexedTextureChannels = 0;
  3360. success = create_with_rigged(gObjectEmissiveProgram,
  3361. gSkinnedObjectEmissiveProgram);
  3362. }
  3363. if (success && !gUsePBRShaders)
  3364. {
  3365. gObjectEmissiveWaterProgram.setup("Emissive water shader",
  3366. shader_level,
  3367. "objects/emissiveV.glsl",
  3368. "objects/fullbrightWaterF.glsl");
  3369. gObjectEmissiveWaterProgram.mFeatures.calculatesAtmospherics = true;
  3370. gObjectEmissiveWaterProgram.mFeatures.isFullbright = true;
  3371. gObjectEmissiveWaterProgram.mFeatures.hasWaterFog = true;
  3372. gObjectEmissiveWaterProgram.mFeatures.hasTransport = true;
  3373. gObjectEmissiveWaterProgram.mFeatures.mIndexedTextureChannels = 0;
  3374. gObjectEmissiveWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3375. success = create_with_rigged(gObjectEmissiveWaterProgram,
  3376. gSkinnedObjectEmissiveWaterProgram);
  3377. }
  3378. if (success && !gUsePBRShaders)
  3379. {
  3380. shaderp = &gObjectFullbrightAlphaMaskProgram;
  3381. shaderp->setup("Fullbright alpha mask shader", shader_level,
  3382. "objects/fullbrightV.glsl", "objects/fullbrightF.glsl");
  3383. shaderp->mFeatures.calculatesAtmospherics = true;
  3384. shaderp->mFeatures.hasGamma = true;
  3385. shaderp->mFeatures.hasTransport = true;
  3386. shaderp->mFeatures.isFullbright = true;
  3387. shaderp->mFeatures.hasAlphaMask = true;
  3388. shaderp->mFeatures.hasSrgb = true;
  3389. shaderp->mFeatures.mIndexedTextureChannels = 0;
  3390. success = create_with_rigged(*shaderp,
  3391. gSkinnedObjectFullbrightAlphaMaskProgram);
  3392. }
  3393. if (success && !gUsePBRShaders)
  3394. {
  3395. shaderp = &gObjectFullbrightWaterAlphaMaskProgram;
  3396. shaderp->setup("Fullbright water alpha mask shader", shader_level,
  3397. "objects/fullbrightV.glsl",
  3398. "objects/fullbrightWaterF.glsl");
  3399. shaderp->mFeatures.calculatesAtmospherics = true;
  3400. shaderp->mFeatures.isFullbright = true;
  3401. shaderp->mFeatures.hasWaterFog = true;
  3402. shaderp->mFeatures.hasTransport = true;
  3403. shaderp->mFeatures.hasAlphaMask = true;
  3404. shaderp->mFeatures.mIndexedTextureChannels = 0;
  3405. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3406. success =
  3407. create_with_rigged(*shaderp,
  3408. gSkinnedObjectFullbrightWaterAlphaMaskProgram);
  3409. }
  3410. if (success && !gUsePBRShaders)
  3411. {
  3412. gObjectShinyProgram.setup("Shiny shader", shader_level,
  3413. "objects/shinyV.glsl",
  3414. "objects/shinyF.glsl");
  3415. gObjectShinyProgram.mFeatures.calculatesAtmospherics = true;
  3416. gObjectShinyProgram.mFeatures.calculatesLighting = true;
  3417. gObjectShinyProgram.mFeatures.hasGamma = true;
  3418. gObjectShinyProgram.mFeatures.hasAtmospherics = true;
  3419. gObjectShinyProgram.mFeatures.isShiny = true;
  3420. gObjectShinyProgram.mFeatures.mIndexedTextureChannels = 0;
  3421. success = create_with_rigged(gObjectShinyProgram,
  3422. gSkinnedObjectShinyProgram);
  3423. }
  3424. if (success && !gUsePBRShaders)
  3425. {
  3426. gObjectShinyWaterProgram.setup("Shiny water shader", shader_level,
  3427. "objects/shinyV.glsl",
  3428. "objects/shinyWaterF.glsl");
  3429. gObjectShinyWaterProgram.mFeatures.calculatesAtmospherics = true;
  3430. gObjectShinyWaterProgram.mFeatures.calculatesLighting = true;
  3431. gObjectShinyWaterProgram.mFeatures.isShiny = true;
  3432. gObjectShinyWaterProgram.mFeatures.hasWaterFog = true;
  3433. gObjectShinyWaterProgram.mFeatures.hasAtmospherics = true;
  3434. gObjectShinyWaterProgram.mFeatures.mIndexedTextureChannels = 0;
  3435. gObjectShinyWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3436. success = create_with_rigged(gObjectShinyWaterProgram,
  3437. gSkinnedObjectShinyWaterProgram);
  3438. }
  3439. if (success && !gUsePBRShaders)
  3440. {
  3441. gObjectFullbrightShinyProgram.setup("Fullbright shiny shader",
  3442. shader_level,
  3443. "objects/fullbrightShinyV.glsl",
  3444. "objects/fullbrightShinyF.glsl");
  3445. gObjectFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
  3446. gObjectFullbrightShinyProgram.mFeatures.isFullbright = true;
  3447. gObjectFullbrightShinyProgram.mFeatures.isShiny = true;
  3448. gObjectFullbrightShinyProgram.mFeatures.hasGamma = true;
  3449. gObjectFullbrightShinyProgram.mFeatures.hasTransport = true;
  3450. gObjectFullbrightShinyProgram.mFeatures.mIndexedTextureChannels = 0;
  3451. success = create_with_rigged(gObjectFullbrightShinyProgram,
  3452. gSkinnedObjectFullbrightShinyProgram);
  3453. }
  3454. if (success && !gUsePBRShaders)
  3455. {
  3456. shaderp = &gObjectFullbrightShinyWaterProgram;
  3457. shaderp->setup("Fullbright shiny water shader", shader_level,
  3458. "objects/fullbrightShinyV.glsl",
  3459. "objects/fullbrightShinyWaterF.glsl");
  3460. shaderp->mFeatures.calculatesAtmospherics = true;
  3461. shaderp->mFeatures.isFullbright = true;
  3462. shaderp->mFeatures.isShiny = true;
  3463. shaderp->mFeatures.hasGamma = true;
  3464. shaderp->mFeatures.hasTransport = true;
  3465. shaderp->mFeatures.hasWaterFog = true;
  3466. shaderp->mFeatures.mIndexedTextureChannels = 0;
  3467. shaderp->mShaderGroup = LLGLSLShader::SG_WATER;
  3468. success =
  3469. create_with_rigged(*shaderp,
  3470. gSkinnedObjectFullbrightShinyWaterProgram);
  3471. }
  3472. if (success)
  3473. {
  3474. llinfos << "Object shaders loaded at level: " << shader_level
  3475. << llendl;
  3476. }
  3477. else
  3478. {
  3479. mShaderLevel[SHADER_OBJECT] = 0;
  3480. }
  3481. return success;
  3482. }
  3483. bool LLViewerShaderMgr::loadShadersAvatar()
  3484. {
  3485. S32 shader_level = mShaderLevel[SHADER_AVATAR];
  3486. if (shader_level == 0 || gUsePBRShaders)
  3487. {
  3488. gAvatarWaterProgram.unload();
  3489. }
  3490. if (shader_level == 0)
  3491. {
  3492. gAvatarProgram.unload();
  3493. gAvatarEyeballProgram.unload();
  3494. return true;
  3495. }
  3496. gAvatarProgram.setup("Avatar shader", shader_level,
  3497. "avatar/avatarV.glsl", "avatar/avatarF.glsl");
  3498. gAvatarProgram.mFeatures.hasSkinning = true;
  3499. gAvatarProgram.mFeatures.calculatesAtmospherics = true;
  3500. gAvatarProgram.mFeatures.calculatesLighting = true;
  3501. gAvatarProgram.mFeatures.hasGamma = true;
  3502. gAvatarProgram.mFeatures.hasAtmospherics = true;
  3503. gAvatarProgram.mFeatures.hasLighting = true;
  3504. gAvatarProgram.mFeatures.hasAlphaMask = true;
  3505. gAvatarProgram.mFeatures.disableTextureIndex = true;
  3506. bool success = gAvatarProgram.createShader();
  3507. if (success && !gUsePBRShaders)
  3508. {
  3509. gAvatarWaterProgram.setup("Avatar water shader",
  3510. // Note: no cloth under water:
  3511. llmin(shader_level, 1),
  3512. "avatar/avatarV.glsl",
  3513. "objects/simpleWaterF.glsl");
  3514. gAvatarWaterProgram.mFeatures.hasSkinning = true;
  3515. gAvatarWaterProgram.mFeatures.calculatesAtmospherics = true;
  3516. gAvatarWaterProgram.mFeatures.calculatesLighting = true;
  3517. gAvatarWaterProgram.mFeatures.hasWaterFog = true;
  3518. gAvatarWaterProgram.mFeatures.hasAtmospherics = true;
  3519. gAvatarWaterProgram.mFeatures.hasLighting = true;
  3520. gAvatarWaterProgram.mFeatures.hasAlphaMask = true;
  3521. gAvatarWaterProgram.mFeatures.disableTextureIndex = true;
  3522. gAvatarWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
  3523. success = gAvatarWaterProgram.createShader();
  3524. }
  3525. // Keep track of avatar levels
  3526. if (gAvatarProgram.mShaderLevel != mShaderLevel[SHADER_AVATAR])
  3527. {
  3528. shader_level = mMaxAvatarShaderLevel = mShaderLevel[SHADER_AVATAR] =
  3529. gAvatarProgram.mShaderLevel;
  3530. }
  3531. if (success)
  3532. {
  3533. gAvatarEyeballProgram.setup("Avatar eyeball program", shader_level,
  3534. "avatar/eyeballV.glsl",
  3535. "avatar/eyeballF.glsl");
  3536. gAvatarEyeballProgram.mFeatures.calculatesLighting = true;
  3537. gAvatarEyeballProgram.mFeatures.isSpecular = true;
  3538. gAvatarEyeballProgram.mFeatures.calculatesAtmospherics = true;
  3539. gAvatarEyeballProgram.mFeatures.hasGamma = true;
  3540. gAvatarEyeballProgram.mFeatures.hasAtmospherics = true;
  3541. gAvatarEyeballProgram.mFeatures.hasLighting = true;
  3542. gAvatarEyeballProgram.mFeatures.hasAlphaMask = true;
  3543. gAvatarEyeballProgram.mFeatures.disableTextureIndex = true;
  3544. success = gAvatarEyeballProgram.createShader();
  3545. }
  3546. if (success)
  3547. {
  3548. llinfos << "Avatar shaders loaded at level: " << shader_level
  3549. << llendl;
  3550. }
  3551. else
  3552. {
  3553. mShaderLevel[SHADER_AVATAR] = 0;
  3554. mMaxAvatarShaderLevel = 0;
  3555. }
  3556. return success;
  3557. }
  3558. bool LLViewerShaderMgr::loadShadersInterface()
  3559. {
  3560. sHasIrrandiance = false;
  3561. S32 shader_level = mShaderLevel[SHADER_INTERFACE];
  3562. gHighlightProgram.setup("Highlight shader", shader_level,
  3563. "interface/highlightV.glsl",
  3564. "interface/highlightF.glsl");
  3565. bool success = create_with_rigged(gHighlightProgram,
  3566. gSkinnedHighlightProgram);
  3567. if (success)
  3568. {
  3569. gHighlightNormalProgram.setup("Highlight normals shader", shader_level,
  3570. "interface/highlightNormV.glsl",
  3571. "interface/highlightF.glsl");
  3572. success = gHighlightNormalProgram.createShader();
  3573. }
  3574. if (success)
  3575. {
  3576. gHighlightSpecularProgram.setup("Highlight specular shader",
  3577. shader_level,
  3578. "interface/highlightSpecV.glsl",
  3579. "interface/highlightF.glsl");
  3580. success = gHighlightSpecularProgram.createShader();
  3581. }
  3582. if (success)
  3583. {
  3584. gUIProgram.setup("UI shader", shader_level,
  3585. "interface/uiV.glsl", "interface/uiF.glsl");
  3586. success = gUIProgram.createShader();
  3587. }
  3588. if (success && !gUsePBRShaders)
  3589. {
  3590. gSplatTextureRectProgram.setup("Splat texture rect shader",
  3591. shader_level,
  3592. "interface/splattexturerectV.glsl",
  3593. "interface/splattexturerectF.glsl");
  3594. success = gSplatTextureRectProgram.createShader();
  3595. if (success)
  3596. {
  3597. gSplatTextureRectProgram.bind();
  3598. gSplatTextureRectProgram.uniform1i(sScreenMap, 0);
  3599. gSplatTextureRectProgram.unbind();
  3600. }
  3601. }
  3602. if (success)
  3603. {
  3604. gGlowCombineProgram.setup("Glow combine shader", shader_level,
  3605. "interface/glowcombineV.glsl",
  3606. "interface/glowcombineF.glsl");
  3607. success = gGlowCombineProgram.createShader();
  3608. if (success)
  3609. {
  3610. gGlowCombineProgram.bind();
  3611. gGlowCombineProgram.uniform1i(sGlowMap, 0);
  3612. gGlowCombineProgram.uniform1i(sScreenMap, 1);
  3613. gGlowCombineProgram.unbind();
  3614. }
  3615. }
  3616. if (success)
  3617. {
  3618. gGlowCombineFXAAProgram.setup("Glow combine FXAA shader",
  3619. shader_level,
  3620. "interface/glowcombineFXAAV.glsl",
  3621. "interface/glowcombineFXAAF.glsl");
  3622. success = gGlowCombineFXAAProgram.createShader();
  3623. if (success)
  3624. {
  3625. gGlowCombineFXAAProgram.bind();
  3626. gGlowCombineFXAAProgram.uniform1i(sGlowMap, 0);
  3627. gGlowCombineFXAAProgram.uniform1i(sScreenMap, 1);
  3628. gGlowCombineFXAAProgram.unbind();
  3629. }
  3630. }
  3631. if (success && !gUsePBRShaders)
  3632. {
  3633. gOneTextureNoColorProgram.setup("One texture no color shader",
  3634. shader_level,
  3635. "interface/onetexturenocolorV.glsl",
  3636. "interface/onetexturenocolorF.glsl");
  3637. success = gOneTextureNoColorProgram.createShader();
  3638. if (success)
  3639. {
  3640. gOneTextureNoColorProgram.bind();
  3641. gOneTextureNoColorProgram.uniform1i(sTex0, 0);
  3642. gOneTextureNoColorProgram.unbind();
  3643. }
  3644. }
  3645. if (success)
  3646. {
  3647. gSolidColorProgram.setup("Solid color shader", shader_level,
  3648. "interface/solidcolorV.glsl",
  3649. "interface/solidcolorF.glsl");
  3650. success = gSolidColorProgram.createShader();
  3651. if (success)
  3652. {
  3653. gSolidColorProgram.bind();
  3654. gSolidColorProgram.uniform1i(sTex0, 0);
  3655. gSolidColorProgram.unbind();
  3656. }
  3657. }
  3658. if (success)
  3659. {
  3660. gOcclusionProgram.setup("Occlusion shader", shader_level,
  3661. "interface/occlusionV.glsl",
  3662. "interface/occlusionF.glsl");
  3663. gOcclusionProgram.mRiggedVariant = &gSkinnedOcclusionProgram;
  3664. success = gOcclusionProgram.createShader();
  3665. }
  3666. if (success)
  3667. {
  3668. gSkinnedOcclusionProgram.setup("Skinned occlusion shader",
  3669. shader_level,
  3670. "interface/occlusionSkinnedV.glsl",
  3671. "interface/occlusionF.glsl");
  3672. gSkinnedOcclusionProgram.mFeatures.hasObjectSkinning = true;
  3673. success = gSkinnedOcclusionProgram.createShader();
  3674. }
  3675. if (success)
  3676. {
  3677. gOcclusionCubeProgram.setup("Occlusion cube shader", shader_level,
  3678. "interface/occlusionCubeV.glsl",
  3679. "interface/occlusionF.glsl");
  3680. success = gOcclusionCubeProgram.createShader();
  3681. }
  3682. if (success)
  3683. {
  3684. gDebugProgram.setup("Debug shader", shader_level,
  3685. "interface/debugV.glsl", "interface/debugF.glsl");
  3686. success = create_with_rigged(gDebugProgram, gSkinnedDebugProgram);
  3687. }
  3688. if (success && gUsePBRShaders)
  3689. {
  3690. static const char* normal = "Normal debug shader";
  3691. static const char* tangents = "Normal debug shader with tangents";
  3692. for (S32 i = 0; success && i < NORMAL_DEBUG_SHADER_COUNT; ++i)
  3693. {
  3694. bool with_tangents = i == NORMAL_DEBUG_SHADER_WITH_TANGENTS;
  3695. LLGLSLShader& shader = gNormalDebugProgram[i];
  3696. shader.setup(with_tangents ? tangents : normal, shader_level,
  3697. "interface/normaldebugV.glsl",
  3698. "interface/normaldebugF.glsl",
  3699. "interface/normaldebugG.glsl"); // Geometry shader
  3700. if (with_tangents)
  3701. {
  3702. shader.addPermutation("HAS_ATTRIBUTE_TANGENT", "1");
  3703. }
  3704. success = create_with_rigged(shader,
  3705. gSkinnedNormalDebugProgram[i]);
  3706. }
  3707. }
  3708. if (success)
  3709. {
  3710. gClipProgram.setup("Clip shader", shader_level,
  3711. "interface/clipV.glsl", "interface/clipF.glsl");
  3712. success = gClipProgram.createShader();
  3713. }
  3714. if (success && !gUsePBRShaders)
  3715. {
  3716. gDownsampleDepthProgram.setup("Downsample depth shader", shader_level,
  3717. "interface/downsampleDepthV.glsl",
  3718. "interface/downsampleDepthF.glsl");
  3719. success = gDownsampleDepthProgram.createShader();
  3720. }
  3721. if (success)
  3722. {
  3723. gBenchmarkProgram.setup("Benchmark shader", shader_level,
  3724. "interface/benchmarkV.glsl",
  3725. "interface/benchmarkF.glsl");
  3726. success = gBenchmarkProgram.createShader();
  3727. }
  3728. if (success && gUsePBRShaders)
  3729. {
  3730. gReflectionProbeDisplayProgram.setup("Reflection probe display shader",
  3731. shader_level,
  3732. "interface/reflectionprobeV.glsl",
  3733. "interface/reflectionprobeF.glsl");
  3734. gReflectionProbeDisplayProgram.mFeatures.hasReflectionProbes = true;
  3735. gReflectionProbeDisplayProgram.mFeatures.hasSrgb = true;
  3736. gReflectionProbeDisplayProgram.mFeatures.calculatesAtmospherics = true;
  3737. gReflectionProbeDisplayProgram.mFeatures.hasAtmospherics = true;
  3738. gReflectionProbeDisplayProgram.mFeatures.hasGamma = true;
  3739. gReflectionProbeDisplayProgram.mFeatures.isDeferred = true;
  3740. success = gReflectionProbeDisplayProgram.createShader();
  3741. }
  3742. if (success && gUsePBRShaders)
  3743. {
  3744. gCopyProgram.setup("Copy shader", shader_level,
  3745. "interface/copyV.glsl", "interface/copyF.glsl");
  3746. success = gCopyProgram.createShader();
  3747. }
  3748. if (success && gUsePBRShaders)
  3749. {
  3750. gCopyDepthProgram.setup("Copy depth shader", shader_level,
  3751. "interface/copyV.glsl",
  3752. "interface/copyF.glsl");
  3753. gCopyDepthProgram.addPermutation("COPY_DEPTH", "1");
  3754. success = gCopyDepthProgram.createShader();
  3755. }
  3756. if (success && !gUsePBRShaders)
  3757. {
  3758. gDownsampleDepthRectProgram.setup("Downsample depth rect shader",
  3759. shader_level,
  3760. "interface/downsampleDepthV.glsl",
  3761. "interface/downsampleDepthRectF.glsl");
  3762. success = gDownsampleDepthRectProgram.createShader();
  3763. }
  3764. if (success)
  3765. {
  3766. gAlphaMaskProgram.setup("Alpha mask shader", shader_level,
  3767. "interface/alphamaskV.glsl",
  3768. "interface/alphamaskF.glsl");
  3769. success = gAlphaMaskProgram.createShader();
  3770. }
  3771. if (success && gUsePBRShaders)
  3772. {
  3773. gReflectionMipProgram.setup("Reflection mip shader", shader_level,
  3774. "interface/splattexturerectV.glsl",
  3775. "interface/reflectionmipF.glsl");
  3776. gReflectionMipProgram.mFeatures.isDeferred = true;
  3777. gReflectionMipProgram.mFeatures.hasGamma = true;
  3778. gReflectionMipProgram.mFeatures.hasAtmospherics = true;
  3779. gReflectionMipProgram.mFeatures.calculatesAtmospherics = true;
  3780. success = gReflectionMipProgram.createShader();
  3781. }
  3782. if (success && gUsePBRShaders)
  3783. {
  3784. gGaussianProgram.setup("Reflection gaussian shader", shader_level,
  3785. "interface/splattexturerectV.glsl",
  3786. "interface/gaussianF.glsl");
  3787. gGaussianProgram.mFeatures.isDeferred = true;
  3788. gGaussianProgram.mFeatures.hasGamma = true;
  3789. gGaussianProgram.mFeatures.hasAtmospherics = true;
  3790. gGaussianProgram.mFeatures.calculatesAtmospherics = true;
  3791. success = gGaussianProgram.createShader();
  3792. }
  3793. if (success && gUsePBRShaders)
  3794. {
  3795. success = gGLManager.mHasCubeMapArray;
  3796. if (success)
  3797. {
  3798. gRadianceGenProgram.setup("Radiance gen shader", shader_level,
  3799. "interface/radianceGenV.glsl",
  3800. "interface/radianceGenF.glsl");
  3801. gRadianceGenProgram.addPermutation("PROBE_FILTER_SAMPLES", "32");
  3802. success = gRadianceGenProgram.createShader();
  3803. }
  3804. if (success)
  3805. {
  3806. gHeroRadianceGenProgram.setup("Hero radiance gen shader",
  3807. shader_level,
  3808. "interface/radianceGenV.glsl",
  3809. "interface/radianceGenF.glsl");
  3810. //gHeroRadianceGenProgram.addPermutation("HERO_PROBES", "1");
  3811. gHeroRadianceGenProgram.addPermutation("PROBE_FILTER_SAMPLES",
  3812. "4");
  3813. success = gHeroRadianceGenProgram.createShader();
  3814. }
  3815. if (success)
  3816. {
  3817. gIrradianceGenProgram.setup("Irradiance gen shader", shader_level,
  3818. "interface/irradianceGenV.glsl",
  3819. "interface/irradianceGenF.glsl");
  3820. success = gIrradianceGenProgram.createShader();
  3821. }
  3822. sHasIrrandiance = success;
  3823. if (!success)
  3824. {
  3825. llwarns << "No cube map array support: refection maps will not render."
  3826. << llendl;
  3827. success = true; // Do not care, and still allow PBR to run. HB
  3828. }
  3829. }
  3830. if (success)
  3831. {
  3832. llinfos << "Interface shaders loaded at level: " << shader_level
  3833. << llendl;
  3834. }
  3835. else
  3836. {
  3837. mShaderLevel[SHADER_INTERFACE] = 0;
  3838. }
  3839. return success;
  3840. }
  3841. bool LLViewerShaderMgr::loadShadersWindLight()
  3842. {
  3843. S32 shader_level = mShaderLevel[SHADER_WINDLIGHT];
  3844. if (shader_level < 2 || gUsePBRShaders)
  3845. {
  3846. gWLSkyProgram.unload();
  3847. gWLCloudProgram.unload();
  3848. gWLSunProgram.unload();
  3849. gWLMoonProgram.unload();
  3850. return true;
  3851. }
  3852. gWLSkyProgram.setup("Windlight sky shader", shader_level,
  3853. "windlight/skyV.glsl", "windlight/skyF.glsl");
  3854. gWLSkyProgram.mFeatures.calculatesAtmospherics = true;
  3855. gWLSkyProgram.mFeatures.hasTransport = true;
  3856. gWLSkyProgram.mFeatures.hasGamma = true;
  3857. gWLSkyProgram.mFeatures.hasSrgb = true;
  3858. gWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3859. bool success = gWLSkyProgram.createShader();
  3860. if (success)
  3861. {
  3862. gWLCloudProgram.setup("Windlight cloud program", shader_level,
  3863. "windlight/cloudsV.glsl",
  3864. "windlight/cloudsF.glsl");
  3865. gWLCloudProgram.mFeatures.calculatesAtmospherics = true;
  3866. gWLCloudProgram.mFeatures.hasTransport = true;
  3867. gWLCloudProgram.mFeatures.hasGamma = true;
  3868. gWLCloudProgram.mFeatures.hasSrgb = true;
  3869. gWLCloudProgram.addConstant(LLGLSLShader::CONST_CLOUD_MOON_DEPTH);
  3870. gWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3871. success = gWLCloudProgram.createShader();
  3872. }
  3873. if (success)
  3874. {
  3875. gWLSunProgram.setup("Windlight Sun program", shader_level,
  3876. "windlight/sunDiscV.glsl",
  3877. "windlight/sunDiscF.glsl");
  3878. gWLSunProgram.mFeatures.calculatesAtmospherics = true;
  3879. gWLSunProgram.mFeatures.hasTransport = true;
  3880. gWLSunProgram.mFeatures.hasGamma = true;
  3881. gWLSunProgram.mFeatures.hasAtmospherics = true;
  3882. gWLSunProgram.mFeatures.isFullbright = true;
  3883. gWLSunProgram.mFeatures.disableTextureIndex = true;
  3884. gWLSunProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3885. success = gWLSunProgram.createShader();
  3886. }
  3887. if (success)
  3888. {
  3889. gWLMoonProgram.setup("Windlight Moon program", shader_level,
  3890. "windlight/moonV.glsl",
  3891. "windlight/moonF.glsl");
  3892. gWLMoonProgram.mFeatures.calculatesAtmospherics = true;
  3893. gWLMoonProgram.mFeatures.hasTransport = true;
  3894. gWLMoonProgram.mFeatures.hasGamma = true;
  3895. gWLMoonProgram.mFeatures.hasAtmospherics = true;
  3896. gWLMoonProgram.mFeatures.isFullbright = true;
  3897. gWLMoonProgram.mFeatures.disableTextureIndex = true;
  3898. gWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY;
  3899. gWLMoonProgram.addConstant(LLGLSLShader::CONST_CLOUD_MOON_DEPTH);
  3900. success = gWLMoonProgram.createShader();
  3901. }
  3902. if (success)
  3903. {
  3904. llinfos << "Windlight shaders loaded at level: " << shader_level
  3905. << llendl;
  3906. }
  3907. return success;
  3908. }
  3909. //virtual
  3910. void LLViewerShaderMgr::updateShaderUniforms(LLGLSLShader* shaderp)
  3911. {
  3912. LL_TRACY_TIMER(TRC_UPD_SHADER_UNIFORMS);
  3913. gEnvironment.updateShaderUniforms(shaderp);
  3914. }