1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377 |
- /**
- * @file llpipeline.cpp
- * @brief Rendering pipeline.
- *
- * $LicenseInfo:firstyear=2005&license=viewergpl$
- *
- * Copyright (c) 2005-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include <utility>
- #include "GL/smaa.h"
- #include "llpipeline.h"
- #include "imageids.h"
- #include "llaudioengine.h" // For sound beacons
- #include "llcubemap.h"
- #include "llfasttimer.h"
- #include "llrenderutils.h" // For gl_draw_box*()
- #include "llagent.h"
- #include "llappviewer.h"
- #include "lldrawpoolalpha.h"
- #include "lldrawpoolavatar.h"
- #include "lldrawpoolterrain.h"
- #include "lldrawpooltree.h"
- #include "lldrawpoolwater.h"
- #include "lldrawpoolwlsky.h"
- #include "llenvironment.h"
- #include "llenvsettings.h"
- #include "llface.h"
- #include "llfeaturemanager.h"
- #include "hbfloatersoundslist.h"
- #include "llfloaterstats.h"
- #include "llfloatertelehub.h"
- #include "llgltfscenemanager.h"
- #include "llhudmanager.h"
- #include "llhudtext.h"
- #include "llmeshrepository.h"
- #include "llpanelface.h"
- #include "llprefsgraphics.h"
- //MK
- #include "mkrlinterface.h"
- //mk
- #include "llselectmgr.h"
- #include "llsky.h"
- #include "llspatialpartition.h"
- #include "llstartup.h"
- #include "lltexturecache.h"
- #include "lltexturefetch.h"
- #include "lltracker.h"
- #include "lltool.h"
- #include "lltoolmgr.h"
- #include "lltoolpie.h"
- #include "llviewercamera.h"
- #include "llviewercontrol.h"
- #include "llviewerdisplay.h"
- #include "llviewerjoystick.h"
- #include "llviewermediafocus.h"
- #include "llviewermenu.h" // For handle_refresh_probes()
- #include "llviewerobjectlist.h"
- #include "llvieweroctree.h" // For ll_setup_cube_vb()
- #include "llviewerparcelmgr.h"
- #include "llviewerregion.h"
- #include "llviewershadermgr.h"
- #include "llviewerwindow.h"
- #include "llvoavatarself.h"
- #include "llvocache.h"
- #include "llvopartgroup.h"
- #include "llvosurfacepatch.h"
- #include "llvotree.h"
- #include "llvovolume.h"
- #include "llvowater.h"
- #include "llvowlsky.h"
- #include "llworld.h"
- // Set to 0 to disable optimized deferred shaders uniforms setting
- #define OPTIMIZED_UNIFORMS 1
- // Set to 1 to debug deferred shaders uniforms setting
- #define DEBUG_OPTIMIZED_UNIFORMS 0
- LLPipeline gPipeline;
- const LLMatrix4* gGLLastMatrix = NULL;
- bool gShiftFrame = false;
- // Cached settings
- bool LLPipeline::RenderDeferred;
- F32 LLPipeline::RenderDeferredSunWash;
- F32 LLPipeline::RenderDeferredDisplayGamma;
- U32 LLPipeline::RenderFSAASamples;
- S32 LLPipeline::RenderDeferredAAQuality;
- bool LLPipeline::RenderDeferredAASharpen;
- U32 LLPipeline::RenderResolutionDivisor;
- U32 LLPipeline::RenderShadowDetail;
- bool LLPipeline::RenderDeferredSSAO;
- bool LLPipeline::RenderShadowSoften;
- F32 LLPipeline::RenderShadowResolutionScale;
- U32 LLPipeline::RenderLocalLightCount;
- bool LLPipeline::RenderDelayCreation;
- bool LLPipeline::RenderAnimateRes;
- bool LLPipeline::RenderSpotLightsInNondeferred;
- LLColor4 LLPipeline::PreviewAmbientColor;
- LLColor4 LLPipeline::PreviewDiffuse0;
- LLColor4 LLPipeline::PreviewSpecular0;
- LLColor4 LLPipeline::PreviewDiffuse1;
- LLColor4 LLPipeline::PreviewSpecular1;
- LLColor4 LLPipeline::PreviewDiffuse2;
- LLColor4 LLPipeline::PreviewSpecular2;
- LLVector3 LLPipeline::PreviewDirection0;
- LLVector3 LLPipeline::PreviewDirection1;
- LLVector3 LLPipeline::PreviewDirection2;
- bool LLPipeline::RenderGlow;
- F32 LLPipeline::RenderGlowMinLuminance;
- F32 LLPipeline::RenderGlowMaxExtractAlpha;
- F32 LLPipeline::RenderGlowWarmthAmount;
- LLVector3 LLPipeline::RenderGlowLumWeights;
- LLVector3 LLPipeline::RenderGlowWarmthWeights;
- U32 LLPipeline::RenderGlowResolutionPow;
- U32 LLPipeline::RenderGlowIterations;
- F32 LLPipeline::RenderGlowWidth;
- F32 LLPipeline::RenderGlowStrength;
- bool LLPipeline::RenderDepthOfField;
- bool LLPipeline::RenderDepthOfFieldInEditMode;
- F32 LLPipeline::RenderShadowNoise;
- F32 LLPipeline::RenderShadowBlurSize;
- F32 LLPipeline::RenderSSAOScale;
- U32 LLPipeline::RenderSSAOMaxScale;
- F32 LLPipeline::RenderSSAOFactor;
- LLVector3 LLPipeline::RenderSSAOEffect;
- F32 LLPipeline::RenderShadowBiasError;
- F32 LLPipeline::RenderShadowOffset;
- F32 LLPipeline::RenderShadowOffsetNoSSAO;
- F32 LLPipeline::RenderShadowBias;
- F32 LLPipeline::RenderSpotShadowOffset;
- F32 LLPipeline::RenderSpotShadowBias;
- LLVector3 LLPipeline::RenderShadowGaussian;
- F32 LLPipeline::RenderShadowBlurDistFactor;
- bool LLPipeline::RenderDeferredAtmospheric;
- U32 LLPipeline::RenderWaterReflectionType;
- bool LLPipeline::RenderTransparentWater = true;
- LLVector3 LLPipeline::RenderShadowClipPlanes;
- LLVector3 LLPipeline::RenderShadowOrthoClipPlanes;
- F32 LLPipeline::RenderFarClip;
- LLVector3 LLPipeline::RenderShadowSplitExponent;
- F32 LLPipeline::RenderShadowErrorCutoff;
- F32 LLPipeline::RenderShadowFOVCutoff;
- bool LLPipeline::CameraOffset;
- F32 LLPipeline::CameraMaxCoF;
- F32 LLPipeline::CameraDoFResScale;
- U32 LLPipeline::RenderAutoHideGeometryMemoryLimit;
- F32 LLPipeline::RenderAutoHideSurfaceAreaLimit;
- S32 LLPipeline::RenderBufferVisualization;
- U32 LLPipeline::RenderScreenSpaceReflectionIterations;
- F32 LLPipeline::RenderScreenSpaceReflectionRayStep;
- F32 LLPipeline::RenderScreenSpaceReflectionDistanceBias;
- F32 LLPipeline::RenderScreenSpaceReflectionDepthRejectBias;
- F32 LLPipeline::RenderScreenSpaceReflectionAdaptiveStepMultiplier;
- U32 LLPipeline::RenderScreenSpaceReflectionGlossySamples;
- S32 LLPipeline::sRenderPBRTerrainDetail = -4;
- bool LLPipeline::sRenderPBRTerrain = false;
- bool LLPipeline::RenderScreenSpaceReflections = false;
- bool LLPipeline::sRenderMirrors = false;
- bool LLPipeline::sRenderScriptedBeacons = false;
- bool LLPipeline::sRenderScriptedTouchBeacons = false;
- bool LLPipeline::sRenderPhysicalBeacons = false;
- bool LLPipeline::sRenderPermanentBeacons = false;
- bool LLPipeline::sRenderCharacterBeacons = false;
- bool LLPipeline::sRenderSoundBeacons = false;
- bool LLPipeline::sRenderInvisibleSoundBeacons = false;
- bool LLPipeline::sRenderParticleBeacons = false;
- bool LLPipeline::sRenderMOAPBeacons = false;
- bool LLPipeline::sRenderHighlight = true;
- bool LLPipeline::sRenderBeacons = false;
- bool LLPipeline::sRenderAttachments = false;
- bool LLPipeline::sRenderingHUDs = false;
- U32 LLPipeline::sRenderByOwner = 0;
- U32 LLPipeline::DebugBeaconLineWidth;
- LLRender::eTexIndex LLPipeline::sRenderHighlightTextureChannel = LLRender::DIFFUSE_MAP;
- LLVector4a LLPipeline::sWaterPlane;
- constexpr F32 LIGHT_FADE_TIME = 0.2f;
- constexpr F32 ALPHA_BLEND_CUTOFF = 0.598f;
- constexpr U32 AUX_VB_MASK = LLVertexBuffer::MAP_VERTEX |
- LLVertexBuffer::MAP_TEXCOORD0 |
- LLVertexBuffer::MAP_TEXCOORD1;
- static LLDrawable* sRenderSpotLight = NULL;
- static LLStaticHashedString sDelta("delta");
- static LLStaticHashedString sDistFactor("dist_factor");
- static LLStaticHashedString sKern("kern");
- static LLStaticHashedString sKernScale("kern_scale");
- static LLStaticHashedString sSmaaRTMetrics("SMAA_RT_METRICS");
- static LLStaticHashedString sSharpness("sharpen_params");
- static LLStaticHashedString sMipLevel("mipLevel");
- static LLStaticHashedString sDT("dt");
- static LLStaticHashedString sNoiseVec("noiseVec");
- static LLStaticHashedString sExpParams("dynamic_exposure_params");
- static LLStaticHashedString sExposure("exposure");
- static LLStaticHashedString sAcesMix("aces_mix");
- static LLStaticHashedString sIrradianceScale("ssao_irradiance_scale");
- static LLStaticHashedString sIrradianceMax("ssao_irradiance_max");
- static LLStaticHashedString sAboveWater("above_water");
- static LLStaticHashedString sLuminanceScale("diffuse_luminance_scale");
- std::string gPoolNames[LLDrawPool::NUM_POOL_TYPES] =
- {
- // Correspond to LLDrawpool enum render type
- "NONE",
- "POOL_SKY",
- "POOL_WL_SKY",
- "POOL_SIMPLE",
- "POOL_FULLBRIGHT",
- "POOL_BUMP",
- "POOL_TERRAIN,"
- "POOL_MATERIALS",
- "POOL_MAT_PBR",
- "POOL_GRASS",
- "POOL_MAT_PBR_ALPHA_MASK",
- "POOL_TREE",
- "POOL_ALPHA_MASK",
- "POOL_FULLBRIGHT_ALPHA_MASK",
- "POOL_INVISIBLE",
- "POOL_AVATAR",
- "POOL_PUPPET",
- "POOL_GLOW",
- "POOL_ALPHA_PRE_WATER",
- "POOL_VOIDWATER",
- "POOL_WATER",
- "POOL_ALPHA_POST_WATER",
- "POOL_ALPHA"
- };
- bool LLPipeline::sFreezeTime = false;
- bool LLPipeline::sPickAvatar = true;
- bool LLPipeline::sDynamicLOD = true;
- bool LLPipeline::sShowHUDAttachments = true;
- bool LLPipeline::sRenderBeaconsFloaterOpen = false;
- bool LLPipeline::sAutoMaskAlphaDeferred = true;
- bool LLPipeline::sAutoMaskAlphaNonDeferred = false;
- bool LLPipeline::sUseFarClip = true;
- bool LLPipeline::sShadowRender = false;
- bool LLPipeline::sCanRenderGlow = false;
- bool LLPipeline::sReflectionRender = false;
- bool LLPipeline::sImpostorRender = false;
- bool LLPipeline::sImpostorRenderAlphaDepthPass = false;
- bool LLPipeline::sAvatarPreviewRender = false;
- bool LLPipeline::sUnderWaterRender = false;
- bool LLPipeline::sRenderFrameTest = false;
- bool LLPipeline::sRenderAttachedLights = true;
- bool LLPipeline::sRenderAttachedParticles = true;
- bool LLPipeline::sRenderDeferred = false;
- bool LLPipeline::sRenderWater = true;
- bool LLPipeline::sReflectionProbesEnabled = false;
- S32 LLPipeline::sUseOcclusion = 0;
- S32 LLPipeline::sVisibleLightCount = 0;
- // Per-frame materials usage flags. HB
- bool LLPipeline::sUsingALM = false;
- bool LLPipeline::sUsingPBR = false;
- bool LLPipeline::sLacksLegacyFallback = false;
- bool LLPipeline::sLacksBaseColorFallback = false;
- LLCullResult* LLPipeline::sCull = NULL;
- static const LLMatrix4a TRANS_MAT(LLVector4a(0.5f, 0.f, 0.f, 0.f),
- LLVector4a(0.f, 0.5f, 0.f, 0.f),
- LLVector4a(0.f, 0.f, 0.5f, 0.f),
- LLVector4a(0.5f, 0.5f, 0.5f, 1.f));
- // Utility functions only used here
- static LLMatrix4a look_proj(const LLVector3& pos_in, const LLVector3& dir_in,
- const LLVector3& up_in)
- {
- const LLVector4a pos(pos_in.mV[VX], pos_in.mV[VY], pos_in.mV[VZ], 1.f);
- LLVector4a dir(dir_in.mV[VX], dir_in.mV[VY], dir_in.mV[VZ]);
- const LLVector4a up(up_in.mV[VX], up_in.mV[VY], up_in.mV[VZ]);
- LLVector4a left_norm;
- left_norm.setCross3(dir, up);
- left_norm.normalize3fast();
- LLVector4a up_norm;
- up_norm.setCross3(left_norm, dir);
- up_norm.normalize3fast();
- LLVector4a& dir_norm = dir;
- dir.normalize3fast();
- LLVector4a left_dot;
- left_dot.setAllDot3(left_norm, pos);
- left_dot.negate();
- LLVector4a up_dot;
- up_dot.setAllDot3(up_norm, pos);
- up_dot.negate();
- LLVector4a dir_dot;
- dir_dot.setAllDot3(dir_norm, pos);
- dir_norm.negate();
- LLMatrix4a ret;
- ret.setRow<0>(left_norm);
- ret.setRow<1>(up_norm);
- ret.setRow<2>(dir_norm);
- ret.setRow<3>(LLVector4a(0.f, 0.f, 0.f, 1.f));
- ret.getRow<0>().copyComponent<3>(left_dot);
- ret.getRow<1>().copyComponent<3>(up_dot);
- ret.getRow<2>().copyComponent<3>(dir_dot);
- ret.transpose();
- return ret;
- }
- static bool addDeferredAttachments(LLRenderTarget& target)
- {
- if (gUsePBRShaders)
- {
- // frag-data[1] specular OR PBR ORM
- return target.addColorAttachment(GL_RGBA) &&
- // frag_data[2] normal+z+fogmask,
- // See: class1/deferred/materialF.glsl & softenlight
- target.addColorAttachment(GL_RGBA16F) &&
- // frag_data[3] PBR emissive
- target.addColorAttachment(GL_RGB16F);
- }
- return target.addColorAttachment(GL_SRGB8_ALPHA8) && // Specular
- target.addColorAttachment(GL_RGBA12); // Normal + z
- }
- LLPipeline::LLPipeline()
- : mNeedsDrawStats(false),
- mPoissonOffset(0),
- mBatchCount(0),
- mMatrixOpCount(0),
- mTextureMatrixOps(0),
- mMaxBatchSize(0),
- mMinBatchSize(0),
- mTrianglesDrawn(0),
- mNumVisibleNodes(0),
- mInitialized(false),
- mVertexShadersLoaded(-1),
- mRenderDebugFeatureMask(0),
- mRenderDebugMask(0),
- mOldRenderDebugMask(0),
- mMeshDirtyQueryObject(0),
- mGroupQLocked(false),
- mResetVertexBuffers(false),
- mLastRebuildPool(NULL),
- mAlphaPool(NULL),
- mAlphaPoolPreWater(NULL),
- mAlphaPoolPostWater(NULL),
- mSkyPool(NULL),
- mTerrainPool(NULL),
- mWaterPool(NULL),
- mSimplePool(NULL),
- mGrassPool(NULL),
- mAlphaMaskPool(NULL),
- mFullbrightAlphaMaskPool(NULL),
- mFullbrightPool(NULL),
- mInvisiblePool(NULL),
- mGlowPool(NULL),
- mBumpPool(NULL),
- mMaterialsPool(NULL),
- mWLSkyPool(NULL),
- mPBROpaquePool(NULL),
- mPBRAlphaMaskPool(NULL),
- mLightMask(0),
- mNoiseMap(0),
- mTrueNoiseMap(0),
- mAreaMap(0),
- mSearchMap(0),
- mLightFunc(0),
- mProbeAmbiance(0.f),
- mSkyGamma(1.f),
- mEyeAboveWater(0.f),
- mWaterHeight(0.f),
- mIsSunUp(true),
- mIsMoonUp(false)
- {
- }
- void LLPipeline::connectRefreshCachedSettingsSafe(const char* name)
- {
- LLPointer<LLControlVariable> cvp = gSavedSettings.getControl(name);
- if (cvp.isNull())
- {
- llwarns << "Global setting name not found: " << name << llendl;
- return;
- }
- cvp->getSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
- }
- void LLPipeline::createAuxVBs()
- {
- mCubeVB = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX);
- if (!ll_setup_cube_vb(mCubeVB))
- {
- llwarns << "Could not setup a cube VB !" << llendl;
- mCubeVB = NULL;
- }
- mDeferredVB = new LLVertexBuffer(AUX_VB_MASK);
- mDeferredVB->allocateBuffer(8, 0);
- mScreenTriangleVB = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->allocateBuffer(3, 0);
- LLStrider<LLVector3> v;
- if (mScreenTriangleVB->getVertexStrider(v))
- {
- v[0].set(-1.f, 1.f, 0.f);
- v[1].set(-1.f, -3.f, 0.f);
- v[2].set(3.f, 1.f, 0.f);
- }
- else
- {
- llwarns << "Could not initialize mScreenTriangleVB strider !"
- << llendl;
- }
- mScreenTriangleVB->unmapBuffer();
- if (!gUsePBRShaders)
- {
- mGlowCombineVB = new LLVertexBuffer(AUX_VB_MASK);
- mGlowCombineVB->allocateBuffer(3, 0);
- LLStrider<LLVector3> v;
- LLStrider<LLVector2> uv1;
- if (mGlowCombineVB->getVertexStrider(v) &&
- mGlowCombineVB->getTexCoord0Strider(uv1))
- {
- uv1[0].clear();
- uv1[1].set(0.f, 2.f);
- uv1[2].set(2.f, 0.f);
- v[0].set(-1.f, -1.f, 0.f);
- v[1].set(-1.f, 3.f, 0.f);
- v[2].set(3.f, -1.f, 0.f);
- }
- else
- {
- llwarns << "Could not initialize mGlowCombineVB striders !"
- << llendl;
- }
- mGlowCombineVB->unmapBuffer();
- }
- #if LL_DEBUG_VB_ALLOC
- if (mCubeVB)
- {
- mCubeVB->setOwner("LLPipeline cube VB");
- }
- mDeferredVB->setOwner("LLPipeline deferred VB");
- if (mGlowCombineVB)
- {
- mGlowCombineVB->setOwner("LLPipeline glow combine VB");
- }
- if (mScreenTriangleVB)
- {
- mScreenTriangleVB->setOwner("LLPipeline screen triangle VB");
- }
- #endif
- }
- void LLPipeline::init()
- {
- mRT = &mMainRT;
- // The following three lines used to be in llappviewer.cpp, in
- // settings_to_globals(). HB
- sRenderDeferred = gUsePBRShaders ||
- gSavedSettings.getBool("RenderDeferred");
- LLRenderTarget::sUseFBO = sRenderDeferred;
- #if 1 // This should only taken into account after a restart, thus why it
- // is set here. HB
- RenderFSAASamples = llmin((U32)gSavedSettings.getU32("RenderFSAASamples"),
- 16U);
- #endif
- refreshCachedSettings();
- gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
- gOctreeMinSize = gSavedSettings.getF32("OctreeMinimumNodeSize");
- sDynamicLOD = gSavedSettings.getBool("RenderDynamicLOD");
- sRenderAttachedLights = gSavedSettings.getBool("RenderAttachedLights");
- sRenderAttachedParticles =
- gSavedSettings.getBool("RenderAttachedParticles");
- sAutoMaskAlphaDeferred =
- gSavedSettings.getBool("RenderAutoMaskAlphaDeferred");
- sAutoMaskAlphaNonDeferred =
- gSavedSettings.getBool("RenderAutoMaskAlphaNonDeferred");
- if (gFeatureManager.isFeatureAvailable("RenderCompressTextures"))
- {
- LLImageGL::sCompressTextures =
- gGLManager.mGLVersion >= 2.1f &&
- gSavedSettings.getBool("RenderCompressTextures");
- LLImageGL::sCompressThreshold =
- gSavedSettings.getU32("RenderCompressThreshold");
- }
- // Create render pass pools
- if (gUsePBRShaders)
- {
- getPool(LLDrawPool::POOL_ALPHA_PRE_WATER);
- getPool(LLDrawPool::POOL_ALPHA_POST_WATER);
- }
- else
- {
- getPool(LLDrawPool::POOL_ALPHA);
- }
- getPool(LLDrawPool::POOL_SIMPLE);
- getPool(LLDrawPool::POOL_ALPHA_MASK);
- getPool(LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK);
- getPool(LLDrawPool::POOL_GRASS);
- getPool(LLDrawPool::POOL_FULLBRIGHT);
- if (!gUsePBRShaders)
- {
- getPool(LLDrawPool::POOL_INVISIBLE);
- }
- getPool(LLDrawPool::POOL_BUMP);
- getPool(LLDrawPool::POOL_MATERIALS);
- getPool(LLDrawPool::POOL_GLOW);
- if (gUsePBRShaders)
- {
- getPool(LLDrawPool::POOL_MAT_PBR);
- getPool(LLDrawPool::POOL_MAT_PBR_ALPHA_MASK);
- }
- mTrianglesDrawnStat.reset();
- resetFrameStats();
- setAllRenderTypes(); // All rendering types start enabled
- mRenderDebugFeatureMask = 0xffffffff; // All debugging features on
- mRenderDebugMask = 0; // All debug starts off
- mOldRenderDebugMask = mRenderDebugMask;
- for (U32 i = 0; i < 2; ++i)
- {
- mSpotLightFade[i] = 1.f;
- }
- createAuxVBs();
- // Enable features
- // Must be set before calling setShaders().
- mInitialized = true;
- // Note: this will set mVertexShadersLoaded to 1 if basic shaders get
- // successfully loaded, or to -1 on failure.
- gViewerShaderMgrp->setShaders();
- stop_glerror();
- if (!gSavedSettings.getBool("SkipStaticVectorSizing"))
- {
- // Reserve some space in permanent vectors to avoid fragmentation,
- // based on the statistics we got for real sessions.
- // By setting SkipStaticVectorSizing to true (and restarting the
- // viewer), you may skip this pre-sizing of vectors so to verify (via
- // "Advanced" -> "Consoles" -> "Info to Debug Console" ->
- // "Memory Stats") what capacity is naturally reached during a session
- // and check it against the capacity reserved below (this is how I
- // determined the suitable values). HB
- mMovedList.reserve(1024);
- mMovedBridge.reserve(1024);
- mGroupQ.reserve(8192);
- mMeshDirtyGroup.reserve(2048);
- mShiftList.reserve(65536);
- }
- // Register settings callbacks
- connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaDeferred");
- connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaNonDeferred");
- connectRefreshCachedSettingsSafe("RenderUseFarClip");
- connectRefreshCachedSettingsSafe("UseOcclusion");
- connectRefreshCachedSettingsSafe("RenderDeferred");
- connectRefreshCachedSettingsSafe("RenderDeferredSunWash");
- connectRefreshCachedSettingsSafe("RenderDeferredAASharpen");
- connectRefreshCachedSettingsSafe("RenderResolutionDivisor");
- connectRefreshCachedSettingsSafe("RenderShadowResolutionScale");
- connectRefreshCachedSettingsSafe("RenderDelayCreation");
- connectRefreshCachedSettingsSafe("RenderAnimateRes");
- connectRefreshCachedSettingsSafe("RenderLocalLightCount");
- connectRefreshCachedSettingsSafe("RenderSpotLightsInNondeferred");
- connectRefreshCachedSettingsSafe("PreviewAmbientColor");
- connectRefreshCachedSettingsSafe("PreviewDiffuse0");
- connectRefreshCachedSettingsSafe("PreviewSpecular0");
- connectRefreshCachedSettingsSafe("PreviewDiffuse1");
- connectRefreshCachedSettingsSafe("PreviewSpecular1");
- connectRefreshCachedSettingsSafe("PreviewDiffuse2");
- connectRefreshCachedSettingsSafe("PreviewSpecular2");
- connectRefreshCachedSettingsSafe("PreviewDirection0");
- connectRefreshCachedSettingsSafe("PreviewDirection1");
- connectRefreshCachedSettingsSafe("PreviewDirection2");
- connectRefreshCachedSettingsSafe("RenderGlowMinLuminance");
- connectRefreshCachedSettingsSafe("RenderGlowMaxExtractAlpha");
- connectRefreshCachedSettingsSafe("RenderGlowWarmthAmount");
- connectRefreshCachedSettingsSafe("RenderGlowLumWeights");
- connectRefreshCachedSettingsSafe("RenderGlowWarmthWeights");
- connectRefreshCachedSettingsSafe("RenderGlowIterations");
- connectRefreshCachedSettingsSafe("RenderGlowWidth");
- connectRefreshCachedSettingsSafe("RenderGlowStrength");
- connectRefreshCachedSettingsSafe("RenderDepthOfFieldInEditMode");
- connectRefreshCachedSettingsSafe("RenderHeroProbeResLevel");
- connectRefreshCachedSettingsSafe("RenderShadowNoise");
- connectRefreshCachedSettingsSafe("RenderShadowBlurSize");
- connectRefreshCachedSettingsSafe("RenderShadowSoften");
- connectRefreshCachedSettingsSafe("RenderSSAOScale");
- connectRefreshCachedSettingsSafe("RenderSSAOMaxScale");
- connectRefreshCachedSettingsSafe("RenderSSAOFactor");
- connectRefreshCachedSettingsSafe("RenderSSAOEffect");
- connectRefreshCachedSettingsSafe("RenderShadowBiasError");
- connectRefreshCachedSettingsSafe("RenderShadowOffset");
- connectRefreshCachedSettingsSafe("RenderShadowOffsetNoSSAO");
- connectRefreshCachedSettingsSafe("RenderShadowBias");
- connectRefreshCachedSettingsSafe("RenderSpotShadowOffset");
- connectRefreshCachedSettingsSafe("RenderSpotShadowBias");
- connectRefreshCachedSettingsSafe("RenderShadowGaussian");
- connectRefreshCachedSettingsSafe("RenderShadowBlurDistFactor");
- connectRefreshCachedSettingsSafe("RenderDeferredAtmospheric");
- connectRefreshCachedSettingsSafe("RenderShadowClipPlanes");
- connectRefreshCachedSettingsSafe("RenderShadowOrthoClipPlanes");
- connectRefreshCachedSettingsSafe("RenderFarClip");
- connectRefreshCachedSettingsSafe("RenderShadowSplitExponent");
- connectRefreshCachedSettingsSafe("RenderShadowErrorCutoff");
- connectRefreshCachedSettingsSafe("RenderShadowFOVCutoff");
- connectRefreshCachedSettingsSafe("CameraOffset");
- connectRefreshCachedSettingsSafe("CameraMaxCoF");
- connectRefreshCachedSettingsSafe("CameraDoFResScale");
- connectRefreshCachedSettingsSafe("RenderAutoHideGeometryMemoryLimit");
- connectRefreshCachedSettingsSafe("RenderAutoHideSurfaceAreaLimit");
- connectRefreshCachedSettingsSafe("RenderWater");
- // PBR related settings
- connectRefreshCachedSettingsSafe("RenderBufferVisualization");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflections");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionIterations");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionRayStep");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionDistanceBias");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionDepthRejectBias");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionAdaptiveStepMultiplier");
- connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionGlossySamples");
- // Beacons stuff
- connectRefreshCachedSettingsSafe("scriptsbeacon");
- connectRefreshCachedSettingsSafe("scripttouchbeacon");
- connectRefreshCachedSettingsSafe("physicalbeacon");
- connectRefreshCachedSettingsSafe("permanentbeacon");
- connectRefreshCachedSettingsSafe("characterbeacon");
- connectRefreshCachedSettingsSafe("soundsbeacon");
- connectRefreshCachedSettingsSafe("invisiblesoundsbeacon");
- connectRefreshCachedSettingsSafe("particlesbeacon");
- connectRefreshCachedSettingsSafe("moapbeacon");
- connectRefreshCachedSettingsSafe("renderhighlights");
- connectRefreshCachedSettingsSafe("renderbeacons");
- connectRefreshCachedSettingsSafe("renderattachment");
- connectRefreshCachedSettingsSafe("renderbyowner");
- connectRefreshCachedSettingsSafe("DebugBeaconLineWidth");
- }
- // This must be called at the very start of a render frame. HB
- void LLPipeline::toggleRenderer()
- {
- // Force a GL states check here.
- bool old_debug_gl = gDebugGL;
- gDebugGL = true;
- LL_GL_CHECK_STATES;
- gDebugGL = old_debug_gl;
- // First, cleanup everything.
- GLbitfield mask = GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT;
- if (!gUsePBRShaders)
- {
- mask |= GL_STENCIL_BUFFER_BIT;
- }
- glClear(mask);
- mResetVertexBuffers = true;
- doResetVertexBuffers(true);
- releaseGLBuffers();
- LLRenderTarget::reset();
- gCubeSnapshot = false; // Paranoia (should already be false).
- while (true) // Avoids a goto.
- {
- // Toggle now.
- gUsePBRShaders = !gUsePBRShaders;
- llinfos << "Toggling the renderer to the "
- << (gUsePBRShaders ? "PBR" : "EE") << " mode..." << llendl;
- // Resync render pass pools
- if (gUsePBRShaders)
- {
- removePool(mAlphaPool);
- removePool(mInvisiblePool);
- getPool(LLDrawPool::POOL_ALPHA_PRE_WATER);
- getPool(LLDrawPool::POOL_ALPHA_POST_WATER);
- getPool(LLDrawPool::POOL_MAT_PBR);
- getPool(LLDrawPool::POOL_MAT_PBR_ALPHA_MASK);
- }
- else
- {
- mReflectionMapManager.cleanup();
- mHeroProbeManager.cleanup();
- removePool(mAlphaPoolPreWater);
- removePool(mAlphaPoolPostWater);
- removePool(mPBROpaquePool);
- removePool(mPBRAlphaMaskPool);
- getPool(LLDrawPool::POOL_ALPHA);
- getPool(LLDrawPool::POOL_INVISIBLE);
- }
- // Do not keep a pointer for a pool that might have been removed...
- mLastRebuildPool = NULL;
- // Reload/resync the shaders (also refreshes the pipeline cached
- // settings and recreates GL buffers on success).
- gViewerShaderMgrp->setShaders();
- if (gUsePBRShaders && !LLViewerShaderMgr::sInitialized)
- {
- // We failed to load the mandatory PBR shaders, and we need to
- // switch back to the EE renderer immediately (otherwise we would
- // crash later on while rendering).
- gSavedSettings.setBool("RenderUsePBR", false); // Resync setting
- // Must be set back to true so that setShaders() can proceed.
- LLViewerShaderMgr::sInitialized = true;
- continue; // Loop back...
- }
- break; // Success. Exit the "loop".
- }
- // Refresh again graphics preferences (when open) after shader loading
- // since the status of some check boxes depends on what got actually
- // loaded. HB
- LLPrefsGraphics::refresh();
- // Rebuild everything
- mResetVertexBuffers = true;
- doResetVertexBuffers(true);
- // Force-rebuild all objects in the render pipeline.
- for (S32 i = 0, count = gObjectList.getNumObjects(); i < count; ++i)
- {
- LLViewerObject* objectp = gObjectList.getObject(i);
- if (objectp && !objectp->isDead())
- {
- objectp->markForUpdate(true);
- }
- }
- // Force-rebuild all the draw info.
- rebuildDrawInfo();
- // Rebuild draw pools
- rebuildPools();
- // Force a GL states check here.
- gDebugGL = true;
- LL_GL_CHECK_STATES;
- gDebugGL = old_debug_gl;
- if (gUsePBRShaders)
- {
- // Force a reflection probes rebuild.
- handle_refresh_probes(NULL);
- }
- }
- void LLPipeline::cleanup()
- {
- llinfos << "Total number of occlusion query timeouts: "
- << LLOcclusionCullingGroup::getTimeouts() << llendl;
- mGroupQ.clear();
- mGroupSaveQ.clear();
- for (pool_set_t::iterator iter = mPools.begin(),
- end = mPools.end();
- iter != end; )
- {
- pool_set_t::iterator curiter = iter++;
- LLDrawPool* poolp = *curiter;
- if (!poolp) // Paranoia
- {
- llwarns << "Found a NULL pool !" << llendl;
- continue;
- }
- if (poolp->isFacePool())
- {
- LLFacePool* face_pool = (LLFacePool*)poolp;
- if (face_pool->mReferences.empty())
- {
- mPools.erase(curiter);
- removeFromQuickLookup(poolp);
- delete poolp;
- }
- }
- else
- {
- mPools.erase(curiter);
- removeFromQuickLookup(poolp);
- delete poolp;
- }
- }
- if (!mTerrainPools.empty())
- {
- llwarns << "Terrain pools not cleaned up" << llendl;
- }
- if (!mTreePools.empty())
- {
- llwarns << "Tree pools not cleaned up" << llendl;
- }
- delete mAlphaPool;
- mAlphaPool = NULL;
- delete mAlphaPoolPreWater;
- mAlphaPoolPreWater = NULL;
- delete mAlphaPoolPostWater;
- mAlphaPoolPostWater = NULL;
- delete mSkyPool;
- mSkyPool = NULL;
- delete mTerrainPool;
- mTerrainPool = NULL;
- delete mWaterPool;
- mWaterPool = NULL;
- delete mSimplePool;
- mSimplePool = NULL;
- delete mFullbrightPool;
- mFullbrightPool = NULL;
- delete mInvisiblePool;
- mInvisiblePool = NULL;
- delete mGlowPool;
- mGlowPool = NULL;
- delete mBumpPool;
- mBumpPool = NULL;
- #if 0 // Do not delete WL sky pool: already done above in the for loop.
- delete mWLSkyPool;
- #endif
- mWLSkyPool = NULL;
- delete mPBROpaquePool;
- mPBROpaquePool = NULL;
- delete mPBRAlphaMaskPool;
- mPBRAlphaMaskPool = NULL;
- releaseGLBuffers();
- mFaceSelectImagep = NULL;
- mMovedList.clear();
- mMovedBridge.clear();
- mShiftList.clear();
- mMeshDirtyGroup.clear();
- mInitialized = false;
- mDeferredVB = mGlowCombineVB = mCubeVB = mScreenTriangleVB = NULL;
- mReflectionMapManager.cleanup();
- mHeroProbeManager.cleanup();
- }
- void LLPipeline::dumpStats()
- {
- llinfos << "mMovedList vector capacity reached: " << mMovedList.capacity()
- << " - mMovedBridge vector capacity reached: "
- << mMovedBridge.capacity()
- << " - mShiftList vector capacity reached: "
- << mShiftList.capacity()
- << " - mGroupQ vector capacity reached: " << mGroupQ.capacity()
- << " - mMeshDirtyGroup vector capacity reached: "
- << mMeshDirtyGroup.capacity() << llendl;
- }
- void LLPipeline::destroyGL()
- {
- unloadShaders();
- mHighlightFaces.clear();
- resetDrawOrders();
- resetVertexBuffers();
- releaseGLBuffers();
- if (mMeshDirtyQueryObject)
- {
- glDeleteQueries(1, &mMeshDirtyQueryObject);
- mMeshDirtyQueryObject = 0;
- }
- stop_glerror();
- }
- void LLPipeline::resizeShadowTexture()
- {
- gResizeShadowTexture = false;
- releaseShadowTargets();
- allocateShadowBuffer(mRT->mWidth, mRT->mHeight);
- }
- void LLPipeline::resizeScreenTexture()
- {
- static U32 res_divisor = 0;
- LL_FAST_TIMER(FTM_RESIZE_SCREEN_TEXTURE);
- gResizeScreenTexture = false;
- if (shadersLoaded())
- {
- GLuint res_x = gViewerWindowp->getWindowDisplayWidth();
- GLuint res_y = gViewerWindowp->getWindowDisplayHeight();
- if (res_x != mRT->mScreen.getWidth() ||
- res_y != mRT->mScreen.getHeight() ||
- res_divisor != RenderResolutionDivisor)
- {
- res_divisor = RenderResolutionDivisor;
- releaseScreenBuffers();
- allocateScreenBuffer(res_x, res_y);
- }
- }
- }
- void LLPipeline::allocatePhysicsBuffer()
- {
- GLuint res_x = gViewerWindowp->getWindowDisplayWidth();
- GLuint res_y = gViewerWindowp->getWindowDisplayHeight();
- if (mPhysicsDisplay.getWidth() != res_x ||
- mPhysicsDisplay.getHeight() != res_y)
- {
- mPhysicsDisplay.release();
- mPhysicsDisplay.allocate(res_x, res_y, GL_RGBA, true, false,
- LLTexUnit::TT_RECT_TEXTURE);
- }
- }
- void LLPipeline::allocateScreenBuffer(U32 res_x, U32 res_y)
- {
- refreshCachedSettings();
- U32 samples = RenderFSAASamples;
- // Try to allocate screen buffers at requested resolution and samples:
- // - on failure, shrink number of samples and try again
- // - if not multisampled, shrink resolution and try again (favor X
- // resolution over Y)
- // Make sure to call "releaseScreenBuffers" after each failure to cleanup
- // the partially loaded state
- if (!allocateScreenBuffer(res_x, res_y, samples))
- {
- releaseScreenBuffers();
- // Reduce number of samples
- while (samples > 0)
- {
- samples /= 2;
- if (allocateScreenBuffer(res_x, res_y, samples))
- {
- return; // success
- }
- releaseScreenBuffers();
- }
- samples = 0;
- // Reduce resolution
- while (res_y > 0 && res_x > 0)
- {
- res_y /= 2;
- if (allocateScreenBuffer(res_x, res_y, samples))
- {
- return;
- }
- releaseScreenBuffers();
- res_x /= 2;
- if (allocateScreenBuffer(res_x, res_y, samples))
- {
- return;
- }
- releaseScreenBuffers();
- }
- llwarns << "Unable to allocate screen buffer at any resolution !"
- << llendl;
- }
- }
- bool LLPipeline::allocateScreenBuffer(U32 res_x, U32 res_y, U32 samples)
- {
- refreshCachedSettings();
- llinfos << "Allocating ";
- if (gCubeSnapshot)
- {
- llcont << "auxillary ";
- }
- llcont << "target buffers at size " << res_x << "x" << res_y
- << " with " << samples << " samples..." << llendl;
- // *HACK: allocate auxillary PBR buffers when mRT == &mMainRT.
- // Note: we now always need auxillary buffers (even when reflection probes
- // are disabled), because they are used for dynamic textures and PBR
- // materials preview... HB
- if (gUsePBRShaders && mRT == &mMainRT)
- {
- U32 res = 512;
- if (sReflectionProbesEnabled)
- {
- mReflectionMapManager.initReflectionMaps();
- // Multiply by 4 because probes will be 16x super sampled
- res = mReflectionMapManager.mProbeResolution * 4;
- }
- // Note: gCubeSnapshot acts as a flag for the auxilliary buffers
- // allocation step. HB
- gCubeSnapshot = true;
- mRT = &mAuxillaryRT;
- allocateScreenBuffer(res, res, samples);
- if (sRenderMirrors)
- {
- mHeroProbeManager.initReflectionMaps();
- // We also scale the hero probe RT to the probe res since we do not
- // super sample it.
- res = mHeroProbeManager.mProbeResolution;
- mRT = &mHeroProbeRT;
- allocateScreenBuffer(res, res, samples);
- }
- mRT = &mMainRT;
- gCubeSnapshot = false;
- }
- U32 res_mod = RenderResolutionDivisor;
- if (res_mod > 1 && res_mod < res_x && res_mod < res_y)
- {
- res_x /= res_mod;
- res_y /= res_mod;
- }
- // Remember these dimensions
- mRT->mWidth = res_x;
- mRT->mHeight = res_y;
- if (!sRenderDeferred && !gUsePBRShaders) // Forward rendering
- {
- mFXAABuffer.release();
- mSMAABlendBuffer.release();
- mSMAAEdgeBuffer.release();
- mScratchBuffer.release();
- mRT->mDeferredLight.release();
- releaseShadowTargets();
- mRT->mScreen.release();
- // Make sure to release any render targets that share a depth buffer
- // with mDeferredScreen first:
- mRT->mDeferredScreen.release();
- if (!gUsePBRShaders)
- {
- mDeferredDepth.release();
- mOcclusionDepth.release();
- }
- if (!mRT->mScreen.allocate(res_x, res_y, GL_RGBA, true, true,
- LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the screen buffer." << llendl;
- return false;
- }
- gGL.getTexUnit(0)->disable();
- stop_glerror();
- llinfos << "Allocation successful." << llendl;
- return true;
- }
- if (!gUsePBRShaders)
- {
- // Set this flag in case we crash while resizing window or allocating
- // space for deferred rendering targets
- gSavedSettings.setBool("RenderInitError", true);
- gAppViewerp->saveGlobalSettings();
- }
- constexpr U32 occlusion_divisor = 3;
- // Allocate deferred rendering color buffers
- if (gUsePBRShaders)
- {
- if (!mRT->mDeferredScreen.allocate(res_x, res_y, GL_RGBA, true))
- {
- llwarns << "Failed to allocate the deferred screen buffer."
- << llendl;
- return false;
- }
- }
- else if (!mRT->mDeferredScreen.allocate(res_x, res_y, GL_SRGB8_ALPHA8,
- true, true,
- LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the deferred screen buffer."
- << llendl;
- return false;
- }
- if (!addDeferredAttachments(mRT->mDeferredScreen))
- {
- llwarns << "Failed to attach the deferred screen buffer." << llendl;
- return false;
- }
- if (!gUsePBRShaders)
- {
- if (!mDeferredDepth.allocate(res_x, res_y, 0, true, false,
- LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the deferred depth buffer."
- << llendl;
- return false;
- }
- if (!mOcclusionDepth.allocate(res_x / occlusion_divisor,
- res_y / occlusion_divisor, 0, true,
- false, LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the occlusion depth buffer."
- << llendl;
- return false;
- }
- }
- if (gUsePBRShaders)
- {
- if (!mRT->mScreen.allocate(res_x, res_y, GL_RGBA16F))
- {
- llwarns << "Failed to allocate the screen buffer." << llendl;
- return false;
- }
- }
- else
- {
- GLuint screen_format = GL_RGBA16;
- if (gGLManager.mIsAMD)
- {
- static LLCachedControl<bool> use_rgba16(gSavedSettings,
- "RenderUseRGBA16ATI");
- if (!use_rgba16 || gGLManager.mGLVersion < 4.f)
- {
- screen_format = GL_RGBA12;
- }
- }
- else if (gGLManager.mIsNVIDIA && gGLManager.mGLVersion < 4.f)
- {
- screen_format = GL_RGBA16F;
- }
- if (!mRT->mScreen.allocate(res_x, res_y, screen_format, false, false,
- LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the screen buffer." << llendl;
- return false;
- }
- }
- // Share depth buffer between deferred targets
- mRT->mDeferredScreen.shareDepthBuffer(mRT->mScreen);
- // Note: when RenderResolutionDivisor is larger than 1 (i.e. we ask for a
- // lower resolution render), we do not really need any anti-aliasing... HB
- if (samples > 0 && res_mod <= 1 && !gCubeSnapshot)
- {
- if (gUsePBRShaders)
- {
- if (!mFXAABuffer.allocate(res_x, res_y, GL_RGBA))
- {
- llwarns << "Failed to allocate the FXAA buffer." << llendl;
- return false;
- }
- if (!mSMAAEdgeBuffer.allocate(res_x, res_y, GL_RGBA, true))
- {
- llwarns << "Failed to allocate the SMAA edge buffer."
- << llendl;
- return false;
- }
- if (!mSMAABlendBuffer.allocate(res_x, res_y, GL_RGBA))
- {
- llwarns << "Failed to allocate the SMAA blend buffer."
- << llendl;
- return false;
- }
- mSMAAEdgeBuffer.shareDepthBuffer(mSMAABlendBuffer);
- if (!mScratchBuffer.allocate(res_x, res_y, GL_RGBA))
- {
- llwarns << "Failed to allocate the scratch buffer."
- << llendl;
- return false;
- }
- }
- else
- {
- if (!mFXAABuffer.allocate(res_x, res_y, GL_RGBA, false, false))
- {
- llwarns << "Failed to allocate the FXAA buffer." << llendl;
- return false;
- }
- if (!mSMAAEdgeBuffer.allocate(res_x, res_y, GL_RGBA, true, true))
- {
- llwarns << "Failed to allocate the SMAA edge buffer."
- << llendl;
- return false;
- }
- if (!mSMAABlendBuffer.allocate(res_x, res_y, GL_RGBA, false,
- false))
- {
- llwarns << "Failed to allocate the SMAA blend buffer."
- << llendl;
- return false;
- }
- mSMAAEdgeBuffer.shareDepthBuffer(mSMAABlendBuffer);
- if (!mScratchBuffer.allocate(res_x, res_y, GL_RGBA, false, false))
- {
- llwarns << "Failed to allocate the scratch buffer."
- << llendl;
- return false;
- }
- }
- }
- else if (!gCubeSnapshot)
- {
- mFXAABuffer.release();
- mSMAABlendBuffer.release();
- mSMAAEdgeBuffer.release();
- mScratchBuffer.release();
- }
- if (samples > 0 || RenderShadowDetail || RenderDeferredSSAO ||
- RenderDepthOfField)
- {
- // Only need mDeferredLight for shadows or SSAO or DOF or FXAA
- if (gUsePBRShaders)
- {
- if (!mRT->mDeferredLight.allocate(res_x, res_y, GL_RGBA16F))
- {
- llwarns << "Failed to allocate the deferred light buffer."
- << llendl;
- return false;
- }
- }
- else if (!mRT->mDeferredLight.allocate(res_x, res_y, GL_RGBA,
- false, false,
- LLTexUnit::TT_RECT_TEXTURE))
- {
- llwarns << "Failed to allocate the deferred light buffer."
- << llendl;
- return false;
- }
- }
- else
- {
- mRT->mDeferredLight.release();
- }
- allocateShadowBuffer(res_x, res_y);
- if (gUsePBRShaders && !gCubeSnapshot)
- {
- if (RenderScreenSpaceReflections &&
- !mSceneMap.allocate(res_x, res_y, GL_RGB16F, true))
- {
- llwarns << "Failed to allocate the scene map buffer." << llendl;
- return false;
- }
- if (!mPostMap.allocate(res_x, res_y, GL_RGBA))
- {
- llwarns << "Failed to allocate the post map buffer." << llendl;
- return false;
- }
- }
- if (!gUsePBRShaders)
- {
- // Clear the flag set to disable shaders on next session
- gSavedSettings.setBool("RenderInitError", false);
- gAppViewerp->saveGlobalSettings();
- }
- gGL.getTexUnit(0)->disable();
- stop_glerror();
- if (!gCubeSnapshot)
- {
- llinfos << "Allocation successful." << llendl;
- }
- return true;
- }
- // Must be even to avoid a stripe in the horizontal shadow blur
- LL_INLINE static U32 blur_happy_size(U32 x, F32 scale)
- {
- return (U32((F32)x * scale) + 16) & ~0xF;
- }
- bool LLPipeline::allocateShadowBuffer(U32 res_x, U32 res_y)
- {
- refreshCachedSettings();
- if (!sRenderDeferred && !gUsePBRShaders)
- {
- return true;
- }
- constexpr U32 occlusion_divisor = 3;
- F32 scale = RenderShadowResolutionScale;
- if (RenderShadowDetail)
- {
- // Allocate 4 sun shadow maps
- U32 sun_shadow_map_width = blur_happy_size(res_x, scale);
- U32 sun_shadow_map_height = blur_happy_size(res_y, scale);
- llinfos << (gCubeSnapshot ? "Reflection probes " : "")
- << "Sun shadows maps (4) size: " << sun_shadow_map_width << "x"
- << sun_shadow_map_height << " pixels." << llendl;
- if (gUsePBRShaders)
- {
- for (U32 i = 0; i < 4; ++i)
- {
- if (!mRT->mSunShadow[i].allocate(sun_shadow_map_width,
- sun_shadow_map_height, 0,
- true))
- {
- llwarns << "Failed to allocate the Sun shadows buffer."
- << llendl;
- return false;
- }
- }
- }
- else
- {
- for (U32 i = 0; i < 4; ++i)
- {
- if (!mShadow[i].allocate(sun_shadow_map_width,
- sun_shadow_map_height, 0, true,
- false))
- {
- llwarns << "Failed to allocate the Sun shadows buffers."
- << llendl;
- return false;
- }
- if (!mShadowOcclusion[i].allocate(sun_shadow_map_width /
- occlusion_divisor,
- sun_shadow_map_height /
- occlusion_divisor,
- 0, true, false))
- {
- llwarns << "Failed to allocate the Sun shadow occlusions buffers."
- << llendl;
- return false;
- }
- }
- }
- }
- else if (gUsePBRShaders)
- {
- releaseSunShadowTargets();
- }
- else
- {
- for (U32 i = 0; i < 4; ++i)
- {
- releaseShadowTarget(i);
- }
- }
- if (RenderShadowDetail > 1)
- {
- // Allocate two spot shadow maps
- U32 size = res_x * scale;
- llinfos << (gCubeSnapshot ? "Reflection probes s" : "S")
- << "pot shadows maps (2) size: " << size << "x" << size
- << " pixels." << llendl;
- if (!gUsePBRShaders)
- {
- for (U32 i = 4; i < 6; ++i)
- {
- if (!mShadow[i].allocate(size, size, 0, true, false))
- {
- llwarns << "Failed to allocate the spot shadows buffers."
- << llendl;
- return false;
- }
- if (!mShadowOcclusion[i].allocate(size / occlusion_divisor,
- size / occlusion_divisor,
- 0, true, false))
- {
- llwarns << "Failed to allocate the spot shadow occlusions buffers."
- << llendl;
- return false;
- }
- }
- }
- // *HACK: !gCubeSnapshot to prevent allocating spot shadow maps during
- // ReflectionMapManager init.
- else if (!gCubeSnapshot)
- {
- for (U32 i = 0; i < 2; ++i)
- {
- if (!mSpotShadow[i].allocate(size, size, 0, true))
- {
- llwarns << "Failed to allocate the spot shadows buffers."
- << llendl;
- return false;
- }
- }
- }
- }
- else if (!gUsePBRShaders)
- {
- for (U32 i = 4; i < 6; ++i)
- {
- releaseShadowTarget(i);
- }
- }
- // *HACK: !gCubeSnapshot to prevent touching spot shadow maps during
- // ReflectionMapManager init.
- else if (!gCubeSnapshot)
- {
- releaseSpotShadowTargets();
- }
- if (!gUsePBRShaders || !RenderShadowDetail)
- {
- return true;
- }
- // Set up shadow map filtering and compare modes
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- if (RenderShadowDetail)
- {
- for (U32 i = 0; i < 4; ++i)
- {
- LLRenderTarget* targetp = &mRT->mSunShadow[i];
- if (!targetp) continue;
- unit0->bind(targetp, true);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_ANISOTROPIC);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_COMPARE_R_TO_TEXTURE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- }
- }
- if (RenderShadowDetail > 1 && !gCubeSnapshot)
- {
- for (U32 i = 0; i < 2; ++i)
- {
- LLRenderTarget* targetp = &mSpotShadow[i];
- if (!targetp) continue;
- unit0->bind(targetp, true);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_ANISOTROPIC);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_COMPARE_R_TO_TEXTURE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- }
- }
- return true;
- }
- //static
- U32 LLPipeline::waterReflectionType()
- {
- if (gUsePBRShaders)
- {
- if (!RenderTransparentWater)
- {
- return 0;
- }
- }
- else if (RenderWaterReflectionType <= 1)
- {
- return RenderWaterReflectionType;
- }
- static LLCachedControl<F32> far_clip(gSavedSettings, "RenderFarClip");
- if (gPipeline.mEyeAboveWater > F32(far_clip))
- {
- // Draw minimal water (opaque for PBR or sky reflections only for EE)
- // when farther than draw distance.
- return gUsePBRShaders ? 0 : 1;
- }
- return gUsePBRShaders ? 1 : RenderWaterReflectionType;
- }
- //static
- void LLPipeline::updateRenderDeferred()
- {
- if (gUsePBRShaders)
- {
- // If we could switch to the PBR renderer, then we obviously can render
- // in deferred mode. HB
- sRenderDeferred = LLRenderTarget::sUseFBO = true;
- return;
- }
- sRenderDeferred = RenderDeferred && !gUseWireframe &&
- gFeatureManager.isFeatureAvailable("RenderDeferred");
- LLRenderTarget::sUseFBO = sRenderDeferred;
- }
- // IMPORTANT: this method shall not reallocate buffers or call another method
- // that could trigger a change in the settings it gets called for (since this
- // would incur a recursion). It may also be called several times as the result
- // of a single callback (e.g. when reloading shaders). HB
- //static
- void LLPipeline::refreshCachedSettings()
- {
- static LLCachedControl<bool> scriptseacon(gSavedSettings, "scriptsbeacon");
- sRenderScriptedBeacons = scriptseacon;
- static LLCachedControl<bool> scripttouchbeacon(gSavedSettings,
- "scripttouchbeacon");
- sRenderScriptedTouchBeacons = scripttouchbeacon;
- static LLCachedControl<bool> physbeacon(gSavedSettings, "physicalbeacon");
- sRenderPhysicalBeacons = physbeacon;
- static LLCachedControl<bool> permbeacon(gSavedSettings, "permanentbeacon");
- sRenderPermanentBeacons = permbeacon;
- static LLCachedControl<bool> charbeacon(gSavedSettings, "characterbeacon");
- sRenderCharacterBeacons = charbeacon;
- static LLCachedControl<bool> soundsbeacon(gSavedSettings, "soundsbeacon");
- sRenderSoundBeacons = soundsbeacon;
- static LLCachedControl<bool> invisisoundsbeacon(gSavedSettings,
- "invisiblesoundsbeacon");
- sRenderInvisibleSoundBeacons = invisisoundsbeacon;
- static LLCachedControl<bool> particlesbeacon(gSavedSettings,
- "particlesbeacon");
- sRenderParticleBeacons = particlesbeacon;
- static LLCachedControl<bool> moapbeacon(gSavedSettings, "moapbeacon");
- sRenderMOAPBeacons = moapbeacon;
- static LLCachedControl<bool> renderbeacons(gSavedSettings,
- "renderbeacons");
- sRenderBeacons = renderbeacons;
- static LLCachedControl<bool> renderhighlights(gSavedSettings,
- "renderhighlights");
- sRenderHighlight = renderhighlights;
- static LLCachedControl<bool> renderattachment(gSavedSettings,
- "renderattachment");
- sRenderAttachments = renderattachment;
- static LLCachedControl<U32> renderbyowner(gSavedSettings, "renderbyowner");
- sRenderByOwner = renderbyowner;
- static LLCachedControl<U32> beacon_width(gSavedSettings,
- "DebugBeaconLineWidth");
- DebugBeaconLineWidth = beacon_width;
- static LLCachedControl<bool> mask_alpha_def(gSavedSettings,
- "RenderAutoMaskAlphaDeferred");
- sAutoMaskAlphaDeferred = mask_alpha_def;
- static LLCachedControl<bool> mask_alpha(gSavedSettings,
- "RenderAutoMaskAlphaNonDeferred");
- sAutoMaskAlphaNonDeferred = mask_alpha;
- static LLCachedControl<bool> use_far_clip(gSavedSettings,
- "RenderUseFarClip");
- sUseFarClip = use_far_clip;
- static LLCachedControl<bool> use_occlusion(gSavedSettings, "UseOcclusion");
- sUseOcclusion = use_occlusion && !gUseWireframe &&
- gFeatureManager.isFeatureAvailable("UseOcclusion") ? 2 : 0;
- static LLCachedControl<bool> render_water(gSavedSettings, "RenderWater");
- sRenderWater = render_water;
- static LLCachedControl<bool> render_deferred(gSavedSettings,
- "RenderDeferred");
- RenderDeferred = render_deferred;
- static LLCachedControl<F32> sun_wash(gSavedSettings,
- "RenderDeferredSunWash");
- RenderDeferredSunWash = sun_wash;
- static LLCachedControl<F32> gamma(gSavedSettings,
- "RenderDeferredDisplayGamma");
- RenderDeferredDisplayGamma = gamma > 0.1f ? gamma : 2.2f;
- #if 0 // This should only taken into account after a restart. HB
- static LLCachedControl<U32> fsaa_samp(gSavedSettings, "RenderFSAASamples");
- RenderFSAASamples = llmin((U32)fsaa_samp, 16U);
- #endif
- static LLCachedControl<S32> aa_quality(gSavedSettings,
- "RenderDeferredAAQuality");
- if (aa_quality >= 0)
- {
- RenderDeferredAAQuality = llmin((S32)aa_quality, 3);
- }
- else if (RenderFSAASamples > 8)
- {
- RenderDeferredAAQuality = 3;
- }
- else if (RenderFSAASamples > 4)
- {
- RenderDeferredAAQuality = 2;
- }
- else if (RenderFSAASamples > 2)
- {
- RenderDeferredAAQuality = 1;
- }
- else
- {
- RenderDeferredAAQuality = 0;
- }
- static LLCachedControl<bool> sharpen(gSavedSettings,
- "RenderDeferredAASharpen");
- RenderDeferredAASharpen = sharpen;
- static LLCachedControl<U32> res_divisor(gSavedSettings,
- "RenderResolutionDivisor");
- RenderResolutionDivisor = llclamp((U32)res_divisor, 1, 8);
- static LLCachedControl<U32> shadow_detail(gSavedSettings,
- "RenderShadowDetail");
- RenderShadowDetail = shadow_detail;
- static LLCachedControl<U32> deferred_ssao(gSavedSettings,
- "RenderDeferredSSAO");
- RenderDeferredSSAO = deferred_ssao > 1 ||
- (deferred_ssao == 1 && RenderShadowDetail);
- static LLCachedControl<bool> soften_shadows(gSavedSettings,
- "RenderShadowSoften");
- RenderShadowSoften = soften_shadows && RenderShadowDetail;
- static LLCachedControl<F32> shadow_res_scl(gSavedSettings,
- "RenderShadowResolutionScale");
- RenderShadowResolutionScale = llclamp((F32)shadow_res_scl, 0.25f, 1.f);
- static LLCachedControl<U32> local_lights(gSavedSettings,
- "RenderLocalLightCount");
- RenderLocalLightCount = llmin(U32(local_lights), 1024);
- static LLCachedControl<bool> delay_creation(gSavedSettings,
- "RenderDelayCreation");
- RenderDelayCreation = delay_creation;
- static LLCachedControl<bool> anim_res(gSavedSettings, "RenderAnimateRes");
- RenderAnimateRes = anim_res;
- static LLCachedControl<bool> spot_lights_nd(gSavedSettings,
- "RenderSpotLightsInNondeferred");
- RenderSpotLightsInNondeferred = spot_lights_nd;
- static LLCachedControl<LLColor4> preview_amb_col(gSavedSettings,
- "PreviewAmbientColor");
- PreviewAmbientColor = preview_amb_col;
- static LLCachedControl<LLColor4> preview_diff0(gSavedSettings,
- "PreviewDiffuse0");
- PreviewDiffuse0 = preview_diff0;
- static LLCachedControl<LLColor4> preview_spec0(gSavedSettings,
- "PreviewSpecular0");
- PreviewSpecular0 = preview_spec0;
- static LLCachedControl<LLVector3> preview_dir0(gSavedSettings,
- "PreviewDirection0");
- PreviewDirection0 = preview_dir0;
- PreviewDirection0.normalize();
- static LLCachedControl<LLColor4> preview_diff1(gSavedSettings,
- "PreviewDiffuse1");
- PreviewDiffuse1 = preview_diff1;
- static LLCachedControl<LLColor4> preview_spec1(gSavedSettings,
- "PreviewSpecular1");
- PreviewSpecular1 = preview_spec1;
- static LLCachedControl<LLVector3> preview_dir1(gSavedSettings,
- "PreviewDirection1");
- PreviewDirection1 = preview_dir1;
- PreviewDirection1.normalize();
- static LLCachedControl<LLColor4> preview_diff2(gSavedSettings,
- "PreviewDiffuse2");
- PreviewDiffuse2 = preview_diff2;
- static LLCachedControl<LLColor4> preview_spec2(gSavedSettings,
- "PreviewSpecular2");
- PreviewSpecular2 = preview_spec2;
- static LLCachedControl<LLVector3> preview_dir2(gSavedSettings,
- "PreviewDirection2");
- PreviewDirection2 = preview_dir2;
- PreviewDirection2.normalize();
- static LLCachedControl<bool> render_glow(gSavedSettings, "RenderGlow");
- RenderGlow = sCanRenderGlow && render_glow;
- static LLCachedControl<F32> glow_min_lum(gSavedSettings,
- "RenderGlowMinLuminance");
- RenderGlowMinLuminance = llmax((F32)glow_min_lum, 0.f);
- static LLCachedControl<F32> glow_max_alpha(gSavedSettings,
- "RenderGlowMaxExtractAlpha");
- RenderGlowMaxExtractAlpha = glow_max_alpha;
- static LLCachedControl<F32> glow_warmth_a(gSavedSettings,
- "RenderGlowWarmthAmount");
- RenderGlowWarmthAmount = glow_warmth_a;
- static LLCachedControl<LLVector3> glow_lum_w(gSavedSettings,
- "RenderGlowLumWeights");
- RenderGlowLumWeights = glow_lum_w;
- static LLCachedControl<LLVector3> glow_warmth_w(gSavedSettings,
- "RenderGlowWarmthWeights");
- RenderGlowWarmthWeights = glow_warmth_w;
- static LLCachedControl<U32> glow_res_pow(gSavedSettings,
- "RenderGlowResolutionPow");
- RenderGlowResolutionPow = glow_res_pow;
- static LLCachedControl<U32> glow_iterations(gSavedSettings,
- "RenderGlowIterations");
- RenderGlowIterations = glow_iterations;
- static LLCachedControl<F32> glow_width(gSavedSettings, "RenderGlowWidth");
- RenderGlowWidth = glow_width;
- static LLCachedControl<F32> glow_strength(gSavedSettings,
- "RenderGlowStrength");
- RenderGlowStrength = llmax(0.f, (F32)glow_strength);
- static LLCachedControl<bool> depth_of_field(gSavedSettings,
- "RenderDepthOfField");
- RenderDepthOfField = depth_of_field;
- static LLCachedControl<bool> dof_in_edit(gSavedSettings,
- "RenderDepthOfFieldInEditMode");
- RenderDepthOfFieldInEditMode = dof_in_edit;
- static LLCachedControl<F32> shadow_noise(gSavedSettings,
- "RenderShadowNoise");
- RenderShadowNoise = shadow_noise;
- static LLCachedControl<F32> shadow_blur_size(gSavedSettings,
- "RenderShadowBlurSize");
- RenderShadowBlurSize = shadow_blur_size;
- static LLCachedControl<F32> ssao_scale(gSavedSettings, "RenderSSAOScale");
- RenderSSAOScale = ssao_scale;
- static LLCachedControl<U32> ssao_max_scale(gSavedSettings,
- "RenderSSAOMaxScale");
- RenderSSAOMaxScale = ssao_max_scale;
- static LLCachedControl<F32> ssao_fact(gSavedSettings, "RenderSSAOFactor");
- RenderSSAOFactor = ssao_fact;
- static LLCachedControl<LLVector3> ssao_effect(gSavedSettings,
- "RenderSSAOEffect");
- RenderSSAOEffect = ssao_effect;
- static LLCachedControl<F32> shadow_bias_error(gSavedSettings,
- "RenderShadowBiasError");
- RenderShadowBiasError = shadow_bias_error;
- static LLCachedControl<F32> shadow_offset(gSavedSettings,
- "RenderShadowOffset");
- RenderShadowOffset = shadow_offset;
- static LLCachedControl<F32> shadow_off_no_ssao(gSavedSettings,
- "RenderShadowOffsetNoSSAO");
- RenderShadowOffsetNoSSAO = shadow_off_no_ssao;
- static LLCachedControl<F32> shadow_bias(gSavedSettings,
- "RenderShadowBias");
- RenderShadowBias = shadow_bias;
- static LLCachedControl<F32> spot_shadow_offset(gSavedSettings,
- "RenderSpotShadowOffset");
- RenderSpotShadowOffset = spot_shadow_offset;
- static LLCachedControl<F32> spot_shadow_bias(gSavedSettings,
- "RenderSpotShadowBias");
- RenderSpotShadowBias = spot_shadow_bias;
- static LLCachedControl<LLVector3> shadow_gaussian(gSavedSettings,
- "RenderShadowGaussian");
- RenderShadowGaussian = shadow_gaussian;
- static LLCachedControl<F32> shadow_blur_dist(gSavedSettings,
- "RenderShadowBlurDistFactor");
- RenderShadowBlurDistFactor = shadow_blur_dist;
- static LLCachedControl<bool> deferred_atmos(gSavedSettings,
- "RenderDeferredAtmospheric");
- RenderDeferredAtmospheric = deferred_atmos;
- static LLCachedControl<U32> reflection_type(gSavedSettings,
- "RenderWaterReflectionType");
- RenderWaterReflectionType = reflection_type;
- static LLCachedControl<bool> transparent_water(gSavedSettings,
- "RenderTransparentWater");
- RenderTransparentWater = transparent_water;
- static LLCachedControl<LLVector3> shadow_planes(gSavedSettings,
- "RenderShadowClipPlanes");
- RenderShadowClipPlanes = shadow_planes;
- static LLCachedControl<LLVector3> shadow_ortho(gSavedSettings,
- "RenderShadowOrthoClipPlanes");
- RenderShadowOrthoClipPlanes = shadow_ortho;
- static LLCachedControl<F32> far_clip(gSavedSettings, "RenderFarClip");
- RenderFarClip = far_clip;
- static LLCachedControl<LLVector3> shadow_split_exp(gSavedSettings,
- "RenderShadowSplitExponent");
- RenderShadowSplitExponent = shadow_split_exp;
- static LLCachedControl<F32> shadow_error_cutoff(gSavedSettings,
- "RenderShadowErrorCutoff");
- RenderShadowErrorCutoff = shadow_error_cutoff;
- static LLCachedControl<F32> shadow_fov_cutoff(gSavedSettings,
- "RenderShadowFOVCutoff");
- RenderShadowFOVCutoff = llmin((F32)shadow_fov_cutoff, 1.4f);
- static LLCachedControl<bool> camera_offset(gSavedSettings, "CameraOffset");
- CameraOffset = camera_offset;
- static LLCachedControl<F32> camera_max_cof(gSavedSettings, "CameraMaxCoF");
- CameraMaxCoF = camera_max_cof;
- static LLCachedControl<F32> camera_dof_scale(gSavedSettings,
- "CameraDoFResScale");
- CameraDoFResScale = camera_dof_scale;
- static LLCachedControl<U32> auto_hide_mem(gSavedSettings,
- "RenderAutoHideGeometryMemoryLimit");
- RenderAutoHideGeometryMemoryLimit = auto_hide_mem;
- static LLCachedControl<F32> auto_hide_area(gSavedSettings,
- "RenderAutoHideSurfaceAreaLimit");
- RenderAutoHideSurfaceAreaLimit = auto_hide_area;
- sRenderSpotLight = NULL;
- static LLCachedControl<S32> pbr_visu(gSavedSettings,
- "RenderBufferVisualization");
- RenderBufferVisualization = llclamp(S32(pbr_visu), -1, 4);
- static LLCachedControl<U32> refl_iter(gSavedSettings,
- "RenderScreenSpaceReflectionIterations");
- RenderScreenSpaceReflectionIterations = refl_iter;
- static LLCachedControl<F32> refl_step(gSavedSettings,
- "RenderScreenSpaceReflectionRayStep");
- RenderScreenSpaceReflectionRayStep = llmax(0.f, refl_step);
- static LLCachedControl<F32> refl_bias(gSavedSettings,
- "RenderScreenSpaceReflectionDistanceBias");
- RenderScreenSpaceReflectionDistanceBias = llmax(0.f, refl_bias);
- static LLCachedControl<F32> refl_rej(gSavedSettings,
- "RenderScreenSpaceReflectionDepthRejectBias");
- RenderScreenSpaceReflectionDepthRejectBias = llmax(0.f, refl_rej);
- static LLCachedControl<F32> refl_mult(gSavedSettings,
- "RenderScreenSpaceReflectionAdaptiveStepMultiplier");
- RenderScreenSpaceReflectionDepthRejectBias = llmax(0.f, refl_mult);
- static LLCachedControl<U32> refl_glos(gSavedSettings,
- "RenderScreenSpaceReflectionGlossySamples");
- RenderScreenSpaceReflectionGlossySamples = refl_glos;
- static LLCachedControl<U32> reflections(gSavedSettings,
- "RenderReflectionProbes");
- sReflectionProbesEnabled = gUsePBRShaders && LLViewerShaderMgr::sHasRP &&
- reflections;
- bool had_mirrors = sRenderMirrors;
- static LLCachedControl<U32> hero_res(gSavedSettings,
- "RenderHeroProbeResLevel");
- sRenderMirrors = sReflectionProbesEnabled && hero_res > 0;
- if (gUsePBRShaders && sRenderMirrors != had_mirrors)
- {
- handle_refresh_probes(NULL);
- }
- static LLCachedControl<bool> refl_space(gSavedSettings,
- "RenderScreenSpaceReflections");
- RenderScreenSpaceReflections = sReflectionProbesEnabled && reflections;
- static LLCachedControl<bool> pbr_terrain(gSavedSettings,
- "RenderTerrainPBREnabled");
- sRenderPBRTerrain = gUsePBRShaders && pbr_terrain &&
- gGLManager.mNumTextureImageUnits >= 16;
- static LLCachedControl<U32> pbr_terrain_detail(gSavedSettings,
- "RenderTerrainPBRDetail");
- S32 terrain_details = 0;
- if (sRenderPBRTerrain)
- {
- terrain_details = pbr_terrain_detail;
- if (terrain_details > 3 && gGLManager.mNumTextureImageUnits <= 16)
- {
- terrain_details = 3; // Remove emissive map support
- }
- }
- sRenderPBRTerrainDetail = llmin(0, terrain_details - 4);
- updateRenderDeferred();
- LLPrefsGraphics::refresh();
- }
- void LLPipeline::releaseGLBuffers()
- {
- if (mNoiseMap)
- {
- LLImageGL::deleteTextures(1, &mNoiseMap);
- mNoiseMap = 0;
- }
- if (mTrueNoiseMap)
- {
- LLImageGL::deleteTextures(1, &mTrueNoiseMap);
- mTrueNoiseMap = 0;
- }
- if (mAreaMap)
- {
- LLImageGL::deleteTextures(1, &mAreaMap);
- mAreaMap = 0;
- }
- if (mSearchMap)
- {
- LLImageGL::deleteTextures(1, &mSearchMap);
- mSearchMap = 0;
- }
- releaseLUTBuffers();
- if (gUsePBRShaders)
- {
- mSceneMap.release();
- mPostMap.release();
- }
- else
- {
- mWaterRef.release();
- }
- mWaterDis.release();
- for (U32 i = 0; i < 3; ++i)
- {
- mGlow[i].release();
- }
- releaseScreenBuffers();
- LLVOAvatar::resetImpostors();
- }
- void LLPipeline::releaseLUTBuffers()
- {
- if (mLightFunc)
- {
- LLImageGL::deleteTextures(1, &mLightFunc);
- mLightFunc = 0;
- }
- if (gUsePBRShaders)
- {
- mPbrBrdfLut.release();
- mExposureMap.release();
- mLuminanceMap.release();
- mLastExposure.release();
- }
- }
- void LLPipeline::releasePackBuffers(RenderTargetPack* packp)
- {
- mRT = packp;
- releaseShadowTargets();
- mRT->mScreen.release();
- mRT->mDeferredScreen.release();
- mRT->mDeferredLight.release();
- }
- void LLPipeline::releaseScreenBuffers()
- {
- mFXAABuffer.release();
- mSMAAEdgeBuffer.release();
- mSMAABlendBuffer.release();
- mScratchBuffer.release();
- if (gUsePBRShaders)
- {
- releasePackBuffers(&mAuxillaryRT);
- releasePackBuffers(&mHeroProbeRT);
- mReflectionMapManager.cleanup();
- mHeroProbeManager.cleanup();
- }
- else
- {
- mPhysicsDisplay.release();
- mDeferredDepth.release();
- mOcclusionDepth.release();
- }
- releasePackBuffers(&mMainRT);
- }
- void LLPipeline::releaseShadowTarget(U32 index)
- {
- llassert(!gUsePBRShaders); // EE rendering only
- mShadow[index].release();
- mShadowOcclusion[index].release();
- }
- void LLPipeline::releaseSunShadowTargets()
- {
- llassert(gUsePBRShaders); // PBR rendering only
- mRT->mSunShadow[0].release();
- mRT->mSunShadow[1].release();
- mRT->mSunShadow[2].release();
- mRT->mSunShadow[3].release();
- }
- void LLPipeline::releaseSpotShadowTargets()
- {
- llassert(gUsePBRShaders); // PBR rendering only
- // *HACK: do not release during auxiliary target allocation
- if (!gCubeSnapshot)
- {
- mSpotShadow[0].release();
- mSpotShadow[1].release();
- }
- }
- void LLPipeline::releaseShadowTargets()
- {
- if (gUsePBRShaders)
- {
- releaseSunShadowTargets();
- releaseSpotShadowTargets();
- }
- else
- {
- for (U32 i = 0; i < 6; ++i)
- {
- mShadow[i].release();
- mShadowOcclusion[i].release();
- }
- }
- }
- void LLPipeline::createGLBuffers()
- {
- updateRenderDeferred();
- GLuint res_x = gViewerWindowp->getWindowDisplayWidth();
- GLuint res_y = gViewerWindowp->getWindowDisplayHeight();
- if (gUsePBRShaders)
- {
- // We need this buffer to be as large as the screen space, since it is
- // used to copy the screen buffer for screen-wide water and atmospheric
- // haze as well as for water distortions and reflections... HB
- mWaterDis.allocate(res_x, res_y, GL_RGBA16F, true);
- }
- else
- {
- // Water reflection texture
- // Set up SRGB targets if we are doing deferred-path reflection rendering
- U32 res = llmax(gSavedSettings.getU32("RenderWaterRefResolution"),
- 512);
- mWaterRef.allocate(res, res, GL_RGBA, true, false);
- mWaterDis.allocate(res, res, GL_RGBA, true, false);
- }
- // Screen space glow buffers
- U32 glow_pow = gSavedSettings.getU32("RenderGlowResolutionPow");
- // Limited between 16 and 512
- const U32 glow_res = 1 << llclamp(glow_pow, 4U, 9U);
- for (U32 i = 0; i < 3; ++i)
- {
- if (gUsePBRShaders)
- {
- mGlow[i].allocate(512, glow_res, GL_RGBA);
- }
- else
- {
- mGlow[i].allocate(512, glow_res, GL_RGBA, false, false);
- }
- }
- allocateScreenBuffer(res_x, res_y);
- if (!sRenderDeferred) // Forward rendering
- {
- stop_glerror();
- return;
- }
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- if (!mNoiseMap)
- {
- constexpr U32 noise_res = 128;
- LLVector3 noise[noise_res * noise_res];
- F32 scaler = gSavedSettings.getF32("RenderDeferredNoise") / 100.f;
- for (U32 i = 0; i < noise_res * noise_res; ++i)
- {
- noise[i].set(ll_frand() - 0.5f, ll_frand() - 0.5f, 0.f);
- noise[i].normalize();
- noise[i].mV[2] = ll_frand() * scaler + 1.f - scaler * 0.5f;
- }
- LLImageGL::generateTextures(1, &mNoiseMap);
- unit0->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
- LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE),
- 0, GL_RGB16F, noise_res, noise_res, GL_RGB,
- GL_FLOAT, noise, false);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_POINT);
- unit0->disable();
- }
- if (!mTrueNoiseMap)
- {
- constexpr U32 noise_res = 128;
- F32 noise[noise_res * noise_res * 3];
- for (U32 i = 0; i < noise_res * noise_res * 3; ++i)
- {
- noise[i] = ll_frand() * 2.f - 1.f;
- }
- LLImageGL::generateTextures(1, &mTrueNoiseMap);
- unit0->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
- LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE),
- 0, GL_RGB16F, noise_res, noise_res, GL_RGB,
- GL_FLOAT, noise, false);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_POINT);
- unit0->disable();
- }
- if (!mAreaMap)
- {
- std::vector<unsigned char> temp_buff(AREATEX_SIZE);
- for (size_t y = 0; y < AREATEX_HEIGHT; ++y)
- {
- size_t src_y = AREATEX_HEIGHT - 1 - y;
- memcpy(&temp_buff[y * AREATEX_PITCH],
- areaTexBytes + src_y * AREATEX_PITCH, AREATEX_PITCH);
- }
- LLImageGL::generateTextures(1, &mAreaMap);
- unit0->bindManual(LLTexUnit::TT_TEXTURE, mAreaMap);
- LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE),
- 0, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT,
- GL_RG, GL_UNSIGNED_BYTE, temp_buff.data(),
- false);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->disable();
- }
- if (!mSearchMap)
- {
- std::vector<unsigned char> temp_buff(SEARCHTEX_SIZE);
- for (size_t y = 0; y < SEARCHTEX_HEIGHT; ++y)
- {
- size_t src_y = SEARCHTEX_HEIGHT - 1 - y;
- memcpy(&temp_buff[y * SEARCHTEX_PITCH],
- searchTexBytes + src_y * SEARCHTEX_PITCH, SEARCHTEX_PITCH);
- }
- LLImageGL::generateTextures(1, &mSearchMap);
- unit0->bindManual(LLTexUnit::TT_TEXTURE, mSearchMap);
- LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE),
- 0, GL_RG8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT,
- GL_RED, GL_UNSIGNED_BYTE, temp_buff.data(),
- false);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->disable();
- }
- createLUTBuffers();
- stop_glerror();
- }
- void LLPipeline::createLUTBuffers()
- {
- if (!sRenderDeferred || mLightFunc)
- {
- return;
- }
- static LLCachedControl<U32> light_res_x(gSavedSettings,
- "RenderSpecularResX");
- static LLCachedControl<U32> light_res_y(gSavedSettings,
- "RenderSpecularResY");
- static LLCachedControl<F32> spec_exp(gSavedSettings,
- "RenderSpecularExponent");
- F32* ls = new F32[light_res_x * light_res_y];
- // Calculate the (normalized) blinn-phong specular lookup texture (with a
- // few tweaks).
- for (U32 y = 0; y < light_res_y; ++y)
- {
- for (U32 x = 0; x < light_res_x; ++x)
- {
- ls[y * light_res_x + x] = 0.f;
- F32 sa = (F32)x / (F32)(light_res_x - 1);
- F32 spec = (F32)y / (F32)(light_res_y - 1);
- F32 n = spec * spec * spec_exp;
- // Nothing special here, just your typical blinn-phong term
- spec = powf(sa, n);
- // Apply our normalization function.
- // Note: This is the full equation that applies the full
- // normalization curve, not an approximation. This is fine, given
- // we only need to create our LUT once per buffer initialization.
- // The only trade off is we have a really low dynamic range. This
- // means we have to account for things not being able to exceed 0
- // to 1 in our shaders.
- spec *= (n + 2.f) * (n + 4.f) /
- (8.f * F_PI * (powf(2.f, -0.5f * n) + n));
- // Since we use R16F, we no longer have a dynamic range issue we
- // need to work around here. Though some older drivers may not like
- // this, newer drivers should not have this problem.
- ls[y * light_res_x + x] = spec;
- }
- }
- #if LL_DARWIN
- // Work around for limited precision with 10.6.8 and older drivers
- constexpr U32 pix_format = GL_R32F;
- #else
- constexpr U32 pix_format = GL_R16F;
- #endif
- LLImageGL::generateTextures(1, &mLightFunc);
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
- LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE),
- 0, pix_format, light_res_x, light_res_y,
- GL_RED, GL_FLOAT, ls, false);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- delete[] ls;
- if (!gUsePBRShaders)
- {
- return;
- }
- mPbrBrdfLut.allocate(512, 512, GL_RG16F);
- mPbrBrdfLut.bindTarget();
- gDeferredGenBrdfLutProgram.bind();
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.vertex2f(-1.f, -1.f);
- gGL.vertex2f(-1.f, 1.f);
- gGL.vertex2f(1.f, -1.f);
- gGL.vertex2f(1.f, 1.f);
- gGL.end(true);
- gDeferredGenBrdfLutProgram.unbind();
- mPbrBrdfLut.flush();
- mExposureMap.allocate(1, 1, GL_R16F);
- mExposureMap.bindTarget();
- glClearColor(1.f, 1.f, 1.f, 0.f);
- mExposureMap.clear();
- glClearColor(0.f, 0.f, 0.f, 0.f);
- mExposureMap.flush();
- mLuminanceMap.allocate(256, 256, GL_R16F, false, LLTexUnit::TT_TEXTURE,
- LLTexUnit::TMG_AUTO);
- mLastExposure.allocate(1, 1, GL_R16F);
- }
- void LLPipeline::restoreGL()
- {
- gViewerShaderMgrp->setShaders();
- #if 0 // Failed attempt at properly restoring terrain after GL restart with
- // core GL profile enabled. HB
- LLViewerTextureList::dirty_list_t textures;
- for (pool_tex_map_t::iterator it = mTerrainPools.begin(),
- end = mTerrainPools.end();
- it != end; ++it)
- {
- textures.insert((LLViewerFetchedTexture*)it->first);
- }
- dirtyPoolObjectTextures(textures);
- #elif 0 // Second failed attempt at properly restoring terrain after GL
- // restart with core GL profile enabled. HB
- for (pool_tex_map_t::iterator it = mTerrainPools.begin(),
- end = mTerrainPools.end();
- it != end; ++it)
- {
- LLDrawPool* poolp = it->second;
- if (poolp->isTerrainPool()) // Paranoia
- {
- ((LLDrawPoolTerrain*)poolp)->rebuildPatches();
- }
- }
- #endif
- }
- bool LLPipeline::canUseWindLightShaders() const
- {
- if (gUsePBRShaders)
- {
- // If we could switch to PBR rendering, then we can do Windlight. HB
- return true;
- }
- return gWLSkyProgram.mProgramObject &&
- gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_WINDLIGHT) > 1;
- }
- void LLPipeline::unloadShaders()
- {
- gViewerShaderMgrp->unloadShaders();
- if (mVertexShadersLoaded != -1)
- {
- mVertexShadersLoaded = 0;
- }
- }
- class LLOctreeDirtyTexture final : public OctreeTraveler
- {
- public:
- LLOctreeDirtyTexture(const LLViewerTextureList::dirty_list_t& textures)
- : mTextures(textures)
- {
- }
- void visit(const OctreeNode* nodep) override
- {
- LLSpatialGroup* groupp = (LLSpatialGroup*)nodep->getListener(0);
- if (!groupp) return;
- if (!groupp->isEmpty() &&
- !groupp->hasState(LLSpatialGroup::GEOM_DIRTY))
- {
- LLViewerTextureList::dirty_list_t::const_iterator textures_end =
- mTextures.end();
- for (LLSpatialGroup::draw_map_t::const_iterator
- it = groupp->mDrawMap.begin(), end = groupp->mDrawMap.end();
- it != end; ++it)
- {
- const LLSpatialGroup::drawmap_elem_t& draw_info = it->second;
- for (U32 i = 0, count = draw_info.size(); i < count; ++i)
- {
- LLDrawInfo* infop = draw_info[i].get();
- LLViewerFetchedTexture* texp =
- LLViewerTextureManager::staticCast(infop->mTexture);
- if (texp && mTextures.find(texp) != textures_end)
- {
- groupp->setState(LLSpatialGroup::GEOM_DIRTY);
- }
- }
- }
- }
- LLSpatialGroup::bridge_list_t& blist = groupp->mBridgeList;
- for (U32 i = 0, count = blist.size(); i < count; ++i)
- {
- traverse(blist[i]->mOctree);
- }
- }
- public:
- const LLViewerTextureList::dirty_list_t& mTextures;
- };
- // Called when a texture changes # of channels (causes faces to move to alpha
- // pool)
- void LLPipeline::dirtyPoolObjectTextures(const LLViewerTextureList::dirty_list_t& textures)
- {
- // *TODO: This is inefficient and causes frame spikes; need a better way to
- // do this. Most of the time is spent in dirty.traverse.
- for (pool_set_t::iterator iter = mPools.begin(), end = mPools.end();
- iter != end; ++iter)
- {
- LLDrawPool* poolp = *iter;
- // Only LLDrawPoolTerrain was using dirtyTextures() so I de-virtualized
- // the latter and added the isTerrainPool() virtual, which is tested
- // instead of isFacePool() with a useless call to an empty virtual
- // dirtyTextures() mesthod for all other face pools... HB
- if (poolp->isTerrainPool())
- {
- ((LLDrawPoolTerrain*)poolp)->dirtyTextures(textures);
- }
- }
- LLOctreeDirtyTexture dirty(textures);
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- dirty.traverse(partp->mOctree);
- }
- }
- }
- LLDrawPool* LLPipeline::findPool(U32 type, LLViewerTexture* tex0)
- {
- LLDrawPool* poolp = NULL;
- switch (type)
- {
- case LLDrawPool::POOL_SIMPLE:
- poolp = mSimplePool;
- break;
- case LLDrawPool::POOL_GRASS:
- poolp = mGrassPool;
- break;
- case LLDrawPool::POOL_ALPHA_MASK:
- poolp = mAlphaMaskPool;
- break;
- case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
- poolp = mFullbrightAlphaMaskPool;
- break;
- case LLDrawPool::POOL_FULLBRIGHT:
- poolp = mFullbrightPool;
- break;
- case LLDrawPool::POOL_INVISIBLE:
- poolp = mInvisiblePool;
- break;
- case LLDrawPool::POOL_GLOW:
- poolp = mGlowPool;
- break;
- case LLDrawPool::POOL_TREE:
- poolp = get_ptr_in_map(mTreePools, (uintptr_t)tex0);
- break;
- case LLDrawPool::POOL_TERRAIN:
- poolp = get_ptr_in_map(mTerrainPools, (uintptr_t)tex0);
- break;
- case LLDrawPool::POOL_BUMP:
- poolp = mBumpPool;
- break;
- case LLDrawPool::POOL_MATERIALS:
- poolp = mMaterialsPool;
- break;
- case LLDrawPool::POOL_ALPHA_PRE_WATER:
- poolp = mAlphaPoolPreWater;
- break;
- case LLDrawPool::POOL_ALPHA_POST_WATER:
- poolp = mAlphaPoolPostWater;
- break;
- case LLDrawPool::POOL_ALPHA:
- poolp = mAlphaPool;
- break;
- case LLDrawPool::POOL_AVATAR:
- case LLDrawPool::POOL_PUPPET:
- break; // Do nothing
- case LLDrawPool::POOL_SKY:
- poolp = mSkyPool;
- break;
- case LLDrawPool::POOL_WATER:
- poolp = mWaterPool;
- break;
- case LLDrawPool::POOL_WL_SKY:
- poolp = mWLSkyPool;
- break;
- case LLDrawPool::POOL_MAT_PBR:
- poolp = mPBROpaquePool;
- break;
- case LLDrawPool::POOL_MAT_PBR_ALPHA_MASK:
- poolp = mPBRAlphaMaskPool;
- break;
- default:
- llerrs << "Invalid Pool Type: " << type << llendl;
- }
- return poolp;
- }
- LLDrawPool* LLPipeline::getPool(U32 type, LLViewerTexture* tex0)
- {
- LLDrawPool* poolp = findPool(type, tex0);
- if (poolp)
- {
- return poolp;
- }
- poolp = LLDrawPool::createPool(type, tex0);
- addPool(poolp);
- return poolp;
- }
- //static
- LLDrawPool* LLPipeline::getPoolFromTE(const LLTextureEntry* tep,
- LLViewerTexture* imagep)
- {
- return gPipeline.getPool(getPoolTypeFromTE(tep, imagep), imagep);
- }
- //static
- U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* tep,
- LLViewerTexture* imagep)
- {
- if (!tep || !imagep)
- {
- return 0;
- }
- LLMaterial* matp = tep->getMaterialParams().get();
- LLGLTFMaterial* gltfp = NULL;
- if (gUsePBRShaders)
- {
- gltfp = tep->getGLTFRenderMaterial();
- }
- bool color_alpha = tep->getAlpha() < 0.999f;
- bool alpha = color_alpha;
- if (!alpha && imagep)
- {
- S32 components = imagep->getComponents();
- alpha = components == 2 ||
- (components == 4 &&
- imagep->getType() != LLViewerTexture::MEDIA_TEXTURE);
- }
- if (alpha && matp)
- {
- if (matp->getDiffuseAlphaMode() == 1)
- {
- // Material's alpha mode is set to blend. Toss it into the alpha
- // draw pool.
- return LLDrawPool::POOL_ALPHA;
- }
- // 0 -> Material alpha mode set to none, never go to alpha pool
- // 3 -> Material alpha mode set to emissive, never go to alpha pool
- // other -> Material alpha mode set to "mask", go to alpha pool if
- // fullbright, or material alpha mode is set to none, mask or
- // emissive. Toss it into the opaque material draw pool.
- alpha = color_alpha; // Use the pool matching the te alpha
- }
- if (alpha ||
- (gltfp && gltfp->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND))
- {
- return LLDrawPool::POOL_ALPHA;
- }
- if ((tep->getBumpmap() || tep->getShiny()) &&
- (!matp || matp->getNormalID().isNull()))
- {
- return LLDrawPool::POOL_BUMP;
- }
- if (gltfp)
- {
- return LLDrawPool::POOL_MAT_PBR;
- }
- return matp ? LLDrawPool::POOL_MATERIALS : LLDrawPool::POOL_SIMPLE;
- }
- void LLPipeline::addPool(LLDrawPool* new_poolp)
- {
- mPools.insert(new_poolp);
- addToQuickLookup(new_poolp);
- }
- void LLPipeline::allocDrawable(LLViewerObject* objp)
- {
- LLDrawable* drawablep = new LLDrawable(objp);
- objp->mDrawable = drawablep;
- // Encompass completely sheared objects by taking the most extreme
- // point possible (<1.0, 1.0, 0.5>)
- F32 radius = LLVector3(1.f, 1.f, 0.5f).scaleVec(objp->getScale()).length();
- drawablep->setRadius(radius);
- if (objp->isOrphaned())
- {
- drawablep->setState(LLDrawable::FORCE_INVISIBLE);
- }
- drawablep->updateXform(true);
- }
- void LLPipeline::unlinkDrawable(LLDrawable* drawable)
- {
- LL_FAST_TIMER(FTM_UNLINK);
- // Make sure the drawable does not get deleted before we are done
- LLPointer<LLDrawable> drawablep = drawable;
- // Based on flags, remove the drawable from the queues that it is on.
- if (drawablep->isState(LLDrawable::ON_MOVE_LIST))
- {
- LL_FAST_TIMER(FTM_REMOVE_FROM_MOVE_LIST);
- for (U32 i = 0, count = mMovedList.size(); i < count; ++i)
- {
- if (mMovedList[i] == drawablep)
- {
- if (i < count - 1)
- {
- mMovedList[i] = std::move(mMovedList.back());
- }
- mMovedList.pop_back();
- break;
- }
- }
- }
- LLSpatialGroup* groupp = drawablep->getSpatialGroup();
- if (groupp && groupp->getSpatialPartition())
- {
- LL_FAST_TIMER(FTM_REMOVE_FROM_SPATIAL_PARTITION);
- if (!groupp->getSpatialPartition()->remove(drawablep, groupp))
- {
- llwarns << "Could not remove object from spatial group" << llendl;
- llassert(false);
- }
- }
- {
- LL_FAST_TIMER(FTM_REMOVE_FROM_LIGHT_SET);
- mLights.erase(drawablep);
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- if (iter->drawable == drawablep)
- {
- mNearbyLights.erase(iter);
- break;
- }
- }
- }
- for (U32 i = 0; i < 2; ++i)
- {
- if (mShadowSpotLight[i] == drawablep)
- {
- mShadowSpotLight[i] = NULL;
- }
- if (mTargetShadowSpotLight[i] == drawablep)
- {
- mTargetShadowSpotLight[i] = NULL;
- }
- }
- }
- U32 LLPipeline::addObject(LLViewerObject* objp)
- {
- if (RenderDelayCreation)
- {
- mCreateQ.emplace_back(objp);
- }
- else
- {
- createObject(objp);
- }
- return 1;
- }
- void LLPipeline::createObjects(F32 max_dtime)
- {
- LL_FAST_TIMER(FTM_PIPELINE_CREATE);
- LLTimer update_timer;
- while (!mCreateQ.empty() && update_timer.getElapsedTimeF32() < max_dtime)
- {
- LLViewerObject* objp = mCreateQ.front();
- if (objp && !objp->isDead())
- {
- createObject(objp);
- }
- mCreateQ.pop_front();
- }
- }
- void LLPipeline::createObject(LLViewerObject* objp)
- {
- LLDrawable* drawablep = objp->mDrawable;
- if (!drawablep)
- {
- drawablep = objp->createDrawable();
- llassert(drawablep);
- }
- else
- {
- llerrs << "Redundant drawable creation !" << llendl;
- }
- LLViewerObject* parentp = (LLViewerObject*)objp->getParent();
- if (parentp)
- {
- // LLPipeline::addObject 1
- objp->setDrawableParent(parentp->mDrawable);
- }
- else
- {
- // LLPipeline::addObject 2
- objp->setDrawableParent(NULL);
- }
- markRebuild(drawablep);
- if (RenderAnimateRes && drawablep->getVOVolume())
- {
- // Fun animated res
- drawablep->updateXform(true);
- drawablep->clearState(LLDrawable::MOVE_UNDAMPED);
- drawablep->setScale(LLVector3::zero);
- drawablep->makeActive();
- }
- }
- void LLPipeline::resetFrameStats()
- {
- static LLCachedControl<bool> render_info(gSavedSettings,
- "DebugShowRenderInfo");
- if (render_info)
- {
- mNeedsDrawStats = true;
- }
- else if (mNeedsDrawStats && !LLFloaterStats::findInstance())
- {
- mNeedsDrawStats = false;
- }
- if (mNeedsDrawStats)
- {
- mTrianglesDrawnStat.addValue(F32(mTrianglesDrawn) * .001f);
- mTrianglesDrawn = 0;
- }
- if (mOldRenderDebugMask != mRenderDebugMask)
- {
- gObjectList.clearDebugText();
- mOldRenderDebugMask = mRenderDebugMask;
- }
- }
- // External functions for asynchronous updating
- void LLPipeline::updateMoveDampedAsync(LLDrawable* drawablep)
- {
- if (sFreezeTime)
- {
- return;
- }
- if (!drawablep)
- {
- llerrs << "Called with NULL drawable" << llendl;
- return;
- }
- if (drawablep->isState(LLDrawable::EARLY_MOVE))
- {
- return;
- }
- // Update drawable now
- drawablep->clearState(LLDrawable::MOVE_UNDAMPED); // Force to DAMPED
- drawablep->updateMove(); // Returns done
- // Flag says we already did an undamped move this frame:
- drawablep->setState(LLDrawable::EARLY_MOVE);
- // Put on move list so that EARLY_MOVE gets cleared
- if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
- {
- mMovedList.emplace_back(drawablep);
- drawablep->setState(LLDrawable::ON_MOVE_LIST);
- }
- }
- void LLPipeline::updateMoveNormalAsync(LLDrawable* drawablep)
- {
- if (sFreezeTime)
- {
- return;
- }
- if (!drawablep)
- {
- llerrs << "Called with NULL drawable" << llendl;
- }
- if (drawablep->isState(LLDrawable::EARLY_MOVE))
- {
- return;
- }
- // Update drawable now
- drawablep->setState(LLDrawable::MOVE_UNDAMPED); // Force to UNDAMPED
- drawablep->updateMove();
- // Flag says we already did an undamped move this frame:
- drawablep->setState(LLDrawable::EARLY_MOVE);
- // Put on move list so that EARLY_MOVE gets cleared
- if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
- {
- mMovedList.emplace_back(drawablep);
- drawablep->setState(LLDrawable::ON_MOVE_LIST);
- }
- }
- void LLPipeline::updateMovedList(LLDrawable::draw_vec_t& moved_list)
- {
- LL_TRACY_TIMER(TRC_MOVED_LIST);
- for (U32 i = 0, count = moved_list.size(); i < count; )
- {
- LLDrawable* drawablep = moved_list[i];
- bool done = true;
- if (!drawablep->isDead() &&
- !drawablep->isState(LLDrawable::EARLY_MOVE))
- {
- done = drawablep->updateMove();
- }
- drawablep->clearState(LLDrawable::EARLY_MOVE |
- LLDrawable::MOVE_UNDAMPED);
- if (done)
- {
- if (drawablep->isRoot() && !drawablep->isState(LLDrawable::ACTIVE))
- {
- drawablep->makeStatic();
- }
- drawablep->clearState(LLDrawable::ON_MOVE_LIST);
- if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
- {
- // Will likely not receive any future world matrix updates;
- // this keeps attachments from getting stuck in space and
- // falling off your avatar
- drawablep->clearState(LLDrawable::ANIMATED_CHILD);
- markRebuild(drawablep, LLDrawable::REBUILD_VOLUME);
- LLViewerObject* objp = drawablep->getVObj().get();
- if (objp)
- {
- objp->dirtySpatialGroup();
- }
- }
- if (i < --count)
- {
- moved_list[i] = std::move(moved_list.back());
- }
- moved_list.pop_back();
- }
- else
- {
- ++i;
- }
- }
- }
- void LLPipeline::updateMove(bool balance_vo_cache)
- {
- LL_FAST_TIMER(FTM_UPDATE_MOVE);
- if (sFreezeTime)
- {
- return;
- }
- for (LLDrawable::draw_set_t::iterator iter = mRetexturedList.begin(),
- end = mRetexturedList.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- if (drawablep && !drawablep->isDead())
- {
- drawablep->updateTexture();
- }
- }
- mRetexturedList.clear();
- updateMovedList(mMovedList);
- // Balance octrees
- {
- LL_FAST_TIMER(FTM_OCTREE_BALANCE);
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; ++i)
- {
- if (i == LLViewerRegion::PARTITION_VO_CACHE &&
- !balance_vo_cache)
- {
- continue;
- }
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- if (partp)
- {
- partp->mOctree->balance();
- }
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // Culling and occlusion testing
- /////////////////////////////////////////////////////////////////////////////
- //static
- F32 LLPipeline::calcPixelArea(LLVector3 center, LLVector3 size,
- LLCamera& camera)
- {
- LLVector3 lookAt = center - camera.getOrigin();
- F32 dist = lookAt.length();
- // Ramp down distance for nearby objects; shrink dist by dist / 16.
- if (dist < 16.f)
- {
- dist /= 16.f;
- dist *= dist;
- dist *= 16.f;
- }
- if (dist <= 0.f)
- {
- dist = F32_MIN;
- }
- // Get area of circle around node
- F32 app_angle = atanf(size.length() / dist);
- F32 radius = app_angle * LLDrawable::sCurPixelAngle;
- return radius * radius * F_PI;
- }
- //static
- F32 LLPipeline::calcPixelArea(const LLVector4a& center, const LLVector4a& size,
- LLCamera& camera)
- {
- LLVector4a origin;
- origin.load3(camera.getOrigin().mV);
- LLVector4a lookAt;
- lookAt.setSub(center, origin);
- F32 dist = lookAt.getLength3().getF32();
- // Ramp down distance for nearby objects.
- // Shrink dist by dist/16.
- if (dist < 16.f)
- {
- dist *= 0.0625f; // 1/16
- dist *= dist;
- dist *= 16.f;
- }
- if (dist <= 0.f)
- {
- dist = F32_MIN;
- }
- // Get area of circle around node
- F32 app_angle = atanf(size.getLength3().getF32() / dist);
- F32 radius = app_angle * LLDrawable::sCurPixelAngle;
- return radius * radius * F_PI;
- }
- void LLPipeline::grabReferences(LLCullResult& result)
- {
- sCull = &result;
- }
- void LLPipeline::clearReferences()
- {
- sCull = NULL;
- mGroupSaveQ.clear();
- }
- #if LL_DEBUG
- static void check_references(LLSpatialGroup* groupp, LLDrawable* drawablep)
- {
- const LLSpatialGroup::element_list& data = groupp->getData();
- for (U32 i = 0, count = data.size(); i < count; ++i)
- {
- if (drawablep == (LLDrawable*)data[i]->getDrawable())
- {
- llerrs << "LLDrawable deleted while actively reference by LLPipeline."
- << llendl;
- }
- }
- }
- static void check_references(LLDrawable* drawablep, LLFace* facep)
- {
- for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
- {
- if (drawablep->getFace(i) == facep)
- {
- llerrs << "LLFace deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- }
- static void check_references(LLSpatialGroup* groupp, LLFace* facep)
- {
- const LLSpatialGroup::element_list& data = groupp->getData();
- for (U32 i = 0, count = data.size(); i < count; ++i)
- {
- LLDrawable* drawablep = (LLDrawable*)data[i]->getDrawable();
- if (drawablep)
- {
- check_references(drawablep, facep);
- }
- }
- }
- static void check_references(LLSpatialGroup* groupp, LLDrawInfo* draw_infop)
- {
- for (LLSpatialGroup::draw_map_t::const_iterator
- it = groupp->mDrawMap.begin(), end = groupp->mDrawMap.end();
- it != end; ++it)
- {
- const LLSpatialGroup::drawmap_elem_t& draw_vec = it->second;
- for (U32 i = 0, count = draw_vec.size(); i < count; ++i)
- {
- LLDrawInfo* paramsp = draw_vec[i].get();
- if (paramsp == draw_infop)
- {
- llerrs << "LLDrawInfo deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- }
- }
- void LLPipeline::checkReferences(LLFace* facep)
- {
- if (sCull)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- check_references(visible_groups[i], facep);
- }
- LLCullResult::sg_list_t& alpha_groups = sCull->getAlphaGroups();
- for (U32 i = 0, count = alpha_groups.size(); i < count; ++i)
- {
- check_references(alpha_groups[i], facep);
- }
- LLCullResult::sg_list_t& rig_groups = sCull->getRiggedAlphaGroups();
- for (U32 i = 0, count = rig_groups.size(); i < count; ++i)
- {
- check_references(rig_groups[i], facep);
- }
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- check_references(draw_groups[i], facep);
- }
- LLCullResult::drawable_list_t& visible = sCull->getVisibleList();
- for (U32 i = 0, count = visible.size(); i < count; ++i)
- {
- LLDrawable* drawablep = visible[i];
- check_references(drawablep, facep);
- }
- }
- }
- void LLPipeline::checkReferences(LLDrawable* drawablep)
- {
- if (sCull)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- check_references(visible_groups[i], drawablep);
- }
- LLCullResult::sg_list_t& alpha_groups = sCull->getAlphaGroups();
- for (U32 i = 0, count = alpha_groups.size(); i < count; ++i)
- {
- check_references(alpha_groups[i], drawablep);
- }
- LLCullResult::sg_list_t& rig_groups = sCull->getRiggedAlphaGroups();
- for (U32 i = 0, count = rig_groups.size(); i < count; ++i)
- {
- check_references(rig_groups[i], drawablep);
- }
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- check_references(draw_groups[i], drawablep);
- }
- LLCullResult::drawable_list_t& visible = sCull->getVisibleList();
- for (U32 i = 0, count = visible.size(); i < count; ++i)
- {
- if (drawablep == visible[i])
- {
- llerrs << "LLDrawable deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- }
- }
- void LLPipeline::checkReferences(LLDrawInfo* draw_infop)
- {
- if (sCull)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- check_references(visible_groups[i], draw_infop);
- }
- LLCullResult::sg_list_t& alpha_groups = sCull->getAlphaGroups();
- for (U32 i = 0, count = alpha_groups.size(); i < count; ++i)
- {
- check_references(alpha_groups[i], draw_infop);
- }
- LLCullResult::sg_list_t& rig_groups = sCull->getRiggedAlphaGroups();
- for (U32 i = 0, count = rig_groups.size(); i < count; ++i)
- {
- check_references(rig_groups[i], draw_infop);
- }
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- check_references(draw_groups[i], draw_infop);
- }
- }
- }
- void LLPipeline::checkReferences(LLSpatialGroup* groupp)
- {
- if (sCull)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- if (groupp == visible_groups[i])
- {
- llerrs << "LLSpatialGroup deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- LLCullResult::sg_list_t& alpha_groups = sCull->getAlphaGroups();
- for (U32 i = 0, count = alpha_groups.size(); i < count; ++i)
- {
- if (groupp == alpha_groups[i])
- {
- llerrs << "LLSpatialGroup deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- LLCullResult::sg_list_t& rig_groups = sCull->getRiggedAlphaGroups();
- for (U32 i = 0, count = rig_groups.size(); i < count; ++i)
- {
- if (groupp == rig_groups[i])
- {
- llerrs << "LLSpatialGroup deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- if (groupp == draw_groups[i])
- {
- llerrs << "LLSpatialGroup deleted while actively referenced by LLPipeline."
- << llendl;
- }
- }
- }
- }
- #endif
- bool LLPipeline::getVisibleExtents(LLCamera& camera, LLVector3& min,
- LLVector3& max)
- {
- constexpr F32 max_val = 65536.f;
- constexpr F32 min_val = -65536.f;
- min.set(max_val, max_val, max_val);
- max.set(min_val, min_val, min_val);
- S32 saved_camera_id = LLViewerCamera::sCurCameraID;
- LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
- bool res = true;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType) &&
- !partp->getVisibleExtents(camera, min, max))
- {
- res = false;
- }
- }
- }
- LLViewerCamera::sCurCameraID = saved_camera_id;
- return res;
- }
- //static
- bool LLPipeline::isWaterClip()
- {
- if (sRenderMirrors && gPipeline.mHeroProbeManager.isMirrorPass())
- {
- // We always pretend that we are not clipping water when rendering
- // mirrors.
- return false;
- }
- return (!RenderTransparentWater || gCubeSnapshot) && !sRenderingHUDs;
- }
- // Branched version for the PBR renderer
- void LLPipeline::updateCullPBR(LLCamera& camera, LLCullResult& result)
- {
- if (isWaterClip())
- {
- LLVector3 pnorm;
- if (sUnderWaterRender)
- {
- // Camera is below water, cull above water
- pnorm.set(0.f, 0.f, 1.f);
- }
- else
- {
- // Camera is above water, cull below water
- pnorm.set(0.f, 0.f, -1.f);
- }
- LLPlane plane(LLVector3(0.f, 0.f, mWaterHeight), pnorm);
- camera.setUserClipPlane(plane);
- }
- else
- {
- camera.disableUserClipPlane();
- }
- grabReferences(result);
- sCull->clear();
- bool do_occlusion_cull = sUseOcclusion > 0;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType))
- {
- partp->cull(camera);
- }
- }
- // Scan the VO Cache tree
- LLVOCachePartition* vo_partp = regionp->getVOCachePartition();
- if (vo_partp)
- {
- vo_partp->cull(camera, do_occlusion_cull);
- }
- }
- if (hasRenderType(RENDER_TYPE_SKY) &&
- gSky.mVOSkyp.notNull() && gSky.mVOSkyp->mDrawable.notNull())
- {
- gSky.mVOSkyp->mDrawable->setVisible(camera);
- sCull->pushDrawable(gSky.mVOSkyp->mDrawable);
- gSky.updateCull();
- }
- if (hasRenderType(RENDER_TYPE_WL_SKY) &&
- gSky.mVOWLSkyp.notNull() && gSky.mVOWLSkyp->mDrawable.notNull())
- {
- gSky.mVOWLSkyp->mDrawable->setVisible(camera);
- sCull->pushDrawable(gSky.mVOWLSkyp->mDrawable);
- }
- }
- void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result,
- LLPlane* planep, bool hud_attachments)
- {
- LL_FAST_TIMER(FTM_CULL);
- if (gUsePBRShaders)
- {
- updateCullPBR(camera, result);
- return;
- }
- if (planep)
- {
- camera.setUserClipPlane(*planep);
- }
- else
- {
- camera.disableUserClipPlane();
- }
- grabReferences(result);
- sCull->clear();
- bool to_texture = sUseOcclusion > 1 && shadersLoaded();
- if (to_texture)
- {
- if (sRenderDeferred && sUseOcclusion > 1)
- {
- mOcclusionDepth.bindTarget();
- }
- else
- {
- mRT->mScreen.bindTarget();
- }
- }
- if (sUseOcclusion > 1)
- {
- gGL.setColorMask(false, false);
- }
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadMatrix(gGLLastProjection);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLLastModelView);
- LLGLDisable blend(GL_BLEND);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- bool bound_shader = false;
- if (shadersLoaded() && !LLGLSLShader::sCurBoundShader)
- {
- // If no shader is currently bound, use the occlusion shader instead of
- // fixed function if we can (shadow render uses a special shader that
- // clamps to clip planes)
- bound_shader = true;
- gOcclusionCubeProgram.bind();
- }
- if (sUseOcclusion > 1)
- {
- if (mCubeVB.isNull())
- {
- sUseOcclusion = 0;
- llwarns << "No available Cube VB, disabling occlusion" << llendl;
- }
- else
- {
- mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- }
- }
- bool do_occlusion_cull = sUseOcclusion > 1 && !gUseWireframe;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType) ||
- (!hud_attachments && i == LLViewerRegion::PARTITION_BRIDGE))
- {
- partp->cull(camera);
- }
- }
- // Scan the VO Cache tree
- LLVOCachePartition* vo_partp = regionp->getVOCachePartition();
- if (vo_partp)
- {
- vo_partp->cull(camera, do_occlusion_cull);
- }
- }
- if (bound_shader)
- {
- gOcclusionCubeProgram.unbind();
- }
- if (hasRenderType(RENDER_TYPE_SKY) &&
- gSky.mVOSkyp.notNull() && gSky.mVOSkyp->mDrawable.notNull())
- {
- gSky.mVOSkyp->mDrawable->setVisible(camera);
- sCull->pushDrawable(gSky.mVOSkyp->mDrawable);
- gSky.updateCull();
- }
- bool can_use_wl_shaders = canUseWindLightShaders();
- if (can_use_wl_shaders &&
- hasRenderType(RENDER_TYPE_WL_SKY) &&
- gSky.mVOWLSkyp.notNull() && gSky.mVOWLSkyp->mDrawable.notNull())
- {
- gSky.mVOWLSkyp->mDrawable->setVisible(camera);
- sCull->pushDrawable(gSky.mVOWLSkyp->mDrawable);
- }
- if (!sReflectionRender &&
- (hasRenderType(RENDER_TYPE_WATER) ||
- hasRenderType(RENDER_TYPE_VOIDWATER)))
- {
- gWorld.precullWaterObjects(camera, sCull);
- }
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- if (sUseOcclusion > 1)
- {
- gGL.setColorMask(true, false);
- }
- if (to_texture)
- {
- if (sRenderDeferred && sUseOcclusion > 1)
- {
- mOcclusionDepth.flush();
- }
- else
- {
- mRT->mScreen.flush();
- }
- }
- }
- void LLPipeline::markNotCulled(LLSpatialGroup* groupp, LLCamera& camera)
- {
- if (groupp->isEmpty())
- {
- return;
- }
- groupp->setVisible();
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
- !gCubeSnapshot)
- {
- groupp->updateDistance(camera);
- }
- if (!groupp->getSpatialPartition()->mRenderByGroup)
- {
- // Render by drawable
- sCull->pushDrawableGroup(groupp);
- }
- else
- {
- // Render by group
- sCull->pushVisibleGroup(groupp);
- }
- ++mNumVisibleNodes;
- if (!gUsePBRShaders)
- {
- return;
- }
- S32 frame = LLViewerOctreeEntryData::getCurrentFrame() - 1;
- if (groupp->needsUpdate() ||
- groupp->getVisible(LLViewerCamera::sCurCameraID) < frame)
- {
- // Include this group in occlusion groups, not because we know it is an
- // occluder, but because we want to run an occlusion query to find out
- // if it is an occluder.
- markOccluder(groupp);
- }
- }
- void LLPipeline::markOccluder(LLSpatialGroup* groupp)
- {
- if (sUseOcclusion > 1 && groupp &&
- !groupp->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION))
- {
- LLSpatialGroup* parentp = groupp->getParent();
- if (!parentp || !parentp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- // Only mark top most occluders as active occlusion
- sCull->pushOcclusionGroup(groupp);
- groupp->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
- if (parentp &&
- !parentp->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION) &&
- parentp->getElementCount() == 0 && parentp->needsUpdate())
- {
- sCull->pushOcclusionGroup(groupp);
- parentp->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
- }
- }
- }
- }
- // Used only by the EE renderer
- void LLPipeline::downsampleDepthBuffer(LLRenderTarget& source,
- LLRenderTarget& dest,
- LLRenderTarget* scratch_space)
- {
- LLGLSLShader* last_shaderp = LLGLSLShader::sCurBoundShaderPtr;
- if (scratch_space)
- {
- scratch_space->copyContents(source, 0, 0,
- source.getWidth(), source.getHeight(),
- 0, 0, scratch_space->getWidth(),
- scratch_space->getHeight(),
- GL_DEPTH_BUFFER_BIT, GL_NEAREST);
- }
- dest.bindTarget();
- dest.clear(GL_DEPTH_BUFFER_BIT);
- LLStrider<LLVector3> vert;
- if (mDeferredVB.isNull() || !mDeferredVB->getVertexStrider(vert))
- {
- return;
- }
- vert[0].set(-1.f, 1.f, 0.f);
- vert[1].set(-1.f, -3.f, 0.f);
- vert[2].set(3.f, 1.f, 0.f);
- LLGLSLShader* shaderp;
- if (source.getUsage() == LLTexUnit::TT_RECT_TEXTURE)
- {
- shaderp = &gDownsampleDepthRectProgram;
- shaderp->bind();
- shaderp->uniform2f(sDelta, 1.f, 1.f);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- source.getWidth(), source.getHeight());
- }
- else
- {
- shaderp = &gDownsampleDepthProgram;
- shaderp->bind();
- shaderp->uniform2f(sDelta, 1.f / source.getWidth(),
- 1.f / source.getHeight());
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, 1.f, 1.f);
- }
- gGL.getTexUnit(0)->bind(scratch_space ? scratch_space : &source, true);
- {
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- dest.flush();
- if (last_shaderp)
- {
- last_shaderp->bind();
- }
- else
- {
- shaderp->unbind();
- }
- }
- // Used only by the EE renderer
- void LLPipeline::doOcclusion(LLCamera& camera, LLRenderTarget& source,
- LLRenderTarget& dest,
- LLRenderTarget* scratch_space)
- {
- downsampleDepthBuffer(source, dest, scratch_space);
- dest.bindTarget();
- doOcclusion(camera);
- dest.flush();
- }
- // Branched version for the PBR renderer
- void LLPipeline::doOcclusionPBR(LLCamera& camera)
- {
- if (sReflectionProbesEnabled && !sShadowRender && !gCubeSnapshot)
- {
- gGL.setColorMask(false, false);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- gOcclusionCubeProgram.bind();
- mCubeVB->setBuffer();
- mReflectionMapManager.doOcclusion();
- gOcclusionCubeProgram.unbind();
- gGL.setColorMask(true, true);
- }
- if (sRenderMirrors && !sShadowRender && !gCubeSnapshot)
- {
- gGL.setColorMask(false, false);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- gOcclusionCubeProgram.bind();
- mCubeVB->setBuffer();
- mHeroProbeManager.doOcclusion();
- gOcclusionCubeProgram.unbind();
- gGL.setColorMask(true, true);
- }
- if (!sCull->hasOcclusionGroups() &&
- !LLVOCachePartition::sNeedsOcclusionCheck)
- {
- return;
- }
- LLVertexBuffer::unbind();
- gGL.setColorMask(false, false);
- LLGLDisable blend(GL_BLEND);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- gOcclusionCubeProgram.bind();
- mCubeVB->setBuffer();
- LLCullResult::sg_list_t& occ_groups = sCull->getOcclusionGroups();
- for (U32 i = 0, count = occ_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = occ_groups[i];
- if (!groupp->isDead())
- {
- groupp->doOcclusion(&camera);
- groupp->clearOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
- }
- }
- // Note: only actually done in processOccluders() for CAMERA_WORLD. HB
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD)
- {
- // Apply occlusion culling to object cache tree
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLVOCachePartition* partp = (*iter)->getVOCachePartition();
- if (partp)
- {
- partp->processOccluders(&camera);
- }
- }
- }
- gGL.setColorMask(true, true);
- }
- void LLPipeline::doOcclusion(LLCamera& camera)
- {
- if (sUseOcclusion <= 1)
- {
- return;
- }
- if (mCubeVB.isNull())
- {
- sUseOcclusion = 0;
- llwarns << "No available Cube VB, disabling occlusion" << llendl;
- return;
- }
- if (gUsePBRShaders)
- {
- doOcclusionPBR(camera);
- return;
- }
- // Note: we do not stop occluding during teleportation for PBR, thus why
- // this boolean is only tested here. HB
- if (LLSpatialPartition::sTeleportRequested)
- {
- return;
- }
- if (!sCull->hasOcclusionGroups() &&
- !LLVOCachePartition::sNeedsOcclusionCheck)
- {
- return;
- }
- LLVertexBuffer::unbind();
- if (hasRenderDebugMask(RENDER_DEBUG_OCCLUSION))
- {
- gGL.setColorMask(true, false, false, false);
- }
- else
- {
- gGL.setColorMask(false, false);
- }
- LLGLDisable blend(GL_BLEND);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- bool bind_shader = !LLGLSLShader::sCurBoundShader;
- if (bind_shader)
- {
- if (sShadowRender)
- {
- gDeferredShadowCubeProgram.bind();
- }
- else
- {
- gOcclusionCubeProgram.bind();
- }
- }
- mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- LLCullResult::sg_list_t& occ_groups = sCull->getOcclusionGroups();
- for (U32 i = 0, count = occ_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = occ_groups[i];
- if (!groupp->isDead())
- {
- groupp->doOcclusion(&camera);
- groupp->clearOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
- }
- }
- // Note: only actually done in processOccluders() for CAMERA_WORLD. HB
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD)
- {
- // Apply occlusion culling to object cache tree
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLVOCachePartition* partp = (*iter)->getVOCachePartition();
- if (partp)
- {
- partp->processOccluders(&camera);
- }
- }
- }
- if (bind_shader)
- {
- if (sShadowRender)
- {
- gDeferredShadowCubeProgram.unbind();
- }
- else
- {
- gOcclusionCubeProgram.unbind();
- }
- }
- gGL.setColorMask(true, false);
- }
- bool LLPipeline::updateDrawableGeom(LLDrawable* drawablep)
- {
- bool update_complete = drawablep->updateGeometry();
- if (update_complete)
- {
- drawablep->setState(LLDrawable::BUILT);
- }
- return update_complete;
- }
- void LLPipeline::updateGL()
- {
- LL_FAST_TIMER(FTM_UPDATE_GL);
- while (!LLGLUpdate::sGLQ.empty())
- {
- LLGLUpdate* glup = LLGLUpdate::sGLQ.front();
- glup->updateGL();
- glup->mInQ = false;
- LLGLUpdate::sGLQ.pop_front();
- LL_DEBUGS("MarkGLRebuild") << "Rebuilt GL for: " << std::hex
- << (intptr_t)glup << std::dec << LL_ENDL;
- }
- }
- // Iterates through all groups on the build queue and remove all the groups
- // that do not correspond to HUD objects.
- void LLPipeline::clearRebuildGroups()
- {
- mGroupQLocked = true;
- for (S32 i = 0, count = mGroupQ.size(); i < count; )
- {
- LLSpatialGroup* groupp = mGroupQ[i].get();
- if (!groupp->isHUDGroup())
- {
- // Not a HUD object, so clear the build state.
- // NOTE: since isHUDGroup() also tests for isDead() and returns
- // false when the group is dead, dead groups will also be properly
- // removed from mGroupQ. HB
- groupp->clearState(LLSpatialGroup::IN_BUILD_QUEUE);
- if (i < --count)
- {
- mGroupQ[i] = std::move(mGroupQ.back());
- }
- mGroupQ.pop_back();
- }
- else
- {
- ++i;
- }
- }
- mGroupQLocked = false;
- }
- void LLPipeline::clearRebuildDrawables()
- {
- // Clear all drawables on the build queue,
- for (LLDrawable::draw_list_t::iterator iter = mBuildQ.begin(),
- end = mBuildQ.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- if (drawablep && !drawablep->isDead())
- {
- drawablep->clearState(LLDrawable::IN_REBUILD_QUEUE);
- }
- }
- mBuildQ.clear();
- // Clear all moving bridges
- U32 bits = LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED |
- LLDrawable::ON_MOVE_LIST | LLDrawable::ANIMATED_CHILD;
- for (U32 i = 0, count = mMovedBridge.size(); i < count; ++i)
- {
- LLDrawable* drawablep = mMovedBridge[i];
- if (drawablep) // Paranoia
- {
- drawablep->clearState(bits);
- }
- }
- mMovedBridge.clear();
- // Clear all moving drawables
- for (U32 i = 0, count = mMovedList.size(); i < count; ++i)
- {
- LLDrawable* drawablep = mMovedList[i];
- if (drawablep) // Paranoia
- {
- drawablep->clearState(bits);
- }
- }
- mMovedList.clear();
- // Clear all shifting drawables
- bits |= LLDrawable::ON_SHIFT_LIST;
- for (U32 i = 0, count = mShiftList.size(); i < count; ++i)
- {
- LLDrawable* drawablep = mShiftList[i];
- if (drawablep)
- {
- drawablep->clearState(bits);
- }
- }
- mShiftList.clear();
- }
- void LLPipeline::rebuildPriorityGroups()
- {
- LL_FAST_TIMER(FTM_REBUILD_PRIORITY_GROUPS);
- {
- LL_FAST_TIMER(FTM_REBUILD_MESH);
- gMeshRepo.notifyLoadedMeshes();
- }
- mGroupQLocked = true;
- // Iterate through all drawables on the build queue
- for (LLSpatialGroup::sg_vector_t::iterator iter = mGroupQ.begin();
- iter != mGroupQ.end(); ++iter)
- {
- LLSpatialGroup* groupp = iter->get();
- groupp->rebuildGeom();
- groupp->clearState(LLSpatialGroup::IN_BUILD_QUEUE);
- }
- mGroupSaveQ.clear();
- mGroupSaveQ.swap(mGroupQ); // This clears mGroupQ
- mGroupQLocked = false;
- }
- void LLPipeline::updateGeom(F32 max_dtime)
- {
- if (gCubeSnapshot)
- {
- return;
- }
- LL_FAST_TIMER(FTM_GEO_UPDATE);
- // Notify various object types to reset internal cost metrics, etc.
- // for now, only LLVOVolume does this to throttle LOD changes
- LLVOVolume::preUpdateGeom();
- LLPointer<LLDrawable> drawablep;
- // Iterate through all drawables on the priority build queue,
- for (LLDrawable::draw_list_t::iterator iter = mBuildQ.begin(),
- end = mBuildQ.end();
- iter != end; )
- {
- LLDrawable::draw_list_t::iterator curiter = iter++;
- drawablep = *curiter;
- bool remove = drawablep.isNull() || drawablep->isDead();
- if (!remove)
- {
- remove = updateDrawableGeom(drawablep);
- }
- if (remove)
- {
- if (drawablep)
- {
- drawablep->clearState(LLDrawable::IN_REBUILD_QUEUE);
- }
- mBuildQ.erase(curiter);
- }
- }
- updateMovedList(mMovedBridge);
- }
- void LLPipeline::markVisible(LLDrawable* drawablep, LLCamera& camera)
- {
- if (!drawablep || drawablep->isDead())
- {
- return;
- }
- if (drawablep->isSpatialBridge())
- {
- const LLDrawable* rootp = ((LLSpatialBridge*)drawablep)->mDrawable;
- if (rootp && rootp->getVObj()->isAttachment())
- {
- LLDrawable* parentp = rootp->getParent();
- if (parentp) // This IS sometimes NULL
- {
- LLViewerObject* objp = parentp->getVObj();
- if (objp)
- {
- LLVOAvatar* avp = objp->asAvatar();
- if (avp &&
- (avp->isImpostor() || avp->isInMuteList() ||
- (avp->getVisualMuteSettings() ==
- LLVOAvatar::AV_DO_NOT_RENDER &&
- !avp->needsImpostorUpdate())))
- {
- return;
- }
- }
- }
- }
- sCull->pushBridge((LLSpatialBridge*)drawablep);
- }
- else
- {
- sCull->pushDrawable(drawablep);
- }
- drawablep->setVisible(camera);
- }
- void LLPipeline::markMoved(LLDrawable* drawablep, bool damped_motion)
- {
- if (!drawablep || drawablep->isDead())
- {
- return;
- }
- LLDrawable* parentp = drawablep->getParent();
- if (parentp)
- {
- // Ensure that parent drawables are moved first
- markMoved(parentp, damped_motion);
- }
- if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
- {
- if (drawablep->isSpatialBridge())
- {
- mMovedBridge.emplace_back(drawablep);
- }
- else
- {
- mMovedList.emplace_back(drawablep);
- }
- drawablep->setState(LLDrawable::ON_MOVE_LIST);
- }
- if (!damped_motion)
- {
- // UNDAMPED trumps DAMPED
- drawablep->setState(LLDrawable::MOVE_UNDAMPED);
- }
- else if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
- {
- drawablep->clearState(LLDrawable::MOVE_UNDAMPED);
- }
- }
- void LLPipeline::markShift(LLDrawable* drawablep)
- {
- if (!drawablep || drawablep->isDead())
- {
- return;
- }
- if (!drawablep->isState(LLDrawable::ON_SHIFT_LIST))
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- if (objp)
- {
- objp->setChanged(LLXform::SHIFTED | LLXform::SILHOUETTE);
- }
- LLDrawable* parentp = drawablep->getParent();
- if (parentp)
- {
- markShift(parentp);
- }
- mShiftList.emplace_back(drawablep);
- drawablep->setState(LLDrawable::ON_SHIFT_LIST);
- }
- }
- void LLPipeline::shiftObjects(const LLVector3& offset)
- {
- glClear(GL_DEPTH_BUFFER_BIT);
- gDepthDirty = true;
- LLVector4a offseta;
- offseta.load3(offset.mV);
- {
- LL_FAST_TIMER(FTM_SHIFT_DRAWABLE);
- for (U32 i = 0, count = mShiftList.size(); i < count; ++i)
- {
- LLDrawable* drawablep = mShiftList[i].get();
- if (drawablep && !drawablep->isDead())
- {
- drawablep->shiftPos(offseta);
- drawablep->clearState(LLDrawable::ON_SHIFT_LIST);
- }
- }
- mShiftList.clear();
- }
- {
- LL_FAST_TIMER(FTM_SHIFT_OCTREE);
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- if (partp)
- {
- partp->shift(offseta);
- }
- }
- }
- }
- if (gUsePBRShaders)
- {
- mReflectionMapManager.shift(offseta);
- }
- {
- LL_FAST_TIMER(FTM_SHIFT_HUD);
- LLHUDText::shiftAll(offset);
- }
- display_update_camera();
- }
- void LLPipeline::markTextured(LLDrawable* drawablep)
- {
- if (drawablep && !drawablep->isDead())
- {
- mRetexturedList.emplace(drawablep);
- }
- }
- void LLPipeline::markGLRebuild(LLGLUpdate* glup)
- {
- if (glup && !glup->mInQ)
- {
- LLGLUpdate::sGLQ.push_back(glup);
- glup->mInQ = true;
- }
- }
- void LLPipeline::markPartitionMove(LLDrawable* drawablep)
- {
- if (!drawablep->isState(LLDrawable::PARTITION_MOVE) &&
- !drawablep->getPositionGroup().equals3(LLVector4a::getZero()))
- {
- drawablep->setState(LLDrawable::PARTITION_MOVE);
- mPartitionQ.emplace_back(drawablep);
- }
- }
- void LLPipeline::processPartitionQ()
- {
- LL_FAST_TIMER(FTM_PROCESS_PARTITIONQ);
- for (U32 i = 0, count = mPartitionQ.size(); i < count; ++i)
- {
- LLDrawable* drawablep = mPartitionQ[i].get();
- if (!drawablep) continue; // Paranoia
- if (!drawablep->isDead())
- {
- drawablep->updateBinRadius();
- drawablep->movePartition();
- }
- drawablep->clearState(LLDrawable::PARTITION_MOVE);
- }
- mPartitionQ.clear();
- }
- void LLPipeline::markMeshDirty(LLSpatialGroup* groupp)
- {
- mMeshDirtyGroup.emplace_back(groupp);
- }
- void LLPipeline::markRebuild(LLSpatialGroup* groupp)
- {
- if (groupp && !groupp->isDead() && groupp->getSpatialPartition() &&
- !groupp->hasState(LLSpatialGroup::IN_BUILD_QUEUE))
- {
- mGroupQ.emplace_back(groupp);
- groupp->setState(LLSpatialGroup::IN_BUILD_QUEUE);
- }
- }
- void LLPipeline::markRebuild(LLDrawable* drawablep,
- LLDrawable::EDrawableFlags flag)
- {
- if (drawablep && !drawablep->isDead())
- {
- if (!drawablep->isState(LLDrawable::IN_REBUILD_QUEUE))
- {
- mBuildQ.emplace_back(drawablep);
- // Mark drawable as being in build queue
- drawablep->setState(LLDrawable::IN_REBUILD_QUEUE);
- }
- if (flag & (LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION))
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- if (objp)
- {
- objp->setChanged(LLXform::SILHOUETTE);
- }
- }
- drawablep->setState(flag);
- }
- }
- void LLPipeline::stateSort(LLCamera& camera, LLCullResult& result)
- {
- if (hasAnyRenderType(RENDER_TYPE_AVATAR, RENDER_TYPE_PUPPET,
- RENDER_TYPE_TERRAIN, RENDER_TYPE_TREE,
- RENDER_TYPE_SKY, RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_WATER, END_RENDER_TYPES))
- {
- // Clear faces from face pools
- LL_FAST_TIMER(FTM_RESET_DRAWORDER);
- resetDrawOrders();
- }
- LL_FAST_TIMER(FTM_STATESORT);
- grabReferences(result);
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = draw_groups[i];
- if (!groupp || groupp->isDead()) continue;
- groupp->checkOcclusion();
- if (sUseOcclusion > 1 &&
- groupp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- markOccluder(groupp);
- continue;
- }
- groupp->setVisible();
- const LLSpatialGroup::element_list& data = groupp->getData();
- for (U32 j = 0, count2 = data.size(); j < count2; ++j)
- {
- LLDrawable* drawablep = (LLDrawable*)data[j]->getDrawable();
- markVisible(drawablep, camera);
- }
- // Rebuild mesh as soon as we know it is visible
- groupp->rebuildMesh();
- }
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
- !gCubeSnapshot)
- {
- bool fov_changed = gViewerCamera.isDefaultFOVChanged();
- LLSpatialGroup* last_groupp = NULL;
- LLCullResult::bridge_list_t& bridges = sCull->getVisibleBridge();
- for (U32 i = 0, count = bridges.size(); i < count; ++i)
- {
- LLSpatialBridge* bridgep = bridges[i];
- if (!bridgep) continue;
- LLSpatialGroup* groupp = bridgep->getSpatialGroup();
- if (groupp->isDead()) continue;
- if (!last_groupp)
- {
- last_groupp = groupp;
- }
- if (groupp && !bridgep->isDead() &&
- !groupp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- stateSort(bridgep, camera, fov_changed);
- }
- if (last_groupp && last_groupp != groupp &&
- last_groupp->changeLOD())
- {
- last_groupp->mLastUpdateDistance = last_groupp->mDistance;
- }
- last_groupp = groupp;
- }
- if (last_groupp && last_groupp->changeLOD())
- {
- last_groupp->mLastUpdateDistance = last_groupp->mDistance;
- }
- }
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = visible_groups[i];
- if (!groupp || groupp->isDead()) continue;
- groupp->checkOcclusion();
- if (sUseOcclusion > 1 &&
- groupp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- markOccluder(groupp);
- }
- else
- {
- groupp->setVisible();
- stateSort(groupp, camera);
- // Rebuild mesh as soon as we know it is visible
- groupp->rebuildMesh();
- }
- }
- {
- LL_FAST_TIMER(FTM_STATESORT_DRAWABLE);
- LLCullResult::drawable_list_t& visible = sCull->getVisibleList();
- for (U32 i = 0, count = visible.size(); i < count; ++i)
- {
- LLDrawable* drawablep = visible[i];
- if (drawablep && !drawablep->isDead())
- {
- stateSort(drawablep, camera);
- }
- }
- }
- postSort(camera);
- }
- void LLPipeline::stateSort(LLSpatialGroup* groupp, LLCamera& camera)
- {
- if (groupp->changeLOD())
- {
- const LLSpatialGroup::element_list& data = groupp->getData();
- for (U32 i = 0, count = data.size(); i < count; ++i)
- {
- LLDrawable* drawablep = (LLDrawable*)data[i]->getDrawable();
- stateSort(drawablep, camera);
- }
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
- !gCubeSnapshot)
- {
- // Avoid redundant stateSort calls
- groupp->mLastUpdateDistance = groupp->mDistance;
- }
- }
- }
- void LLPipeline::stateSort(LLSpatialBridge* bridgep, LLCamera& camera,
- bool fov_changed)
- {
- if (fov_changed || bridgep->getSpatialGroup()->changeLOD())
- {
- // false = do not force update
- bridgep->updateDistance(camera, false);
- }
- }
- void LLPipeline::stateSort(LLDrawable* drawablep, LLCamera& camera)
- {
- if (!drawablep || drawablep->isDead() ||
- !hasRenderType(drawablep->getRenderType()))
- {
- return;
- }
- // SL-11353: ignore our own geometry when rendering spotlight shadowmaps...
- if (drawablep == sRenderSpotLight)
- {
- return;
- }
- LLViewerObject* objp = drawablep->getVObj().get();
- if (gSelectMgr.mHideSelectedObjects && objp && objp->isSelected() &&
- //MK
- (!gRLenabled || !gRLInterface.mContainsEdit))
- //mk
- {
- return;
- }
- if (drawablep->isAvatar())
- {
- // Do not draw avatars beyond render distance or if we do not have a
- // spatial group.
- LLSpatialGroup* groupp = drawablep->getSpatialGroup();
- if (!groupp || groupp->mDistance > LLVOAvatar::sRenderDistance)
- {
- return;
- }
- LLVOAvatar* avatarp = (LLVOAvatar*)objp;
- if (avatarp && !avatarp->isVisible())
- {
- return;
- }
- }
- if (hasRenderType(drawablep->mRenderType) &&
- !drawablep->isState(LLDrawable::INVISIBLE |
- LLDrawable::FORCE_INVISIBLE))
- {
- drawablep->setVisible(camera, NULL, false);
- }
- if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
- !gCubeSnapshot)
- {
- #if 0 // isVisible() check here is redundant, if it was not visible, it would
- // not be here
- if (drawablep->isVisible())
- #endif
- {
- if (!drawablep->isActive())
- {
- // false = do not force update = false;
- drawablep->updateDistance(camera, false);
- }
- else if (drawablep->isAvatar())
- {
- // Calls objp->updateLOD() which calls
- // LLVOAvatar::updateVisibility()
- drawablep->updateDistance(camera, false);
- }
- }
- }
- if (!drawablep->getVOVolume())
- {
- for (U32 i = 0, count = drawablep->mFaces.size(); i < count; ++i)
- {
- LLFace* facep = drawablep->mFaces[i];
- if (facep->hasGeometry())
- {
- LLFacePool* poolp = facep->getPool();
- if (!poolp)
- {
- break;
- }
- poolp->enqueue(facep);
- }
- }
- }
- }
- void forAllDrawables(LLCullResult::sg_list_t& group_data,
- void (*func)(LLDrawable*))
- {
- for (U32 i = 0, count = group_data.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = group_data[i];
- if (groupp->isDead()) continue;
- const LLSpatialGroup::element_list& octree_data = groupp->getData();
- for (U32 j = 0, count2 = octree_data.size(); j < count2; ++j)
- {
- if (octree_data[j]->hasDrawable())
- {
- func((LLDrawable*)octree_data[j]->getDrawable());
- }
- }
- }
- }
- void LLPipeline::forAllVisibleDrawables(void (*func)(LLDrawable*))
- {
- forAllDrawables(sCull->getDrawableGroups(), func);
- forAllDrawables(sCull->getVisibleGroups(), func);
- }
- //static
- U32 LLPipeline::highlightable(const LLViewerObject* objp)
- {
- if (!objp || objp->isAvatar()) return 0;
- if (sRenderByOwner == 1 && !objp->permYouOwner()) return 0;
- if (sRenderByOwner == 2 && objp->permYouOwner()) return 0;
- LLViewerObject* parentp = (LLViewerObject*)objp->getParent();
- if (!parentp) return 1;
- if (!sRenderAttachments) return 0;
- // Attachments can be highlighted but are not marked with beacons since
- // it would mark the avatar itself... But, we highlight all the
- // primitives of the attachments instead of just the root primitive
- // (which could be buried into the avatar or be too small to be
- // visible). HB
- if (parentp->isAvatar())
- {
- return 2;
- }
- LLViewerObject* rootp = (LLViewerObject*)objp->getRoot();
- if (rootp && rootp->isAvatar())
- {
- return 2;
- }
- return 0;
- }
- // Function for creating scripted beacons
- void renderScriptedBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->flagScripted())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(1.f, 0.f, 0.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderScriptedTouchBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->flagScripted() && objp->flagHandleTouch())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(1.f, 0.f, 0.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderPhysicalBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->flagUsePhysics())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(0.f, 1.f, 0.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderPermanentBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->flagObjectPermanent())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(0.f, 1.f, 1.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderCharacterBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->flagCharacter())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(0.5f, 0.5f, 0.5f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderSoundBeacons(LLDrawable* drawablep)
- {
- // Look for attachments, objects, etc.
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->isAudioSource())
- {
- if ((LLPipeline::sRenderBeacons ||
- !LLPipeline::sRenderInvisibleSoundBeacons) && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(1.f, 1.f, 0.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderParticleBeacons(LLDrawable* drawablep)
- {
- // Look for attachments, objects, etc.
- LLViewerObject* objp = drawablep->getVObj().get();
- U32 type = LLPipeline::highlightable(objp);
- if (type != 0 && objp->isParticleSource())
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(0.5f, 0.5f, 1.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void renderMOAPBeacons(LLDrawable* drawablep)
- {
- LLViewerObject* objp = drawablep->getVObj().get();
- if (!objp || objp->isAvatar()) return;
- U32 type = LLPipeline::highlightable(objp);
- if (type == 0) return;
- bool beacon = false;
- U8 tecount = objp->getNumTEs();
- for (S32 x = 0; x < tecount; ++x)
- {
- LLTextureEntry* tep = objp->getTE(x);
- if (tep && tep->hasMedia())
- {
- beacon = true;
- break;
- }
- }
- if (beacon)
- {
- if (LLPipeline::sRenderBeacons && type != 2)
- {
- gObjectList.addDebugBeacon(objp->getPositionAgent(), "",
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- LLPipeline::DebugBeaconLineWidth);
- }
- if (LLPipeline::sRenderHighlight)
- {
- for (S32 face_id = 0, count = drawablep->getNumFaces();
- face_id < count; ++face_id)
- {
- LLFace* facep = drawablep->getFace(face_id);
- if (facep)
- {
- gPipeline.mHighlightFaces.push_back(facep);
- }
- }
- }
- }
- }
- void LLPipeline::touchTexture(LLViewerTexture* texp, F32 vsize)
- {
- if (texp)
- {
- LLImageGL* imagep = texp->getGLImage();
- if (imagep && imagep->updateBindStats())
- {
- texp->addTextureStats(vsize);
- }
- }
- }
- void LLPipeline::touchTextures(LLDrawInfo* infop)
- {
- // Update out materials usage statistics. HB
- static LLCachedControl<bool> attachments(gSavedSettings,
- "AccountAttachmentsMaterials");
- static LLCachedControl<U32> min_vsize(gSavedSettings,
- "AccountMaterialsMinVSize");
- if (infop->mVSize >= F32(min_vsize) &&
- (!infop->mIsAgentAttachment || attachments))
- {
- if (infop->mHasALM)
- {
- sUsingALM = true;
- }
- if (infop->mHasPBR)
- {
- sUsingPBR = true;
- if (!infop->mHasLegacyFallback)
- {
- sLacksLegacyFallback = true;
- if (!infop->mHasBasecolorFallback)
- {
- sLacksBaseColorFallback = true;
- }
- }
- }
- }
- for (U32 i = 0, count = infop->mTextureList.size(); i < count; ++i)
- {
- touchTexture(infop->mTextureList[i], infop->mTextureListVSize[i]);
- }
- F32 vsize = infop->mVSize;
- if (gUsePBRShaders)
- {
- LLFetchedGLTFMaterial* gltfp = infop->mGLTFMaterial.get();
- if (gltfp)
- {
- touchTexture(gltfp->mBaseColorTexture, vsize);
- touchTexture(gltfp->mNormalTexture, vsize);
- touchTexture(gltfp->mMetallicRoughnessTexture, vsize);
- touchTexture(gltfp->mEmissiveTexture, vsize);
- return;
- }
- }
- touchTexture(infop->mTexture, vsize);
- if (sRenderDeferred)
- {
- touchTexture(infop->mSpecularMap, vsize);
- touchTexture(infop->mNormalMap, vsize);
- }
- }
- void LLPipeline::postSort(LLCamera& camera)
- {
- LL_FAST_TIMER(FTM_STATESORT_POSTSORT);
- if (!gCubeSnapshot)
- {
- // Rebuild drawable geometry
- LLCullResult::sg_list_t& draw_groups = sCull->getDrawableGroups();
- for (U32 i = 0, count = draw_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = draw_groups[i];
- if (groupp->isDead())
- {
- continue;
- }
- if (!sUseOcclusion ||
- !groupp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- groupp->rebuildGeom();
- }
- }
- // Rebuild groups
- sCull->assertDrawMapsEmpty();
- rebuildPriorityGroups();
- }
- // Build render map
- bool has_type_pass_alpha = hasRenderType(RENDER_TYPE_PASS_ALPHA);
- bool has_alpha_type = hasRenderType(LLDrawPool::POOL_ALPHA);
- bool is_world_camera =
- LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD;
- U32 bytes_limit = RenderAutoHideGeometryMemoryLimit * 1048576;
- bool limit_surf_area = RenderAutoHideSurfaceAreaLimit > 0.f;
- LLVector4a bounds;
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, vcount = visible_groups.size(); i < vcount; ++i)
- {
- LLSpatialGroup* groupp = visible_groups[i];
- if (groupp->isDead())
- {
- continue;
- }
- if (sUseOcclusion &&
- groupp->isOcclusionState(LLSpatialGroup::OCCLUDED))
- {
- continue;
- }
- if (bytes_limit && groupp->mGeometryBytes > bytes_limit)
- {
- continue;
- }
- if (limit_surf_area &&
- groupp->mSurfaceArea >
- RenderAutoHideSurfaceAreaLimit * groupp->mObjectBoxSize)
- {
- continue;
- }
- bool needs_rebuild = !gCubeSnapshot &&
- groupp->hasState(LLSpatialGroup::NEW_DRAWINFO) &&
- groupp->hasState(LLSpatialGroup::GEOM_DIRTY);
- if (needs_rebuild)
- {
- // No way this group is going to be drawable without a rebuild
- groupp->rebuildGeom();
- }
- bool needs_touch;
- if (gUsePBRShaders)
- {
- needs_touch = !gCubeSnapshot && !sShadowRender;
- }
- else
- {
- // Note: sReflectionRender is true while rendering impostors in EE
- // non-deferred mode, but then we still want impostors textures to
- // be touched so that they would not vanish. HB
- needs_touch = !sShadowRender &&
- (!sReflectionRender || sImpostorRender);
- }
- for (LLSpatialGroup::draw_map_t::iterator j = groupp->mDrawMap.begin(),
- end = groupp->mDrawMap.end();
- j != end; ++j)
- {
- LLSpatialGroup::drawmap_elem_t& src_vec = j->second;
- if (!hasRenderType(j->first))
- {
- continue;
- }
- for (U32 k = 0, dcount = src_vec.size(); k < dcount; ++k)
- {
- LLDrawInfo* infop = src_vec[k].get();
- sCull->pushDrawInfo(j->first, infop);
- if (needs_touch)
- {
- if (!needs_rebuild)
- {
- touchTextures(infop);
- }
- addTrianglesDrawn(infop->mCount);
- }
- }
- }
- if (has_type_pass_alpha)
- {
- if (groupp->mDrawMap.count(LLRenderPass::PASS_ALPHA))
- {
- // Store alpha groups for sorting
- if (is_world_camera && !gCubeSnapshot)
- {
- LLSpatialBridge* bridgep =
- groupp->getSpatialPartition()->asBridge();
- if (bridgep)
- {
- LLCamera trans_camera =
- bridgep->transformCamera(camera);
- groupp->updateDistance(trans_camera);
- }
- else
- {
- groupp->updateDistance(camera);
- }
- }
- if (has_alpha_type)
- {
- sCull->pushAlphaGroup(groupp);
- }
- }
- if (has_alpha_type &&
- groupp->mDrawMap.count(LLRenderPass::PASS_ALPHA_RIGGED))
- {
- // Store rigged alpha groups for LLDrawPoolAlpha prepass
- // (skip distance update, rigged attachments use depth buffer)
- sCull->pushRiggedAlphaGroup(groupp);
- }
- }
- }
- // Pack vertex buffers for groups that chose to delay their updates
- for (U32 i = 0, count = mMeshDirtyGroup.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = mMeshDirtyGroup[i].get();
- if (groupp)
- {
- groupp->rebuildMesh();
- }
- }
- mMeshDirtyGroup.clear();
- if (!sShadowRender)
- {
- // Order alpha groups by distance
- std::sort(sCull->beginAlphaGroups(), sCull->endAlphaGroups(),
- LLSpatialGroup::CompareDepthGreater());
- // Order rigged alpha groups by avatar attachment order
- std::sort(sCull->beginRiggedAlphaGroups(),
- sCull->endRiggedAlphaGroups(),
- LLSpatialGroup::CompareRenderOrder());
- }
- if (gCubeSnapshot)
- {
- // Do not render beacons or highlights during cube snapshot.
- return;
- }
- // This is the position for the sounds list floater beacon:
- LLVector3d selected_pos = HBFloaterSoundsList::selectedLocation();
- // Only render if the flag is set. The flag is only set if we are in edit
- // mode or the toggle is set in the menus.
- static LLCachedControl<bool> beacons_always_on(gSavedSettings,
- "BeaconAlwaysOn");
- if ((sRenderBeaconsFloaterOpen || beacons_always_on) &&
- //MK
- !(gRLenabled &&
- (gRLInterface.mContainsEdit || gRLInterface.mVisionRestricted)) &&
- //mk
- !sShadowRender)
- {
- if (sRenderScriptedTouchBeacons)
- {
- // Only show the beacon on the root object.
- forAllVisibleDrawables(renderScriptedTouchBeacons);
- }
- else if (sRenderScriptedBeacons)
- {
- // Only show the beacon on the root object.
- forAllVisibleDrawables(renderScriptedBeacons);
- }
- if (sRenderPhysicalBeacons)
- {
- // Only show the beacon on the root object.
- forAllVisibleDrawables(renderPhysicalBeacons);
- }
- if (sRenderPermanentBeacons)
- {
- // Only show the beacon on the root object.
- forAllVisibleDrawables(renderPermanentBeacons);
- }
- if (sRenderCharacterBeacons)
- {
- // Only show the beacon on the root object.
- forAllVisibleDrawables(renderCharacterBeacons);
- }
- if (sRenderSoundBeacons && gAudiop)
- {
- if (sRenderInvisibleSoundBeacons && sRenderBeacons)
- {
- static const LLColor4 semi_yellow(1.f, 1.f, 0.f, 0.5f);
- static const LLColor4 semi_white(1.f, 1.f, 0.f, 0.5f);
- // Walk all sound sources and render out beacons for them.
- // Note, this is not done in the ForAllVisibleDrawables
- // function, because some are not visible.
- for (LLAudioEngine::source_map_t::const_iterator
- iter = gAudiop->mAllSources.begin(),
- end = gAudiop->mAllSources.end();
- iter != end; ++iter)
- {
- const LLAudioSource* sourcep = iter->second;
- if (!sourcep) continue; // Paranoia
- // Verify source owner and match against renderbyowner
- const LLUUID& owner_id = sourcep->getOwnerID();
- if ((sRenderByOwner == 1 && owner_id != gAgentID) ||
- (sRenderByOwner == 2 && owner_id == gAgentID))
- {
- continue;
- }
- LLVector3d pos_global = sourcep->getPositionGlobal();
- if (selected_pos.isExactlyZero() ||
- pos_global != selected_pos)
- {
- LLVector3 pos =
- gAgent.getPosAgentFromGlobal(pos_global);
- gObjectList.addDebugBeacon(pos, "", semi_yellow,
- semi_white,
- DebugBeaconLineWidth);
- }
- }
- }
- // Now deal with highlights for all those seeable sound sources
- forAllVisibleDrawables(renderSoundBeacons);
- }
- if (sRenderParticleBeacons)
- {
- forAllVisibleDrawables(renderParticleBeacons);
- }
- if (sRenderMOAPBeacons)
- {
- forAllVisibleDrawables(renderMOAPBeacons);
- }
- }
- // Render the sound beacon for the sounds list floater, if needed.
- if (!selected_pos.isExactlyZero())
- {
- gObjectList.addDebugBeacon(gAgent.getPosAgentFromGlobal(selected_pos),
- "",
- // Oranger yellow than sound normal beacons
- LLColor4(1.f, 0.8f, 0.f, 0.5f),
- LLColor4(1.f, 1.f, 1.f, 0.5f),
- DebugBeaconLineWidth);
- }
- // If managing your telehub, draw beacons at telehub and currently selected
- // spawnpoint.
- if (LLFloaterTelehub::renderBeacons())
- {
- LLFloaterTelehub::addBeacons();
- }
- if (!sShadowRender)
- {
- mSelectedFaces.clear();
- sRenderHighlightTextureChannel =
- LLPanelFace::getTextureChannelToEdit();
- // Draw face highlights for selected faces.
- if (gSelectMgr.getTEMode())
- {
- struct f final : public LLSelectedTEFunctor
- {
- bool apply(LLViewerObject* object, S32 te) override
- {
- LLDrawable* drawablep = object->mDrawable;
- if (drawablep)
- {
- LLFace* facep = drawablep->getFace(te);
- if (facep)
- {
- gPipeline.mSelectedFaces.push_back(facep);
- }
- }
- return true;
- }
- } func;
- gSelectMgr.getSelection()->applyToTEs(&func);
- }
- }
- }
- void render_hud_elements()
- {
- gPipeline.disableLights();
- LLGLSUIDefault gls_ui;
- LLGLEnable stencil(gUsePBRShaders ? 0 : GL_STENCIL_TEST);
- if (!gUsePBRShaders)
- {
- glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
- glStencilMask(0xFFFFFFFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- }
- gUIProgram.bind();
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- if (!LLPipeline::sReflectionRender &&
- gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
- {
- bool sample = !gUsePBRShaders && LLPipeline::RenderFSAASamples > 0;
- LLGLEnable multisample(sample ? GL_MULTISAMPLE : 0);
- // For HUD version in render_ui_3d()
- gViewerWindowp->renderSelections(false, false, false);
- // Draw the tracking overlays
- gTracker.render3D();
- //MK
- if (!gRLenabled || !gRLInterface.mVisionRestricted)
- //mk
- {
- // Show the property lines
- gWorld.renderPropertyLines();
- gViewerParcelMgr.render();
- gViewerParcelMgr.renderParcelCollision();
- }
- // Note: for PBR this is done in render_ui() (llviewerdisplay.cpp) so
- // to avoid seeing the text anti-aliased.
- if (!gUsePBRShaders)
- {
- // Render name tags and hover texts.
- LLHUDObject::renderAll();
- }
- }
- else if (gForceRenderLandFence)
- {
- // This is only set when not rendering the UI, for parcel snapshots
- gViewerParcelMgr.render();
- }
- else if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
- {
- LLHUDText::renderAllHUD();
- }
- gUIProgram.unbind();
- gGL.flush();
- }
- void LLPipeline::renderHighlights()
- {
- S32 selected_count = mSelectedFaces.size();
- S32 highlighted_count = mHighlightFaces.size();
- if ((!selected_count && !highlighted_count) ||
- !hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED))
- {
- // Nothing to draw
- return;
- }
- LLGLSPipelineAlpha gls_pipeline_alpha;
- disableLights();
- bool shader_interface =
- gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0;
- std::vector<LLFace*>::iterator sel_start, sel_end;
- if (selected_count)
- {
- sel_start = mSelectedFaces.begin();
- sel_end = mSelectedFaces.end();
- }
- if (highlighted_count)
- {
- // Beacons face highlights
- if (shader_interface)
- {
- gHighlightProgram.bind();
- }
- LLColor4 color(1.f, 0.f, 0.f, .5f);
- for (S32 i = 0; i < highlighted_count; ++i)
- {
- LLFace* facep = mHighlightFaces[i];
- if (facep && !facep->getDrawable()->isDead())
- {
- if (!selected_count ||
- // Exclude selected faces from beacon highlights
- std::find(sel_start, sel_end, facep) == sel_end)
- {
- facep->renderSelected(LLViewerTexture::sNullImagep, color);
- }
- }
- else if (gDebugGL)
- {
- llwarns << "Bad face in beacons highlights" << llendl;
- }
- }
- if (shader_interface)
- {
- gHighlightProgram.unbind();
- }
- mHighlightFaces.clear();
- }
- if (selected_count)
- {
- // Selection image initialization if needed
- if (!mFaceSelectImagep)
- {
- mFaceSelectImagep =
- LLViewerTextureManager::getFetchedTexture(IMG_FACE_SELECT);
- }
- // Make sure the selection image gets downloaded and decoded
- F32 max_area = gMaxImageSizeDefault * gMaxImageSizeDefault;
- mFaceSelectImagep->addTextureStats(max_area);
- // Use the color matching the channel we are editing
- LLColor4 color;
- LLRender::eTexIndex active_channel = sRenderHighlightTextureChannel;
- switch (active_channel)
- {
- case LLRender::NORMAL_MAP:
- color = LLColor4(1.f, .5f, .5f, .5f);
- break;
- case LLRender::SPECULAR_MAP:
- color = LLColor4(0.f, .3f, 1.f, .8f);
- break;
- case LLRender::DIFFUSE_MAP:
- default:
- color = LLColor4(1.f, 1.f, 1.f, .5f);
- }
- LLGLSLShader* prev_shaderp = NULL;
- for (S32 i = 0; i < selected_count; ++i)
- {
- LLFace* facep = mSelectedFaces[i];
- if (facep && !facep->getDrawable()->isDead())
- {
- LLMaterial* matp = NULL;
- if (sRenderDeferred && active_channel != LLRender::DIFFUSE_MAP)
- {
- // Fetch the material info, if any
- const LLTextureEntry* tep = facep->getTextureEntry();
- if (tep)
- {
- matp = tep->getMaterialParams().get();
- }
- }
- if (shader_interface)
- {
- // Default to diffuse map highlighting
- LLGLSLShader* new_shaderp = &gHighlightProgram;
- // Use normal or specular maps highlighting where possible
- // (i.e. material exists and got a corresponding map)
- if (active_channel == LLRender::NORMAL_MAP && matp &&
- matp->getNormalID().notNull())
- {
- new_shaderp = &gHighlightNormalProgram;
- }
- else if (active_channel == LLRender::SPECULAR_MAP &&
- matp && matp->getSpecularID().notNull())
- {
- new_shaderp = &gHighlightSpecularProgram;
- }
- // Change the shader if not already the one in use
- if (shader_interface && new_shaderp != prev_shaderp)
- {
- if (prev_shaderp)
- {
- prev_shaderp->unbind();
- }
- new_shaderp->bind();
- prev_shaderp = new_shaderp;
- }
- }
- // Draw the selection on the face.
- facep->renderSelected(mFaceSelectImagep, color);
- }
- else if (gDebugGL)
- {
- llwarns << "Bad face in selection" << llendl;
- }
- }
- // Unbind the last shader, if any
- if (prev_shaderp)
- {
- prev_shaderp->unbind();
- }
- }
- }
- // Debug use
- U32 LLPipeline::sCurRenderPoolType = 0;
- // Only for use by the EE renderer (in forward rendering mode)
- void LLPipeline::renderGeom(LLCamera& camera)
- {
- LL_FAST_TIMER(FTM_RENDER_GEOMETRY);
- // HACK: preserve/restore matrices around HUD render
- LLMatrix4a saved_modelview;
- LLMatrix4a saved_projection;
- bool hud_render = hasRenderType(RENDER_TYPE_HUD);
- if (hud_render)
- {
- saved_modelview = gGLModelView;
- saved_projection = gGLProjection;
- }
- ///////////////////////////////////////////
- // Sync and verify GL state
- LLVertexBuffer::unbind();
- // Do verification of GL state
- LL_GL_CHECK_STATES;
- if (mRenderDebugMask & RENDER_DEBUG_VERIFY)
- {
- if (!verify())
- {
- llerrs << "Pipeline verification failed !" << llendl;
- }
- }
- // Initialize lots of GL state to "safe" values
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- gGL.matrixMode(LLRender::MM_TEXTURE);
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- LLGLSPipeline gls_pipeline;
- LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE : 0);
- // Toggle backface culling for debugging
- // Note: this used to be a toggle based on a mBackfaceCull boolean, but the
- // latter was always true. HB
- LLGLEnable cull_face(GL_CULL_FACE);
- // Set fog
- gSky.updateFog(camera.getFar());
- if (!hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_FOG))
- {
- sUnderWaterRender = false;
- }
- if (LLViewerFetchedTexture::sDefaultImagep)
- {
- unit0->bind(LLViewerFetchedTexture::sDefaultImagep);
- LLViewerFetchedTexture::sDefaultImagep->setAddressMode(LLTexUnit::TAM_WRAP);
- }
- //////////////////////////////////////////////
- // Actually render all of the geometry
- pool_set_t::iterator pools_end = mPools.end();
- for (pool_set_t::iterator iter = mPools.begin(); iter != pools_end; ++iter)
- {
- LLDrawPool* poolp = *iter;
- if (hasRenderType(poolp->getType()))
- {
- poolp->prerender();
- }
- }
- {
- LL_FAST_TIMER(FTM_POOLS);
- // *HACK: do not calculate local lights if we are rendering the HUD !
- // Removing this check will cause bad flickering when there are HUD
- // elements being rendered AND the user is in flycam mode. -nyx
- if (!hud_render)
- {
- calcNearbyLights(camera);
- setupHWLights();
- }
- bool occlude = sUseOcclusion > 1;
- U32 cur_type = 0;
- pool_set_t::iterator iter1 = mPools.begin();
- while (iter1 != pools_end)
- {
- LLDrawPool* poolp = *iter1;
- cur_type = poolp->getType();
- // Debug use
- sCurRenderPoolType = cur_type;
- if (occlude && cur_type >= LLDrawPool::POOL_GRASS)
- {
- occlude = false;
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- LLGLSLShader::unbind();
- doOcclusion(camera);
- }
- pool_set_t::iterator iter2 = iter1;
- S32 passes;
- if (hasRenderType(poolp->getType()) &&
- (passes = poolp->getNumPasses()) > 0)
- {
- LL_FAST_TIMER(FTM_POOLRENDER);
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- for (S32 i = 0; i < passes; ++i)
- {
- LLVertexBuffer::unbind();
- poolp->beginRenderPass(i);
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- p->render(i);
- }
- poolp->endRenderPass(i);
- LLVertexBuffer::unbind();
- if (gDebugGL && iter2 != pools_end)
- {
- std::string msg = llformat("%s pass %d",
- gPoolNames[cur_type].c_str(),
- i);
- LLGLState::checkStates(msg);
- }
- }
- }
- else
- {
- // Skip all pools of this type
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- }
- }
- iter1 = iter2;
- }
- LLVertexBuffer::unbind();
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- if (occlude)
- {
- occlude = false;
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- LLGLSLShader::unbind();
- doOcclusion(camera);
- }
- }
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- if (!sImpostorRender)
- {
- if (!sReflectionRender)
- {
- renderHighlights();
- }
- // Contains a list of the faces of beacon-targeted objects that are
- // also to be highlighted.
- mHighlightFaces.clear();
- renderDebug();
- LLVertexBuffer::unbind();
- // HACK: preserve/restore matrices around HUD render
- if (hud_render)
- {
- gGLModelView = saved_modelview;
- gGLProjection = saved_projection;
- }
- }
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- // Version for use only by the PBR renderer
- void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
- {
- LL_FAST_TIMER(FTM_RENDER_GEOMETRY);
- if (gUseWireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- }
- if (&camera == &gViewerCamera && !sAvatarPreviewRender)
- {
- // A bit hacky: this is the start of the main render frame, figure out
- // delta between last modelview matrix and current modelview matrix.
- LLMatrix4a mat(gGLLastModelView);
- // The goal is to have a matrix here that goes from the last frame's
- // camera space to the current frame's camera space
- mat.invert();
- mat.setMul(gGLModelView, mat);
- gGLDeltaModelView = mat;
- mat.invert();
- gGLInverseDeltaModelView = mat;
- }
- bool occlude = do_occlusion && sUseOcclusion > 1 &&
- !LLGLSLShader::sProfileEnabled;
- setupHWLights();
- {
- LL_FAST_TIMER(FTM_POOLS);
- LLGLEnable cull(GL_CULL_FACE);
- pool_set_t::iterator pools_end = mPools.end();
- for (pool_set_t::iterator it = mPools.begin(); it != pools_end; ++it)
- {
- LLDrawPool* poolp = *it;
- if (hasRenderType(poolp->getType()))
- {
- poolp->prerender();
- }
- }
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- if (gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_DEFERRED) > 1)
- {
- // Update reflection probe uniform
- mReflectionMapManager.updateUniforms();
- mHeroProbeManager.updateUniforms();
- }
- U32 cur_type = 0;
- gGL.setColorMask(true, true);
- pool_set_t::iterator iter1 = mPools.begin();
- while (iter1 != pools_end)
- {
- LLDrawPool* poolp = *iter1;
- cur_type = poolp->getType();
- if (occlude && cur_type >= LLDrawPool::POOL_GRASS)
- {
- occlude = false;
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- doOcclusion(camera);
- }
- pool_set_t::iterator iter2 = iter1;
- S32 passes;
- if (hasRenderType(poolp->getType()) &&
- (passes = poolp->getNumDeferredPasses()) > 0)
- {
- LL_FAST_TIMER(FTM_POOLRENDER);
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- for (S32 i = 0; i < passes; ++i)
- {
- LLVertexBuffer::unbind();
- poolp->beginDeferredPass(i);
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- p->renderDeferred(i);
- }
- poolp->endDeferredPass(i);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- }
- else
- {
- // Skip all pools of this type
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- }
- }
- iter1 = iter2;
- }
- gGLLastMatrix = NULL;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(gGLModelView);
- gGL.setColorMask(true, false);
- stop_glerror();
- }
- if (gUseWireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- }
- // Version for use only by the EE renderer
- void LLPipeline::renderGeomDeferred(LLCamera& camera)
- {
- // *HACK: branch to the PBR version when used without 'do_occlusion'
- // parameter, so to simplify the dual renderer code. HB
- if (gUsePBRShaders)
- {
- renderGeomDeferred(camera, false);
- return;
- }
- LL_FAST_TIMER(FTM_RENDER_GEOMETRY);
- {
- LL_FAST_TIMER(FTM_POOLS);
- LLGLEnable cull(GL_CULL_FACE);
- LLGLEnable stencil(GL_STENCIL_TEST);
- glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- pool_set_t::iterator pools_end = mPools.end();
- for (pool_set_t::iterator it = mPools.begin(); it != pools_end; ++it)
- {
- LLDrawPool* poolp = *it;
- if (hasRenderType(poolp->getType()))
- {
- poolp->prerender();
- }
- }
- LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE : 0);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- U32 cur_type = 0;
- gGL.setColorMask(true, true);
- pool_set_t::iterator iter1 = mPools.begin();
- while (iter1 != pools_end)
- {
- LLDrawPool* poolp = *iter1;
- cur_type = poolp->getType();
- pool_set_t::iterator iter2 = iter1;
- S32 passes;
- if (hasRenderType(poolp->getType()) &&
- (passes = poolp->getNumDeferredPasses()) > 0)
- {
- LL_FAST_TIMER(FTM_POOLRENDER);
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- for (S32 i = 0; i < passes; ++i)
- {
- LLVertexBuffer::unbind();
- poolp->beginDeferredPass(i);
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- p->renderDeferred(i);
- }
- poolp->endDeferredPass(i);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- }
- else
- {
- // Skip all pools of this type
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- }
- }
- iter1 = iter2;
- }
- gGLLastMatrix = NULL;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(gGLModelView);
- gGL.setColorMask(true, false);
- stop_glerror();
- }
- }
- void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion)
- {
- LL_FAST_TIMER(FTM_POOLS);
- bool occlude;
- bool sample;
- if (gUsePBRShaders)
- {
- sample = occlude = false;
- if (gUseWireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- }
- }
- else
- {
- occlude = do_occlusion && sUseOcclusion > 1;
- sample = LLPipeline::RenderFSAASamples > 0;
- }
- LLGLEnable cull(GL_CULL_FACE);
- LLGLEnable multisample(sample ? GL_MULTISAMPLE : 0);
- // Skip PBR atmospherics/haze when in EE rendering, or when rendering HUDs,
- // or when rendering impostors, or when not rendering atmospherics.
- bool done_atmospherics = !gUsePBRShaders || sRenderingHUDs ||
- sImpostorRender || !RenderDeferredAtmospheric;
- bool done_water_haze = done_atmospherics;
- // Do atmospheric haze just before water pass when below water, or just
- // before post water alpha when above water.
- U32 atm_pass = sUnderWaterRender ? LLDrawPool::POOL_WATER
- : LLDrawPool::POOL_ALPHA_POST_WATER;
- // Do water haze just before pre water alpha.
- constexpr U32 water_haze_pass = LLDrawPool::POOL_ALPHA_PRE_WATER;
- calcNearbyLights(camera);
- setupHWLights();
- if (gUsePBRShaders)
- {
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- }
- gGL.setColorMask(true, false);
- pool_set_t::iterator iter1 = mPools.begin();
- pool_set_t::iterator pools_end = mPools.end();
- while (iter1 != pools_end)
- {
- LLDrawPool* poolp = *iter1;
- U32 cur_type = poolp->getType();
- // Used only in EE rendering mode. HB
- if (occlude && cur_type >= LLDrawPool::POOL_GRASS)
- {
- occlude = false;
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- LLGLSLShader::unbind();
- doOcclusion(camera, mRT->mScreen, mOcclusionDepth,
- &mDeferredDepth);
- gGL.setColorMask(true, false);
- }
- // Used only in PBR rendering mode. HB
- if (!done_atmospherics && cur_type >= atm_pass)
- {
- doAtmospherics();
- done_atmospherics = true;
- }
- if (!done_water_haze && cur_type >= water_haze_pass)
- {
- doWaterHaze();
- done_water_haze = true;
- }
- pool_set_t::iterator iter2 = iter1;
- S32 passes;
- if (hasRenderType(poolp->getType()) &&
- (passes = poolp->getNumPostDeferredPasses()) > 0)
- {
- LL_FAST_TIMER(FTM_POOLRENDER);
- // In PBR rendering mode, some draw pools do not use at all the
- // deferred pass, so we must ensure prerender() has been called for
- // them ! HB
- if (gUsePBRShaders && !poolp->getNumDeferredPasses())
- {
- poolp->prerender();
- }
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- for (S32 i = 0; i < passes; ++i)
- {
- LLVertexBuffer::unbind();
- poolp->beginPostDeferredPass(i);
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- p->renderPostDeferred(i);
- }
- poolp->endPostDeferredPass(i);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- }
- else
- {
- // Skip all pools of this type
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- }
- }
- iter1 = iter2;
- }
- gGLLastMatrix = NULL;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(gGLModelView);
- if (gUsePBRShaders)
- {
- if (!gCubeSnapshot)
- {
- // Render highlights, etc.
- renderHighlights();
- mHighlightFaces.clear();
- renderDebug();
- }
- if (gUseWireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- }
- else if (occlude)
- {
- LLGLSLShader::unbind();
- doOcclusion(camera);
- gGLLastMatrix = NULL;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(gGLModelView);
- }
- stop_glerror();
- }
- // PBR only
- void LLPipeline::doAtmospherics()
- {
- LL_TRACY_TIMER(TRC_DO_ATMOSPHERICS);
- {
- // Copy depth buffer for use in haze shader (use water displacement map
- // as temp storage).
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mRT->mScreen.flush();
- mWaterDis.bindTarget();
- gCopyDepthProgram.bind();
- S32 diff_map =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
- S32 depth_map =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
- gGL.getTexUnit(diff_map)->bind(&mRT->mScreen);
- gGL.getTexUnit(depth_map)->bind(&mRT->mDeferredScreen, true);
- gGL.setColorMask(false, false);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mWaterDis.flush();
- mRT->mScreen.bindTarget();
- }
- LLGLEnable blend(GL_BLEND);
- gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA,
- LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
- gGL.setColorMask(true, true);
- // Apply haze
- bindDeferredShader(gHazeProgram, NULL, &mWaterDis);
- gHazeProgram.uniform1i(LLShaderMgr::SUN_UP_FACTOR, mIsSunUp ? 1 : 0);
- gHazeProgram.uniform3fv(LLShaderMgr::LIGHTNORM, 1,
- gEnvironment.getClampedLightNorm().mV);
- gHazeProgram.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1,
- sWaterPlane.getF32ptr());
- LLGLDepthTest depth(GL_FALSE);
- // Full screen blit
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- unbindDeferredShader(gHazeProgram);
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- }
- // PBR only
- void LLPipeline::doWaterHaze()
- {
- LL_TRACY_TIMER(TRC_DO_WATER_HAZE);
- {
- // Copy depth buffer for use in haze shader (use water displacement map
- // as temp storage).
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mRT->mScreen.flush();
- mWaterDis.bindTarget();
- gCopyDepthProgram.bind();
- S32 diff_map =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
- S32 depth_map =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
- gGL.getTexUnit(diff_map)->bind(&mRT->mScreen);
- gGL.getTexUnit(depth_map)->bind(&mRT->mDeferredScreen, true);
- gGL.setColorMask(false, false);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mWaterDis.flush();
- mRT->mScreen.bindTarget();
- }
- gGL.setColorMask(true, true);
- {
- LLGLEnable blend(GL_BLEND);
- gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA,
- LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
- // Apply haze
- bindDeferredShader(gHazeWaterProgram, NULL, &mWaterDis);
- gHazeWaterProgram.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1,
- sWaterPlane.getF32ptr());
- if (sUnderWaterRender)
- {
- gHazeWaterProgram.uniform1i(sAboveWater, -1);
- LLGLDepthTest depth(GL_FALSE);
- // Full screen blit
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- else
- {
- gHazeWaterProgram.uniform1i(sAboveWater, 1);
- // Render water patches like LLDrawPoolWater does
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- if (mWaterPool)
- {
- mWaterPool->pushFaceGeometry();
- }
- }
- unbindDeferredShader(gHazeWaterProgram);
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- }
- // Moved from the now removed LLDrawPoolWater::beginPostDeferredPass(): the
- // latter was pointlessly executed for *each* water pool, while all we need
- // is a frame buffer copy of the screen just before the first pass of the
- // first water pool: do this here, since doWaterHaze() is called precisely
- // at this right time ! HB
- if (waterReflectionType() && !gCubeSnapshot)
- {
- // Copy framebuffer contents so far to a texture to be used for
- // reflections and refractions
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mWaterDis.bindTarget();
- gCopyDepthProgram.bind();
- S32 diff_chan =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
- S32 depth_chan =
- gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
- gGL.getTexUnit(diff_chan)->bind(&mRT->mScreen);
- gGL.getTexUnit(depth_chan)->bind(&mRT->mDeferredScreen, true);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- gCopyDepthProgram.unbind();
- mWaterDis.flush();
- }
- }
- void LLPipeline::renderGeomShadow(LLCamera& camera)
- {
- U32 cur_type = 0;
- LLGLEnable cull(GL_CULL_FACE);
- LLVertexBuffer::unbind();
- pool_set_t::iterator iter1 = mPools.begin();
- pool_set_t::iterator pools_end = mPools.end();
- while (iter1 != pools_end)
- {
- LLDrawPool* poolp = *iter1;
- cur_type = poolp->getType();
- pool_set_t::iterator iter2 = iter1;
- S32 passes;
- if (hasRenderType(poolp->getType()) &&
- (passes = poolp->getNumShadowPasses()) > 0)
- {
- poolp->prerender();
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- for (S32 i = 0; i < passes; ++i)
- {
- LLVertexBuffer::unbind();
- poolp->beginShadowPass(i);
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- p->renderShadow(i);
- }
- poolp->endShadowPass(i);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- }
- else
- {
- // Skip all pools of this type
- for (iter2 = iter1; iter2 != pools_end; ++iter2)
- {
- LLDrawPool* p = *iter2;
- if (p->getType() != cur_type)
- {
- break;
- }
- }
- }
- iter1 = iter2;
- }
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- stop_glerror();
- }
- void LLPipeline::addTrianglesDrawn(U32 index_count)
- {
- if (mNeedsDrawStats)
- {
- U32 count = index_count / 3;
- mTrianglesDrawn += count;
- if (count > mMaxBatchSize)
- {
- mMaxBatchSize = count;
- }
- if (count < mMinBatchSize)
- {
- mMinBatchSize = count;
- }
- ++mBatchCount;
- }
- if (sRenderFrameTest)
- {
- gWindowp->swapBuffers();
- ms_sleep(16);
- }
- }
- void LLPipeline::renderPhysicsDisplay()
- {
- if (!gUsePBRShaders)
- {
- allocatePhysicsBuffer();
- gGL.flush();
- mPhysicsDisplay.bindTarget();
- glClearColor(0.f, 0.f, 0.f, 1.f);
- gGL.setColorMask(true, true);
- mPhysicsDisplay.clear();
- glClearColor(0.f, 0.f, 0.f, 0.f);
- gGL.setColorMask(true, false);
- gDebugProgram.bind();
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType))
- {
- partp->renderPhysicsShapes();
- }
- }
- }
- gGL.flush();
- gDebugProgram.unbind();
- mPhysicsDisplay.flush();
- return;
- }
- gGL.flush();
- gDebugProgram.bind();
- LLGLEnable(GL_POLYGON_OFFSET_LINE);
- glPolygonOffset(3.f, 3.f);
- glLineWidth(3.f);
- LLGLEnable blend(GL_BLEND);
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- for (U32 pass = 0; pass < 3; ++pass)
- {
- // Pass 0 - depth write enabled, color write disabled, fill
- // Pass 1 - depth write disabled, color write enabled, fill
- // Pass 2 - depth write disabled, color write enabled, wireframe
- gGL.setColorMask(pass >= 1, false);
- LLGLDepthTest depth(GL_TRUE, pass == 0);
- bool wireframe = pass == 2;
- if (wireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- }
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* region = *iter;
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = region->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType))
- {
- partp->renderPhysicsShapes(wireframe);
- }
- }
- }
- gGL.flush();
- if (wireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- }
- glLineWidth(1.f);
- gDebugProgram.unbind();
- }
- void LLPipeline::renderDebug()
- {
- bool hud_only = hasRenderType(RENDER_TYPE_HUD);
- bool render_blips = !hud_only && !mDebugBlips.empty();
- // If no debug feature is on and there's no blip to render, return now
- if (mRenderDebugMask == 0 && !render_blips) return;
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- gGL.setColorMask(true, false);
- if (render_blips)
- {
- // Render debug blips
- gUIProgram.bind();
- gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep, true);
- glPointSize(8.f);
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- gGL.begin(LLRender::POINTS);
- for (std::list<DebugBlip>::iterator iter = mDebugBlips.begin(),
- end = mDebugBlips.end();
- iter != end; )
- {
- DebugBlip& blip = *iter;
- blip.mAge += gFrameIntervalSeconds;
- if (blip.mAge > 2.f)
- {
- iter = mDebugBlips.erase(iter);
- }
- else
- {
- ++iter;
- }
- blip.mPosition.mV[2] += gFrameIntervalSeconds * 2.f;
- gGL.color4fv(blip.mColor.mV);
- gGL.vertex3fv(blip.mPosition.mV);
- }
- gGL.end(true);
- glPointSize(1.f);
- gUIProgram.unbind();
- stop_glerror();
- }
- // If no debug feature is on, return now
- if (mRenderDebugMask == 0) return;
- // This is a no-op when gUsePBRShaders is true. HB
- LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL, gUsePBRShaders);
- // Debug stuff.
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- if (hud_only)
- {
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- U32 type = partp->mDrawableType;
- if (type == RENDER_TYPE_HUD ||
- type == RENDER_TYPE_HUD_PARTICLES)
- {
- partp->renderDebug();
- }
- }
- }
- else
- {
- for (U32 i = 0; i < LLViewerRegion::PARTITION_VO_CACHE; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (hasRenderType(partp->mDrawableType))
- {
- partp->renderDebug();
- }
- }
- }
- }
- LLCullResult::bridge_list_t& bridges = sCull->getVisibleBridge();
- for (U32 i = 0, count = bridges.size(); i < count; ++i)
- {
- LLSpatialBridge* bridgep = bridges[i];
- if (bridgep && !bridgep->isDead() &&
- hasRenderType(bridgep->mDrawableType))
- {
- gGL.pushMatrix();
- gGL.multMatrix(bridgep->mDrawable->getRenderMatrix().getF32ptr());
- bridgep->renderDebug();
- gGL.popMatrix();
- }
- }
- constexpr U32 GLTF_DEBUG_MASK = RENDER_DEBUG_BBOXES |
- RENDER_DEBUG_RAYCAST |
- RENDER_DEBUG_NODES;
- if (gUsePBRShaders && hasRenderDebugMask(GLTF_DEBUG_MASK))
- {
- LLGLTFSceneManager::renderDebug();
- }
- if (hasRenderDebugMask(RENDER_DEBUG_OCCLUSION) &&
- !gVisibleSelectedGroups.empty())
- {
- // Render visible selected group occlusion geometry
- gDebugProgram.bind();
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- gGL.diffuseColor3f(1.f, 0.f, 1.f);
- LLVector4a fudge, size;
- for (spatial_groups_set_t::iterator
- iter = gVisibleSelectedGroups.begin(),
- end = gVisibleSelectedGroups.end();
- iter != end; ++iter)
- {
- LLSpatialGroup* group = *iter;
- fudge.splat(0.25f); // SG_OCCLUSION_FUDGE
- const LLVector4a* bounds = group->getBounds();
- size.setAdd(fudge, bounds[1]);
- // Used to be called in drawBox(), now replaced with gl_draw_box()
- // which does not call this. HB
- LLVertexBuffer::unbind();
- gl_draw_box(bounds[0], size);
- }
- }
- gVisibleSelectedGroups.clear();
- bool check_probes = gUsePBRShaders && !hud_only;
- if (check_probes &&
- gPipeline.hasRenderDebugMask(RENDER_DEBUG_REFLECTION_PROBES))
- {
- mReflectionMapManager.renderDebug();
- }
- static LLCachedControl<bool> render_probes(gSavedSettings,
- "RenderReflectionProbeVolumes");
- if (check_probes && render_probes)
- {
- bindDeferredShader(gReflectionProbeDisplayProgram);
- mScreenTriangleVB->setBuffer();
- LLGLEnable blend(GL_BLEND);
- LLGLDepthTest depth(GL_FALSE);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- unbindDeferredShader(gReflectionProbeDisplayProgram);
- }
- gUIProgram.bind();
- if (!hud_only && gDebugRaycastParticle &&
- hasRenderDebugMask(RENDER_DEBUG_RAYCAST))
- {
- // Draw crosshairs on particle intersection
- gDebugProgram.bind();
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLVector3 center(gDebugRaycastParticleIntersection.getF32ptr());
- LLVector3 size(0.1f, 0.1f, 0.1f);
- LLVector3 p[6];
- p[0] = center + size.scaledVec(LLVector3(1.f, 0.f, 0.f));
- p[1] = center + size.scaledVec(LLVector3(-1.f, 0.f, 0.f));
- p[2] = center + size.scaledVec(LLVector3(0.f, 1.f, 0.f));
- p[3] = center + size.scaledVec(LLVector3(0.f, -1.f, 0.f));
- p[4] = center + size.scaledVec(LLVector3(0.f, 0.f, 1.f));
- p[5] = center + size.scaledVec(LLVector3(0.f, 0.f, -1.f));
- gGL.begin(LLRender::LINES);
- gGL.diffuseColor3f(1.f, 1.f, 0.f);
- for (U32 i = 0; i < 6; ++i)
- {
- gGL.vertex3fv(p[i].mV);
- }
- gGL.end(true);
- gDebugProgram.unbind();
- stop_glerror();
- }
- if (!hud_only && hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA))
- {
- LLVertexBuffer::unbind();
- LLGLEnable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLGLDisable cull(GL_CULL_FACE);
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- static const F32 colors[] =
- {
- 1.f, 0.f, 0.f, 0.1f,
- 0.f, 1.f, 0.f, 0.1f,
- 0.f, 0.f, 1.f, 0.1f,
- 1.f, 0.f, 1.f, 0.1f,
- 1.f, 1.f, 0.f, 0.1f,
- 0.f, 1.f, 1.f, 0.1f,
- 1.f, 1.f, 1.f, 0.1f,
- 1.f, 0.f, 1.f, 0.1f,
- };
- for (U32 i = 0; i < 8; ++i)
- {
- LLVector3* frust = mShadowCamera[i].mAgentFrustum;
- if (i > 3)
- {
- // Render shadow frusta as volumes
- if (mShadowFrustPoints[i - 4].empty())
- {
- continue;
- }
- gGL.color4fv(colors + (i - 4) * 4);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- {
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[4].mV);
- gGL.vertex3fv(frust[1].mV);
- gGL.vertex3fv(frust[5].mV);
- gGL.vertex3fv(frust[2].mV);
- gGL.vertex3fv(frust[6].mV);
- gGL.vertex3fv(frust[3].mV);
- gGL.vertex3fv(frust[7].mV);
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[4].mV);
- }
- gGL.end();
- gGL.begin(LLRender::TRIANGLE_STRIP);
- {
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[1].mV);
- gGL.vertex3fv(frust[3].mV);
- gGL.vertex3fv(frust[2].mV);
- }
- gGL.end();
- gGL.begin(LLRender::TRIANGLE_STRIP);
- {
- gGL.vertex3fv(frust[4].mV);
- gGL.vertex3fv(frust[5].mV);
- gGL.vertex3fv(frust[7].mV);
- gGL.vertex3fv(frust[6].mV);
- }
- gGL.end();
- }
- if (i < 4)
- {
- #if 0
- if (i == 0 || !mShadowFrustPoints[i].empty())
- #endif
- {
- // Render visible point cloud
- gGL.flush();
- glPointSize(8.f);
- gGL.begin(LLRender::POINTS);
- gGL.color3fv(colors + i * 4);
- for (U32 j = 0, size = mShadowFrustPoints[i].size();
- j < size; ++j)
- {
- gGL.vertex3fv(mShadowFrustPoints[i][j].mV);
- }
- gGL.end(true);
- glPointSize(1.f);
- LLVector3* ext = mShadowExtents[i];
- LLVector3 pos = (ext[0] + ext[1]) * 0.5f;
- LLVector3 size = (ext[1] - ext[0]) * 0.5f;
- gl_draw_box_outline(pos, size);
- // Render camera frustum splits as outlines
- gGL.begin(LLRender::LINES);
- {
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[1].mV);
- gGL.vertex3fv(frust[1].mV);
- gGL.vertex3fv(frust[2].mV);
- gGL.vertex3fv(frust[2].mV);
- gGL.vertex3fv(frust[3].mV);
- gGL.vertex3fv(frust[3].mV);
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[4].mV);
- gGL.vertex3fv(frust[5].mV);
- gGL.vertex3fv(frust[5].mV);
- gGL.vertex3fv(frust[6].mV);
- gGL.vertex3fv(frust[6].mV);
- gGL.vertex3fv(frust[7].mV);
- gGL.vertex3fv(frust[7].mV);
- gGL.vertex3fv(frust[4].mV);
- gGL.vertex3fv(frust[0].mV);
- gGL.vertex3fv(frust[4].mV);
- gGL.vertex3fv(frust[1].mV);
- gGL.vertex3fv(frust[5].mV);
- gGL.vertex3fv(frust[2].mV);
- gGL.vertex3fv(frust[6].mV);
- gGL.vertex3fv(frust[3].mV);
- gGL.vertex3fv(frust[7].mV);
- }
- gGL.end();
- }
- }
- gGL.flush();
- }
- stop_glerror();
- }
- LLViewerRegion* regionp = gAgent.getRegion();
- if (regionp && (mRenderDebugMask & RENDER_DEBUG_WIND_VECTORS))
- {
- regionp->mWind.renderVectors();
- }
- if (regionp && (mRenderDebugMask & RENDER_DEBUG_COMPOSITION))
- {
- // Debug composition layers
- F32 x, y;
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- gGL.begin(LLRender::POINTS);
- // Draw the composition layer for the region that I am in.
- for (x = 0; x <= 260; ++x)
- {
- for (y = 0; y <= 260; ++y)
- {
- if (x > 255 || y > 255)
- {
- gGL.color4f(1.f, 0.f, 0.f, 1.f);
- }
- else
- {
- gGL.color4f(0.f, 0.f, 1.f, 1.f);
- }
- F32 z = regionp->getCompositionXY((S32)x, (S32)y);
- z *= 5.f;
- z += 50.f;
- gGL.vertex3f(x, y, z);
- }
- }
- gGL.end();
- stop_glerror();
- }
- gGL.flush();
- gUIProgram.unbind();
- }
- void LLPipeline::rebuildPools()
- {
- S32 max_count = mPools.size();
- pool_set_t::iterator iter1 = mPools.upper_bound(mLastRebuildPool);
- while (max_count > 0 && mPools.size() > 0) // && num_rebuilds < MAX_REBUILDS)
- {
- if (iter1 == mPools.end())
- {
- iter1 = mPools.begin();
- }
- LLDrawPool* poolp = *iter1;
- if (poolp->isDead())
- {
- mPools.erase(iter1++);
- removeFromQuickLookup(poolp);
- if (poolp == mLastRebuildPool)
- {
- mLastRebuildPool = NULL;
- }
- delete poolp;
- }
- else
- {
- mLastRebuildPool = poolp;
- ++iter1;
- }
- --max_count;
- }
- }
- void LLPipeline::addToQuickLookup(LLDrawPool* new_poolp)
- {
- switch (new_poolp->getType())
- {
- case LLDrawPool::POOL_SIMPLE:
- if (mSimplePool)
- {
- llwarns << "Ignoring duplicate simple pool." << llendl;
- llassert(false);
- }
- else
- {
- mSimplePool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_ALPHA_MASK:
- if (mAlphaMaskPool)
- {
- llwarns << "Ignoring duplicate alpha mask pool." << llendl;
- llassert(false);
- }
- else
- {
- mAlphaMaskPool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
- if (mFullbrightAlphaMaskPool)
- {
- llwarns << "Ignoring duplicate alpha mask pool." << llendl;
- llassert(false);
- }
- else
- {
- mFullbrightAlphaMaskPool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_GRASS:
- if (mGrassPool)
- {
- llwarns << "Ignoring duplicate grass pool." << llendl;
- llassert(false);
- }
- else
- {
- mGrassPool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_FULLBRIGHT:
- if (mFullbrightPool)
- {
- llwarns << "Ignoring duplicate simple pool." << llendl;
- llassert(false);
- }
- else
- {
- mFullbrightPool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_INVISIBLE:
- if (mInvisiblePool)
- {
- llwarns << "Ignoring duplicate simple pool." << llendl;
- llassert(false);
- }
- else
- {
- mInvisiblePool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_GLOW:
- if (mGlowPool)
- {
- llwarns << "Ignoring duplicate glow pool." << llendl;
- llassert(false);
- }
- else
- {
- mGlowPool = (LLRenderPass*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_TREE:
- mTreePools.emplace(uintptr_t(new_poolp->getTexture()), new_poolp);
- break;
- case LLDrawPool::POOL_TERRAIN:
- mTerrainPools.emplace(uintptr_t(new_poolp->getTexture()),
- new_poolp);
- break;
- case LLDrawPool::POOL_BUMP:
- if (mBumpPool)
- {
- llwarns << "Ignoring duplicate bump pool." << llendl;
- llassert(false);
- }
- else
- {
- mBumpPool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_MATERIALS:
- if (mMaterialsPool)
- {
- llwarns << "Ignoring duplicate materials pool." << llendl;
- llassert(false);
- }
- else
- {
- mMaterialsPool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_ALPHA_PRE_WATER:
- if (mAlphaPoolPreWater)
- {
- llwarns << "Ignoring duplicate pre-water alpha pool" << llendl;
- llassert(false);
- }
- else
- {
- mAlphaPoolPreWater = (LLDrawPoolAlpha*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_ALPHA_POST_WATER:
- if (mAlphaPoolPostWater)
- {
- llwarns << "Ignoring duplicate post-water alpha pool" << llendl;
- llassert(false);
- }
- else
- {
- mAlphaPoolPostWater = (LLDrawPoolAlpha*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_ALPHA:
- if (mAlphaPool)
- {
- llwarns << "Ignoring duplicate alpha pool" << llendl;
- llassert(false);
- }
- else
- {
- mAlphaPool = (LLDrawPoolAlpha*)new_poolp;
- }
- break;
- case LLDrawPool::POOL_AVATAR:
- case LLDrawPool::POOL_PUPPET:
- break; // Do nothing
- case LLDrawPool::POOL_SKY:
- if (mSkyPool)
- {
- llwarns << "Ignoring duplicate sky pool" << llendl;
- llassert(false);
- }
- else
- {
- mSkyPool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_WATER:
- if (mWaterPool)
- {
- llwarns << "Ignoring duplicate water pool" << llendl;
- llassert(false);
- }
- else
- {
- mWaterPool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_WL_SKY:
- if (mWLSkyPool)
- {
- llwarns << "Ignoring duplicate Windlight sky pool" << llendl;
- llassert(false);
- }
- else
- {
- mWLSkyPool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_MAT_PBR:
- if (mPBROpaquePool)
- {
- llwarns << "Ignoring duplicate PBR opaque pool" << llendl;
- llassert(false);
- }
- else
- {
- mPBROpaquePool = new_poolp;
- }
- break;
- case LLDrawPool::POOL_MAT_PBR_ALPHA_MASK:
- if (mPBRAlphaMaskPool)
- {
- llwarns << "Ignoring duplicate PBR alpha mask pool" << llendl;
- llassert(false);
- }
- else
- {
- mPBRAlphaMaskPool = new_poolp;
- }
- break;
- default:
- llerrs << "Invalid pool type: " << new_poolp->getType() << llendl;
- }
- }
- void LLPipeline::removePool(LLDrawPool* poolp)
- {
- removeFromQuickLookup(poolp);
- mPools.erase(poolp);
- delete poolp;
- }
- void LLPipeline::removeFromQuickLookup(LLDrawPool* poolp)
- {
- switch (poolp->getType())
- {
- case LLDrawPool::POOL_SIMPLE:
- llassert(mSimplePool == poolp);
- mSimplePool = NULL;
- break;
- case LLDrawPool::POOL_ALPHA_MASK:
- llassert(mAlphaMaskPool == poolp);
- mAlphaMaskPool = NULL;
- break;
- case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
- llassert(mFullbrightAlphaMaskPool == poolp);
- mFullbrightAlphaMaskPool = NULL;
- break;
- case LLDrawPool::POOL_GRASS:
- llassert(mGrassPool == poolp);
- mGrassPool = NULL;
- break;
- case LLDrawPool::POOL_FULLBRIGHT:
- llassert(mFullbrightPool == poolp);
- mFullbrightPool = NULL;
- break;
- case LLDrawPool::POOL_INVISIBLE:
- llassert(mInvisiblePool == poolp);
- mInvisiblePool = NULL;
- break;
- case LLDrawPool::POOL_WL_SKY:
- llassert(mWLSkyPool == poolp);
- mWLSkyPool = NULL;
- break;
- case LLDrawPool::POOL_GLOW:
- llassert(mGlowPool == poolp);
- mGlowPool = NULL;
- break;
- case LLDrawPool::POOL_TREE:
- {
- #if LL_DEBUG
- bool found = mTreePools.erase((uintptr_t)poolp->getTexture());
- llassert(found);
- #else
- mTreePools.erase((uintptr_t)poolp->getTexture());
- #endif
- break;
- }
- case LLDrawPool::POOL_TERRAIN:
- {
- #if LL_DEBUG
- bool found = mTerrainPools.erase((uintptr_t)poolp->getTexture());
- llassert(found);
- #else
- mTerrainPools.erase((uintptr_t)poolp->getTexture());
- #endif
- break;
- }
- case LLDrawPool::POOL_BUMP:
- llassert(poolp == mBumpPool);
- mBumpPool = NULL;
- break;
- case LLDrawPool::POOL_MATERIALS:
- llassert(poolp == mMaterialsPool);
- mMaterialsPool = NULL;
- break;
- case LLDrawPool::POOL_ALPHA_PRE_WATER:
- llassert(poolp == mAlphaPoolPreWater);
- mAlphaPoolPreWater = NULL;
- break;
- case LLDrawPool::POOL_ALPHA_POST_WATER:
- llassert(poolp == mAlphaPoolPostWater);
- mAlphaPoolPostWater = NULL;
- break;
- case LLDrawPool::POOL_ALPHA:
- llassert(poolp == mAlphaPool);
- mAlphaPool = NULL;
- break;
- case LLDrawPool::POOL_AVATAR:
- case LLDrawPool::POOL_PUPPET:
- break; // Do nothing
- case LLDrawPool::POOL_SKY:
- llassert(poolp == mSkyPool);
- mSkyPool = NULL;
- break;
- case LLDrawPool::POOL_WATER:
- llassert(poolp == mWaterPool);
- mWaterPool = NULL;
- break;
- case LLDrawPool::POOL_MAT_PBR:
- llassert(poolp == mPBROpaquePool);
- mPBROpaquePool = NULL;
- break;
- case LLDrawPool::POOL_MAT_PBR_ALPHA_MASK:
- llassert(poolp == mPBRAlphaMaskPool);
- mPBRAlphaMaskPool = NULL;
- break;
- default:
- llerrs << "Invalid pool type: " << poolp->getType() << llendl;
- break;
- }
- }
- void LLPipeline::resetDrawOrders()
- {
- // Iterate through all of the draw pools and rebuild them.
- for (pool_set_t::iterator iter = mPools.begin(), end = mPools.end();
- iter != end; ++iter)
- {
- LLDrawPool* poolp = *iter;
- poolp->resetDrawOrders();
- }
- }
- //============================================================================
- // Once-per-frame setup of hardware lights, including sun/moon, avatar
- // backlight, and up to 6 local lights
- void LLPipeline::setupAvatarLights(bool for_edit)
- {
- LLLightState* lightp = gGL.getLight(1);
- if (for_edit)
- {
- static const LLColor4 white_transparent(1.f, 1.f, 1.f, 0.f);
- mHWLightColors[1] = white_transparent;
- LLMatrix4 camera_mat = gViewerCamera.getModelview();
- LLMatrix4 camera_rot(camera_mat.getMat3());
- camera_rot.invert();
- // w = 0 => directional light
- static const LLVector4 light_pos_cam(-8.f, 0.25f, 10.f, 0.f);
- LLVector4 light_pos = light_pos_cam * camera_rot;
- light_pos.normalize();
- lightp->setDiffuse(white_transparent);
- lightp->setAmbient(LLColor4::black);
- lightp->setSpecular(LLColor4::black);
- lightp->setPosition(light_pos);
- lightp->setConstantAttenuation(1.f);
- lightp->setLinearAttenuation(0.f);
- lightp->setQuadraticAttenuation(0.f);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- }
- else
- {
- mHWLightColors[1] = LLColor4::black;
- lightp->setDiffuse(LLColor4::black);
- lightp->setAmbient(LLColor4::black);
- lightp->setSpecular(LLColor4::black);
- }
- }
- static F32 calc_light_dist(LLVOVolume* lightvolp, const LLVector3& cam_pos,
- F32 max_dist)
- {
- if (lightvolp->getLightIntensity() < .001f)
- {
- return max_dist;
- }
- if (lightvolp->isSelected())
- {
- return 0.f; // Selected lights get highest priority
- }
- F32 radius = lightvolp->getLightRadius();
- F32 dist = dist_vec(lightvolp->getRenderPosition(), cam_pos) - radius;
- if (lightvolp->mDrawable.notNull() &&
- lightvolp->mDrawable->isState(LLDrawable::ACTIVE))
- {
- // Moving lights get a little higher priority (too much causes
- // artifacts)
- dist -= radius * 0.25f;
- }
- return llclamp(dist, 0.f, max_dist);
- }
- void LLPipeline::calcNearbyLights(LLCamera& camera)
- {
- if (sReflectionRender || sRenderingHUDs || sAvatarPreviewRender ||
- gCubeSnapshot)
- {
- return;
- }
- if (RenderLocalLightCount)
- {
- // mNearbyLight (and all light_set_t's) are sorted such that
- // begin() == the closest light and rbegin() == the farthest light
- constexpr S32 MAX_LOCAL_LIGHTS = 6;
- LLVector3 cam_pos = camera.getOrigin();
- F32 max_dist;
- if (sRenderDeferred)
- {
- max_dist = RenderFarClip;
- }
- else
- {
- max_dist = llmax(RenderFarClip, LIGHT_MAX_RADIUS * 4.f);
- }
- // UPDATE THE EXISTING NEARBY LIGHTS
- light_set_t cur_nearby_lights;
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- const Light* lightp = &(*iter);
- if (!lightp) continue; // Paranoia
- LLDrawable* drawablep = lightp->drawable;
- if (!drawablep) continue; // Paranoia
- LLVOVolume* lightvolp = drawablep->getVOVolume();
- if (!lightvolp || !drawablep->isState(LLDrawable::LIGHT))
- {
- drawablep->clearState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- if (lightp->fade <= -LIGHT_FADE_TIME)
- {
- drawablep->clearState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- if (!sRenderAttachedLights && lightvolp->isAttachment())
- {
- drawablep->clearState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- LLVOAvatar* avp = lightvolp->getAvatar();
- if (avp && avp->isVisuallyMuted())
- {
- drawablep->clearState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- F32 dist = calc_light_dist(lightvolp, cam_pos, max_dist);
- F32 fade = lightp->fade;
- // Note: actual fade gets decreased/increased by setupHWLights()
- // and lightp->fade value is 'time' (positive for light to become
- // visible as value increases, negative for fading out).
- if (dist < max_dist)
- {
- if (fade < 0.f)
- {
- // Mark light to fade in: if fade was -LIGHT_FADE_TIME,
- // it was fully invisible, if negative it was fully visible
- // and visibility goes up from 0 to LIGHT_FADE_TIME.
- fade += LIGHT_FADE_TIME;
- }
- }
- // Mark light to fade out. Visibility goes down from -0 to
- // -LIGHT_FADE_TIME.
- else if (fade >= LIGHT_FADE_TIME)
- {
- fade = -0.0001f; // Was fully visible
- }
- else if (fade >= 0.f)
- {
- // 0.75 visible light should stay 0.75 visible, but should
- // reverse direction.
- fade -= LIGHT_FADE_TIME;
- }
- cur_nearby_lights.emplace(drawablep, dist, fade);
- }
- mNearbyLights.swap(cur_nearby_lights);
- // FIND NEW LIGHTS THAT ARE IN RANGE
- light_set_t new_nearby_lights;
- for (LLDrawable::draw_set_t::iterator iter = mLights.begin(),
- end = mLights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- LLVOVolume* lightvolp = drawablep->getVOVolume();
- if (!lightvolp || drawablep->isState(LLDrawable::NEARBY_LIGHT) ||
- lightvolp->isHUDAttachment())
- {
- continue;
- }
- if (!sRenderAttachedLights && lightvolp->isAttachment())
- {
- continue;
- }
- LLVOAvatar* avp = lightvolp->getAvatar();
- if (avp && avp->isVisuallyMuted())
- {
- drawablep->clearState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- F32 dist = calc_light_dist(lightvolp, cam_pos, max_dist);
- if (dist >= max_dist)
- {
- continue;
- }
- new_nearby_lights.emplace(drawablep, dist, 0.f);
- if (!sRenderDeferred &&
- new_nearby_lights.size() > (U32)MAX_LOCAL_LIGHTS)
- {
- new_nearby_lights.erase(--new_nearby_lights.end());
- const Light& last = *new_nearby_lights.rbegin();
- max_dist = last.dist;
- }
- }
- // INSERT ANY NEW LIGHTS
- for (light_set_t::iterator iter = new_nearby_lights.begin(),
- end = new_nearby_lights.end();
- iter != end; ++iter)
- {
- const Light* lightp = &(*iter);
- if (sRenderDeferred ||
- mNearbyLights.size() < (U32)MAX_LOCAL_LIGHTS)
- {
- mNearbyLights.emplace(*lightp);
- ((LLDrawable*)lightp->drawable)->setState(LLDrawable::NEARBY_LIGHT);
- continue;
- }
- // Crazy cast so that we can overwrite the fade value even though
- // gcc enforces sets as const (fade value does not affect sort so
- // this is safe)
- Light* farthestp = const_cast<Light*>(&(*(mNearbyLights.rbegin())));
- if (lightp->dist >= farthestp->dist)
- {
- break; // None of the other lights are closer
- }
- // This is a mess, but for now it needs to be in sync with fade
- // code above. Ex: code above detects distance < max, sets fade
- // time to positive, this code then detects closer lights and sets
- // fade time negative, fully compensating for the code above.
- if (farthestp->fade >= LIGHT_FADE_TIME)
- {
- farthestp->fade = -0.0001f; // Was fully visible
- }
- else if (farthestp->fade >= 0.f)
- {
- farthestp->fade -= LIGHT_FADE_TIME;
- }
- }
- // Mark nearby lights not-removable.
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- const Light* lightp = &(*iter);
- ((LLViewerOctreeEntryData*)lightp->drawable)->setVisible();
- }
- }
- }
- // This method allows to read the sky values only once per frame and caches
- // them for use by the various pipeline methods called during that frame. HB
- void LLPipeline::cacheEnvironment()
- {
- const LLSettingsSky::ptr_t& skyp = gEnvironment.getCurrentSky();
- if (!skyp) return; // Paranoia
- // Ambient
- static LLCachedControl<U32> reflections(gSavedSettings,
- "RenderReflectionProbes");
- static LLCachedControl<bool> adjust(gSavedSettings,
- "RenderSkyAutoAdjustLegacy");
- static LLCachedControl<F32> adj_scale(gSavedSettings,
- "RenderSkyAutoAdjustSunColorScale");
- mTotalAmbient = skyp->getTotalAmbient();
- if (gUsePBRShaders)
- {
- // Cache the sky settings values for the reflection probes ambiance and
- // the gamma. Note: when RenderReflectionProbes is 0, we must use 1.f
- // for the probe ambiance, else the rendering is way too dark. HB
- mProbeAmbiance =
- reflections ? skyp->getReflectionProbeAmbiance(adjust) : 1.f;
- mSkyGamma = skyp->getGamma();
- }
- mIsSunUp = skyp->getIsSunUp();
- mIsMoonUp = skyp->getIsMoonUp();
- // Prevent underlighting from having neither lightsource facing us
- if (!mIsSunUp && !mIsMoonUp)
- {
- mSunDir.set(0.f, 1.f, 0.f, 0.f);
- mMoonDir.set(0.f, 1.f, 0.f, 0.f);
- mSunLightColor.setToBlack();
- mMoonLightColor.setToBlack();
- }
- else
- {
- mSunDir.set(skyp->getSunDirection(), 0.f);
- mMoonDir.set(skyp->getMoonDirection(), 0.f);
- mSunLightColor.set(skyp->getSunlightColor(), 1.f);
- mMoonLightColor.set(skyp->getMoonlightColor(), 1.f);
- }
- // Sun or Moon (All objects)
- F32 max_color = llmax(mSunLightColor.mV[0], mSunLightColor.mV[1],
- mSunLightColor.mV[2]);
- if (max_color > 1.f)
- {
- mSunLightColor *= 1.f / max_color;
- }
- mSunLightColor.clamp();
- mSunLightColorScaled = mSunLightColor;
- if (gUsePBRShaders && adjust && skyp->canAutoAdjust())
- {
- mSunLightColorScaled *= adj_scale;
- }
- max_color = llmax(mMoonLightColor.mV[0], mMoonLightColor.mV[1],
- mMoonLightColor.mV[2]);
- if (max_color > 1.f)
- {
- mMoonLightColor *= 1.f / max_color;
- }
- mMoonLightColor.clamp();
- // Also cache this for use by render pipeline and draw pools.
- LLViewerRegion* regionp = gAgent.getRegion();
- mWaterHeight = regionp ? regionp->getWaterHeight() : 0.f;
- mEyeAboveWater = gViewerCamera.getOrigin().mV[VZ] - mWaterHeight;
- }
- void LLPipeline::setupHWLights()
- {
- if (sRenderingHUDs || sAvatarPreviewRender)
- {
- return;
- }
- gGL.setAmbientLightColor(mTotalAmbient);
- // Darken local lights when probe ambiance is above 1
- F32 light_scale = gCubeSnapshot ? mReflectionMapManager.mLightScale : 1.f;
- LLLightState* lightp = gGL.getLight(0);
- lightp->setPosition(mIsSunUp ? mSunDir : mMoonDir);
- LLColor4 light_diffuse = mIsSunUp ? mSunLightColor : mMoonLightColor;
- mHWLightColors[0] = light_diffuse;
- lightp->setDiffuse(light_diffuse);
- lightp->setSunPrimary(mIsSunUp);
- lightp->setDiffuseB(mMoonLightColor);
- lightp->setAmbient(mTotalAmbient);
- lightp->setSpecular(LLColor4::black);
- lightp->setConstantAttenuation(1.f);
- lightp->setLinearAttenuation(0.f);
- lightp->setQuadraticAttenuation(0.f);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- // Nearby lights = LIGHT 2-7
- S32 cur_light = 2;
- if (RenderLocalLightCount)
- {
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = iter->drawable;
- LLVOVolume* volp = drawablep->getVOVolume();
- if (!volp)
- {
- continue;
- }
- bool is_attachment = volp->isAttachment();
- if (is_attachment && !sRenderAttachedLights)
- {
- continue;
- }
- const LLViewerObject* objp = drawablep->getVObj();
- if (objp)
- {
- LLVOAvatar* avp = is_attachment ? objp->getAvatar()
- : NULL;
- if (avp && !avp->isSelf() &&
- (avp->isInMuteList() || avp->isTooComplex()))
- {
- continue;
- }
- }
- // Send linear light color to shader
- LLColor4 light_color = volp->getLightLinearColor() * light_scale;
- light_color.mV[3] = 0.f;
- F32 fade = iter->fade;
- if (fade < LIGHT_FADE_TIME)
- {
- constexpr F32 LIGHT_FADE_TIME_INV = 1.f / LIGHT_FADE_TIME;
- // Fade in/out light
- if (fade >= 0.f)
- {
- fade *= LIGHT_FADE_TIME_INV;
- ((Light*)(&(*iter)))->fade += gFrameIntervalSeconds;
- }
- else
- {
- fade = 1.f + fade * LIGHT_FADE_TIME_INV;
- ((Light*)(&(*iter)))->fade -= gFrameIntervalSeconds;
- }
- fade = llclamp(fade, 0.f, 1.f);
- light_color *= fade;
- }
- if (light_color.lengthSquared() < 0.001f)
- {
- continue;
- }
- F32 adjusted_radius = volp->getLightRadius();
- if (sRenderDeferred)
- {
- adjusted_radius *= 1.5f;
- }
- if (adjusted_radius <= 0.001f)
- {
- continue;
- }
- LLVector4 light_pos_gl(volp->getRenderPosition(), 1.f);
- // Why this magic ? Probably trying to match a historic behavior:
- F32 x = 3.f * (1.f + volp->getLightFalloff(2.f));
- F32 linatten = x / adjusted_radius;
- mHWLightColors[cur_light] = light_color;
- lightp = gGL.getLight(cur_light);
- lightp->setPosition(light_pos_gl);
- lightp->setDiffuse(light_color);
- lightp->setAmbient(LLColor4::black);
- lightp->setConstantAttenuation(0.f);
- lightp->setLinearAttenuation(linatten);
- lightp->setSize(volp->getLightRadius() * 1.5f);
- F32 fall_off = volp->getLightFalloff(0.5f);
- lightp->setFalloff(fall_off);
- if (sRenderDeferred)
- {
- // Get falloff to match for forward deferred rendering lights
- lightp->setQuadraticAttenuation(1.f + fall_off);
- }
- else
- {
- lightp->setQuadraticAttenuation(0);
- }
- if (volp->isLightSpotlight() && // Directional (spot-)light
- // These are only rendered as GL spotlights if we are in
- // deferred rendering mode *or* the setting forces them on:
- (sRenderDeferred || RenderSpotLightsInNondeferred))
- {
- LLQuaternion quat = volp->getRenderRotation();
- // This matches deferred rendering's object light direction:
- LLVector3 at_axis(0.f, 0.f, -1.f);
- at_axis *= quat;
- lightp->setSpotDirection(at_axis);
- lightp->setSpotCutoff(90.f);
- lightp->setSpotExponent(2.f);
- LLVector3 spot_params = volp->getSpotLightParams();
- const LLColor4 specular(0.f, 0.f, 0.f, spot_params[2]);
- lightp->setSpecular(specular);
- }
- else // Omnidirectional (point) light
- {
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- // We use z = 1.f as a cheap hack for the shaders to know that
- // this is omnidirectional rather than a spotlight
- lightp->setSpecular(LLColor4(0.f, 0.f, 1.f, 0.f));
- }
- if (++cur_light >= 8)
- {
- break; // safety
- }
- }
- }
- for ( ; cur_light < 8; ++cur_light)
- {
- mHWLightColors[cur_light] = LLColor4::black;
- lightp = gGL.getLight(cur_light);
- lightp->setSunPrimary(true);
- lightp->setDiffuse(LLColor4::black);
- lightp->setAmbient(LLColor4::black);
- lightp->setSpecular(LLColor4::black);
- }
- static LLCachedControl<bool> customize_lighting(gSavedSettings,
- "AvatarCustomizeLighting");
- if (customize_lighting && isAgentAvatarValid() &&
- gAgentAvatarp->mSpecialRenderMode == 3)
- {
- LLVector3 light_pos(gViewerCamera.getOrigin());
- LLVector4 light_pos_gl(light_pos, 1.f);
- F32 light_radius = 16.f;
- F32 x = 3.f;
- F32 linatten = x / light_radius; // % of brightness at radius
- lightp = gGL.getLight(2);
- LLColor4 light_color;
- light_color = LLColor4::white;
- lightp->setDiffuseB(light_color * 0.25f);
- mHWLightColors[2] = light_color;
- lightp->setPosition(light_pos_gl);
- lightp->setDiffuse(light_color);
- lightp->setDiffuseB(light_color * 0.25f);
- lightp->setAmbient(LLColor4::black);
- lightp->setSpecular(LLColor4::black);
- lightp->setQuadraticAttenuation(0.f);
- lightp->setConstantAttenuation(0.f);
- lightp->setLinearAttenuation(linatten);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- }
- for (S32 i = 0; i < 8; ++i)
- {
- gGL.getLight(i)->disable();
- }
- mLightMask = 0;
- }
- void LLPipeline::enableLights(U32 mask)
- {
- if (!RenderLocalLightCount)
- {
- mask &= 0xf003; // Sun and backlight only (and fullbright bit)
- }
- if (mLightMask != mask)
- {
- if (mask)
- {
- for (S32 i = 0; i < 8; ++i)
- {
- LLLightState* lightp = gGL.getLight(i);
- if (mask & (1 << i))
- {
- lightp->enable();
- lightp->setDiffuse(mHWLightColors[i]);
- }
- else
- {
- lightp->disable();
- lightp->setDiffuse(LLColor4::black);
- }
- }
- }
- mLightMask = mask;
- }
- }
- void LLPipeline::enableLightsStatic()
- {
- constexpr U32 mask = 0xff & ~2;
- enableLights(mask);
- }
- void LLPipeline::enableLightsDynamic()
- {
- U32 mask = 0xff & (~2); // Local lights
- enableLights(mask);
- if (isAgentAvatarValid() && RenderLocalLightCount)
- {
- if (gAgentAvatarp->mSpecialRenderMode == 0) // Normal
- {
- enableLightsAvatar();
- }
- else if (gAgentAvatarp->mSpecialRenderMode >= 1) // Anim preview
- {
- enableLightsAvatarEdit();
- }
- }
- }
- void LLPipeline::enableLightsAvatar()
- {
- setupAvatarLights(false);
- enableLights(0xff); // All lights
- }
- void LLPipeline::enableLightsPreview()
- {
- disableLights();
- gGL.setAmbientLightColor(PreviewAmbientColor);
- LLLightState* lightp = gGL.getLight(1);
- lightp->enable();
- lightp->setPosition(LLVector4(PreviewDirection0, 0.f));
- lightp->setDiffuse(PreviewDiffuse0);
- lightp->setAmbient(PreviewAmbientColor);
- lightp->setSpecular(PreviewSpecular0);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- lightp = gGL.getLight(2);
- lightp->enable();
- lightp->setPosition(LLVector4(PreviewDirection1, 0.f));
- lightp->setDiffuse(PreviewDiffuse1);
- lightp->setAmbient(PreviewAmbientColor);
- lightp->setSpecular(PreviewSpecular1);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- lightp = gGL.getLight(3);
- lightp->enable();
- lightp->setPosition(LLVector4(PreviewDirection2, 0.f));
- lightp->setDiffuse(PreviewDiffuse2);
- lightp->setAmbient(PreviewAmbientColor);
- lightp->setSpecular(PreviewSpecular2);
- lightp->setSpotExponent(0.f);
- lightp->setSpotCutoff(180.f);
- }
- void LLPipeline::enableLightsAvatarEdit()
- {
- U32 mask = 0x2002; // Avatar backlight only, set ambient
- setupAvatarLights(true);
- enableLights(mask);
- gGL.setAmbientLightColor(LLColor4(0.7f, 0.6f, 0.3f, 1.f));
- }
- void LLPipeline::enableLightsFullbright()
- {
- U32 mask = 0x1000; // Non-0 mask, set ambient
- enableLights(mask);
- }
- void LLPipeline::disableLights()
- {
- enableLights(0); // No lighting (full bright)
- }
- #if LL_DEBUG && 0
- void LLPipeline::findReferences(LLDrawable* drawablep)
- {
- if (mLights.find(drawablep) != mLights.end())
- {
- llinfos << "In mLights" << llendl;
- }
- if (std::find(mMovedList.begin(), mMovedList.end(),
- drawablep) != mMovedList.end())
- {
- llinfos << "In mMovedList" << llendl;
- }
- if (std::find(mShiftList.begin(), mShiftList.end(),
- drawablep) != mShiftList.end())
- {
- llinfos << "In mShiftList" << llendl;
- }
- if (mRetexturedList.find(drawablep) != mRetexturedList.end())
- {
- llinfos << "In mRetexturedList" << llendl;
- }
- if (std::find(mBuildQ.begin(), mBuildQ.end(), drawablep) != mBuildQ.end())
- {
- llinfos << "In mBuildQ" << llendl;
- }
- S32 count;
- count = gObjectList.findReferences(drawablep);
- if (count)
- {
- llinfos << "In other drawables: " << count << " references" << llendl;
- }
- }
- #endif
- bool LLPipeline::verify()
- {
- bool ok = true;
- for (pool_set_t::iterator iter = mPools.begin(), end = mPools.end();
- iter != end; ++iter)
- {
- LLDrawPool* poolp = *iter;
- if (!poolp->verify())
- {
- ok = false;
- }
- }
- if (!ok)
- {
- llwarns << "Pipeline verify failed !" << llendl;
- }
- return ok;
- }
- //////////////////////////////
- // Collision detection
- ///////////////////////////////////////////////////////////////////////////////
- /**
- * A method to compute a ray-AABB intersection.
- * Original code by Andrew Woo, from "Graphics Gems", Academic Press, 1990
- * Optimized code by Pierre Terdiman, 2000 (~20-30% faster on my Celeron 500)
- * Epsilon value added by Klaus Hartmann. (discarding it saves a few cycles only)
- *
- * Hence this version is faster as well as more robust than the original one.
- *
- * Should work provided:
- * 1) the integer representation of 0.f is 0x00000000
- * 2) the sign bit of the float is the most significant one
- *
- * Report bugs: [email protected]
- *
- * \param aabb [in] the axis-aligned bounding box
- * \param origin [in] ray origin
- * \param dir [in] ray direction
- * \param coord [out] impact coordinates
- * \return true if ray intersects AABB
- */
- ///////////////////////////////////////////////////////////////////////////////
- //#define RAYAABB_EPSILON 0.00001f
- #define IR(x) ((U32&)x)
- bool LLRayAABB(const LLVector3& center, const LLVector3& size,
- const LLVector3& origin, const LLVector3& dir,
- LLVector3& coord, F32 epsilon)
- {
- bool inside = true;
- LLVector3 MinB = center - size;
- LLVector3 MaxB = center + size;
- LLVector3 MaxT;
- MaxT.mV[VX] = MaxT.mV[VY] = MaxT.mV[VZ] = -1.f;
- // Find candidate planes.
- for (U32 i = 0; i < 3; ++i)
- {
- if (origin.mV[i] < MinB.mV[i])
- {
- coord.mV[i] = MinB.mV[i];
- inside = false;
- // Calculate T distances to candidate planes
- if (IR(dir.mV[i]))
- {
- MaxT.mV[i] = (MinB.mV[i] - origin.mV[i]) / dir.mV[i];
- }
- }
- else if (origin.mV[i] > MaxB.mV[i])
- {
- coord.mV[i] = MaxB.mV[i];
- inside = false;
- // Calculate T distances to candidate planes
- if (IR(dir.mV[i]))
- {
- MaxT.mV[i] = (MaxB.mV[i] - origin.mV[i]) / dir.mV[i];
- }
- }
- }
- // Ray origin inside bounding box
- if (inside)
- {
- coord = origin;
- return true;
- }
- // Get largest of the maxT's for final choice of intersection
- U32 WhichPlane = 0;
- if (MaxT.mV[1] > MaxT.mV[WhichPlane])
- {
- WhichPlane = 1;
- }
- if (MaxT.mV[2] > MaxT.mV[WhichPlane])
- {
- WhichPlane = 2;
- }
- // Check final candidate actually inside box
- if (IR(MaxT.mV[WhichPlane]) & 0x80000000)
- {
- return false;
- }
- for (U32 i = 0; i < 3; ++i)
- {
- if (i != WhichPlane)
- {
- coord.mV[i] = origin.mV[i] + MaxT.mV[WhichPlane] * dir.mV[i];
- if (epsilon > 0)
- {
- if (coord.mV[i] < MinB.mV[i] - epsilon ||
- coord.mV[i] > MaxB.mV[i] + epsilon)
- {
- return false;
- }
- }
- else if (coord.mV[i] < MinB.mV[i] || coord.mV[i] > MaxB.mV[i])
- {
- return false;
- }
- }
- }
- return true; // ray hits box
- }
- void LLPipeline::setLight(LLDrawable* drawablep, bool is_light)
- {
- if (drawablep)
- {
- if (is_light)
- {
- mLights.emplace(drawablep);
- drawablep->setState(LLDrawable::LIGHT);
- }
- else
- {
- drawablep->clearState(LLDrawable::LIGHT);
- mLights.erase(drawablep);
- }
- }
- }
- //static
- void LLPipeline::toggleRenderType(U32 type)
- {
- //MK
- // Force the render type to true if our vision is restricted
- if (gRLenabled &&
- (type == RENDER_TYPE_AVATAR || type == RENDER_TYPE_PUPPET) &&
- gRLInterface.mVisionRestricted)
- {
- gPipeline.mRenderTypeEnabled[type] = true;
- return;
- }
- //mk
- gPipeline.mRenderTypeEnabled[type] = !gPipeline.mRenderTypeEnabled[type];
- if (type == RENDER_TYPE_WATER)
- {
- gPipeline.mRenderTypeEnabled[RENDER_TYPE_VOIDWATER] =
- !gPipeline.mRenderTypeEnabled[RENDER_TYPE_VOIDWATER];
- }
- }
- //static
- void LLPipeline::toggleRenderTypeControl(void* data)
- {
- U32 type = (U32)(intptr_t)data;
- U32 bit = 1 << type;
- if (gPipeline.hasRenderType(type))
- {
- llinfos << "Toggling render type mask " << std::hex << bit << " off"
- << std::dec << llendl;
- }
- else
- {
- llinfos << "Toggling render type mask " << std::hex << bit << " on"
- << std::dec << llendl;
- }
- gPipeline.toggleRenderType(type);
- }
- //static
- bool LLPipeline::hasRenderTypeControl(void* data)
- {
- U32 type = (U32)(intptr_t)data;
- return gPipeline.hasRenderType(type);
- }
- // Allows UI items labeled "Hide foo" instead of "Show foo"
- //static
- bool LLPipeline::toggleRenderTypeControlNegated(void* data)
- {
- U32 type = (U32)(intptr_t)data;
- return !gPipeline.hasRenderType(type);
- }
- //static
- void LLPipeline::toggleRenderDebug(void* data)
- {
- U32 bit = (U32)(intptr_t)data;
- //MK
- if (gRLenabled && gRLInterface.mVisionRestricted)
- {
- bit = 0;
- }
- //mk
- if (gPipeline.hasRenderDebugMask(bit))
- {
- llinfos << "Toggling render debug mask " << std::hex << bit << " off"
- << std::dec << llendl;
- }
- else
- {
- llinfos << "Toggling render debug mask " << std::hex << bit << " on"
- << std::dec << llendl;
- }
- gPipeline.mRenderDebugMask ^= bit;
- }
- //static
- bool LLPipeline::toggleRenderDebugControl(void* data)
- {
- U32 bit = (U32)(intptr_t)data;
- return gPipeline.hasRenderDebugMask(bit);
- }
- //static
- void LLPipeline::toggleRenderDebugFeature(void* data)
- {
- U32 bit = (U32)(intptr_t)data;
- gPipeline.mRenderDebugFeatureMask ^= bit;
- }
- //static
- bool LLPipeline::toggleRenderDebugFeatureControl(void* data)
- {
- U32 bit = (U32)(intptr_t)data;
- return gPipeline.hasRenderDebugFeatureMask(bit);
- }
- //static
- void LLPipeline::setRenderDebugFeatureControl(U32 bit, bool value)
- {
- if (value)
- {
- gPipeline.mRenderDebugFeatureMask |= bit;
- }
- else
- {
- gPipeline.mRenderDebugFeatureMask &= !bit;
- }
- }
- LLVOPartGroup* LLPipeline::lineSegmentIntersectParticle(const LLVector4a& start,
- const LLVector4a& end,
- LLVector4a* intersectp,
- S32* face_hitp)
- {
- LLVector4a local_end = end;
- LLVector4a position;
- LLDrawable* drawablep = NULL;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- wend = gWorld.getRegionList().end();
- iter != wend; ++iter)
- {
- LLViewerRegion* region = *iter;
- if (!region) continue; // Paranoia
- LLSpatialPartition* partp =
- region->getSpatialPartition(LLViewerRegion::PARTITION_PARTICLE);
- // PARTITION_PARTICLE cannot be NULL
- if (hasRenderType(partp->mDrawableType))
- {
- LLDrawable* hitp = partp->lineSegmentIntersect(start, local_end,
- true, false,
- face_hitp,
- &position);
- if (hitp)
- {
- drawablep = hitp;
- local_end = position;
- }
- }
- }
- LLVOPartGroup* partp = NULL;
- if (drawablep)
- {
- // Make sure we are returning an LLVOPartGroup
- partp = drawablep->getVObj().get()->asVOPartGroup();
- }
- if (intersectp)
- {
- *intersectp = position;
- }
- return partp;
- }
- LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector4a& start,
- const LLVector4a& end,
- bool pick_transparent,
- bool pick_rigged,
- S32* face_hitp,
- S32* gltf_node_hitp,
- S32* gltf_prim_hitp,
- LLVector4a* intersectp,
- LLVector2* tcoordp,
- LLVector4a* normalp,
- LLVector4a* tangentp)
- {
- LLDrawable* drawablep = NULL;
- LLVector4a local_end = end;
- LLVector4a position;
- sPickAvatar = false; // !gToolMgr.inBuildMode();
- // Only check these non-avatar partitions in a first step
- static const U32 non_avatars[] =
- {
- LLViewerRegion::PARTITION_TERRAIN,
- LLViewerRegion::PARTITION_TREE,
- LLViewerRegion::PARTITION_GRASS,
- LLViewerRegion::PARTITION_VOLUME,
- LLViewerRegion::PARTITION_BRIDGE,
- LLViewerRegion::PARTITION_PUPPET,
- };
- constexpr U32 non_avatars_count = LL_ARRAY_SIZE(non_avatars);
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- wend = gWorld.getRegionList().end();
- iter != wend; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- if (!regionp) continue; // Paranoia
- for (U32 j = 0; j < non_avatars_count; ++j)
- {
- U32 type = non_avatars[j];
- LLSpatialPartition* partp = regionp->getSpatialPartition(type);
- // None of the partitions under PARTITION_VO_CACHE can be NULL
- if (!hasRenderType(partp->mDrawableType))
- {
- continue;
- }
- LLDrawable* hitp =
- partp->lineSegmentIntersect(start, local_end,
- // Terrain, tree and grass cannot
- // be transparent neither rigged !
- // HB
- pick_transparent && j >= 3,
- pick_rigged && j >= 3,
- face_hitp, &position, tcoordp,
- normalp, tangentp);
- if (hitp)
- {
- drawablep = hitp;
- local_end = position;
- }
- }
- }
- if (!sPickAvatar)
- {
- // Save hit info in case we need to restore due to attachment override
- LLVector4a local_normal;
- LLVector4a local_tangent;
- LLVector2 local_texcoord;
- S32 local_face_hit = -1;
- if (face_hitp)
- {
- local_face_hit = *face_hitp;
- }
- if (tcoordp)
- {
- local_texcoord = *tcoordp;
- }
- if (tangentp)
- {
- local_tangent = *tangentp;
- }
- else
- {
- local_tangent.clear();
- }
- if (normalp)
- {
- local_normal = *normalp;
- }
- else
- {
- local_normal.clear();
- }
- constexpr F32 ATTACHMENT_OVERRIDE_DIST = 0.1f;
- // Check against avatars
- sPickAvatar = true;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- wend = gWorld.getRegionList().end();
- iter != wend; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- if (!regionp) continue; // Paranoia
- LLSpatialPartition* partp =
- regionp->getSpatialPartition(LLViewerRegion::PARTITION_AVATAR);
- // Note: PARTITION_AVATAR cannot be NULL
- if (!hasRenderType(partp->mDrawableType))
- {
- continue;
- }
- LLDrawable* hitp =
- partp->lineSegmentIntersect(start, local_end, pick_transparent,
- pick_rigged, face_hitp, &position,
- tcoordp, normalp, tangentp);
- if (hitp)
- {
- LLVector4a delta;
- delta.setSub(position, local_end);
- if (!drawablep || !drawablep->getVObj()->isAttachment() ||
- delta.getLength3().getF32() > ATTACHMENT_OVERRIDE_DIST)
- {
- // Avatar overrides if previously hit drawable is not
- // an attachment or attachment is far enough away from
- // detected intersection
- drawablep = hitp;
- local_end = position;
- }
- else
- {
- // Prioritize attachments over avatars
- position = local_end;
- if (face_hitp)
- {
- *face_hitp = local_face_hit;
- }
- if (tcoordp)
- {
- *tcoordp = local_texcoord;
- }
- if (tangentp)
- {
- *tangentp = local_tangent;
- }
- if (normalp)
- {
- *normalp = local_normal;
- }
- }
- }
- }
- }
- // Check all avatar name tags
- for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
- {
- LLVOAvatar* avp = (LLVOAvatar*)LLCharacter::sInstances[i];
- if (avp && avp->mNameText.notNull() &&
- avp->mNameText->lineSegmentIntersect(start, local_end, position))
- {
- drawablep = avp->mDrawable;
- local_end = position;
- }
- }
- if (gUsePBRShaders)
- {
- S32 node_hit = -1;
- S32 prim_hit = -1;
- LLDrawable* hit_drawp =
- LLGLTFSceneManager::lineSegmentIntersect(start, local_end,
- pick_transparent,
- pick_rigged, &node_hit,
- &prim_hit, &position,
- tcoordp, normalp,
- tangentp);
- if (hit_drawp)
- {
- drawablep = hit_drawp;
- //local_end = position;
- }
- if (gltf_node_hitp)
- {
- *gltf_node_hitp = node_hit;
- }
- if (gltf_prim_hitp)
- {
- *gltf_prim_hitp = prim_hit;
- }
- }
- if (intersectp)
- {
- *intersectp = position;
- }
- return drawablep ? drawablep->getVObj().get() : NULL;
- }
- LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector4a& start,
- const LLVector4a& end,
- bool pick_transparent,
- S32* face_hitp,
- LLVector4a* intersectp,
- LLVector2* tcoordp,
- LLVector4a* normalp,
- LLVector4a* tangentp)
- {
- LLDrawable* drawablep = NULL;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- wend = gWorld.getRegionList().end();
- iter != wend; ++iter)
- {
- LLViewerRegion* region = *iter;
- bool toggle = false;
- if (!hasRenderType(RENDER_TYPE_HUD))
- {
- toggleRenderType(RENDER_TYPE_HUD);
- toggle = true;
- }
- LLSpatialPartition* partp =
- region->getSpatialPartition(LLViewerRegion::PARTITION_HUD);
- // PARTITION_HUD cannot be NULL
- LLDrawable* hitp = partp->lineSegmentIntersect(start, end,
- pick_transparent, false,
- face_hitp, intersectp,
- tcoordp, normalp,
- tangentp);
- if (hitp)
- {
- drawablep = hitp;
- }
- if (toggle)
- {
- toggleRenderType(RENDER_TYPE_HUD);
- }
- }
- return drawablep ? drawablep->getVObj().get() : NULL;
- }
- LLSpatialPartition* LLPipeline::getSpatialPartition(LLViewerObject* objp)
- {
- if (objp)
- {
- LLViewerRegion* regionp = objp->getRegion();
- if (regionp)
- {
- return regionp->getSpatialPartition(objp->getPartitionType());
- }
- }
- return NULL;
- }
- void LLPipeline::resetVertexBuffers(LLDrawable* drawablep)
- {
- if (drawablep)
- {
- for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
- {
- LLFace* facep = drawablep->getFace(i);
- if (facep)
- {
- facep->clearVertexBuffer();
- }
- }
- }
- }
- void LLPipeline::resetVertexBuffers()
- {
- mResetVertexBuffers = true;
- updateRenderDeferred();
- }
- void LLPipeline::doResetVertexBuffers(bool forced)
- {
- if (!mResetVertexBuffers)
- {
- return;
- }
- // Wait for teleporting to finish
- if (!forced && LLSpatialPartition::sTeleportRequested)
- {
- if (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE)
- {
- // Teleporting aborted
- LLSpatialPartition::sTeleportRequested = false;
- mResetVertexBuffers = false;
- }
- return;
- }
- LL_FAST_TIMER(FTM_RESET_VB);
- mResetVertexBuffers = false;
- gGL.flush();
- glFinish();
- LLVertexBuffer::unbind();
- // Delete our utility buffers
- mDeferredVB = mGlowCombineVB = mCubeVB = mScreenTriangleVB = NULL;
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; ++i)
- {
- LLSpatialPartition* partp = regionp->getSpatialPartition(i);
- if (partp)
- {
- partp->resetVertexBuffers();
- }
- }
- }
- if (LLSpatialPartition::sTeleportRequested)
- {
- LLSpatialPartition::sTeleportRequested = false;
- // Do not do this for the PBR renderer. HB
- if (!gUsePBRShaders)
- {
- gWorld.clearAllVisibleObjects();
- clearRebuildDrawables();
- }
- }
- resetDrawOrders();
- gSky.resetVertexBuffers();
- gGL.resetVertexBuffer();
- LLVertexBuffer::cleanupClass();
- #if LL_DEBUG_VB_ALLOC
- if (LLVertexBuffer::getGLCount())
- {
- llwarns << "VBO wipe failed: " << LLVertexBuffer::getGLCount()
- << " buffers remaining." << llendl;
- LLVertexBuffer::dumpInstances();
- }
- #endif
- updateRenderDeferred();
- LLVertexBuffer::initClass();
- gGL.initVertexBuffer();
- createAuxVBs(); // Recreate our utility buffers...
- LLDrawPoolWater::restoreGL();
- LLDrawPoolWLSky::restoreGL();
- }
- void LLPipeline::renderObjects(U32 type, U32 mask, bool texture,
- bool batch_texture, bool rigged)
- {
- LL_TRACY_TIMER(TRC_RENDER_OBJECTS);
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- if (rigged)
- {
- mSimplePool->pushRiggedBatches(type + 1, mask, texture, batch_texture);
- }
- else
- {
- mSimplePool->pushBatches(type, mask, texture, batch_texture);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- // Used only by the PBR renderer
- void LLPipeline::renderGLTFObjects(U32 type, bool texture, bool rigged)
- {
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- if (rigged)
- {
- LLRenderPass::pushRiggedGLTFBatches(type + 1, texture);
- }
- else
- {
- LLRenderPass::pushGLTFBatches(type, texture);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- if (!rigged)
- {
- LLGLTFSceneManager::renderOpaque();
- }
- }
- // Branched version for the PBR renderer
- void LLPipeline::renderAlphaObjectsPBR(bool rigged)
- {
- LL_TRACY_TIMER(TRC_RENDER_ALPHA_OBJECTS);
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- constexpr U32 type = LLRenderPass::PASS_ALPHA;
- const F32 width = LLRenderTarget::sCurResX;
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- LLCullResult::drawinfo_list_t& draw_list = getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- bool has_avatar = paramsp->mAvatar.notNull();
- if (rigged != has_avatar)
- {
- // This pool contains both rigged and non-rigged DrawInfos. Only
- // draw the objects we are interested in in this pass.
- continue;
- }
- bool has_pbr_mat = paramsp->mGLTFMaterial.notNull();
- LLGLSLShader* shaderp =
- has_pbr_mat ? &gDeferredShadowGLTFAlphaBlendProgram
- : &gDeferredShadowAlphaMaskProgram;
- shaderp->bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, mIsSunUp);
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, width);
- shaderp->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
- if (rigged && paramsp->mSkinInfo &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!mSimplePool->uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- mSimplePool->uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- if (has_pbr_mat)
- {
- LLRenderPass::pushGLTFBatch(*paramsp);
- }
- else
- {
- mSimplePool->pushBatch(*paramsp, 0, true, true);
- }
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- void LLPipeline::renderAlphaObjects(bool rigged)
- {
- if (gUsePBRShaders)
- {
- renderAlphaObjectsPBR(rigged);
- return;
- }
- LL_TRACY_TIMER(TRC_RENDER_ALPHA_OBJECTS);
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- constexpr U32 type = LLRenderPass::PASS_ALPHA;
- constexpr U32 mask = LLVertexBuffer::MAP_VERTEX |
- LLVertexBuffer::MAP_TEXCOORD0 |
- LLVertexBuffer::MAP_COLOR |
- LLVertexBuffer::MAP_TEXTURE_INDEX;
- LLVOAvatar* last_avatarp = NULL;
- U64 last_hash = 0;
- LLCullResult::drawinfo_list_t& draw_list = getRenderMap(type);
- for (U32 i = 0, count = draw_list.size(); i < count; )
- {
- LLDrawInfo* paramsp = draw_list[i++];
- // Draw info cache prefetching optimization.
- if (i < count)
- {
- _mm_prefetch((char*)draw_list[i]->mVertexBuffer.get(),
- _MM_HINT_NTA);
- if (i + 1 < count)
- {
- _mm_prefetch((char*)draw_list[i + 1], _MM_HINT_NTA);
- }
- }
- bool has_avatar = paramsp->mAvatar.notNull();
- if (rigged != has_avatar)
- {
- // This pool contains both rigged and non-rigged DrawInfos. Only
- // draw the objects we are interested in in this pass.
- continue;
- }
- if (!rigged)
- {
- mSimplePool->pushBatch(*paramsp, mask, true, true);
- continue;
- }
- if (paramsp->mSkinInfo &&
- (paramsp->mAvatar.get() != last_avatarp ||
- paramsp->mSkinInfo->mHash != last_hash))
- {
- #if 0
- if (!mSimplePool->uploadMatrixPalette(*paramsp))
- {
- continue;
- }
- #else
- mSimplePool->uploadMatrixPalette(*paramsp);
- #endif
- last_avatarp = paramsp->mAvatar.get();
- last_hash = paramsp->mSkinInfo->mHash;
- }
- mSimplePool->pushBatch(*paramsp, mask | LLVertexBuffer::MAP_WEIGHT4,
- true, true);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- void LLPipeline::renderMaskedObjects(U32 type, U32 mask, bool texture,
- bool batch_texture, bool rigged)
- {
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- if (rigged)
- {
- mAlphaMaskPool->pushRiggedMaskBatches(type + 1, mask, texture,
- batch_texture);
- }
- else
- {
- mAlphaMaskPool->pushMaskBatches(type, mask, texture, batch_texture);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- void LLPipeline::renderFullbrightMaskedObjects(U32 type, U32 mask,
- bool texture,
- bool batch_texture, bool rigged)
- {
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- if (rigged)
- {
- mFullbrightAlphaMaskPool->pushRiggedMaskBatches(type + 1, mask,
- texture,
- batch_texture);
- }
- else
- {
- mFullbrightAlphaMaskPool->pushMaskBatches(type, mask, texture,
- batch_texture);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- // PBR renderer only
- void LLPipeline::visualizeBuffers(LLRenderTarget* srcp, LLRenderTarget* dstp,
- U32 buff_idx)
- {
- dstp->bindTarget();
- LLGLSLShader* shaderp = &gDeferredBufferVisualProgram;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp, false,
- LLTexUnit::TFO_BILINEAR, buff_idx);
- shaderp->uniform1f(sMipLevel, RenderBufferVisualization == 4 ? 8.f : 0.f);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- dstp->flush();
- }
- // PBR renderer only
- void LLPipeline::generateLuminance(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_LUMINANCE);
- dstp->bindTarget();
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- gLuminanceProgram.bind();
- S32 chan = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE);
- if (chan > -1)
- {
- srcp->bindTexture(0, chan, LLTexUnit::TFO_POINT);
- }
- chan = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
- if (chan > -1)
- {
- mGlow[1].bindTexture(0, chan);
- }
- chan = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_NORMAL);
- if (chan > -1)
- {
- mRT->mDeferredScreen.bindTexture(2, chan, LLTexUnit::TFO_POINT);
- }
- static LLCachedControl<F32> diffuse_scale(gSavedSettings,
- "RenderDiffuseLuminanceScale");
- gLuminanceProgram.uniform1f(sLuminanceScale, diffuse_scale);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- dstp->flush();
- gLuminanceProgram.unbind();
- }
- // PBR renderer only
- void LLPipeline::generateExposure(LLRenderTarget* srcp, LLRenderTarget* dstp,
- bool use_history)
- {
- LL_TRACY_TIMER(TRC_RENDER_EXPOSURE);
- static LLCachedControl<F32> exp_coeff(gSavedSettings,
- "RenderDynamicExposureCoefficient");
- if (use_history)
- {
- // Copy last frame's exposure into mLastExposure
- mLastExposure.bindTarget();
- gCopyProgram.bind();
- gGL.getTexUnit(0)->bind(dstp);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mLastExposure.flush();
- }
- dstp->bindTarget();
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- LLGLSLShader& shader = use_history ? gExposureProgram
- : gExposureProgramNoFade;
- shader.bind();
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
- if (chan > -1)
- {
- mLuminanceMap.bindTexture(0, chan, LLTexUnit::TFO_TRILINEAR);
- }
- if (use_history)
- {
- chan = shader.enableTexture(LLShaderMgr::EXPOSURE_MAP);
- if (chan > -1)
- {
- mLastExposure.bindTexture(0, chan);
- }
- }
- shader.uniform1f(sDT, gFrameIntervalSeconds);
- shader.uniform2f(sNoiseVec, ll_frand() * 2.f - 1.f,
- ll_frand() * 2.f - 1.f);
- F32 exp_min = 1.f;
- F32 exp_max = 1.f;
- static LLCachedControl<U32> reflections(gSavedSettings,
- "RenderReflectionProbes");
- if (reflections && mProbeAmbiance > 0.f)
- {
- F32 hdr_scale = 2.f * sqrtf(mSkyGamma);
- if (hdr_scale > 1.f)
- {
- exp_min = 1.f / hdr_scale;
- exp_max = hdr_scale;
- }
- }
- shader.uniform3f(sExpParams, exp_coeff, exp_min, exp_max);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- if (use_history)
- {
- gGL.getTexUnit(chan)->unbind(mLastExposure.getUsage());
- }
- shader.unbind();
- dstp->flush();
- }
- // PBR renderer only
- void LLPipeline::generateGlow(LLRenderTarget* srcp)
- {
- LL_TRACY_TIMER(TRC_RENDER_GLOW);
- if (!RenderGlow)
- {
- mGlow[1].bindTarget();
- mGlow[1].clear();
- mGlow[1].flush();
- return;
- }
- mGlow[2].bindTarget();
- mGlow[2].clear();
- gGlowExtractProgram.bind();
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MIN_LUMINANCE, 9999);
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MAX_EXTRACT_ALPHA,
- RenderGlowMaxExtractAlpha);
- gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_LUM_WEIGHTS,
- RenderGlowLumWeights.mV[0],
- RenderGlowLumWeights.mV[1],
- RenderGlowLumWeights.mV[2]);
- gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_WARMTH_WEIGHTS,
- RenderGlowWarmthWeights.mV[0],
- RenderGlowWarmthWeights.mV[1],
- RenderGlowWarmthWeights.mV[2]);
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_WARMTH_AMOUNT,
- RenderGlowWarmthAmount);
- static LLCachedControl<bool> with_noise(gSavedSettings, "RenderGlowNoise");
- if (with_noise)
- {
- S32 channel =
- gGlowExtractProgram.enableTexture(LLShaderMgr::GLOW_NOISE_MAP);
- if (channel > -1)
- {
- LLTexUnit* unitp = gGL.getTexUnit(channel);
- unitp->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
- unitp->setTextureFilteringOption(LLTexUnit::TFO_POINT);
- }
- gGlowExtractProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- mGlow[2].getWidth(),
- mGlow[2].getHeight());
- }
- {
- LLGLEnable blend_on(GL_BLEND);
- gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
- gGlowExtractProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, srcp);
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- enableLightsFullbright();
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mGlow[2].flush();
- }
- gGlowExtractProgram.unbind();
- // Power of two between 1 and 1024
- const U32 glow_res = llclamp(1 << RenderGlowResolutionPow, 1, 1024);
- S32 kernel = RenderGlowIterations * 2;
- F32 delta = RenderGlowWidth / (F32)glow_res;
- // Use half the glow width if we have the res set to less than 9 so that it
- // looks almost the same in either case.
- if (RenderGlowResolutionPow < 9)
- {
- delta *= 0.5f;
- }
- gGlowProgram.bind();
- gGlowProgram.uniform1f(LLShaderMgr::GLOW_STRENGTH, RenderGlowStrength);
- for (S32 i = 0; i < kernel; ++i)
- {
- mGlow[i % 2].bindTarget();
- mGlow[i % 2].clear();
- if (i == 0)
- {
- gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, &mGlow[2]);
- }
- else
- {
- gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP,
- &mGlow[(i - 1) % 2]);
- }
- if (i % 2 == 0)
- {
- gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, delta, 0.f);
- }
- else
- {
- gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, 0.f, delta);
- }
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mGlow[i % 2].flush();
- }
- gGlowProgram.unbind();
- }
- // PBR renderer only
- void LLPipeline::combineGlow(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_GLOW_COMBINE);
- dstp->bindTarget();
- gGlowCombineProgram.bind();
- gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp);
- gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_EMISSIVE, &mGlow[1]);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- dstp->flush();
- }
- // PBR renderer only
- void LLPipeline::gammaCorrect(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_GAMMA_CORRECT);
- static LLCachedControl<U32> reflections(gSavedSettings,
- "RenderReflectionProbes");
- static LLCachedControl<bool> no_post(gSavedSettings,
- "RenderDisablePostProcessing");
- static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure");
- dstp->bindTarget();
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- static LLGLSLShader* last_shaderp = NULL;
- LLGLSLShader* shaderp;
- if (gSnapshotNoPost || !reflections || (no_post && gToolMgr.inBuildMode()))
- {
- shaderp = &gNoPostGammaCorrectProgram;
- if (shaderp != last_shaderp)
- {
- llinfos << "Gamma shader in use: gNoPostGammaCorrectProgram"
- << llendl;
- }
- }
- else if (mProbeAmbiance <= 0.f)
- {
- shaderp = &gLegacyPostGammaCorrectProgram;
- if (shaderp != last_shaderp)
- {
- llinfos << "Gamma shader in use: gLegacyPostGammaCorrectProgram"
- << llendl;
- }
- }
- else
- {
- shaderp = &gDeferredPostGammaCorrectProgram;
- if (shaderp != last_shaderp)
- {
- llinfos << "Gamma shader in use: gDeferredPostGammaCorrectProgram"
- << llendl;
- }
- }
- last_shaderp = shaderp;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp, false,
- LLTexUnit::TFO_POINT);
- shaderp->bindTexture(LLShaderMgr::EXPOSURE_MAP, &mExposureMap);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, srcp->getWidth(),
- srcp->getHeight());
- shaderp->uniform1f(sExposure, llclamp(F32(exposure), 0.5f, 4.f));
- static LLCachedControl<bool> use_hdri(gSavedSettings, "RenderHDRIEnabled");
- bool use_hdri_sky = use_hdri && LLDrawPoolWLSky::getHDRISky();
- shaderp->uniform1f(sAcesMix, use_hdri_sky ? 0.f : 0.3f);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- gGL.getTexUnit(0)->unbind(srcp->getUsage());
- shaderp->unbind();
- dstp->flush();
- }
- // PBR renderer only
- void LLPipeline::copyRenderTarget(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_COPY_TARGET);
- dstp->bindTarget();
- LLGLSLShader* shaderp = &gDeferredPostNoDoFProgram;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp);
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->mDeferredScreen,
- true);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- dstp->flush();
- }
- // PBR renderer only. Returns true when FXAA got actually applied. HB
- bool LLPipeline::applyFXAA(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_FXAA);
- if (!LLViewerShaderMgr::sHasFXAA || RenderFSAASamples <= 1 ||
- !mFXAABuffer.isComplete())
- {
- copyRenderTarget(srcp, dstp);
- return false;
- }
- // Bake out texture2D with RGBL for FXAA shader
- mFXAABuffer.bindTarget();
- LLGLSLShader* shaderp = &gGlowCombineFXAAProgram;
- shaderp->bind();
- LLTexUnit::eTextureType mode = srcp->getUsage();
- S32 channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mode);
- if (channel > -1)
- {
- srcp->bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
- }
- LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mode);
- shaderp->unbind();
- mFXAABuffer.flush();
- dstp->bindTarget();
- shaderp = &gFXAAProgram[RenderDeferredAAQuality];
- shaderp->bind();
- channel = shaderp->enableTexture(LLShaderMgr::DIFFUSE_MAP,
- mFXAABuffer.getUsage());
- if (channel > -1)
- {
- mFXAABuffer.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
- }
- gViewerWindowp->setupViewport();
- F32 inv_width = 1.f / F32(mFXAABuffer.getWidth());
- F32 inv_height = 1.f / F32(mFXAABuffer.getHeight());
- F32 scale_x = F32(dstp->getWidth()) * inv_width;
- F32 scale_y = F32(dstp->getHeight()) * inv_height;
- shaderp->uniform2f(LLShaderMgr::FXAA_TC_SCALE, scale_x, scale_y);
- shaderp->uniform2f(LLShaderMgr::FXAA_RCP_SCREEN_RES, inv_width,
- inv_height);
- shaderp->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT,
- -0.5f * inv_width, -0.5f * inv_height,
- 0.5f * inv_width, 0.5f * inv_height);
- shaderp->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT2,
- -2.f * inv_width, -2.f * inv_height,
- 2.f * inv_width, 2.f * inv_height);
- channel = shaderp->getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
- gGL.getTexUnit(channel)->bind(&mRT->mDeferredScreen, true);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- dstp->flush();
- return true;
- }
- // PBR renderer only. Returns true when SMAA got actually applied. HB
- bool LLPipeline::applySMAA(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_SMAA);
- if (!LLViewerShaderMgr::sHasSMAA || RenderFSAASamples <= 1 ||
- !mAreaMap || !mSearchMap || !mSMAAEdgeBuffer.isComplete() ||
- !mSMAABlendBuffer.isComplete() || !mScratchBuffer.isComplete())
- {
- copyRenderTarget(srcp, dstp);
- return false;
- }
- LLGLSLShader* shaderp;
- // Note: all buffers got the same size.
- S32 width = srcp->getWidth();
- S32 height = srcp->getHeight();
- // Bake out texture2D with RGBL for SMAA shader
- mFXAABuffer.bindTarget();
- shaderp = &gGlowCombineFXAAProgram;
- shaderp->bind();
- LLTexUnit::eTextureType mode = srcp->getUsage();
- S32 channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mode);
- if (channel > -1)
- {
- srcp->bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
- }
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, mode);
- shaderp->unbind();
- mFXAABuffer.flush();
- glClearColor(0.f, 0.f, 0.f, 0.f);
- glViewport(0, 0, width, height);
- F32 rt_metrics[] = { 1.f / width, 1.f / height, (F32)width, (F32)height };
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- LLTexUnit* unit1 = gGL.getTexUnit(1);
- LLTexUnit* unit2 = gGL.getTexUnit(2);
- mSMAAEdgeBuffer.bindTarget();
- mSMAAEdgeBuffer.clear(GL_COLOR_BUFFER_BIT);
- shaderp = &gPostSMAAEdgeDetect[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mFXAABuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- unit0->disable();
- shaderp->unbind();
- mSMAAEdgeBuffer.flush();
- mSMAABlendBuffer.bindTarget();
- mSMAABlendBuffer.clear(GL_COLOR_BUFFER_BIT);
- shaderp = &gPostSMAABlendWeights[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mSMAAEdgeBuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- unit1->bindManual(LLTexUnit::TT_TEXTURE, mAreaMap);
- unit1->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit1->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit1->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- unit2->bindManual(LLTexUnit::TT_TEXTURE, mSearchMap);
- unit2->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit2->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit2->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- unit0->disable();
- unit1->disable();
- unit2->disable();
- shaderp->unbind();
- mSMAABlendBuffer.flush();
- // *TODO: it should be possible to modify the NeighborhoodBlend shader to
- // save the intermediate scratch buffer step and avoid the last call to
- // copyRenderTarget() used here to combine the SMAA shaders result with
- // the PBR depth buffer (else things such as over-texts and avatar name
- // tags vanish)... But I am not qualified enough in OpenGL to do this (my
- // only attempt resulted in a red screen), so if you can do it, please be
- // my guest and you will be credited for it ! HB
- mScratchBuffer.bindTarget();
- mScratchBuffer.clear(GL_COLOR_BUFFER_BIT);
- shaderp = &gPostSMAANeighborhoodBlend[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mFXAABuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- mSMAABlendBuffer.bindTexture(0, 1, LLTexUnit::TFO_BILINEAR);
- unit1->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit1->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- // This might also be avoidable with a properly amended shader... HB
- gViewerWindowp->setupViewport();
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- mScratchBuffer.flush();
- unit0->disable();
- unit1->disable();
- shaderp->unbind();
- copyRenderTarget(&mScratchBuffer, dstp);
- return true;
- }
- // PBR renderer only.
- void LLPipeline::applyCAS(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_CAS);
- dstp->bindTarget();
- dstp->clear();
- gPostCASProgram.bind();
- static LLCachedControl<LLVector3> cas_params(gSavedSettings,
- "RenderDeferredCASParams");
- LLVector3 params = LLVector3(cas_params);
- params.clamp(0.f, 1.f);
- gPostCASProgram.uniform3fv(sSharpness, 1, params.mV);
- gPostCASProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp, false,
- LLTexUnit::TFO_POINT);
- LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
- gViewerWindowp->setupViewport();
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- gPostCASProgram.unbind();
- dstp->flush();
- }
- // Helper function used to factorize common code in EE and PBR renderers. HB
- static void calc_doff_params(F32& subject_dist, F32& blur_constant,
- F32& magnification)
- {
- static F32 current_dist = 16.f;
- static F32 start_dist = 16.f;
- static F32 transition_time = 1.f;
- static LLCachedControl<F32> cam_trans_time(gSavedSettings,
- "CameraFocusTransitionTime");
- static LLCachedControl<F32> camera_fnum(gSavedSettings, "CameraFNumber");
- static LLCachedControl<F32> cam_default_focal(gSavedSettings,
- "CameraFocalLength");
- static LLCachedControl<F32> camera_fov(gSavedSettings,
- "CameraFieldOfView");
- LLVector3 focus_point;
- LLViewerMediaFocus* mfocusp = LLViewerMediaFocus::getInstance();
- LLViewerObject* objp = mfocusp->getFocusedObject();
- if (objp && objp->mDrawable && objp->isSelected())
- {
- // Focus on selected media object
- S32 face_idx = mfocusp->getFocusedFace();
- if (objp && objp->mDrawable)
- {
- LLFace* facep = objp->mDrawable->getFace(face_idx);
- if (facep)
- {
- focus_point = facep->getPositionAgent();
- }
- }
- }
- if (focus_point.isExactlyZero())
- {
- if (LLViewerJoystick::getInstance()->getOverrideCamera())
- {
- // Focus on point under cursor
- focus_point.set(gDebugRaycastIntersection.getF32ptr());
- }
- else if (gAgent.cameraMouselook())
- {
- // Focus on point under mouselook crosshairs
- LLVector4a result;
- result.clear();
- gViewerWindowp->cursorIntersect(-1, -1, 512.f, NULL, -1,
- false, false, NULL, NULL, NULL,
- &result);
- focus_point.set(result.getF32ptr());
- }
- else
- {
- // Focus on alt-zoom target
- LLViewerRegion* regionp = gAgent.getRegion();
- if (regionp)
- {
- focus_point = LLVector3(gAgent.getFocusGlobal() -
- regionp->getOriginGlobal());
- }
- }
- }
- LLVector3 eye = gViewerCamera.getOrigin();
- F32 target_dist = 16.f;
- if (!focus_point.isExactlyZero())
- {
- target_dist = gViewerCamera.getAtAxis() * (focus_point - eye);
- }
- if (transition_time >= 1.f &&
- fabsf(current_dist - target_dist) / current_dist > 0.01f)
- {
- // Large shift happened, interpolate smoothly to new target distance
- transition_time = 0.f;
- start_dist = current_dist;
- }
- else if (transition_time < 1.f)
- {
- // Currently in a transition, continue interpolating
- transition_time += 1.f / llmax(F32_MIN,
- cam_trans_time * gFrameIntervalSeconds);
- transition_time = llmin(transition_time, 1.f);
- F32 t = cosf(transition_time * F_PI + F_PI) * 0.5f + 0.5f;
- current_dist = start_dist + (target_dist - start_dist) * t;
- }
- else
- {
- // Small or no change, just snap to target distance
- current_dist = target_dist;
- }
- // From wikipedia -- c = |s2-s1|/s2 * f^2/(N(S1-f))
- // where N = CameraFNumber
- // s2 = dot distance
- // s1 = subject distance
- // f = focal length
- subject_dist = current_dist * 1000.f; // In mm
- F32 dv = 2.f * cam_default_focal * tanf(camera_fov * DEG_TO_RAD * 0.5f);
- F32 focal = dv / (2.f * tanf(gViewerCamera.getView() * 0.5f));
- blur_constant = focal * focal / (camera_fnum * (subject_dist - focal));
- blur_constant *= 0.001f; // Convert to meters for shader
- if (subject_dist == focal)
- {
- magnification = F32_MAX;
- }
- else
- {
- magnification = focal / (subject_dist - focal);
- }
- subject_dist *= 0.001f; // Convert back to meters for shader
- }
- // PBR renderer only. Returns true when DoF got actually applied. HB
- bool LLPipeline::renderDoF(LLRenderTarget* srcp, LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_DOF);
- if (!RenderDepthOfField || gCubeSnapshot ||
- (!RenderDepthOfFieldInEditMode && gToolMgr.inBuildMode()))
- {
- copyRenderTarget(srcp, dstp);
- return false;
- }
- F32 subject_dist, blur_constant, magnification;
- calc_doff_params(subject_dist, blur_constant, magnification);
- LLGLDisable blend(GL_BLEND);
- // Build diffuse + bloom + CoF
- mRT->mDeferredLight.bindTarget();
- LLGLSLShader* shaderp = &gDeferredCoFProgram;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp,
- LLTexUnit::TFO_POINT);
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->mDeferredScreen,
- true);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dstp->getWidth(),
- dstp->getHeight());
- shaderp->uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_dist);
- shaderp->uniform1f(LLShaderMgr::DOF_BLUR_CONSTANT, blur_constant);
- shaderp->uniform1f(LLShaderMgr::DOF_TAN_PIXEL_ANGLE,
- tanf(1.f / LLDrawable::sCurPixelAngle));
- shaderp->uniform1f(LLShaderMgr::DOF_MAGNIFICATION, magnification);
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- mRT->mDeferredLight.flush();
- U32 dof_width = U32(mRT->mScreen.getWidth() * CameraDoFResScale);
- U32 dof_height = U32(mRT->mScreen.getHeight() * CameraDoFResScale);
- // Perform DoF sampling at half-res (preserve alpha channel)
- srcp->bindTarget();
- glViewport(0, 0, dof_width, dof_height);
- gGL.setColorMask(true, false);
- shaderp = &gDeferredPostProgram;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &mRT->mDeferredLight,
- LLTexUnit::TFO_POINT);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dstp->getWidth(),
- dstp->getHeight());
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- srcp->flush();
- gGL.setColorMask(true, true);
- // Combine result based on alpha
- dstp->bindTarget();
- if (RenderFSAASamples > 1 && mFXAABuffer.isComplete())
- {
- glViewport(0, 0, dstp->getWidth(), dstp->getHeight());
- }
- else
- {
- gViewerWindowp->setupViewport();
- }
- shaderp = &gDeferredDoFCombineProgram;
- shaderp->bind();
- shaderp->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, srcp,
- LLTexUnit::TFO_POINT);
- shaderp->bindTexture(LLShaderMgr::DEFERRED_LIGHT, &mRT->mDeferredLight,
- LLTexUnit::TFO_POINT);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dstp->getWidth(),
- dstp->getHeight());
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- shaderp->uniform1f(LLShaderMgr::DOF_WIDTH,
- (dof_width - 1) / (F32)srcp->getWidth());
- shaderp->uniform1f(LLShaderMgr::DOF_HEIGHT,
- (dof_height - 1) / (F32)srcp->getHeight());
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- dstp->flush();
- return true;
- }
- // PBR renderer only
- void LLPipeline::copyScreenSpaceReflections(LLRenderTarget* srcp,
- LLRenderTarget* dstp)
- {
- LL_TRACY_TIMER(TRC_RENDER_SSR_COPY);
- if (!RenderScreenSpaceReflections || gCubeSnapshot)
- {
- return;
- }
- LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
- dstp->bindTarget();
- dstp->clear();
- LLGLSLShader* shaderp = &gCopyDepthProgram;
- shaderp->bind();
- S32 diff_chan = shaderp->getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
- S32 depth_chan = shaderp->getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
- gGL.getTexUnit(diff_chan)->bind(srcp);
- gGL.getTexUnit(depth_chan)->bind(&mRT->mDeferredScreen, true);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- dstp->flush();
- }
- // Branched version for the PBR renderer
- void LLPipeline::renderFinalizePBR()
- {
- LL_FAST_TIMER(FTM_RENDER_BLOOM);
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- LLGLDepthTest depth(GL_FALSE);
- LLGLDisable blend(GL_BLEND);
- LLGLDisable cull(GL_CULL_FACE);
- enableLightsFullbright();
- gGL.setColorMask(true, true);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- copyScreenSpaceReflections(&mRT->mScreen, &mSceneMap);
- generateLuminance(&mRT->mScreen, &mLuminanceMap);
- generateExposure(&mLuminanceMap, &mExposureMap);
- gammaCorrect(&mRT->mScreen, &mPostMap);
- LLVertexBuffer::unbind();
- generateGlow(&mPostMap);
- combineGlow(&mPostMap, &mRT->mScreen);
- gViewerWindowp->setupViewport();
- renderDoF(&mRT->mScreen, &mPostMap);
- LLRenderTarget* final_targetp = &mRT->mScreen;
- LLRenderTarget* work_targetp = &mPostMap;
- static LLCachedControl<bool> use_smaa(gSavedSettings,
- "RenderDeferredUseSMAA");
- if (use_smaa && LLViewerShaderMgr::sHasSMAA)
- {
- applySMAA(work_targetp, final_targetp);
- }
- else
- {
- applyFXAA(work_targetp, final_targetp);
- }
- if (RenderDeferredAASharpen && LLViewerShaderMgr::sHasCAS)
- {
- LLRenderTarget* tempp = work_targetp;
- work_targetp = final_targetp;
- final_targetp = tempp;
- applyCAS(work_targetp, final_targetp);
- }
- if (RenderBufferVisualization > -1)
- {
- final_targetp = work_targetp;
- if (RenderBufferVisualization == 4)
- {
- visualizeBuffers(&mLuminanceMap, final_targetp, 0);
- }
- else
- {
- visualizeBuffers(&mRT->mDeferredScreen, final_targetp,
- RenderBufferVisualization);
- }
- }
- // Present the screen target
- gDeferredPostNoDoFProgram.bind();
- // Whatever is last in the above post processing chain should _always_ be
- // rendered directly here. If not, expect problems.
- gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- final_targetp);
- gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH,
- &mRT->mDeferredScreen, true);
- {
- LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- gDeferredPostNoDoFProgram.unbind();
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- if (hasRenderDebugMask(RENDER_DEBUG_PHYSICS_SHAPES))
- {
- renderPhysicsDisplay();
- }
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- void LLPipeline::renderFinalize()
- {
- if (gUsePBRShaders)
- {
- renderFinalizePBR();
- return;
- }
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- if (gUseWireframe)
- {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- LLVector2 tc1;
- LLVector2 tc2((F32)(mRT->mScreen.getWidth() * 2),
- (F32)(mRT->mScreen.getHeight() * 2));
- LL_FAST_TIMER(FTM_RENDER_BLOOM);
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- LLGLDepthTest depth(GL_FALSE);
- LLGLDisable blend(GL_BLEND);
- LLGLDisable cull(GL_CULL_FACE);
- enableLightsFullbright();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.setColorMask(true, true);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- if (RenderGlow)
- {
- mGlow[2].bindTarget();
- mGlow[2].clear();
- gGlowExtractProgram.bind();
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MIN_LUMINANCE,
- RenderGlowMinLuminance);
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MAX_EXTRACT_ALPHA,
- RenderGlowMaxExtractAlpha);
- gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_LUM_WEIGHTS,
- RenderGlowLumWeights.mV[0],
- RenderGlowLumWeights.mV[1],
- RenderGlowLumWeights.mV[2]);
- gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_WARMTH_WEIGHTS,
- RenderGlowWarmthWeights.mV[0],
- RenderGlowWarmthWeights.mV[1],
- RenderGlowWarmthWeights.mV[2]);
- gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_WARMTH_AMOUNT,
- RenderGlowWarmthAmount);
- {
- LLGLEnable blend_on(GL_BLEND);
- gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
- mRT->mScreen.bindTexture(0, 0, LLTexUnit::TFO_POINT);
- gGL.color4f(1.f, 1.f, 1.f, 1.f);
- enableLightsFullbright();
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- unit0->unbind(mRT->mScreen.getUsage());
- mGlow[2].flush();
- }
- tc1.set(0, 0);
- tc2.set(2, 2);
- // Power of two between 1 and 1024
- const U32 glow_res = llclamp(1 << RenderGlowResolutionPow, 1, 1024);
- S32 kernel = RenderGlowIterations * 2;
- F32 delta = RenderGlowWidth / (F32)glow_res;
- // Use half the glow width if we have the res set to less than 9 so
- // that it looks almost the same in either case.
- if (RenderGlowResolutionPow < 9)
- {
- delta *= 0.5f;
- }
- gGlowProgram.bind();
- gGlowProgram.uniform1f(LLShaderMgr::GLOW_STRENGTH, RenderGlowStrength);
- for (S32 i = 0; i < kernel; ++i)
- {
- mGlow[i % 2].bindTarget();
- mGlow[i % 2].clear();
- if (i == 0)
- {
- unit0->bind(&mGlow[2]);
- }
- else
- {
- unit0->bind(&mGlow[(i - 1) % 2]);
- }
- if (i % 2 == 0)
- {
- gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, delta, 0.f);
- }
- else
- {
- gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, 0.f, delta);
- }
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- mGlow[i % 2].flush();
- }
- gGlowProgram.unbind();
- }
- else // Skip the glow ping-pong and just clear the result target
- {
- mGlow[1].bindTarget();
- mGlow[1].clear();
- mGlow[1].flush();
- }
- gViewerWindowp->setupViewport();
- tc2.set((F32)mRT->mScreen.getWidth(), (F32)mRT->mScreen.getHeight());
- gGL.flush();
- LLVertexBuffer::unbind();
- stop_glerror();
- if (sRenderDeferred)
- {
- bool dof_enabled = RenderDepthOfField &&
- (RenderDepthOfFieldInEditMode ||
- !gToolMgr.inBuildMode()) &&
- !gViewerCamera.cameraUnderWater();
- bool multisample = RenderFSAASamples > 1 &&
- mFXAABuffer.isComplete();
- if (dof_enabled)
- {
- // Depth of field focal plane calculations
- F32 subject_dist, blur_constant, magnification;
- calc_doff_params(subject_dist, blur_constant, magnification);
- LLGLDisable blend(GL_BLEND);
- // Build diffuse + bloom + CoF
- mRT->mDeferredLight.bindTarget();
- LLGLSLShader* shaderp = &gDeferredCoFProgram;
- bindDeferredShader(*shaderp);
- S32 channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mScreen.getUsage());
- if (channel > -1)
- {
- mRT->mScreen.bindTexture(0, channel);
- }
- shaderp->uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_dist);
- shaderp->uniform1f(LLShaderMgr::DOF_BLUR_CONSTANT, blur_constant);
- shaderp->uniform1f(LLShaderMgr::DOF_TAN_PIXEL_ANGLE,
- tanf(1.f / LLDrawable::sCurPixelAngle));
- shaderp->uniform1f(LLShaderMgr::DOF_MAGNIFICATION, magnification);
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- unbindDeferredShader(*shaderp);
- mRT->mDeferredLight.flush();
- U32 dof_width = U32(mRT->mScreen.getWidth() * CameraDoFResScale);
- U32 dof_height = U32(mRT->mScreen.getHeight() * CameraDoFResScale);
- // Perform DoF sampling at half-res (preserve alpha channel)
- mRT->mScreen.bindTarget();
- glViewport(0, 0, dof_width, dof_height);
- gGL.setColorMask(true, false);
- shaderp = &gDeferredPostProgram;
- bindDeferredShader(*shaderp);
- channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mDeferredLight.getUsage());
- if (channel > -1)
- {
- mRT->mDeferredLight.bindTexture(0, channel);
- }
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- unbindDeferredShader(*shaderp);
- mRT->mScreen.flush();
- gGL.setColorMask(true, true);
- // Combine result based on alpha
- if (multisample)
- {
- mRT->mDeferredLight.bindTarget();
- glViewport(0, 0, mRT->mDeferredScreen.getWidth(),
- mRT->mDeferredScreen.getHeight());
- }
- else
- {
- gViewerWindowp->setupViewport();
- }
- shaderp = &gDeferredDoFCombineProgram;
- bindDeferredShader(*shaderp);
- channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mScreen.getUsage());
- if (channel > -1)
- {
- mRT->mScreen.bindTexture(0, channel);
- }
- shaderp->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
- shaderp->uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
- shaderp->uniform1f(LLShaderMgr::DOF_WIDTH, dof_width - 1);
- shaderp->uniform1f(LLShaderMgr::DOF_HEIGHT, dof_height - 1);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- unbindDeferredShader(*shaderp);
- if (multisample)
- {
- mRT->mDeferredLight.flush();
- }
- }
- else
- {
- if (multisample)
- {
- mRT->mDeferredLight.bindTarget();
- }
- LLGLSLShader* shaderp = &gDeferredPostNoDoFProgram;
- bindDeferredShader(*shaderp);
- S32 channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mScreen.getUsage());
- if (channel > -1)
- {
- mRT->mScreen.bindTexture(0, channel);
- }
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- unbindDeferredShader(*shaderp);
- if (multisample)
- {
- mRT->mDeferredLight.flush();
- }
- }
- if (multisample)
- {
- static LLCachedControl<bool> use_smaa(gSavedSettings,
- "RenderDeferredUseSMAA");
- static LLCachedControl<bool> use_stencil(gSavedSettings,
- "RenderDeferredUseSMAAStencil");
- if (use_smaa && LLViewerShaderMgr::sHasSMAA && mAreaMap &&
- mSearchMap && mSMAAEdgeBuffer.isComplete() &&
- mSMAABlendBuffer.isComplete() && mScratchBuffer.isComplete())
- {
- // Note: all buffers got the same size.
- S32 width = mRT->mScreen.getWidth();
- S32 height = mRT->mScreen.getHeight();
- mFXAABuffer.copyContents(mRT->mDeferredLight, 0, 0, width,
- height, 0, 0, width, height,
- GL_COLOR_BUFFER_BIT, GL_NEAREST);
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- glViewport(0, 0, width, height);
- F32 rt_metrics[] = { 1.f / width, 1.f / height,
- (F32)width, (F32)height };
- LLTexUnit* unit1 = gGL.getTexUnit(1);
- LLTexUnit* unit2 = gGL.getTexUnit(2);
- LLGLSLShader* shaderp;
- LLRenderTarget* targetp;
- {
- LLGLState stencil(GL_STENCIL_TEST, use_stencil);
- shaderp = &gPostSMAAEdgeDetect[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mFXAABuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- targetp = &mSMAAEdgeBuffer;
- targetp->bindTarget();
- targetp->clear(GL_COLOR_BUFFER_BIT |
- GL_STENCIL_BUFFER_BIT);
- if (use_stencil)
- {
- glStencilFunc(GL_ALWAYS, 1, 0xFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
- glStencilMask(0xFF);
- }
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- targetp->flush();
- unit0->disable();
- }
- {
- LLGLState stencil(GL_STENCIL_TEST, use_stencil);
- shaderp = &gPostSMAABlendWeights[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mSMAAEdgeBuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- unit1->bindManual(LLTexUnit::TT_TEXTURE, mAreaMap);
- unit1->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit1->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit1->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- unit2->bindManual(LLTexUnit::TT_TEXTURE, mSearchMap);
- unit2->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unit2->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit2->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- targetp = &mSMAABlendBuffer;
- targetp->bindTarget();
- targetp->clear(GL_COLOR_BUFFER_BIT);
- if (use_stencil)
- {
- glStencilFunc(GL_EQUAL, 1, 0xFF);
- glStencilMask(0x00);
- }
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- if (use_stencil)
- {
- glStencilFunc(GL_ALWAYS, 0, 0xFF);
- }
- shaderp->unbind();
- targetp->flush();
- unit0->disable();
- unit1->disable();
- unit2->disable();
- }
- {
- LLGLDisable stencil(GL_STENCIL_TEST);
- shaderp =
- &gPostSMAANeighborhoodBlend[RenderDeferredAAQuality];
- shaderp->bind();
- shaderp->uniform4fv(sSmaaRTMetrics, 1, rt_metrics);
- mFXAABuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- mSMAABlendBuffer.bindTexture(0, 1,
- LLTexUnit::TFO_BILINEAR);
- unit1->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit1->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- if (RenderDeferredAASharpen)
- {
- targetp = &mScratchBuffer;
- targetp->bindTarget();
- targetp->clear(GL_COLOR_BUFFER_BIT);
- }
- else
- {
- gViewerWindowp->setupViewport();
- }
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- if (RenderDeferredAASharpen)
- {
- targetp->flush();
- }
- unit0->disable();
- unit1->disable();
- }
- }
- else if (LLViewerShaderMgr::sHasFXAA)
- {
- // Bake out texture2D with RGBL for FXAA shader
- mFXAABuffer.bindTarget();
- S32 width = mRT->mScreen.getWidth();
- S32 height = mRT->mScreen.getHeight();
- glViewport(0, 0, width, height);
- LLGLSLShader* shaderp = &gGlowCombineFXAAProgram;
- shaderp->bind();
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, width,
- height);
- S32 channel =
- shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mDeferredLight.getUsage());
- if (channel > -1)
- {
- mRT->mDeferredLight.bindTexture(0, channel);
- }
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mDeferredLight.getUsage());
- shaderp->unbind();
- mFXAABuffer.flush();
- shaderp = &gFXAAProgram[RenderDeferredAAQuality];
- shaderp->bind();
- channel = shaderp->enableTexture(LLShaderMgr::DIFFUSE_MAP,
- mFXAABuffer.getUsage());
- if (channel > -1)
- {
- mFXAABuffer.bindTexture(0, channel,
- LLTexUnit::TFO_BILINEAR);
- }
- if (RenderDeferredAASharpen)
- {
- mScratchBuffer.bindTarget();
- glClearColor(0.f, 0.f, 0.f, 0.f);
- mScratchBuffer.clear(GL_COLOR_BUFFER_BIT);
- }
- else
- {
- gViewerWindowp->setupViewport();
- }
- F32 inv_width = 1.f / F32(mFXAABuffer.getWidth());
- F32 inv_height = 1.f / F32(mFXAABuffer.getHeight());
- F32 scale_x = F32(width) * inv_width;
- F32 scale_y = F32(height) * inv_height;
- shaderp->uniform2f(LLShaderMgr::FXAA_TC_SCALE, scale_x, scale_y);
- shaderp->uniform2f(LLShaderMgr::FXAA_RCP_SCREEN_RES, inv_width,
- inv_height);
- shaderp->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT,
- -0.5f * inv_width, -0.5f * inv_height,
- 0.5f * inv_width, 0.5f * inv_height);
- shaderp->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT2,
- -2.f * inv_width, -2.f * inv_height,
- 2.f * inv_width, 2.f * inv_height);
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- shaderp->unbind();
- if (RenderDeferredAASharpen)
- {
- mScratchBuffer.flush();
- }
- unit0->disable();
- }
- if (RenderDeferredAASharpen && LLViewerShaderMgr::sHasCAS)
- {
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- gPostCASProgram.bind();
- static LLCachedControl<LLVector3>
- cas_params(gSavedSettings, "RenderDeferredCASParams");
- LLVector3 params = LLVector3(cas_params);
- params.clamp(0.f, 1.f);
- gPostCASProgram.uniform3fv(sSharpness, 1, params.mV);
- mScratchBuffer.bindTexture(0, 0, LLTexUnit::TFO_BILINEAR);
- unit0->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- unit0->setTextureColorSpace(LLTexUnit::TCS_LINEAR);
- gViewerWindowp->setupViewport();
- mScreenTriangleVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- gPostCASProgram.unbind();
- unit0->disable();
- }
- }
- }
- else
- {
- LLStrider<LLVector2> uv2;
- if (mGlowCombineVB.isNull() ||
- !mGlowCombineVB->getTexCoord1Strider(uv2))
- {
- return;
- }
- uv2[0].clear();
- uv2[1] = LLVector2(0.f, tc2.mV[1] * 2.f);
- uv2[2] = LLVector2(tc2.mV[0] * 2.f, 0.f);
- LLGLDisable blend(GL_BLEND);
- LLTexUnit* unit1 = gGL.getTexUnit(1);
- gGlowCombineProgram.bind();
- unit0->bind(&mGlow[1]);
- unit1->bind(&mRT->mScreen);
- LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE : 0);
- mGlowCombineVB->setBuffer(AUX_VB_MASK);
- mGlowCombineVB->drawArrays(LLRender::TRIANGLE_STRIP, 0, 3);
- gGlowCombineProgram.unbind();
- }
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- if (hasRenderDebugMask(RENDER_DEBUG_PHYSICS_SHAPES))
- {
- gSplatTextureRectProgram.bind();
- gGL.setColorMask(true, false);
- LLVector2 tc1;
- LLVector2 tc2((F32)gViewerWindowp->getWindowDisplayWidth() * 2,
- (F32)gViewerWindowp->getWindowDisplayHeight() * 2);
- LLGLEnable blend(GL_BLEND);
- gGL.color4f(1.f, 1.f, 1.f, 0.75f);
- unit0->bind(&mPhysicsDisplay);
- gGL.begin(LLRender::TRIANGLES);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end(true);
- gSplatTextureRectProgram.unbind();
- }
- if (LLRenderTarget::sUseFBO && mRT->mScreen.getFBO())
- {
- // Copy depth buffer from mScreen to framebuffer
- LLRenderTarget::copyContentsToFramebuffer(mRT->mScreen, 0, 0,
- mRT->mScreen.getWidth(),
- mRT->mScreen.getHeight(),
- 0, 0,
- mRT->mScreen.getWidth(),
- mRT->mScreen.getHeight(),
- GL_DEPTH_BUFFER_BIT,
- GL_NEAREST);
- }
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- void LLPipeline::bindLightFunc(LLGLSLShader& shader)
- {
- S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
- if (channel > -1)
- {
- gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
- }
- if (gUsePBRShaders)
- {
- channel = shader.enableTexture(LLShaderMgr::DEFERRED_BRDF_LUT,
- LLTexUnit::TT_TEXTURE);
- if (channel > -1)
- {
- mPbrBrdfLut.bindTexture(0, channel);
- }
- }
- stop_glerror();
- }
- void LLPipeline::bindShadowMaps(LLGLSLShader& shader)
- {
- if (gUsePBRShaders)
- {
- for (U32 i = 0; i < 4; ++i)
- {
- LLRenderTarget* shadow_targetp = &mRT->mSunShadow[i];
- if (!shadow_targetp) continue;
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i,
- LLTexUnit::TT_TEXTURE);
- if (chan > -1)
- {
- gGL.getTexUnit(chan)->bind(shadow_targetp, true);
- }
- }
- for (U32 i = 4; i < 6; ++i)
- {
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i);
- if (chan > -1)
- {
- LLRenderTarget* shadow_targetp = &mSpotShadow[i - 4];
- if (shadow_targetp)
- {
- gGL.getTexUnit(chan)->bind(shadow_targetp, true);
- }
- }
- }
- stop_glerror();
- return;
- }
- for (U32 i = 0; i < 4; ++i)
- {
- LLRenderTarget* shadow_targetp = &mShadow[i];
- if (!shadow_targetp) continue;
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i,
- LLTexUnit::TT_TEXTURE);
- if (chan <= -1) continue;
- LLTexUnit* unitp = gGL.getTexUnit(chan);
- unitp->bind(shadow_targetp, true);
- unitp->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unitp->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_COMPARE_R_TO_TEXTURE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- }
- for (U32 i = 4; i < 6; ++i)
- {
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i);
- if (chan <= -1) continue;
- LLRenderTarget* shadow_targetp = &mShadow[i];
- if (!shadow_targetp) continue;
- LLTexUnit* unitp = gGL.getTexUnit(chan);
- unitp->bind(shadow_targetp);
- unitp->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
- unitp->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_COMPARE_R_TO_TEXTURE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- }
- stop_glerror();
- }
- void LLPipeline::setEnvMat(LLGLSLShader& shader)
- {
- F32* m = gGLModelView.getF32ptr();
- F32 mat[] =
- {
- m[0], m[1], m[2],
- m[4], m[5], m[6],
- m[8], m[9], m[10]
- };
- shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, GL_TRUE, mat);
- }
- void LLPipeline::bindReflectionProbes(LLGLSLShader& shader)
- {
- if (!sReflectionProbesEnabled)
- {
- return;
- }
- bool bound = false;
- S32 chan = shader.enableTexture(LLShaderMgr::REFLECTION_PROBES,
- LLTexUnit::TT_CUBE_MAP_ARRAY);
- if (chan > -1 && mReflectionMapManager.mTexture.notNull())
- {
- mReflectionMapManager.mTexture->bind(chan);
- bound = true;
- }
- chan = shader.enableTexture(LLShaderMgr::IRRADIANCE_PROBES,
- LLTexUnit::TT_CUBE_MAP_ARRAY);
- if (chan > -1 && mReflectionMapManager.mIrradianceMaps.notNull())
- {
- mReflectionMapManager.mIrradianceMaps->bind(chan);
- bound = true;
- }
- if (sRenderMirrors)
- {
- chan = shader.enableTexture(LLShaderMgr::HERO_PROBE,
- LLTexUnit::TT_CUBE_MAP_ARRAY);
- if (chan > -1 && mHeroProbeManager.mTexture.notNull())
- {
- mHeroProbeManager.mTexture->bind(chan);
- bound = true;
- }
- }
- if (bound)
- {
- mReflectionMapManager.setUniforms();
- setEnvMat(shader);
- }
- // Reflection probe shaders generally sample the scene map as well for SSR
- chan = shader.enableTexture(LLShaderMgr::SCENE_MAP);
- if (chan > -1)
- {
- gGL.getTexUnit(chan)->bind(&mSceneMap);
- }
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ITR_COUNT,
- RenderScreenSpaceReflectionIterations);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_DIST_BIAS,
- RenderScreenSpaceReflectionDistanceBias);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_RAY_STEP,
- RenderScreenSpaceReflectionRayStep);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_GLOSSY_SAMPLES,
- RenderScreenSpaceReflectionGlossySamples);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_REJECT_BIAS,
- RenderScreenSpaceReflectionDepthRejectBias);
- if (++mPoissonOffset + RenderScreenSpaceReflectionGlossySamples > 128)
- {
- mPoissonOffset = 0;
- }
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_NOISE_SINE,
- F32(mPoissonOffset));
- shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ADAPTIVE_STEP_MULT,
- RenderScreenSpaceReflectionAdaptiveStepMultiplier);
- chan = shader.enableTexture(LLShaderMgr::SCENE_DEPTH);
- if (chan > -1)
- {
- gGL.getTexUnit(chan)->bind(&mSceneMap, true);
- }
- }
- void LLPipeline::unbindReflectionProbes(LLGLSLShader& shader)
- {
- S32 chan = shader.disableTexture(LLShaderMgr::REFLECTION_PROBES,
- LLTexUnit::TT_CUBE_MAP);
- if (chan > -1 && mReflectionMapManager.mTexture.notNull())
- {
- mReflectionMapManager.mTexture->unbind();
- if (chan == 0)
- {
- gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
- }
- }
- }
- void LLPipeline::bindDeferredShaderFast(LLGLSLShader& shader)
- {
- // Note: what happens if a shader is flagged mCanBindFast with mMainRT,
- // then reused just after with mAuxillaryRT ?... The wrong render target
- // would be bound and used. I therefore added the is_main_rt tests. HB
- bool is_main_rt = mRT == &mMainRT;
- if (is_main_rt && shader.mCanBindFast)
- {
- shader.bind();
- bindLightFunc(shader);
- bindShadowMaps(shader);
- if (gUsePBRShaders)
- {
- bindReflectionProbes(shader);
- }
- }
- else
- {
- // Was not previously bound, use slow path
- bindDeferredShader(shader);
- shader.mCanBindFast = is_main_rt;
- }
- }
- void LLPipeline::bindDeferredShader(LLGLSLShader& shader,
- LLRenderTarget* light_targetp,
- LLRenderTarget* depth_targetp)
- {
- LL_FAST_TIMER(FTM_BIND_DEFERRED);
- LLRenderTarget* deferred_targetp = &mRT->mDeferredScreen;
- // Note: the EE renderer uses a different buffer for depth target.
- if (!gUsePBRShaders)
- {
- depth_targetp = &mDeferredDepth;
- }
- else if (!depth_targetp)
- {
- depth_targetp = deferred_targetp;
- }
- shader.bind();
- LLTexUnit::eTextureType usage = deferred_targetp->getUsage();
- S32 chan = shader.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, usage);
- if (chan > -1)
- {
- deferred_targetp->bindTexture(0, chan, LLTexUnit::TFO_POINT);
- if (gUsePBRShaders)
- {
- gGL.getTexUnit(chan)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- }
- }
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_SPECULAR, usage);
- if (chan > -1)
- {
- deferred_targetp->bindTexture(1, chan, LLTexUnit::TFO_POINT);
- if (gUsePBRShaders)
- {
- gGL.getTexUnit(chan)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- }
- }
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_NORMAL, usage);
- if (chan > -1)
- {
- deferred_targetp->bindTexture(2, chan, LLTexUnit::TFO_POINT);
- if (gUsePBRShaders)
- {
- gGL.getTexUnit(chan)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- }
- }
- if (gUsePBRShaders)
- {
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE, usage);
- if (chan > -1)
- {
- deferred_targetp->bindTexture(3, chan, LLTexUnit::TFO_POINT);
- gGL.getTexUnit(chan)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
- }
- }
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_DEPTH,
- depth_targetp->getUsage());
- if (chan > -1)
- {
- gGL.getTexUnit(chan)->bind(depth_targetp, true);
- stop_glerror();
- }
- if (gUsePBRShaders)
- {
- chan = shader.enableTexture(LLShaderMgr::EXPOSURE_MAP);
- if (chan > -1)
- {
- gGL.getTexUnit(chan)->bind(&mExposureMap);
- }
- }
- else if (shader.getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX) != -1)
- {
- // This is done in LLRender::syncMatrices() for PBR shaders, but would
- // not be enough for EE rendering, due to a bug involving the deferred
- // renderer regular pushing and popping of matrices.
- LLMatrix4a inv_proj = gGLProjection;
- inv_proj.invert();
- shader.uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1,
- GL_FALSE, inv_proj.getF32ptr());
- }
- if (shader.getUniformLocation(LLShaderMgr::VIEWPORT) != -1)
- {
- shader.uniform4f(LLShaderMgr::VIEWPORT, (F32)gGLViewport[0],
- (F32)gGLViewport[1], (F32)gGLViewport[2],
- (F32)gGLViewport[3]);
- }
- // Note: mReflectionModelView is never calculated for PBR rendering, and
- // sReflectionRender is normally never true, but I added !gUsePBRShaders
- // for good measure. HB
- if (!gUsePBRShaders && sReflectionRender &&
- shader.getUniformLocation(LLShaderMgr::MODELVIEW_MATRIX) != -1)
- {
- shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_MATRIX, 1, GL_FALSE,
- mReflectionModelView.getF32ptr());
- }
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE);
- if (chan > -1)
- {
- LLTexUnit* unitp = gGL.getTexUnit(chan);
- unitp->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
- unitp->setTextureFilteringOption(LLTexUnit::TFO_POINT);
- }
- bindLightFunc(shader);
- if (!light_targetp)
- {
- light_targetp = &mRT->mDeferredLight;
- }
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT,
- light_targetp->getUsage());
- if (chan > -1)
- {
- if (!gUsePBRShaders || light_targetp->isComplete())
- {
- light_targetp->bindTexture(0, chan, LLTexUnit::TFO_POINT);
- }
- else
- {
- gGL.getTexUnit(chan)->bindFast(LLViewerFetchedTexture::sWhiteImagep);
- }
- }
- if (!gUsePBRShaders)
- {
- chan = shader.enableTexture(LLShaderMgr::DEFERRED_BLOOM);
- if (chan > -1)
- {
- mGlow[1].bindTexture(0, chan);
- }
- }
- stop_glerror();
- #if OPTIMIZED_UNIFORMS
- if (shader.mFeatures.hasShadows)
- #endif
- {
- bindShadowMaps(shader);
- F32 mat[16 * 6];
- constexpr size_t total_bytes = sizeof(F32) * 16 * 6;
- memcpy((void*)mat, (void*)mSunShadowMatrix, total_bytes);
- shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_SHADOW_MATRIX, 6,
- GL_FALSE, mat);
- shader.uniform4fv(LLShaderMgr::DEFERRED_SHADOW_CLIP, 1,
- mSunClipPlanes.mV);
- if (gUsePBRShaders)
- {
- shader.uniform2f(LLShaderMgr::DEFERRED_SHADOW_RES,
- mRT->mSunShadow[0].getWidth(),
- mRT->mSunShadow[0].getHeight());
- shader.uniform2f(LLShaderMgr::DEFERRED_PROJ_SHADOW_RES,
- mSpotShadow[0].getWidth(),
- mSpotShadow[0].getHeight());
- }
- else
- {
- shader.uniform2f(LLShaderMgr::DEFERRED_SHADOW_RES,
- mShadow[0].getWidth(),
- mShadow[0].getHeight());
- shader.uniform2f(LLShaderMgr::DEFERRED_PROJ_SHADOW_RES,
- mShadow[4].getWidth(),
- mShadow[4].getHeight());
- }
- shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_OFFSET,
- RenderDeferredSSAO ? RenderShadowOffset
- : RenderShadowOffsetNoSSAO);
- constexpr F32 ONEBYTHREETHOUSANDS = 1.f / 3000.f;
- F32 shadow_bias_error = RenderShadowBiasError * ONEBYTHREETHOUSANDS *
- fabsf(gViewerCamera.getOrigin().mV[2]);
- shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_BIAS,
- RenderShadowBias + shadow_bias_error);
- shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_OFFSET,
- RenderSpotShadowOffset);
- shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_BIAS,
- RenderSpotShadowBias);
- }
- #if DEBUG_OPTIMIZED_UNIFORMS && OPTIMIZED_UNIFORMS
- else if (shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW0) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW_MATRIX) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW_CLIP) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW_RES) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW_OFFSET) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SHADOW_BIAS) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SPOT_SHADOW_OFFSET) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SPOT_SHADOW_BIAS) >= 0)
- {
- llwarns_once << "Shader: " << shader.mName
- << " shall be marked as hasShadows !" << llendl;
- }
- #endif
- if (!sReflectionProbesEnabled)
- {
- chan = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP,
- LLTexUnit::TT_CUBE_MAP);
- if (chan > -1)
- {
- LLCubeMap* cube_mapp = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap()
- : NULL;
- if (cube_mapp)
- {
- cube_mapp->enableTexture(chan);
- cube_mapp->bind();
- const F32* m = gGLModelView.getF32ptr();
- F32 mat[] = { m[0], m[1], m[2],
- m[4], m[5], m[6],
- m[8], m[9], m[10] };
- shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1,
- GL_TRUE, mat);
- }
- }
- }
- if (gUsePBRShaders)
- {
- bindReflectionProbes(shader);
- shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_DELTA_MATRIX, 1,
- GL_FALSE, gGLDeltaModelView.getF32ptr());
- shader.uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_DELTA_MATRIX, 1,
- GL_FALSE,
- gGLInverseDeltaModelView.getF32ptr());
- shader.uniform1i(LLShaderMgr::CUBE_SNAPSHOT, gCubeSnapshot ? 1 : 0);
- }
- shader.uniform1f(LLShaderMgr::DEFERRED_SUN_WASH, RenderDeferredSunWash);
- shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_NOISE, RenderShadowNoise);
- shader.uniform1f(LLShaderMgr::DEFERRED_BLUR_SIZE, RenderShadowBlurSize);
- #if OPTIMIZED_UNIFORMS
- if (shader.mFeatures.hasAmbientOcclusion)
- #endif
- {
- shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS,
- RenderSSAOMaxScale);
- shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR, RenderSSAOFactor);
- }
- #if DEBUG_OPTIMIZED_UNIFORMS && OPTIMIZED_UNIFORMS
- else if (shader.getUniformLocation(LLShaderMgr::DEFERRED_SSAO_RADIUS) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::DEFERRED_SSAO_FACTOR) >= 0)
- {
- llwarns_once << "Shader: " << shader.mName
- << " shall be marked as hasAmbientOcclusion !" << llendl;
- }
- #endif
- constexpr F32 ONETHIRD = 1.f / 3.f;
- F32 matrix_diag = (RenderSSAOEffect[0] + 2.f * RenderSSAOEffect[1]) *
- ONETHIRD;
- F32 matrix_nondiag = (RenderSSAOEffect[0] - RenderSSAOEffect[1]) *
- ONETHIRD;
- // This matrix scales (proj of color onto <1/rt(3),1/rt(3),1/rt(3)>) by
- // value factor, and scales remainder by saturation factor
- F32 ssao_effect_mat[] =
- {
- matrix_diag, matrix_nondiag, matrix_nondiag,
- matrix_nondiag, matrix_diag, matrix_nondiag,
- matrix_nondiag, matrix_nondiag, matrix_diag
- };
- shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_SSAO_EFFECT_MAT, 1, GL_FALSE,
- ssao_effect_mat);
- shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- deferred_targetp->getWidth(),
- deferred_targetp->getHeight());
- shader.uniform1f(LLShaderMgr::DEFERRED_NEAR_CLIP,
- gViewerCamera.getNear() * 2.f);
- shader.uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1,
- mTransformedSunDir.getF32ptr());
- shader.uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1,
- mTransformedMoonDir.getF32ptr());
- if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) > -1)
- {
- LLMatrix4a norm_mat = gGLModelView;
- norm_mat.invert();
- norm_mat.transpose();
- shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, GL_FALSE,
- norm_mat.getF32ptr());
- }
- if (gUsePBRShaders)
- {
- shader.uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, 1,
- mSunLightColorScaled.mV);
- shader.uniform3fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonLightColor.mV);
- shader.uniform1f(LLShaderMgr::REFLECTION_PROBE_MAX_LOD,
- mReflectionMapManager.mMaxProbeLOD);
- }
- else
- {
- shader.uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, mSunLightColor.mV);
- shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonLightColor.mV);
- }
- gEnvironment.updateShaderSkyUniforms(&shader);
- }
- // Branched version for the PBR renderer
- void LLPipeline::renderDeferredLightingPBR()
- {
- F32 light_scale = gCubeSnapshot ? mReflectionMapManager.mLightScale : 1.f;
- LLRenderTarget* screen_targetp = &mRT->mScreen;
- LLRenderTarget* light_targetp = &mRT->mDeferredLight;
- LLGLSLShader* shaderp;
- {
- LL_FAST_TIMER(FTM_RENDER_DEFERRED);
- if (hasRenderType(LLPipeline::RENDER_TYPE_HUD))
- {
- toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
- }
- gGL.setColorMask(true, true);
- // Draw a cube around every light
- LLVertexBuffer::unbind();
- LLGLEnable cull(GL_CULL_FACE);
- LLGLEnable blend(GL_BLEND);
- setupHWLights();
- mTransformedSunDir.loadua(mSunDir.mV);
- gGLModelView.rotate(mTransformedSunDir, mTransformedSunDir);
- mTransformedMoonDir.loadua(mMoonDir.mV);
- gGLModelView.rotate(mTransformedMoonDir, mTransformedMoonDir);
- if (RenderDeferredSSAO || RenderShadowDetail > 0)
- {
- // Paint shadow/SSAO light map (direct lighting lightmap)
- LL_FAST_TIMER(FTM_SUN_SHADOW);
- light_targetp->bindTarget();
- shaderp = &gDeferredSunProgram;
- bindDeferredShader(*shaderp, light_targetp);
- mScreenTriangleVB->setBuffer();
- glClearColor(1.f, 1.f, 1.f, 1.f);
- light_targetp->clear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- #if 0 // The "offset" uniform does not appear to be used... HB
- static LLStaticHashedString sOffset("offset");
- LLMatrix4a inv_trans = gGLModelView;
- inv_trans.invert();
- inv_trans.transpose();
- constexpr U32 slices = 32;
- F32 offset[slices * 3];
- constexpr F32 indice_to_rad = F_PI / 4.f;
- for (U32 i = 0; i < 4; ++i)
- {
- F32 z = -i;
- for (U32 j = 0; j < 8; ++j)
- {
- F32 angle = indice_to_rad * j;
- LLVector4a v(sinf(angle), cosf(angle), z);
- inv_trans.affineTransform(v, v);
- v.normalize3();
- U32 idx = 3 * (8 * i + j);
- offset[idx++] = v[0];
- offset[idx++] = v[2];
- offset[idx] = v[1];
- }
- }
- shaderp->uniform3fv(sOffset, slices, offset);
- #endif
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- light_targetp->getWidth(),
- light_targetp->getHeight());
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- unbindDeferredShader(*shaderp);
- light_targetp->flush();
- }
- if (RenderShadowSoften)
- {
- // Soften direct lighting lightmap
- LL_FAST_TIMER(FTM_SOFTEN_SHADOW);
- // Blur lightmap
- screen_targetp->bindTarget();
- glClearColor(1.f, 1.f, 1.f, 1.f);
- screen_targetp->clear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- shaderp = &gDeferredBlurLightProgram;
- bindDeferredShader(*shaderp);
- // Sample symmetrically with the middle sample falling exactly on
- // 0.0
- F32 x = 0.f;
- F32 shadow_gaussian_x = RenderShadowGaussian.mV[0];
- F32 shadow_gaussian_y = RenderShadowGaussian.mV[1];
- constexpr U32 kern_length = 4;
- LLVector3 gauss[kern_length]; // xweight, yweight, offset
- for (U32 i = 0; i < kern_length; ++i)
- {
- gauss[i].mV[0] = llgaussian(x, shadow_gaussian_x);
- gauss[i].mV[1] = llgaussian(x, shadow_gaussian_y);
- gauss[i].mV[2] = x;
- x += 1.f;
- }
- shaderp->uniform2f(sDelta, 1.f, 0.f);
- shaderp->uniform1f(sDistFactor, RenderShadowBlurDistFactor);
- shaderp->uniform3fv(sKern, kern_length, gauss[0].mV);
- shaderp->uniform1f(sKernScale,
- RenderShadowBlurSize *
- (kern_length * 0.5f - 0.5f));
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- screen_targetp->flush();
- unbindDeferredShader(*shaderp);
- bindDeferredShader(*shaderp, screen_targetp);
- light_targetp->bindTarget();
- shaderp->uniform2f(sDelta, 0.f, 1.f);
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- light_targetp->flush();
- unbindDeferredShader(*shaderp);
- }
- screen_targetp->bindTarget();
- // Clear color buffer here; zeroing alpha (glow) is important or it
- // will accumulate against sky
- glClearColor(0.f, 0.f, 0.f, 0.f);
- screen_targetp->clear(GL_COLOR_BUFFER_BIT);
- if (RenderDeferredAtmospheric)
- {
- // Apply sunlight contribution
- LL_FAST_TIMER(FTM_ATMOSPHERICS);
- shaderp = &gDeferredSoftenProgram;
- bindDeferredShader(*shaderp);
- static LLCachedControl<F32> ssao_scale(gSavedSettings,
- "RenderSSAOIrradianceScale");
- static LLCachedControl<F32> ssao_max(gSavedSettings,
- "RenderSSAOIrradianceMax");
- shaderp->uniform1f(sIrradianceScale, ssao_scale);
- shaderp->uniform1f(sIrradianceMax, ssao_max);
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, mIsSunUp ? 1 : 0);
- shaderp->uniform3fv(LLShaderMgr::LIGHTNORM, 1,
- gEnvironment.getClampedLightNorm().mV);
- shaderp->uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1,
- sWaterPlane.getF32ptr());
- {
- LLGLDepthTest depth(GL_FALSE);
- LLGLDisable blend(GL_BLEND);
- // Full screen blit
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- unbindDeferredShader(*shaderp);
- }
- if (RenderLocalLightCount && mCubeVB.notNull())
- {
- gGL.setSceneBlendType(LLRender::BT_ADD);
- std::list<LLVector4> fullscreen_lights, light_colors;
- LLDrawable::draw_list_t spot_lights, fullscreen_spot_lights;
- if (!gCubeSnapshot)
- {
- for (U32 i = 0; i < 2; ++i)
- {
- mTargetShadowSpotLight[i] = NULL;
- }
- }
- LLVertexBuffer::unbind();
- {
- shaderp = &gDeferredLightProgram;
- bindDeferredShader(*shaderp);
- mCubeVB->setBuffer();
- const LLVector3& cam_origin = gViewerCamera.getOrigin();
- F32 cam_x = cam_origin.mV[0];
- F32 cam_y = cam_origin.mV[1];
- F32 cam_z = cam_origin.mV[2];
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLVector4a center, sa;
- LLColor3 col;
- U32 rendered_count = 0;
- // mNearbyLights already includes distance calculation and
- // excludes muted avatars. It is calculated from mLights and
- // also provides fade value to gracefully fade-out out of range
- // lights
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- if (++rendered_count > RenderLocalLightCount)
- {
- break;
- }
- LLDrawable* drawablep = iter->drawable;
- LLVOVolume* volp = drawablep->getVOVolume();
- if (!volp)
- {
- continue;
- }
- bool is_attachment = volp->isAttachment();
- if (is_attachment && !sRenderAttachedLights)
- {
- continue;
- }
- center.load3(drawablep->getPositionAgent().mV);
- const F32* c = center.getF32ptr();
- F32 s = volp->getLightRadius() * 1.5f;
- if (s <= 0.001f)
- {
- continue;
- }
- // Send light color to shader in linear space
- col = volp->getLightLinearColor() * light_scale;
- if (col.lengthSquared() < 0.001f)
- {
- continue;
- }
- sa.splat(s);
- if (gViewerCamera.AABBInFrustumNoFarClip(center, sa) == 0)
- {
- continue;
- }
- ++sVisibleLightCount;
- if (cam_x > c[0] + s + 0.2f || cam_x < c[0] - s - 0.2f ||
- cam_y > c[1] + s + 0.2f || cam_y < c[1] - s - 0.2f ||
- cam_z > c[2] + s + 0.2f || cam_z < c[2] - s - 0.2f)
- {
- // Draw box if camera is outside box
- if (RenderLocalLightCount)
- {
- if (volp->isLightSpotlight())
- {
- drawablep->getVOVolume()->updateSpotLightPriority();
- spot_lights.emplace_back(drawablep);
- continue;
- }
- LL_FAST_TIMER(FTM_LOCAL_LIGHTS);
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1,
- c);
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1,
- col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- gGL.syncMatrices();
- mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8,
- get_box_fan_indices(&gViewerCamera,
- center));
- }
- }
- else
- {
- if (volp->isLightSpotlight())
- {
- drawablep->getVOVolume()->updateSpotLightPriority();
- fullscreen_spot_lights.emplace_back(drawablep);
- continue;
- }
- gGLModelView.affineTransform(center, center);
- LLVector4 tc(center.getF32ptr());
- tc.mV[VW] = s;
- fullscreen_lights.emplace_back(tc);
- light_colors.emplace_back(col.mV[0], col.mV[1],
- col.mV[2],
- volp->getLightFalloff(0.5f));
- }
- }
- // When editting appearance, we need to add the corresponding
- // light at the camera position.
- static LLCachedControl<bool> custlight(gSavedSettings,
- "AvatarCustomizeLighting");
- if (custlight && isAgentAvatarValid() &&
- gAgentAvatarp->mSpecialRenderMode == 3)
- {
- fullscreen_lights.emplace_back(0.f, 0.f, 0.f, 15.f);
- light_colors.emplace_back(1.f, 1.f, 1.f, 0.f);
- }
- unbindDeferredShader(*shaderp);
- }
- if (!spot_lights.empty())
- {
- LL_FAST_TIMER(FTM_PROJECTORS);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- shaderp = &gDeferredSpotLightProgram;
- bindDeferredShader(*shaderp);
- mCubeVB->setBuffer();
- shaderp->enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- for (LLDrawable::draw_list_t::iterator
- iter = spot_lights.begin(), end = spot_lights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- LLVOVolume* volp = drawablep->getVOVolume();
- LLVector4a center;
- center.load3(drawablep->getPositionAgent().mV);
- const F32* c = center.getF32ptr();
- F32 s = volp->getLightRadius() * 1.5f;
- ++sVisibleLightCount;
- setupSpotLight(*shaderp, drawablep);
- LLColor3 col = volp->getLightLinearColor() * light_scale;
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- gGL.syncMatrices();
- mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8,
- get_box_fan_indices(&gViewerCamera,
- center));
- }
- shaderp->disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- unbindDeferredShader(*shaderp);
- }
- {
- LLGLDepthTest depth(GL_FALSE);
- constexpr U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT;
- LLVector4 light[max_count];
- LLVector4 col[max_count];
- U32 count = 0;
- F32 far_z = 0.f;
- {
- LL_FAST_TIMER(FTM_FULLSCREEN_LIGHTS);
- while (count < max_count && !fullscreen_lights.empty())
- {
- light[count] = fullscreen_lights.front();
- fullscreen_lights.pop_front();
- col[count] = light_colors.front();
- light_colors.pop_front();
- far_z = llmin(light[count].mV[2] - light[count].mV[3],
- far_z);
- if (++count == max_count || fullscreen_lights.empty())
- {
- U32 idx = count - 1;
- shaderp = &gDeferredMultiLightProgram[idx];
- bindDeferredShader(*shaderp);
- shaderp->uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT,
- count);
- shaderp->uniform4fv(LLShaderMgr::MULTI_LIGHT,
- count, (F32*)light);
- shaderp->uniform4fv(LLShaderMgr::MULTI_LIGHT_COL,
- count, (F32*)col);
- shaderp->uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z,
- far_z);
- mScreenTriangleVB->setBuffer();
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES,
- 0, 3);
- unbindDeferredShader(*shaderp);
- far_z = 0.f;
- count = 0;
- }
- }
- }
- shaderp = &gDeferredMultiSpotLightProgram;
- bindDeferredShader(*shaderp);
- shaderp->enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- mScreenTriangleVB->setBuffer();
- {
- LL_FAST_TIMER(FTM_PROJECTORS);
- for (LLDrawable::draw_list_t::iterator
- iter = fullscreen_spot_lights.begin(),
- end = fullscreen_spot_lights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- LLVOVolume* volp = drawablep->getVOVolume();
- LLVector4a center;
- center.load3(drawablep->getPositionAgent().mV);
- F32 s = volp->getLightRadius() * 1.5f;
- ++sVisibleLightCount;
- gGLModelView.affineTransform(center, center);
- setupSpotLight(*shaderp, drawablep);
- LLColor3 col = volp->getLightLinearColor() *
- light_scale;
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1,
- center.getF32ptr());
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1,
- col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- mScreenTriangleVB->drawArrays(LLRender::TRIANGLES,
- 0, 3);
- }
- }
- shaderp->disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- unbindDeferredShader(*shaderp);
- }
- }
- gGL.setColorMask(true, true);
- }
- {
- // Render non-deferred geometry (alpha, fullbright, glow)
- LLGLDisable blend(GL_BLEND);
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_ALPHA,
- RENDER_TYPE_ALPHA_PRE_WATER,
- RENDER_TYPE_ALPHA_POST_WATER,
- RENDER_TYPE_FULLBRIGHT,
- RENDER_TYPE_VOLUME,
- RENDER_TYPE_GLOW,
- RENDER_TYPE_BUMP,
- RENDER_TYPE_MAT_PBR,
- RENDER_TYPE_PASS_SIMPLE,
- RENDER_TYPE_PASS_ALPHA,
- RENDER_TYPE_PASS_ALPHA_MASK,
- RENDER_TYPE_PASS_BUMP,
- RENDER_TYPE_PASS_POST_BUMP,
- RENDER_TYPE_PASS_FULLBRIGHT,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
- RENDER_TYPE_PASS_GLOW,
- RENDER_TYPE_PASS_PBR_GLOW,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_PASS_SHINY,
- RENDER_TYPE_PASS_INVISIBLE,
- RENDER_TYPE_PASS_INVISI_SHINY,
- RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- RENDER_TYPE_ALPHA_MASK,
- RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_WATER,
- END_RENDER_TYPES);
- renderGeomPostDeferred(gViewerCamera);
- popRenderTypeMask();
- }
- screen_targetp->flush();
- if (!gCubeSnapshot)
- {
- // This is the end of the 3D scene render, grab a copy of the model
- // view and projection matrix for use in off-by-one-frame effects in
- // the next frame.
- gGLLastModelView = gGLModelView;
- gGLLastProjection = gGLProjection;
- }
- gGL.setColorMask(true, true);
- }
- void LLPipeline::renderDeferredLighting()
- {
- if (!sCull)
- {
- return;
- }
- if (gUsePBRShaders)
- {
- renderDeferredLightingPBR();
- return;
- }
- LLGLSLShader* shaderp;
- {
- LL_FAST_TIMER(FTM_RENDER_DEFERRED);
- {
- LLGLDepthTest depth(GL_TRUE);
- mDeferredDepth.copyContents(mRT->mDeferredScreen, 0, 0,
- mRT->mDeferredScreen.getWidth(),
- mRT->mDeferredScreen.getHeight(),
- 0, 0,
- mDeferredDepth.getWidth(),
- mDeferredDepth.getHeight(),
- GL_DEPTH_BUFFER_BIT, GL_NEAREST);
- }
- LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE : 0);
- if (hasRenderType(RENDER_TYPE_HUD))
- {
- toggleRenderType(RENDER_TYPE_HUD);
- }
- // ATI does not seem to love actually using the stencil buffer on FBOs
- LLGLDisable stencil(GL_STENCIL_TEST);
- #if 0
- glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);
- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
- #endif
- gGL.setColorMask(true, true);
- // Draw a cube around every light
- LLVertexBuffer::unbind();
- LLGLEnable cull(GL_CULL_FACE);
- LLGLEnable blend(GL_BLEND);
- LLStrider<LLVector3> vert;
- if (mDeferredVB.isNull() || !mDeferredVB->getVertexStrider(vert))
- {
- return;
- }
- vert[0].set(-1.f, 1.f, 0.f);
- vert[1].set(-1.f, -3.f, 0.f);
- vert[2].set(3.f, 1.f, 0.f);
- setupHWLights(); // To set mSunDir/mMoonDir;
- mTransformedSunDir.loadua(mSunDir.mV);
- gGLModelView.rotate(mTransformedSunDir, mTransformedSunDir);
- mTransformedMoonDir.loadua(mMoonDir.mV);
- gGLModelView.rotate(mTransformedMoonDir, mTransformedMoonDir);
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- if (RenderDeferredSSAO || RenderShadowDetail > 0)
- {
- mRT->mDeferredLight.bindTarget();
- {
- // Paint shadow/SSAO light map (direct lighting lightmap)
- LL_FAST_TIMER(FTM_SUN_SHADOW);
- shaderp = &gDeferredSunProgram;
- bindDeferredShader(*shaderp, &mRT->mDeferredLight);
- glClearColor(1.f, 1.f, 1.f, 1.f);
- mRT->mDeferredLight.clear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- mRT->mDeferredLight.getWidth(),
- mRT->mDeferredLight.getHeight());
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- unbindDeferredShader(*shaderp);
- }
- mRT->mDeferredLight.flush();
- }
- if (RenderShadowSoften)
- {
- // Soften direct lighting lightmap
- LL_FAST_TIMER(FTM_SOFTEN_SHADOW);
- // Blur lightmap
- mRT->mScreen.bindTarget();
- glClearColor(1.f, 1.f, 1.f, 1.f);
- mRT->mScreen.clear(GL_COLOR_BUFFER_BIT);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- shaderp = &gDeferredBlurLightProgram;
- bindDeferredShader(*shaderp);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- // Sample symmetrically with the middle sample falling exactly on
- // 0.0
- F32 x = 0.f;
- F32 shadow_gaussian_x = RenderShadowGaussian.mV[0];
- F32 shadow_gaussian_y = RenderShadowGaussian.mV[1];
- constexpr U32 kern_length = 4;
- LLVector3 gauss[kern_length]; // xweight, yweight, offset
- for (U32 i = 0; i < kern_length; ++i)
- {
- gauss[i].mV[0] = llgaussian(x, shadow_gaussian_x);
- gauss[i].mV[1] = llgaussian(x, shadow_gaussian_y);
- gauss[i].mV[2] = x;
- x += 1.f;
- }
- shaderp->uniform2f(sDelta, 1.f, 0.f);
- shaderp->uniform1f(sDistFactor, RenderShadowBlurDistFactor);
- shaderp->uniform3fv(sKern, kern_length, gauss[0].mV);
- shaderp->uniform1f(sKernScale,
- RenderShadowBlurSize *
- (kern_length * 0.5f - 0.5f));
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- mRT->mScreen.flush();
- unbindDeferredShader(*shaderp);
- bindDeferredShader(*shaderp, &mRT->mScreen);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mRT->mDeferredLight.bindTarget();
- shaderp->uniform2f(sDelta, 0.f, 1.f);
- {
- LLGLDisable blend(GL_BLEND);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- mRT->mDeferredLight.flush();
- unbindDeferredShader(*shaderp);
- }
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- mRT->mScreen.bindTarget();
- // Clear color buffer here; zeroing alpha (glow) is important or it
- // will accumulate against sky
- glClearColor(0.f, 0.f, 0.f, 0.f);
- mRT->mScreen.clear(GL_COLOR_BUFFER_BIT);
- if (RenderDeferredAtmospheric)
- {
- // Apply sunlight contribution
- LL_FAST_TIMER(FTM_ATMOSPHERICS);
- shaderp = sUnderWaterRender ? &gDeferredSoftenWaterProgram
- : &gDeferredSoftenProgram;
- bindDeferredShader(*shaderp);
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, mIsSunUp ? 1 : 0);
- shaderp->uniform4fv(LLShaderMgr::LIGHTNORM, 1,
- gEnvironment.getClampedLightNorm().mV);
- {
- LLGLDepthTest depth(GL_FALSE);
- LLGLDisable blend(GL_BLEND);
- // Full screen blit
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- }
- unbindDeferredShader(*shaderp);
- }
- {
- // Render non-deferred geometry (fullbright, alpha, etc)
- LLGLDisable blend(GL_BLEND);
- LLGLDisable stencil(GL_STENCIL_TEST);
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_SKY,
- RENDER_TYPE_CLOUDS,
- RENDER_TYPE_WL_SKY,
- END_RENDER_TYPES);
- renderGeomPostDeferred(gViewerCamera, false);
- popRenderTypeMask();
- }
- if (RenderLocalLightCount)
- {
- gGL.setSceneBlendType(LLRender::BT_ADD);
- std::list<LLVector4> fullscreen_lights, light_colors;
- LLDrawable::draw_list_t spot_lights, fullscreen_spot_lights;
- for (U32 i = 0; i < 2; ++i)
- {
- mTargetShadowSpotLight[i] = NULL;
- }
- LLVertexBuffer::unbind();
- {
- shaderp = &gDeferredLightProgram;
- bindDeferredShader(*shaderp);
- if (mCubeVB.notNull())
- {
- mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- }
- const LLVector3& cam_origin = gViewerCamera.getOrigin();
- F32 cam_x = cam_origin.mV[0];
- F32 cam_y = cam_origin.mV[1];
- F32 cam_z = cam_origin.mV[2];
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- LLVector4a center, sa;
- LLColor3 col;
- U32 rendered_count = 0;
- // mNearbyLights already includes distance calculation and
- // excludes muted avatars. It is calculated from mLights and
- // also provides fade value to gracefully fade-out out of range
- // lights
- for (light_set_t::iterator iter = mNearbyLights.begin(),
- end = mNearbyLights.end();
- iter != end; ++iter)
- {
- if (++rendered_count > RenderLocalLightCount)
- {
- break;
- }
- LLDrawable* drawablep = iter->drawable;
- LLVOVolume* volp = drawablep->getVOVolume();
- if (!volp)
- {
- continue;
- }
- bool is_attachment = volp->isAttachment();
- if (is_attachment && !sRenderAttachedLights)
- {
- continue;
- }
- center.load3(drawablep->getPositionAgent().mV);
- const F32* c = center.getF32ptr();
- F32 s = volp->getLightRadius() * 1.5f;
- if (s <= 0.001f)
- {
- continue;
- }
- // Send light color to shader in linear space
- col = volp->getLightLinearColor();
- if (col.lengthSquared() < 0.001f)
- {
- continue;
- }
- sa.splat(s);
- if (gViewerCamera.AABBInFrustumNoFarClip(center, sa) == 0)
- {
- continue;
- }
- ++sVisibleLightCount;
- if (cam_x > c[0] + s + 0.2f || cam_x < c[0] - s - 0.2f ||
- cam_y > c[1] + s + 0.2f || cam_y < c[1] - s - 0.2f ||
- cam_z > c[2] + s + 0.2f || cam_z < c[2] - s - 0.2f)
- {
- // Draw box if camera is outside box
- if (RenderLocalLightCount && mCubeVB.notNull())
- {
- if (volp->isLightSpotlight())
- {
- drawablep->getVOVolume()->updateSpotLightPriority();
- spot_lights.emplace_back(drawablep);
- continue;
- }
- LL_FAST_TIMER(FTM_LOCAL_LIGHTS);
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1,
- c);
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1,
- col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- gGL.syncMatrices();
- mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8,
- get_box_fan_indices(&gViewerCamera,
- center));
- }
- }
- else
- {
- if (volp->isLightSpotlight())
- {
- drawablep->getVOVolume()->updateSpotLightPriority();
- fullscreen_spot_lights.emplace_back(drawablep);
- continue;
- }
- gGLModelView.affineTransform(center, center);
- LLVector4 tc(center.getF32ptr());
- tc.mV[VW] = s;
- fullscreen_lights.emplace_back(tc);
- light_colors.emplace_back(col.mV[0], col.mV[1],
- col.mV[2],
- volp->getLightFalloff(0.5f));
- }
- }
- stop_glerror();
- // When editting appearance, we need to add the corresponding
- // light at the camera position.
- static LLCachedControl<bool> custlight(gSavedSettings,
- "AvatarCustomizeLighting");
- if (custlight && isAgentAvatarValid() &&
- gAgentAvatarp->mSpecialRenderMode == 3)
- {
- fullscreen_lights.emplace_back(0.f, 0.f, 0.f, 15.f);
- light_colors.emplace_back(1.f, 1.f, 1.f, 0.f);
- }
- unbindDeferredShader(*shaderp);
- }
- if (!spot_lights.empty() && mCubeVB.notNull())
- {
- LL_FAST_TIMER(FTM_PROJECTORS);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE);
- shaderp = &gDeferredSpotLightProgram;
- bindDeferredShader(*shaderp);
- mCubeVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- shaderp->enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- for (LLDrawable::draw_list_t::iterator
- iter = spot_lights.begin(), end = spot_lights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- LLVOVolume* volp = drawablep->getVOVolume();
- LLVector4a center;
- center.load3(drawablep->getPositionAgent().mV);
- const F32* c = center.getF32ptr();
- F32 s = volp->getLightRadius() * 1.5f;
- ++sVisibleLightCount;
- setupSpotLight(*shaderp, drawablep);
- LLColor3 col = volp->getLightLinearColor();
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- gGL.syncMatrices();
- mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8,
- get_box_fan_indices(&gViewerCamera,
- center));
- }
- shaderp->disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- unbindDeferredShader(*shaderp);
- }
- // Reset mDeferredVB to fullscreen triangle
- if (!mDeferredVB->getVertexStrider(vert))
- {
- return;
- }
- vert[0].set(-1.f, 1.f, 0.f);
- vert[1].set(-1.f, -3.f, 0.f);
- vert[2].set(3.f, 1.f, 0.f);
- {
- LLGLDepthTest depth(GL_FALSE);
- // Full screen blit
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- constexpr U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT;
- LLVector4 light[max_count];
- LLVector4 col[max_count];
- U32 count = 0;
- F32 far_z = 0.f;
- {
- LL_FAST_TIMER(FTM_FULLSCREEN_LIGHTS);
- while (count < max_count && !fullscreen_lights.empty())
- {
- light[count] = fullscreen_lights.front();
- fullscreen_lights.pop_front();
- col[count] = light_colors.front();
- light_colors.pop_front();
- far_z = llmin(light[count].mV[2] - light[count].mV[3],
- far_z);
- if (++count == max_count || fullscreen_lights.empty())
- {
- U32 idx = count - 1;
- shaderp = &gDeferredMultiLightProgram[idx];
- bindDeferredShader(*shaderp);
- shaderp->uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT,
- count);
- shaderp->uniform4fv(LLShaderMgr::MULTI_LIGHT,
- count, (F32*)light);
- shaderp->uniform4fv(LLShaderMgr::MULTI_LIGHT_COL,
- count, (F32*)col);
- shaderp->uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z,
- far_z);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- unbindDeferredShader(*shaderp);
- far_z = 0.f;
- count = 0;
- }
- }
- }
- shaderp = &gDeferredMultiSpotLightProgram;
- bindDeferredShader(*shaderp);
- shaderp->enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- mDeferredVB->setBuffer(LLVertexBuffer::MAP_VERTEX);
- {
- LL_FAST_TIMER(FTM_PROJECTORS);
- for (LLDrawable::draw_list_t::iterator
- iter = fullscreen_spot_lights.begin(),
- end = fullscreen_spot_lights.end();
- iter != end; ++iter)
- {
- LLDrawable* drawablep = *iter;
- LLVOVolume* volp = drawablep->getVOVolume();
- LLVector4a center;
- center.load3(drawablep->getPositionAgent().mV);
- F32 s = volp->getLightRadius() * 1.5f;
- ++sVisibleLightCount;
- gGLModelView.affineTransform(center, center);
- setupSpotLight(*shaderp, drawablep);
- LLColor3 col = volp->getLightLinearColor();
- shaderp->uniform3fv(LLShaderMgr::LIGHT_CENTER, 1,
- center.getF32ptr());
- shaderp->uniform1f(LLShaderMgr::LIGHT_SIZE, s);
- shaderp->uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1,
- col.mV);
- shaderp->uniform1f(LLShaderMgr::LIGHT_FALLOFF,
- volp->getLightFalloff(0.5f));
- mDeferredVB->drawArrays(LLRender::TRIANGLES, 0, 3);
- }
- }
- shaderp->disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- unbindDeferredShader(*shaderp);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- }
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- }
- gGL.setColorMask(true, true);
- }
- mRT->mScreen.flush();
- // Gamma-correct lighting
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- gGL.loadIdentity();
- {
- LLGLDepthTest depth(GL_FALSE, GL_FALSE);
- LLVector2 tc1;
- LLVector2 tc2((F32)(mRT->mScreen.getWidth() * 2),
- (F32)(mRT->mScreen.getHeight() * 2));
- mRT->mScreen.bindTarget();
- // Apply gamma correction to the frame here.
- shaderp = &gDeferredPostGammaCorrectProgram;
- shaderp->bind();
- S32 channel = shaderp->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE,
- mRT->mScreen.getUsage());
- if (channel > -1)
- {
- mRT->mScreen.bindTexture(0, channel, LLTexUnit::TFO_POINT);
- }
- shaderp->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
- mRT->mScreen.getWidth(), mRT->mScreen.getHeight());
- shaderp->uniform1f(LLShaderMgr::DISPLAY_GAMMA,
- 1.f / RenderDeferredDisplayGamma);
- gGL.begin(LLRender::TRIANGLE_STRIP);
- gGL.texCoord2f(tc1.mV[0], tc1.mV[1]);
- gGL.vertex2f(-1.f, -1.f);
- gGL.texCoord2f(tc1.mV[0], tc2.mV[1]);
- gGL.vertex2f(-1.f, 3.f);
- gGL.texCoord2f(tc2.mV[0], tc1.mV[1]);
- gGL.vertex2f(3.f, -1.f);
- gGL.end();
- if (channel > -1)
- {
- gGL.getTexUnit(channel)->unbind(mRT->mScreen.getUsage());
- }
- shaderp->unbind();
- mRT->mScreen.flush();
- stop_glerror();
- }
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- mRT->mScreen.bindTarget();
- {
- // Render non-deferred geometry (alpha, fullbright, glow)
- LLGLDisable blend(GL_BLEND);
- LLGLDisable stencil(GL_STENCIL_TEST);
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_ALPHA,
- RENDER_TYPE_FULLBRIGHT,
- RENDER_TYPE_VOLUME,
- RENDER_TYPE_GLOW,
- RENDER_TYPE_BUMP,
- RENDER_TYPE_PASS_SIMPLE,
- RENDER_TYPE_PASS_ALPHA,
- RENDER_TYPE_PASS_ALPHA_MASK,
- RENDER_TYPE_PASS_BUMP,
- RENDER_TYPE_PASS_POST_BUMP,
- RENDER_TYPE_PASS_FULLBRIGHT,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
- RENDER_TYPE_PASS_GLOW,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_PASS_SHINY,
- RENDER_TYPE_PASS_INVISIBLE,
- RENDER_TYPE_PASS_INVISI_SHINY,
- RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- RENDER_TYPE_ALPHA_MASK,
- RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
- END_RENDER_TYPES);
- renderGeomPostDeferred(gViewerCamera);
- popRenderTypeMask();
- }
- // Render highlights, etc.
- renderHighlights();
- mHighlightFaces.clear();
- renderDebug();
- LLVertexBuffer::unbind();
- mRT->mScreen.flush();
- }
- void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep)
- {
- // Construct frustum
- LLVOVolume* volp = drawablep->getVOVolume();
- LLVector3 params = volp->getSpotLightParams();
- F32 fov = params.mV[0];
- F32 focus = params.mV[1];
- LLVector3 pos = drawablep->getPositionAgent();
- LLQuaternion quat = volp->getRenderRotation();
- LLVector3 scale = volp->getScale();
- // Get near clip plane
- LLVector3 at_axis(0.f, 0.f, -scale.mV[2] * 0.5f);
- at_axis *= quat;
- LLVector3 np = pos + at_axis;
- at_axis.normalize();
- // Get origin that has given fov for plane np, at_axis, and given scale
- F32 dist = scale.mV[1] * 0.5f / tanf(fov * 0.5f);
- LLVector3 origin = np - at_axis * dist;
- // Matrix from volume space to agent space
- LLMatrix4 light_mat4(quat, LLVector4(origin,1.f));
- LLMatrix4a light_mat;
- light_mat.loadu(light_mat4.getF32ptr());
- LLMatrix4a light_to_screen;
- light_to_screen.setMul(gGLModelView, light_mat);
- LLMatrix4a screen_to_light = light_to_screen;
- screen_to_light.invert();
- F32 s = volp->getLightRadius() * 1.5f;
- F32 near_clip = dist;
- F32 width = scale.mV[VX];
- F32 height = scale.mV[VY];
- F32 far_clip = s + dist - scale.mV[VZ];
- F32 fovy = fov * RAD_TO_DEG;
- F32 aspect = width / height;
- LLVector4a p1(0.f, 0.f, -(near_clip + 0.01f));
- LLVector4a p2(0.f, 0.f, -(near_clip + 1.f));
- LLVector4a screen_origin;
- screen_origin.clear();
- light_to_screen.affineTransform(p1, p1);
- light_to_screen.affineTransform(p2, p2);
- light_to_screen.affineTransform(screen_origin, screen_origin);
- LLVector4a n;
- n.setSub(p2, p1);
- n.normalize3fast();
- F32 proj_range = far_clip - near_clip;
- LLMatrix4a light_proj = gl_perspective(fovy, aspect, near_clip, far_clip);
- light_proj.setMul(TRANS_MAT, light_proj);
- screen_to_light.setMul(light_proj, screen_to_light);
- shader.uniformMatrix4fv(LLShaderMgr::PROJECTOR_MATRIX, 1, GL_FALSE,
- screen_to_light.getF32ptr());
- shader.uniform3fv(LLShaderMgr::PROJECTOR_P, 1, p1.getF32ptr());
- shader.uniform3fv(LLShaderMgr::PROJECTOR_N, 1, n.getF32ptr());
- shader.uniform3fv(LLShaderMgr::PROJECTOR_ORIGIN, 1,
- screen_origin.getF32ptr());
- shader.uniform1f(LLShaderMgr::PROJECTOR_RANGE, proj_range);
- shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIANCE, params.mV[2]);
- #if OPTIMIZED_UNIFORMS
- if (shader.mFeatures.hasShadows)
- #endif
- {
- S32 s_idx = -1;
- for (U32 i = 0; i < 2; ++i)
- {
- if (mShadowSpotLight[i] == drawablep)
- {
- s_idx = i;
- }
- }
- shader.uniform1i(LLShaderMgr::PROJECTOR_SHADOW_INDEX, s_idx);
- if (s_idx >= 0)
- {
- shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE,
- 1.f - mSpotLightFade[s_idx]);
- }
- else
- {
- shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f);
- }
- if (!gCubeSnapshot)
- {
- LLDrawable* potentialp = drawablep;
- // Determine if this is a good light for casting shadows
- F32 m_pri = volp->getSpotLightPriority();
- for (U32 i = 0; i < 2; ++i)
- {
- F32 pri = 0.f;
- LLDrawable* slightp = mTargetShadowSpotLight[i].get();
- if (slightp)
- {
- pri = slightp->getVOVolume()->getSpotLightPriority();
- }
- if (m_pri > pri)
- {
- LLDrawable* tempp = mTargetShadowSpotLight[i];
- mTargetShadowSpotLight[i] = potentialp;
- potentialp = tempp;
- m_pri = pri;
- }
- }
- }
- }
- #if DEBUG_OPTIMIZED_UNIFORMS && OPTIMIZED_UNIFORMS
- else if (shader.getUniformLocation(LLShaderMgr::PROJECTOR_SHADOW_INDEX) >= 0 ||
- shader.getUniformLocation(LLShaderMgr::PROJECTOR_SHADOW_FADE) >= 0)
- {
- llwarns_once << "Shader: " << shader.mName
- << " shall be marked as hasShadows !" << llendl;
- }
- #endif
- LLViewerTexture* texp = volp->getLightTexture();
- if (!texp)
- {
- texp = LLViewerFetchedTexture::sWhiteImagep;
- }
- S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
- if (channel > -1)
- {
- if (texp)
- {
- gGL.getTexUnit(channel)->bind(texp);
- shader.uniform1f(LLShaderMgr::PROJECTOR_FOCUS, focus);
- static const F32 INVLOG2 = 1.f / logf(2.f);
- F32 lod_range = logf(texp->getWidth()) * INVLOG2;
- shader.uniform1f(LLShaderMgr::PROJECTOR_LOD, lod_range);
- }
- }
- stop_glerror();
- }
- void LLPipeline::unbindDeferredShader(LLGLSLShader& shader)
- {
- LLTexUnit::eTextureType usage = mRT->mDeferredScreen.getUsage();
- shader.disableTexture(LLShaderMgr::DEFERRED_NORMAL, usage);
- shader.disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, usage);
- shader.disableTexture(LLShaderMgr::DEFERRED_SPECULAR, usage);
- if (gUsePBRShaders)
- {
- shader.disableTexture(LLShaderMgr::DEFERRED_EMISSIVE, usage);
- shader.disableTexture(LLShaderMgr::DEFERRED_BRDF_LUT);
- }
- else
- {
- // Not the same buffer used for DEFERRED_DEPTH in EE rendering, unlike
- // what happens for PBR rendering. HB
- usage = mDeferredDepth.getUsage();
- }
- shader.disableTexture(LLShaderMgr::DEFERRED_DEPTH, usage);
- shader.disableTexture(LLShaderMgr::DEFERRED_LIGHT,
- mRT->mDeferredLight.getUsage());
- shader.disableTexture(LLShaderMgr::DIFFUSE_MAP);
- if (!gUsePBRShaders) // "bloomMap" not in use any more in PBR shaders. HB
- {
- shader.disableTexture(LLShaderMgr::DEFERRED_BLOOM);
- }
- #if OPTIMIZED_UNIFORMS
- if (shader.mFeatures.hasShadows)
- #endif
- {
- for (U32 i = 0; i < 6; ++i)
- {
- if (shader.disableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i) > -1)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_NONE);
- }
- }
- }
- shader.disableTexture(LLShaderMgr::DEFERRED_NOISE);
- shader.disableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
- if (!sReflectionProbesEnabled)
- {
- S32 channel = shader.disableTexture(LLShaderMgr::ENVIRONMENT_MAP,
- LLTexUnit::TT_CUBE_MAP);
- if (channel > -1)
- {
- LLCubeMap* cube_mapp = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap()
- : NULL;
- if (cube_mapp)
- {
- cube_mapp->disableTexture();
- }
- }
- }
- if (gUsePBRShaders)
- {
- unbindReflectionProbes(shader);
- }
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- unit0->activate();
- shader.unbind();
- stop_glerror();
- }
- // For EE rendering only
- void LLPipeline::generateWaterReflection()
- {
- if (!LLDrawPoolWater::sNeedsReflectionUpdate)
- {
- if (!gViewerCamera.cameraUnderWater())
- {
- // Initial sky pass is still needed even if water reflection is not
- // rendering.
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_SKY, RENDER_TYPE_WL_SKY,
- RENDER_TYPE_CLOUDS, END_RENDER_TYPES);
- LLCamera camera = gViewerCamera;
- camera.setFar(camera.getFar() * 0.75f);
- updateCull(camera, mSky);
- stateSort(camera, mSky);
- renderGeom(camera);
- popRenderTypeMask();
- }
- return;
- }
- // Disable occlusion culling for reflection/refraction passes.
- LLDisableOcclusionCulling no_occlusion;
- bool skip_avatar_update = false;
- if (!isAgentAvatarValid() || gAgent.getCameraAnimating() ||
- gAgent.getCameraMode() != CAMERA_MODE_MOUSELOOK ||
- !LLVOAvatar::sVisibleInFirstPerson)
- {
- skip_avatar_update = true;
- }
- LLCamera camera = gViewerCamera;
- camera.setFar(camera.getFar() * 0.75f);
- sReflectionRender = true;
- pushRenderTypeMask();
- LLMatrix4a current = gGLModelView;
- LLMatrix4a projection = gGLProjection;
- F32 camera_height = gViewerCamera.getOrigin().mV[VZ];
- LLVector3 reflection_offset(0.f, 0.f,
- fabsf(camera_height - mWaterHeight) * 2.f);
- LLVector3 reflect_origin = gViewerCamera.getOrigin() - reflection_offset;
- const LLVector3& camera_look_at = gViewerCamera.getAtAxis();
- LLVector3 reflection_look_at(camera_look_at.mV[VX], camera_look_at.mV[VY],
- -camera_look_at.mV[VZ]);
- LLVector3 reflect_interest_point = reflect_origin +
- reflection_look_at * 5.f;
- camera.setOriginAndLookAt(reflect_origin, LLVector3::z_axis,
- reflect_interest_point);
- // Plane params
- LLVector3 pnorm;
- bool camera_is_underwater = gViewerCamera.cameraUnderWater();
- if (camera_is_underwater)
- {
- // Camera is below water, cull above water
- pnorm.set(0.f, 0.f, 1.f);
- }
- else
- {
- // Camera is above water, cull below water
- pnorm.set(0.f, 0.f, -1.f);
- }
- LLPlane plane(LLVector3(0.f, 0.f, mWaterHeight), pnorm);
- if (!camera_is_underwater)
- {
- // Generate planar reflection map
- LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WATER0;
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- LLMatrix4a mat;
- mat.setIdentity();
- mat.getRow<2>().negate();
- mat.setTranslateAffine(LLVector3(0.f, 0.f, mWaterHeight * 2.f));
- mat.setMul(current, mat);
- mReflectionModelView = mat;
- gGLModelView = mat;
- gGL.loadMatrix(mat);
- LLViewerCamera::updateFrustumPlanes(camera, false, true);
- LLVector4a origin;
- origin.clear();
- LLMatrix4a inv_mat = mat;
- inv_mat.invert();
- inv_mat.affineTransform(origin, origin);
- camera.setOrigin(origin.getF32ptr());
- glCullFace(GL_FRONT);
- if (LLDrawPoolWater::sNeedsReflectionUpdate)
- {
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- glClearColor(0.f, 0.f, 0.f, 0.f);
- mWaterRef.bindTarget();
- gGL.setColorMask(true, true);
- mWaterRef.clear();
- gGL.setColorMask(true, false);
- mWaterRef.getViewport(gGLViewport);
- // Initial sky pass (no user clip plane)
- // Mask out everything but the sky
- pushRenderTypeMask();
- U32 reflection_type = waterReflectionType();
- if (reflection_type < 5) // Render sky without clouds
- {
- andRenderTypeMask(RENDER_TYPE_SKY, RENDER_TYPE_WL_SKY,
- END_RENDER_TYPES);
- }
- else // Render sky with clouds
- {
- andRenderTypeMask(RENDER_TYPE_SKY, RENDER_TYPE_WL_SKY,
- RENDER_TYPE_CLOUDS, END_RENDER_TYPES);
- }
- updateCull(camera, mSky);
- stateSort(camera, mSky);
- renderGeom(camera);
- popRenderTypeMask();
- if (reflection_type > 1) // If not just sky to render
- {
- pushRenderTypeMask();
- // These have just been rendered above: remove them now.
- clearRenderTypeMask(RENDER_TYPE_WATER, RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_SKY, RENDER_TYPE_CLOUDS,
- END_RENDER_TYPES);
- // Mask out selected geometry based on reflection type
- if (reflection_type < 5) // Remove particles
- {
- clearRenderTypeMask(RENDER_TYPE_PARTICLES,
- END_RENDER_TYPES);
- if (reflection_type < 4) // Remove avatars
- {
- clearRenderTypeMask(RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- END_RENDER_TYPES);
- if (reflection_type < 3) // Remove objects
- {
- clearRenderTypeMask(RENDER_TYPE_VOLUME,
- END_RENDER_TYPES);
- }
- }
- }
- LLGLUserClipPlane clip_plane(plane, mReflectionModelView,
- projection);
- LLGLDisable cull(GL_CULL_FACE);
- updateCull(camera, mReflectedObjects, &plane);
- stateSort(camera, mReflectedObjects);
- renderGeom(camera);
- popRenderTypeMask();
- }
- mWaterRef.flush();
- }
- glCullFace(GL_BACK);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- gGLModelView = current;
- }
- camera.setOrigin(gViewerCamera.getOrigin());
- // Render distortion map
- static bool last_update = true;
- if (last_update)
- {
- pushRenderTypeMask();
- camera.setFar(gViewerCamera.getFar());
- clearRenderTypeMask(RENDER_TYPE_WATER, RENDER_TYPE_VOIDWATER,
- END_RENDER_TYPES);
- // Intentionally inverted so that distortion map contents (objects
- // under the water when we are above it) will properly include water
- // fog effects.
- sUnderWaterRender = !camera_is_underwater;
- if (sUnderWaterRender)
- {
- clearRenderTypeMask(RENDER_TYPE_SKY, RENDER_TYPE_CLOUDS,
- RENDER_TYPE_WL_SKY, END_RENDER_TYPES);
- }
- LLViewerCamera::updateFrustumPlanes(camera);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- if (sUnderWaterRender || LLDrawPoolWater::sNeedsReflectionUpdate)
- {
- LLColor4& col = LLDrawPoolWater::sWaterFogColor;
- glClearColor(col.mV[0], col.mV[1], col.mV[2], 0.f);
- // *HACK: pretend underwater camera is the world camera to fix
- // weird visibility artifacts during distortion render (does not
- // break main render because the camera is the same perspective as
- // world camera and occlusion culling is disabled for this pass).
- LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
- mWaterDis.bindTarget();
- mWaterDis.getViewport(gGLViewport);
- gGL.setColorMask(true, true);
- mWaterDis.clear();
- gGL.setColorMask(true, false);
- // Clip out geometry on the same side of water as the camera with
- // enough margin to not include the water geo itself, but not so
- // much as to clip out parts of avatars that should be seen under
- // the water in the distortion map.
- constexpr F32 nudge_factor = 1.0125f;
- F32 water_dist = mWaterHeight;
- if (camera_is_underwater)
- {
- // Nudge clip plane below water to avoid visible holes in
- // objects intersecting the water surface.
- water_dist *= 1.f / nudge_factor;
- // Camera is below water, clip plane points up
- pnorm.set(0.f, 0.f, -1.f);
- }
- else
- {
- // Nudge clip plane above water to avoid visible holes in
- // objects intersecting the water surface.
- water_dist *= nudge_factor;
- // Camera is above water, clip plane points down
- pnorm.set(0.f, 0.f, 1.f);
- }
- LLPlane plane(LLVector3(0.f, 0.f, water_dist), pnorm);
- LLGLUserClipPlane clip_plane(plane, current, projection);
- gGL.setColorMask(true, true);
- mWaterDis.clear();
- gGL.setColorMask(true, false);
- if (RenderWaterReflectionType)
- {
- updateCull(camera, mRefractedObjects, &plane);
- stateSort(camera, mRefractedObjects);
- renderGeom(camera);
- }
- gUIProgram.bind();
- gWorld.renderPropertyLines();
- gUIProgram.unbind();
- mWaterDis.flush();
- }
- popRenderTypeMask();
- }
- last_update = LLDrawPoolWater::sNeedsReflectionUpdate;
- LLDrawPoolWater::sNeedsReflectionUpdate = false;
- popRenderTypeMask();
- sUnderWaterRender = false;
- sReflectionRender = false;
- if (!LLRenderTarget::sUseFBO)
- {
- glClear(GL_DEPTH_BUFFER_BIT);
- }
- glClearColor(0.f, 0.f, 0.f, 0.f);
- gViewerWindowp->setupViewport();
- LL_GL_CHECK_STATES;
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(gAgent.getCameraMode());
- }
- LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
- }
- // For PBR rendering only
- void LLPipeline::renderShadow(const LLMatrix4a& view, const LLMatrix4a& proj,
- LLCamera& shadow_cam, LLCullResult& result,
- bool depth_clamp)
- {
- LL_FAST_TIMER(FTM_SHADOW_RENDER);
- // Disable occlusion culling during shadow render
- LLDisableOcclusionCulling no_occlusion;
- sShadowRender = true;
- static const U32 types[] =
- {
- LLRenderPass::PASS_SIMPLE,
- LLRenderPass::PASS_FULLBRIGHT,
- LLRenderPass::PASS_SHINY,
- LLRenderPass::PASS_BUMP,
- LLRenderPass::PASS_FULLBRIGHT_SHINY,
- LLRenderPass::PASS_MATERIAL,
- LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
- LLRenderPass::PASS_SPECMAP,
- LLRenderPass::PASS_SPECMAP_EMISSIVE,
- LLRenderPass::PASS_NORMMAP,
- LLRenderPass::PASS_NORMMAP_EMISSIVE,
- LLRenderPass::PASS_NORMSPEC,
- LLRenderPass::PASS_NORMSPEC_EMISSIVE
- };
- LLGLEnable cull(GL_CULL_FACE);
- #if 0 // The OpenGL version required by PBR should have depth clamp. HB
- if (depth_clamp)
- {
- static LLCachedControl<bool> dclamp(gSavedSettings,
- "RenderDepthClampShadows");
- if (!dclamp || !gGLManager.mUseDepthClamp)
- {
- depth_clamp = false;
- }
- }
- #endif
- LLGLEnable clamp_depth(depth_clamp ? GL_DEPTH_CLAMP : 0);
- LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_LESS);
- updateCull(shadow_cam, result);
- stateSort(shadow_cam, result);
- // Generate shadow map
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadMatrix(proj);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- gGL.loadMatrix(view);
- gGLLastMatrix = NULL;
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- stop_glerror();
- LLVertexBuffer::unbind();
- for (U32 rigged = 0; rigged < 2; ++rigged)
- {
- gDeferredShadowProgram.bind(rigged);
- gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
- // If not using VSM, disable color writes
- if (RenderShadowDetail <= 2)
- {
- gGL.setColorMask(false, false);
- }
- LL_FAST_TIMER(FTM_SHADOW_SIMPLE);
- unit0->disable();
- constexpr U32 count = sizeof(types) / sizeof(U32);
- for (U32 i = 0; i < count; ++i)
- {
- renderObjects(types[i], 0, false, false, rigged);
- }
- renderGLTFObjects(LLRenderPass::PASS_MAT_PBR, false, rigged);
- unit0->enable(LLTexUnit::TT_TEXTURE);
- }
- {
- LL_TRACY_TIMER(TRC_SHADOW_GEOM);
- renderGeomShadow(shadow_cam);
- }
- S32 sun_up = mIsSunUp ? 1 : 0;
- const F32 width = LLRenderTarget::sCurResX;
- LLGLSLShader* shaderp;
- {
- LL_FAST_TIMER(FTM_SHADOW_ALPHA);
- for (U32 rigged = 0; rigged < 2; ++rigged)
- {
- gDeferredShadowAlphaMaskProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH,
- width);
- renderMaskedObjects(LLRenderPass::PASS_ALPHA_MASK, 0, true, true,
- rigged);
- renderAlphaObjects(rigged);
- gDeferredShadowFullbrightAlphaMaskProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH,
- width);
- renderFullbrightMaskedObjects(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK,
- 0, true, true, rigged);
- gDeferredTreeShadowProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->setMinimumAlpha(0.598f);
- if (!rigged)
- {
- renderObjects(LLRenderPass::PASS_GRASS, 0, true);
- }
- renderMaskedObjects(LLRenderPass::PASS_NORMSPEC_MASK,
- 0, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
- 0, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_SPECMAP_MASK,
- 0, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_NORMMAP_MASK,
- 0, true, false, rigged);
- }
- }
- for (U32 rigged = 0; rigged < 2; ++rigged)
- {
- gDeferredShadowGLTFAlphaMaskProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, width);
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- constexpr U32 type = LLRenderPass::PASS_MAT_PBR_ALPHA_MASK;
- if (rigged)
- {
- LLRenderPass::pushRiggedGLTFBatches(type + 1);
- }
- else
- {
- LLRenderPass::pushGLTFBatches(type);
- }
- gGL.loadMatrix(gGLModelView);
- gGLLastMatrix = NULL;
- }
- gDeferredShadowCubeProgram.bind();
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- gGL.setColorMask(true, true);
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- gGLLastMatrix = NULL;
- sShadowRender = false;
- }
- // For EE rendering only
- void LLPipeline::renderShadow(const LLMatrix4a& view, const LLMatrix4a& proj,
- LLCamera& shadow_cam, LLCullResult& result,
- bool use_shader, bool use_occlusion,
- U32 target_width)
- {
- LL_FAST_TIMER(FTM_SHADOW_RENDER);
- // Clip out geometry on the same side of water as the camera
- S32 occlude = sUseOcclusion;
- if (!use_occlusion)
- {
- sUseOcclusion = 0;
- }
- sShadowRender = true;
- static const U32 types[] =
- {
- LLRenderPass::PASS_SIMPLE,
- LLRenderPass::PASS_FULLBRIGHT,
- LLRenderPass::PASS_SHINY,
- LLRenderPass::PASS_BUMP,
- LLRenderPass::PASS_FULLBRIGHT_SHINY,
- LLRenderPass::PASS_MATERIAL,
- LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
- LLRenderPass::PASS_SPECMAP,
- LLRenderPass::PASS_SPECMAP_EMISSIVE,
- LLRenderPass::PASS_NORMMAP,
- LLRenderPass::PASS_NORMMAP_EMISSIVE,
- LLRenderPass::PASS_NORMSPEC,
- LLRenderPass::PASS_NORMSPEC_EMISSIVE,
- };
- LLGLEnable cull(GL_CULL_FACE);
- // Enable depth clamping if available and in use for shaders.
- U32 depth_clamp_state = 0;
- if (gGLManager.mUseDepthClamp)
- {
- // Added a debug setting to see if it makes any difference for
- // projectors with some GPU/drivers (no difference seen by me
- // for NVIDIA GPU + proprietary drivers). HB
- static LLCachedControl<bool> dclamp(gSavedSettings,
- "RenderDepthClampShadows");
- if (dclamp)
- {
- depth_clamp_state = GL_DEPTH_CLAMP;
- }
- }
- LLGLEnable depth_clamp(depth_clamp_state);
- if (use_shader)
- {
- gDeferredShadowCubeProgram.bind();
- }
- LLRenderTarget& occlusion_target =
- mShadowOcclusion[LLViewerCamera::sCurCameraID - 1];
- occlusion_target.bindTarget();
- updateCull(shadow_cam, result);
- occlusion_target.flush();
- stateSort(shadow_cam, result);
- // Generate shadow map
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadMatrix(proj);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- gGL.loadMatrix(view);
- gGLLastMatrix = NULL;
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- stop_glerror();
- LLVertexBuffer::unbind();
- S32 sun_up = mIsSunUp ? 1 : 0;
- for (U32 rigged = 0; rigged < 2; ++rigged)
- {
- if (!use_shader)
- {
- // Occlusion program is general purpose depth-only no-textures
- gOcclusionProgram.bind(rigged);
- }
- else
- {
- gDeferredShadowProgram.bind(rigged);
- gDeferredShadowProgram.uniform1i(LLShaderMgr::SUN_UP_FACTOR,
- sun_up);
- }
- gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f);
- // If not using VSM, disable color writes
- if (RenderShadowDetail <= 2)
- {
- gGL.setColorMask(false, false);
- }
- LL_FAST_TIMER(FTM_SHADOW_SIMPLE);
- unit0->disable();
- constexpr U32 count = sizeof(types) / sizeof(U32);
- for (U32 i = 0; i < count; ++i)
- {
- renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, false, false,
- rigged);
- }
- unit0->enable(LLTexUnit::TT_TEXTURE);
- if (!use_shader)
- {
- gOcclusionProgram.unbind();
- }
- stop_glerror();
- }
- if (use_shader)
- {
- LL_TRACY_TIMER(TRC_SHADOW_GEOM);
- gDeferredShadowProgram.unbind();
- renderGeomShadow(shadow_cam);
- gDeferredShadowProgram.bind();
- gDeferredShadowProgram.uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- }
- else
- {
- LL_TRACY_TIMER(TRC_SHADOW_GEOM);
- renderGeomShadow(shadow_cam);
- }
- stop_glerror();
- {
- LL_FAST_TIMER(FTM_SHADOW_ALPHA);
- constexpr U32 NO_IDX_MASK = LLVertexBuffer::MAP_VERTEX |
- LLVertexBuffer::MAP_TEXCOORD0 |
- LLVertexBuffer::MAP_COLOR;
- constexpr U32 IDX_MASK = NO_IDX_MASK |
- LLVertexBuffer::MAP_TEXTURE_INDEX;
- LLGLSLShader* shaderp;
- for (U32 rigged = 0; rigged < 2; ++rigged)
- {
- gDeferredShadowAlphaMaskProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH,
- (F32)target_width);
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- renderMaskedObjects(LLRenderPass::PASS_ALPHA_MASK, IDX_MASK,
- true, true, rigged);
- shaderp->setMinimumAlpha(0.598f);
- renderAlphaObjects(rigged);
- gDeferredShadowFullbrightAlphaMaskProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- shaderp->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH,
- (F32)target_width);
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- renderFullbrightMaskedObjects(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK,
- IDX_MASK, true, true, rigged);
- gDeferredTreeShadowProgram.bind(rigged);
- shaderp = LLGLSLShader::sCurBoundShaderPtr;
- if (!rigged)
- {
- shaderp->setMinimumAlpha(0.598f);
- renderObjects(LLRenderPass::PASS_GRASS,
- LLVertexBuffer::MAP_VERTEX |
- LLVertexBuffer::MAP_TEXCOORD0,
- true);
- }
- shaderp->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
- renderMaskedObjects(LLRenderPass::PASS_NORMSPEC_MASK,
- NO_IDX_MASK, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
- NO_IDX_MASK, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_SPECMAP_MASK,
- NO_IDX_MASK, true, false, rigged);
- renderMaskedObjects(LLRenderPass::PASS_NORMMAP_MASK,
- NO_IDX_MASK, true, false, rigged);
- }
- stop_glerror();
- }
- #if 0
- glCullFace(GL_BACK);
- #endif
- gDeferredShadowCubeProgram.bind();
- gGLLastMatrix = NULL;
- gGL.loadMatrix(gGLModelView);
- LLRenderTarget& occlusion_source =
- mShadow[LLViewerCamera::sCurCameraID - 1];
- doOcclusion(shadow_cam, occlusion_source, occlusion_target);
- if (use_shader)
- {
- gDeferredShadowProgram.unbind();
- }
- gGL.setColorMask(true, true);
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- gGLLastMatrix = NULL;
- sUseOcclusion = occlude;
- sShadowRender = false;
- stop_glerror();
- }
- // Gets point cloud of intersection of frust and min, max
- bool LLPipeline::getVisiblePointCloud(LLCamera& camera,
- LLVector3& min, LLVector3& max,
- std::vector<LLVector3>& fp,
- LLVector3 light_dir)
- {
- LL_FAST_TIMER(FTM_VISIBLE_CLOUD);
- if (getVisibleExtents(camera, min, max))
- {
- return false;
- }
- // Get set of planes on bounding box
- LLPlane bp[] =
- {
- LLPlane(min, LLVector3(-1.f, 0.f, 0.f)),
- LLPlane(min, LLVector3(0.f, -1.f, 0.f)),
- LLPlane(min, LLVector3(0.f, 0.f, -1.f)),
- LLPlane(max, LLVector3(1.f, 0.f, 0.f)),
- LLPlane(max, LLVector3(0.f, 1.f, 0.f)),
- LLPlane(max, LLVector3(0.f, 0.f, 1.f))
- };
- // Potential points
- std::vector<LLVector3> pp;
- // Add corners of AABB
- pp.emplace_back(min.mV[0], min.mV[1], min.mV[2]);
- pp.emplace_back(max.mV[0], min.mV[1], min.mV[2]);
- pp.emplace_back(min.mV[0], max.mV[1], min.mV[2]);
- pp.emplace_back(max.mV[0], max.mV[1], min.mV[2]);
- pp.emplace_back(min.mV[0], min.mV[1], max.mV[2]);
- pp.emplace_back(max.mV[0], min.mV[1], max.mV[2]);
- pp.emplace_back(min.mV[0], max.mV[1], max.mV[2]);
- pp.emplace_back(max.mV[0], max.mV[1], max.mV[2]);
- // Add corners of camera frustum
- for (U32 i = 0; i < LLCamera::AGENT_FRUSTRUM_NUM; ++i)
- {
- pp.emplace_back(camera.mAgentFrustum[i]);
- }
- // Bounding box line segments
- static const U32 bs[] =
- {
- 0, 1,
- 1, 3,
- 3, 2,
- 2, 0,
- 4, 5,
- 5, 7,
- 7, 6,
- 6, 4,
- 0, 4,
- 1, 5,
- 3, 7,
- 2, 6
- };
- for (U32 i = 0; i < 12; ++i) // For each line segment in bounding box
- {
- const LLVector3& v1 = pp[bs[i * 2]];
- const LLVector3& v2 = pp[bs[i * 2 + 1]];
- LLVector3 n, line;
- // For each plane in camera frustum
- for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; ++j)
- {
- const LLPlane& cp = camera.getAgentPlane(j);
- cp.getVector3(n);
- line = v1 - v2;
- F32 d1 = line * n;
- F32 d2 = -cp.dist(v2);
- F32 t = d2 / d1;
- if (t > 0.f && t < 1.f)
- {
- pp.emplace_back(v2 + line * t);
- }
- }
- }
- // Camera frustum line segments
- static const U32 fs[] =
- {
- 0, 1,
- 1, 2,
- 2, 3,
- 3, 0,
- 4, 5,
- 5, 6,
- 6, 7,
- 7, 4,
- 0, 4,
- 1, 5,
- 2, 6,
- 3, 7
- };
- for (U32 i = 0; i < 12; ++i)
- {
- const LLVector3& v1 = pp[fs[i * 2] + 8];
- const LLVector3& v2 = pp[fs[i * 2 + 1] + 8];
- LLVector3 n, line;
- for (U32 j = 0; j < 6; ++j)
- {
- const LLPlane& cp = bp[j];
- cp.getVector3(n);
- line = v1 - v2;
- F32 d1 = line * n;
- F32 d2 = -cp.dist(v2);
- F32 t = d2 / d1;
- if (t > 0.f && t < 1.f)
- {
- pp.emplace_back(v2 + line * t);
- }
- }
- }
- LLVector3 ext[] = { min - LLVector3(0.05f, 0.05f, 0.05f),
- max + LLVector3(0.05f, 0.05f, 0.05f) };
- for (U32 i = 0, count = pp.size(); i < count; ++i)
- {
- bool found = true;
- const F32* p = pp[i].mV;
- for (U32 j = 0; j < 3; ++j)
- {
- if (p[j] < ext[0].mV[j] || p[j] > ext[1].mV[j])
- {
- found = false;
- break;
- }
- }
- for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; ++j)
- {
- const LLPlane& cp = camera.getAgentPlane(j);
- F32 dist = cp.dist(pp[i]);
- if (dist > 0.05f)
- {
- // point is above some plane, not contained
- found = false;
- break;
- }
- }
- if (found)
- {
- fp.emplace_back(pp[i]);
- }
- }
- return !fp.empty();
- }
- void LLPipeline::renderHighlight(const LLViewerObject* objp, F32 fade)
- {
- if (!objp || objp->isDead() || !objp->getVolume())
- {
- return;
- }
- for (LLViewerObject::child_list_t::const_iterator
- it = objp->getChildren().begin(), end = objp->getChildren().end();
- it != end; ++it)
- {
- renderHighlight(*it, fade);
- }
- LLDrawable* drawablep = objp->mDrawable;
- if (!drawablep)
- {
- return;
- }
- LLColor4 color(1.f, 1.f, 1.f, fade);
- for (S32 i = 0, count = drawablep->getNumFaces(); i < count; ++i)
- {
- LLFace* facep = drawablep->getFace(i);
- if (facep)
- {
- facep->renderSelected(LLViewerTexture::sNullImagep, color);
- }
- }
- }
- // Branched version for the PBR renderer
- void LLPipeline::generateSunShadowPBR()
- {
- LLDisableOcclusionCulling no_occlusion;
- bool skip_avatar_update = false;
- if (!isAgentAvatarValid() || gAgent.getCameraAnimating() ||
- gAgent.getCameraMode() != CAMERA_MODE_MOUSELOOK ||
- !LLVOAvatar::sVisibleInFirstPerson)
- {
- skip_avatar_update = true;
- }
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON);
- }
- // Store last_modelview of world camera
- LLMatrix4a last_modelview = gGLLastModelView;
- LLMatrix4a last_projection = gGLLastProjection;
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_SIMPLE,
- RENDER_TYPE_ALPHA,
- RENDER_TYPE_ALPHA_PRE_WATER,
- RENDER_TYPE_ALPHA_POST_WATER,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_MAT_PBR,
- RENDER_TYPE_FULLBRIGHT,
- RENDER_TYPE_BUMP,
- RENDER_TYPE_VOLUME,
- RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- RENDER_TYPE_TREE,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_WATER,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_PASS_ALPHA,
- RENDER_TYPE_PASS_ALPHA_MASK,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_PASS_SIMPLE,
- RENDER_TYPE_PASS_BUMP,
- RENDER_TYPE_PASS_FULLBRIGHT,
- RENDER_TYPE_PASS_SHINY,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
- RENDER_TYPE_PASS_MATERIAL,
- RENDER_TYPE_PASS_MATERIAL_ALPHA,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE,
- RENDER_TYPE_PASS_SPECMAP,
- RENDER_TYPE_PASS_SPECMAP_BLEND,
- RENDER_TYPE_PASS_SPECMAP_MASK,
- RENDER_TYPE_PASS_SPECMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMMAP,
- RENDER_TYPE_PASS_NORMMAP_BLEND,
- RENDER_TYPE_PASS_NORMMAP_MASK,
- RENDER_TYPE_PASS_NORMMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMSPEC,
- RENDER_TYPE_PASS_NORMSPEC_BLEND,
- RENDER_TYPE_PASS_NORMSPEC_MASK,
- RENDER_TYPE_PASS_NORMSPEC_EMISSIVE,
- RENDER_TYPE_PASS_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_SIMPLE_RIGGED,
- RENDER_TYPE_PASS_BUMP_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_RIGGED,
- RENDER_TYPE_PASS_SHINY_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_BLEND_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_MASK_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_BLEND_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_MASK_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_BLEND_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_MASK_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_MAT_PBR,
- RENDER_TYPE_PASS_MAT_PBR_RIGGED,
- RENDER_TYPE_PASS_MAT_ALPHA_MASK_PBR,
- RENDER_TYPE_PASS_MAT_ALPHA_MASK_PBR_RIGGED,
- END_RENDER_TYPES);
- gGL.setColorMask(false, false);
- // Get sun view matrix
- // Store current projection/modelview matrix
- const LLMatrix4a saved_proj = gGLProjection;
- const LLMatrix4a saved_view = gGLModelView;
- LLMatrix4a inv_view(saved_view);
- inv_view.invert();
- LLMatrix4a view[6];
- LLMatrix4a proj[6];
- LLVector3 caster_dir(mIsSunUp ? mSunDir : mMoonDir);
- // Put together a universal "near clip" plane for shadow frusta
- LLPlane shadow_near_clip;
- LLVector3 p = gViewerCamera.getOrigin();
- p += caster_dir * RenderFarClip * 2.f;
- shadow_near_clip.setVec(p, caster_dir);
- LLVector3 light_dir = -caster_dir;
- light_dir.normalize();
- // Create light space camera matrix
- LLVector3 at = light_dir;
- LLVector3 up = gViewerCamera.getAtAxis();
- if (fabsf(up * light_dir) > 0.75f)
- {
- up = gViewerCamera.getUpAxis();
- }
- up.normalize();
- at.normalize();
- LLCamera main_camera = gViewerCamera;
- bool no_shadow_frustra = !gCubeSnapshot &&
- !hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA);
- F32 near_clip = 0.f;
- // Get visible point cloud
- main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum);
- LLVector3 min, max;
- std::vector<LLVector3> fp;
- getVisiblePointCloud(main_camera, min, max, fp);
- if (fp.empty())
- {
- if (no_shadow_frustra)
- {
- mShadowCamera[0] = main_camera;
- mShadowExtents[0][0] = min;
- mShadowExtents[0][1] = max;
- mShadowFrustPoints[0].clear();
- mShadowFrustPoints[1].clear();
- mShadowFrustPoints[2].clear();
- mShadowFrustPoints[3].clear();
- }
- popRenderTypeMask();
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(gAgent.getCameraMode());
- }
- return;
- }
- LLVector4a v;
- // Get good split distances for frustum
- for (U32 i = 0; i < fp.size(); ++i)
- {
- v.load3(fp[i].mV);
- saved_view.affineTransform(v, v);
- fp[i].set(v.getF32ptr());
- }
- min = fp[0];
- max = fp[0];
- // Get camera space bounding box
- for (U32 i = 1; i < fp.size(); ++i)
- {
- update_min_max(min, max, fp[i]);
- }
- near_clip = llclamp(-max.mV[2], 0.01f, 4.f);
- F32 far_clip = llclamp(-min.mV[2] * 2.f, 16.f, 512.f);
- far_clip = llmin(far_clip, gViewerCamera.getFar());
- F32 range = far_clip - near_clip;
- LLVector3 split_exp = RenderShadowSplitExponent;
- F32 da = 1.f - llmax(fabsf(light_dir * up),
- fabsf(light_dir * gViewerCamera.getLeftAxis()));
- da = powf(da, split_exp.mV[2]);
- F32 sxp = split_exp.mV[1] + (split_exp.mV[0] - split_exp.mV[1]) * da;
- for (U32 i = 0; i < 4; ++i)
- {
- F32 x = (F32)(i + 1) * 0.25f;
- x = powf(x, sxp);
- mSunClipPlanes.mV[i] = near_clip + range * x;
- }
- // Bump back first split for transition padding
- mSunClipPlanes.mV[0] *= 1.25f;
- if (gCubeSnapshot)
- {
- // Stretch clip planes for reflection probe renders to reduce number
- // of shadow passes
- mSunClipPlanes.mV[1] = mSunClipPlanes.mV[2];
- mSunClipPlanes.mV[2] = mSunClipPlanes.mV[3];
- mSunClipPlanes.mV[3] *= 1.5f;
- }
- // Convenience array of 4 near clip plane distances
- F32 dist[] = { near_clip,
- mSunClipPlanes.mV[0],
- mSunClipPlanes.mV[1],
- mSunClipPlanes.mV[2],
- mSunClipPlanes.mV[3] };
- if (mSunLightColor == LLColor4::black)
- {
- // Sun diffuse is totally black, shadows do not matter
- LLGLDepthTest depth(GL_TRUE);
- for (S32 j = 0; j < 4; ++j)
- {
- mRT->mSunShadow[j].bindTarget();
- mRT->mSunShadow[j].clear();
- mRT->mSunShadow[j].flush();
- }
- }
- else
- {
- static LLCachedControl<U32> splits(gSavedSettings,
- "RenderShadowSplits");
- U32 max_splits = llclamp((U32)splits, 0, 3);
- for (U32 j = 0, count = gCubeSnapshot ? 2 : 4; j < count; ++j)
- {
- if (no_shadow_frustra)
- {
- mShadowFrustPoints[j].clear();
- }
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SUN_SHADOW0 + j;
- // Restore render matrices
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- LLVector3 eye = gViewerCamera.getOrigin();
- // Camera used for shadow cull/render
- LLCamera shadow_cam = gViewerCamera;
- shadow_cam.setFar(16.f);
- // Create world space camera frustum for this split
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- LLVector3* frust = shadow_cam.mAgentFrustum;
- LLVector3 pn = shadow_cam.getAtAxis();
- // Construct 8 corners of split frustum section
- for (U32 i = 0; i < 4; ++i)
- {
- LLVector3 delta = frust[i + 4] - eye;
- delta += (frust[i + 4] - frust[(i + 2) % 4 + 4]) * 0.05f;
- delta.normalize();
- F32 dp = delta * pn;
- frust[i] = eye + (delta * dist[j] * 0.75f) / dp;
- frust[i + 4] = eye + (delta * dist[j + 1] * 1.25f) / dp;
- }
- shadow_cam.calcAgentFrustumPlanes(frust);
- shadow_cam.mFrustumCornerDist = 0.f;
- if (no_shadow_frustra)
- {
- mShadowCamera[j] = shadow_cam;
- }
- std::vector<LLVector3> fp;
- LLVector3 min, max;
- if (!getVisiblePointCloud(shadow_cam, min, max, fp, light_dir) ||
- j > max_splits)
- {
- // No possible shadow receivers
- if (no_shadow_frustra)
- {
- mShadowExtents[j][0].clear();
- mShadowExtents[j][1].clear();
- mShadowCamera[j + 4] = shadow_cam;
- }
- mRT->mSunShadow[j].bindTarget();
- {
- LLGLDepthTest depth(GL_TRUE);
- mRT->mSunShadow[j].clear();
- }
- mRT->mSunShadow[j].flush();
- continue;
- }
- if (no_shadow_frustra)
- {
- mShadowExtents[j][0] = min;
- mShadowExtents[j][1] = max;
- mShadowFrustPoints[j] = fp;
- }
- // Find a good origin for shadow projection
- LLVector3 origin;
- // Get a temporary view projection
- view[j] = look_proj(gViewerCamera.getOrigin(), light_dir, -up);
- std::vector<LLVector3> wpf;
- LLVector4a p;
- for (U32 i = 0; i < fp.size(); ++i)
- {
- p.load3(fp[i].mV);
- view[j].affineTransform(p, p);
- wpf.emplace_back(LLVector3(p.getF32ptr()));
- }
- min = max = wpf[0];
- for (U32 i = 0; i < fp.size(); ++i)
- {
- // Get AABB in camera space
- update_min_max(min, max, wpf[i]);
- }
- // Construct a perspective transform with perspective along y-axis
- // that contains points in wpf
- // Known:
- // - far clip plane
- // - near clip plane
- // - points in frustum
- // Find:
- // - origin
- // Get some "interesting" points of reference
- LLVector3 center = (min + max) * 0.5f;
- LLVector3 size = (max - min) * 0.5f;
- LLVector3 near_center = center;
- near_center.mV[1] += size.mV[1] * 2.f;
- // Put all points in wpf in quadrant 0, reletive to center of
- // min/max get the best fit line using least squares
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- wpf[i] -= center;
- wpf[i].mV[0] = fabsf(wpf[i].mV[0]);
- wpf[i].mV[2] = fabsf(wpf[i].mV[2]);
- }
- F32 bfm = 0.f;
- F32 bfb = 0.f;
- if (!wpf.empty())
- {
- F32 sx = 0.f;
- F32 sx2 = 0.f;
- F32 sy = 0.f;
- F32 sxy = 0.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- sx += wpf[i].mV[0];
- sx2 += wpf[i].mV[0] * wpf[i].mV[0];
- sy += wpf[i].mV[1];
- sxy += wpf[i].mV[0] * wpf[i].mV[1];
- }
- bfm = (sy * sx - wpf.size() * sxy) /
- (sx * sx - wpf.size() * sx2);
- bfb = (sx * sxy - sy * sx2) / (sx * sx - bfm * sx2);
- }
- if (llisnan(bfm) || llisnan(bfb))
- {
- LL_DEBUGS("Pipeline") << "NaN found. Corresponding shadow rendering aborted. Camera ID: "
- << LLViewerCamera::sCurCameraID
- << LL_ENDL;
- continue;
- }
- {
- // Best fit line is y = bfm * x + bfb
- // Find point that is furthest to the right of line
- F32 off_x = -1.f;
- LLVector3 lp;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- // y = bfm * x + bfb
- // x = (y - bfb) / bfm
- F32 lx = (wpf[i].mV[1] - bfb) / bfm;
- lx = wpf[i].mV[0] - lx;
- if (off_x < lx)
- {
- off_x = lx;
- lp = wpf[i];
- }
- }
- // Get line with slope bfm through lp
- // bfb = y - bfm * x
- bfb = lp.mV[1] - bfm * lp.mV[0];
- // Calculate error
- F32 shadow_error = 0.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- F32 lx = (wpf[i].mV[1] - bfb) / bfm;
- shadow_error += fabsf(wpf[i].mV[0] - lx);
- }
- shadow_error /= wpf.size() * size.mV[0];
- if (llisnan(shadow_error) ||
- shadow_error > RenderShadowErrorCutoff)
- {
- // Just use ortho projection
- origin.clear();
- proj[j] = gl_ortho(min.mV[0], max.mV[0], min.mV[1],
- max.mV[1], -max.mV[2], -min.mV[2]);
- }
- else
- {
- // Origin is where line x = 0;
- origin.set(0, bfb, 0);
- F32 fovz = 1.f;
- F32 fovx = 1.f;
- LLVector3 zp;
- LLVector3 xp;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- LLVector3 atz = wpf[i] - origin;
- atz.mV[0] = 0.f;
- atz.normalize();
- if (fovz > -atz.mV[1])
- {
- zp = wpf[i];
- fovz = -atz.mV[1];
- }
- LLVector3 atx = wpf[i] - origin;
- atx.mV[2] = 0.f;
- atx.normalize();
- if (fovx > -atx.mV[1])
- {
- fovx = -atx.mV[1];
- xp = wpf[i];
- }
- }
- fovx = acosf(fovx);
- fovz = acosf(fovz);
- F32 cutoff = RenderShadowFOVCutoff;
- if (fovx < cutoff && fovz > cutoff)
- {
- // x is a good fit, but z is too big, move away from zp
- // enough so that fovz matches cutoff
- F32 d = zp.mV[2] / tanf(cutoff);
- F32 ny = zp.mV[1] + fabsf(d);
- origin.mV[1] = ny;
- fovz = fovx = 1.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- LLVector3 atz = wpf[i] - origin;
- atz.mV[0] = 0.f;
- atz.normalize();
- fovz = llmin(fovz, -atz.mV[1]);
- LLVector3 atx = wpf[i] - origin;
- atx.mV[2] = 0.f;
- atx.normalize();
- fovx = llmin(fovx, -atx.mV[1]);
- }
- fovx = acosf(fovx);
- fovz = acosf(fovz);
- }
- origin += center;
- F32 ynear = origin.mV[1] - max.mV[1];
- F32 yfar = origin.mV[1] - min.mV[1];
- if (ynear < 0.1f) // keep a sensible near clip plane
- {
- F32 diff = 0.1f - ynear;
- origin.mV[1] += diff;
- ynear += diff;
- yfar += diff;
- }
- if (fovx > cutoff)
- {
- // Just use ortho projection
- origin.clear();
- proj[j] = gl_ortho(min.mV[0], max.mV[0], min.mV[1],
- max.mV[1], -max.mV[2], -min.mV[2]);
- }
- else
- {
- // Get perspective projection
- view[j].invert();
- // Translate view to origin
- LLVector4a origin_agent;
- origin_agent.load3(origin.mV);
- view[j].affineTransform(origin_agent, origin_agent);
- eye = LLVector3(origin_agent.getF32ptr());
- view[j] = look_proj(LLVector3(origin_agent.getF32ptr()),
- light_dir, -up);
- F32 fx = 1.f / tanf(fovx);
- F32 fz = 1.f / tanf(fovz);
- const F32 y1 = (yfar + ynear) / (ynear - yfar);
- const F32 y3 = 2.f * yfar * ynear / (ynear - yfar);
- proj[j].setRow<0>(LLVector4a(-fx, 0.f, 0.f, 0.f));
- proj[j].setRow<1>(LLVector4a(0.f, y1, 0.f, -1.f));
- proj[j].setRow<2>(LLVector4a(0.f, 0.f, -fz, 0.f));
- proj[j].setRow<3>(LLVector4a(0.f, y3, 0.f, 0.f));
- }
- }
- }
- #if 0
- shadow_cam.setFar(128.f);
- #endif
- if (llisnan(eye.mV[VX]) || llisnan(eye.mV[VY]) ||
- llisnan(eye.mV[VZ]))
- {
- LL_DEBUGS("Pipeline") << "NaN found in eye origin. Corresponding shadow rendering aborted. Camera ID: "
- << LLViewerCamera::sCurCameraID
- << LL_ENDL;
- continue;
- }
- shadow_cam.setOriginAndLookAt(eye, up, center);
- shadow_cam.setOrigin(0.f, 0.f, 0.f);
- gGLModelView = view[j];
- gGLProjection = proj[j];
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- // shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR);
- shadow_cam.agentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip);
- gGLModelView = view[j];
- gGLProjection = proj[j];
- gGLLastModelView = mShadowModelview[j];
- gGLLastProjection = mShadowProjection[j];
- mShadowModelview[j] = view[j];
- mShadowProjection[j] = proj[j];
- mSunShadowMatrix[j].setMul(TRANS_MAT, proj[j]);
- mSunShadowMatrix[j].mulAffine(view[j]);
- mSunShadowMatrix[j].mulAffine(inv_view);
- mRT->mSunShadow[j].bindTarget();
- mRT->mSunShadow[j].getViewport(gGLViewport);
- mRT->mSunShadow[j].clear();
- static LLCullResult result[4];
- renderShadow(view[j], proj[j], shadow_cam, result[j], true);
- mRT->mSunShadow[j].flush();
- if (no_shadow_frustra)
- {
- mShadowCamera[j + 4] = shadow_cam;
- }
- }
- }
- // HACK to disable projector shadows
- bool gen_shadow = RenderShadowDetail > 1;
- // Note: skip updating spot shadow maps during cubemap updates
- if (gen_shadow && !gCubeSnapshot)
- {
- F32 fade_amt =
- gFrameIntervalSeconds *
- llmax(LLViewerCamera::getVelocityStat().getCurrentPerSec(), 1.f);
- // Update shadow targets
- for (U32 i = 0; i < 2; ++i)
- {
- // For each current shadow
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SPOT_SHADOW0 + i;
- if (mShadowSpotLight[i].notNull() &&
- (mShadowSpotLight[i] == mTargetShadowSpotLight[0] ||
- mShadowSpotLight[i] == mTargetShadowSpotLight[1]))
- {
- // Keep this spotlight
- mSpotLightFade[i] = llmin(mSpotLightFade[i] + fade_amt, 1.f);
- }
- else
- {
- // Fade out this light
- mSpotLightFade[i] = llmax(mSpotLightFade[i] - fade_amt, 0.f);
- if (mSpotLightFade[i] == 0.f || mShadowSpotLight[i].isNull())
- {
- // Faded out, grab one of the pending spots (whichever one
- // is not already taken)
- if (mTargetShadowSpotLight[0] != mShadowSpotLight[(i + 1) % 2])
- {
- mShadowSpotLight[i] = mTargetShadowSpotLight[0];
- }
- else
- {
- mShadowSpotLight[i] = mTargetShadowSpotLight[1];
- }
- }
- }
- }
- }
- if (gen_shadow)
- {
- for (S32 i = 0; i < 2; ++i)
- {
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- if (mShadowSpotLight[i].isNull())
- {
- continue;
- }
- LLVOVolume* volp = mShadowSpotLight[i]->getVOVolume();
- if (!volp)
- {
- mShadowSpotLight[i] = NULL;
- continue;
- }
- LLDrawable* drawablep = mShadowSpotLight[i];
- LLVector3 params = volp->getSpotLightParams();
- F32 fov = params.mV[0];
- // Get agent->light space matrix (modelview)
- LLVector3 center = drawablep->getPositionAgent();
- LLQuaternion quat = volp->getRenderRotation();
- // Get near clip plane
- LLVector3 scale = volp->getScale();
- LLVector3 at_axis(0.f, 0.f, -scale.mV[2] * 0.5f);
- at_axis *= quat;
- LLVector3 np = center + at_axis;
- at_axis.normalize();
- // Get origin that has given fov for plane np, at_axis, and given
- // scale
- F32 divisor = tanf(fov * 0.5f);
- // Seen happening and causing NaNs in setOrigin() below. HB
- if (divisor == 0.f) continue;
- F32 dist = (scale.mV[1] * 0.5f) / divisor;
- LLVector3 origin = np - at_axis * dist;
- LLMatrix4 mat(quat, LLVector4(origin, 1.f));
- view[i + 4].loadu(mat.getF32ptr());
- view[i + 4].invert();
- // Get perspective matrix
- F32 near_clip = dist + 0.01f;
- F32 width = scale.mV[VX];
- F32 height = scale.mV[VY];
- F32 far_clip = dist + volp->getLightRadius() * 1.5f;
- F32 fovy = fov * RAD_TO_DEG;
- F32 aspect = width / height;
- proj[i + 4] = gl_perspective(fovy, aspect, near_clip, far_clip);
- // Translate and scale from [-1, 1] to [0, 1]
- gGLModelView = view[i + 4];
- gGLProjection = proj[i + 4];
- mSunShadowMatrix[i + 4].setMul(TRANS_MAT, proj[i + 4]);
- mSunShadowMatrix[i + 4].mulAffine(view[i + 4]);
- mSunShadowMatrix[i + 4].mulAffine(inv_view);
- gGLLastModelView = mShadowModelview[i + 4];
- gGLLastProjection = mShadowProjection[i + 4];
- mShadowModelview[i + 4] = view[i + 4];
- mShadowProjection[i + 4] = proj[i + 4];
- // Skip updating spot shadow maps during cubemap updates
- if (!gCubeSnapshot)
- {
- LLCamera shadow_cam = gViewerCamera;
- shadow_cam.setFar(far_clip);
- shadow_cam.setOrigin(origin);
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- mSpotShadow[i].bindTarget();
- mSpotShadow[i].getViewport(gGLViewport);
- mSpotShadow[i].clear();
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SPOT_SHADOW0 + i;
- sRenderSpotLight = drawablep;
- static LLCullResult result[2];
- renderShadow(view[i + 4], proj[i + 4], shadow_cam, result[i],
- false);
- sRenderSpotLight = NULL;
- mSpotShadow[i].flush();
- }
- }
- }
- else
- {
- // No spotlight shadows
- mShadowSpotLight[0] = mShadowSpotLight[1] = NULL;
- }
- if (!CameraOffset)
- {
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- }
- else
- {
- gGLModelView = view[1];
- gGLProjection = proj[1];
- gGL.loadMatrix(view[1]);
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.loadMatrix(proj[1]);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- }
- gGL.setColorMask(true, true);
- gGLLastModelView = last_modelview;
- gGLLastProjection = last_projection;
- popRenderTypeMask();
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(gAgent.getCameraMode());
- }
- }
- void LLPipeline::generateSunShadow()
- {
- if (!sRenderDeferred || !RenderShadowDetail)
- {
- return;
- }
- LL_FAST_TIMER(FTM_GEN_SUN_SHADOW);
- if (gUsePBRShaders)
- {
- generateSunShadowPBR();
- return;
- }
- bool skip_avatar_update = false;
- if (!isAgentAvatarValid() || gAgent.getCameraAnimating() ||
- gAgent.getCameraMode() != CAMERA_MODE_MOUSELOOK ||
- !LLVOAvatar::sVisibleInFirstPerson)
- {
- skip_avatar_update = true;
- }
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON);
- }
- // Store last_modelview of world camera
- LLMatrix4a last_modelview = gGLLastModelView;
- LLMatrix4a last_projection = gGLLastProjection;
- pushRenderTypeMask();
- andRenderTypeMask(RENDER_TYPE_SIMPLE,
- RENDER_TYPE_ALPHA,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_FULLBRIGHT,
- RENDER_TYPE_BUMP,
- RENDER_TYPE_VOLUME,
- RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- RENDER_TYPE_TREE,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_WATER,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_PASS_ALPHA,
- RENDER_TYPE_PASS_ALPHA_MASK,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_PASS_SIMPLE,
- RENDER_TYPE_PASS_BUMP,
- RENDER_TYPE_PASS_FULLBRIGHT,
- RENDER_TYPE_PASS_SHINY,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
- RENDER_TYPE_PASS_MATERIAL,
- RENDER_TYPE_PASS_MATERIAL_ALPHA,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE,
- RENDER_TYPE_PASS_SPECMAP,
- RENDER_TYPE_PASS_SPECMAP_BLEND,
- RENDER_TYPE_PASS_SPECMAP_MASK,
- RENDER_TYPE_PASS_SPECMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMMAP,
- RENDER_TYPE_PASS_NORMMAP_BLEND,
- RENDER_TYPE_PASS_NORMMAP_MASK,
- RENDER_TYPE_PASS_NORMMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMSPEC,
- RENDER_TYPE_PASS_NORMSPEC_BLEND,
- RENDER_TYPE_PASS_NORMSPEC_MASK,
- RENDER_TYPE_PASS_NORMSPEC_EMISSIVE,
- RENDER_TYPE_PASS_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_SIMPLE_RIGGED,
- RENDER_TYPE_PASS_BUMP_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_RIGGED,
- RENDER_TYPE_PASS_SHINY_RIGGED,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK_RIGGED,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_BLEND_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_MASK_RIGGED,
- RENDER_TYPE_PASS_SPECMAP_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_BLEND_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_MASK_RIGGED,
- RENDER_TYPE_PASS_NORMMAP_EMISSIVE_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_BLEND_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_MASK_RIGGED,
- RENDER_TYPE_PASS_NORMSPEC_EMISSIVE_RIGGED,
- END_RENDER_TYPES);
- gGL.setColorMask(false, false);
- // Get sun view matrix
- // Store current projection/modelview matrix
- const LLMatrix4a saved_proj = gGLProjection;
- const LLMatrix4a saved_view = gGLModelView;
- LLMatrix4a inv_view(saved_view);
- inv_view.invert();
- LLMatrix4a view[6];
- LLMatrix4a proj[6];
- // Clip contains parallel split distances for 3 splits
- LLVector3 clip = RenderShadowClipPlanes;
- LLVector3 caster_dir(mIsSunUp ? mSunDir : mMoonDir);
- // Far clip on last split is minimum of camera view distance and 128
- mSunClipPlanes = LLVector4(clip, clip.mV[2] * clip.mV[2] / clip.mV[1]);
- // Put together a universal "near clip" plane for shadow frusta
- LLPlane shadow_near_clip;
- {
- LLVector3 p = gAgent.getPositionAgent();
- p += caster_dir * RenderFarClip * 2.f;
- shadow_near_clip.setVec(p, caster_dir);
- }
- LLVector3 light_dir = -caster_dir;
- light_dir.normalize();
- // Create light space camera matrix
- LLVector3 at = light_dir;
- LLVector3 up = gViewerCamera.getAtAxis();
- if (fabsf(up * light_dir) > 0.75f)
- {
- up = gViewerCamera.getUpAxis();
- }
- up.normalize();
- at.normalize();
- LLCamera main_camera = gViewerCamera;
- bool no_shadow_frustra = !hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA);
- F32 near_clip = 0.f;
- {
- // Get visible point cloud
- main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum);
- LLVector3 min, max;
- std::vector<LLVector3> fp;
- getVisiblePointCloud(main_camera, min, max, fp);
- if (fp.empty())
- {
- if (no_shadow_frustra)
- {
- mShadowCamera[0] = main_camera;
- mShadowExtents[0][0] = min;
- mShadowExtents[0][1] = max;
- mShadowFrustPoints[0].clear();
- mShadowFrustPoints[1].clear();
- mShadowFrustPoints[2].clear();
- mShadowFrustPoints[3].clear();
- }
- popRenderTypeMask();
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(gAgent.getCameraMode());
- }
- return;
- }
- LLVector4a v;
- // Get good split distances for frustum
- for (U32 i = 0; i < fp.size(); ++i)
- {
- v.load3(fp[i].mV);
- saved_view.affineTransform(v, v);
- fp[i].set(v.getF32ptr());
- }
- min = fp[0];
- max = fp[0];
- // Get camera space bounding box
- for (U32 i = 1; i < fp.size(); ++i)
- {
- update_min_max(min, max, fp[i]);
- }
- near_clip = llclamp(-max.mV[2], 0.01f, 4.0f);
- F32 far_clip = llclamp(-min.mV[2] * 2.f, 16.0f, 512.0f);
- far_clip = llmin(far_clip, gViewerCamera.getFar());
- F32 range = far_clip - near_clip;
- LLVector3 split_exp = RenderShadowSplitExponent;
- F32 da = 1.f - llmax(fabsf(light_dir * up),
- fabsf(light_dir * gViewerCamera.getLeftAxis()));
- da = powf(da, split_exp.mV[2]);
- F32 sxp = split_exp.mV[1] + (split_exp.mV[0] - split_exp.mV[1]) * da;
- for (U32 i = 0; i < 4; ++i)
- {
- F32 x = (F32)(i + 1) * 0.25f;
- x = powf(x, sxp);
- mSunClipPlanes.mV[i] = near_clip + range * x;
- }
- // Bump back first split for transition padding
- mSunClipPlanes.mV[0] *= 1.25f;
- }
- // Convenience array of 4 near clip plane distances
- F32 dist[] = { near_clip,
- mSunClipPlanes.mV[0],
- mSunClipPlanes.mV[1],
- mSunClipPlanes.mV[2],
- mSunClipPlanes.mV[3] };
- if (mSunLightColor == LLColor4::black)
- {
- // Sun diffuse is totally black, shadows do not matter
- LLGLDepthTest depth(GL_TRUE);
- for (S32 j = 0; j < 4; ++j)
- {
- mShadow[j].bindTarget();
- mShadow[j].clear();
- mShadow[j].flush();
- }
- }
- else
- {
- for (S32 j = 0; j < 4; ++j)
- {
- if (no_shadow_frustra)
- {
- mShadowFrustPoints[j].clear();
- }
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SUN_SHADOW0 + j;
- // Restore render matrices
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- LLVector3 eye = gViewerCamera.getOrigin();
- // Camera used for shadow cull/render
- LLCamera shadow_cam = gViewerCamera;
- shadow_cam.setFar(16.f);
- // Create world space camera frustum for this split
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- LLVector3* frust = shadow_cam.mAgentFrustum;
- LLVector3 pn = shadow_cam.getAtAxis();
- // Construct 8 corners of split frustum section
- for (U32 i = 0; i < 4; ++i)
- {
- LLVector3 delta = frust[i + 4] - eye;
- delta += (frust[i + 4] - frust[(i + 2) % 4 + 4]) * 0.05f;
- delta.normalize();
- F32 dp = delta * pn;
- frust[i] = eye + (delta * dist[j] * 0.75f) / dp;
- frust[i + 4] = eye + (delta * dist[j + 1] * 1.25f) / dp;
- }
- shadow_cam.calcAgentFrustumPlanes(frust);
- shadow_cam.mFrustumCornerDist = 0.f;
- if (no_shadow_frustra)
- {
- mShadowCamera[j] = shadow_cam;
- }
- std::vector<LLVector3> fp;
- LLVector3 min, max;
- if (!getVisiblePointCloud(shadow_cam, min, max, fp, light_dir))
- {
- // No possible shadow receivers
- if (no_shadow_frustra)
- {
- mShadowExtents[j][0].clear();
- mShadowExtents[j][1].clear();
- mShadowCamera[j + 4] = shadow_cam;
- }
- mShadow[j].bindTarget();
- {
- LLGLDepthTest depth(GL_TRUE);
- mShadow[j].clear();
- }
- mShadow[j].flush();
- continue;
- }
- if (no_shadow_frustra)
- {
- mShadowExtents[j][0] = min;
- mShadowExtents[j][1] = max;
- mShadowFrustPoints[j] = fp;
- }
- // Find a good origin for shadow projection
- LLVector3 origin;
- // Get a temporary view projection
- view[j] = look_proj(gViewerCamera.getOrigin(), light_dir, -up);
- std::vector<LLVector3> wpf;
- LLVector4a p;
- for (U32 i = 0; i < fp.size(); ++i)
- {
- p.load3(fp[i].mV);
- view[j].affineTransform(p, p);
- wpf.emplace_back(LLVector3(p.getF32ptr()));
- }
- min = max = wpf[0];
- for (U32 i = 0; i < fp.size(); ++i)
- {
- // Get AABB in camera space
- update_min_max(min, max, wpf[i]);
- }
- // Construct a perspective transform with perspective along y-axis
- // that contains points in wpf
- // Known:
- // - far clip plane
- // - near clip plane
- // - points in frustum
- // Find:
- // - origin
- // Get some "interesting" points of reference
- LLVector3 center = (min + max) * 0.5f;
- LLVector3 size = (max - min) * 0.5f;
- LLVector3 near_center = center;
- near_center.mV[1] += size.mV[1] * 2.f;
- // Put all points in wpf in quadrant 0, reletive to center of
- // min/max get the best fit line using least squares
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- wpf[i] -= center;
- wpf[i].mV[0] = fabsf(wpf[i].mV[0]);
- wpf[i].mV[2] = fabsf(wpf[i].mV[2]);
- }
- F32 bfm = 0.f;
- F32 bfb = 0.f;
- if (!wpf.empty())
- {
- F32 sx = 0.f;
- F32 sx2 = 0.f;
- F32 sy = 0.f;
- F32 sxy = 0.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- sx += wpf[i].mV[0];
- sx2 += wpf[i].mV[0] * wpf[i].mV[0];
- sy += wpf[i].mV[1];
- sxy += wpf[i].mV[0] * wpf[i].mV[1];
- }
- bfm = (sy * sx - wpf.size() * sxy) /
- (sx * sx - wpf.size() * sx2);
- bfb = (sx * sxy - sy * sx2) / (sx * sx - bfm * sx2);
- }
- if (llisnan(bfm) || llisnan(bfb))
- {
- LL_DEBUGS("Pipeline") << "NaN found. Corresponding shadow rendering aborted. Camera ID: "
- << LLViewerCamera::sCurCameraID
- << LL_ENDL;
- continue;
- }
- {
- // Best fit line is y = bfm * x + bfb
- // Find point that is furthest to the right of line
- F32 off_x = -1.f;
- LLVector3 lp;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- // y = bfm * x + bfb
- // x = (y - bfb) / bfm
- F32 lx = (wpf[i].mV[1] - bfb) / bfm;
- lx = wpf[i].mV[0] - lx;
- if (off_x < lx)
- {
- off_x = lx;
- lp = wpf[i];
- }
- }
- // Get line with slope bfm through lp
- // bfb = y - bfm * x
- bfb = lp.mV[1] - bfm * lp.mV[0];
- // Calculate error
- F32 shadow_error = 0.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- F32 lx = (wpf[i].mV[1] - bfb) / bfm;
- shadow_error += fabsf(wpf[i].mV[0] - lx);
- }
- shadow_error /= wpf.size() * size.mV[0];
- if (llisnan(shadow_error) ||
- shadow_error > RenderShadowErrorCutoff)
- {
- // Just use ortho projection
- origin.clear();
- proj[j] = gl_ortho(min.mV[0], max.mV[0], min.mV[1],
- max.mV[1], -max.mV[2], -min.mV[2]);
- }
- else
- {
- // Origin is where line x = 0;
- origin.set(0, bfb, 0);
- F32 fovz = 1.f;
- F32 fovx = 1.f;
- LLVector3 zp;
- LLVector3 xp;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- LLVector3 atz = wpf[i] - origin;
- atz.mV[0] = 0.f;
- atz.normalize();
- if (fovz > -atz.mV[1])
- {
- zp = wpf[i];
- fovz = -atz.mV[1];
- }
- LLVector3 atx = wpf[i] - origin;
- atx.mV[2] = 0.f;
- atx.normalize();
- if (fovx > -atx.mV[1])
- {
- fovx = -atx.mV[1];
- xp = wpf[i];
- }
- }
- fovx = acosf(fovx);
- fovz = acosf(fovz);
- F32 cutoff = RenderShadowFOVCutoff;
- if (fovx < cutoff && fovz > cutoff)
- {
- // x is a good fit, but z is too big, move away from zp
- // enough so that fovz matches cutoff
- F32 d = zp.mV[2] / tanf(cutoff);
- F32 ny = zp.mV[1] + fabsf(d);
- origin.mV[1] = ny;
- fovz = fovx = 1.f;
- for (U32 i = 0; i < wpf.size(); ++i)
- {
- LLVector3 atz = wpf[i] - origin;
- atz.mV[0] = 0.f;
- atz.normalize();
- fovz = llmin(fovz, -atz.mV[1]);
- LLVector3 atx = wpf[i] - origin;
- atx.mV[2] = 0.f;
- atx.normalize();
- fovx = llmin(fovx, -atx.mV[1]);
- }
- fovx = acosf(fovx);
- fovz = acosf(fovz);
- }
- origin += center;
- F32 ynear = origin.mV[1] - max.mV[1];
- F32 yfar = origin.mV[1] - min.mV[1];
- if (ynear < 0.1f) // keep a sensible near clip plane
- {
- F32 diff = 0.1f - ynear;
- origin.mV[1] += diff;
- ynear += diff;
- yfar += diff;
- }
- if (fovx > cutoff)
- {
- // Just use ortho projection
- origin.clear();
- proj[j] = gl_ortho(min.mV[0], max.mV[0], min.mV[1],
- max.mV[1], -max.mV[2], -min.mV[2]);
- }
- else
- {
- // Get perspective projection
- view[j].invert();
- // Translate view to origin
- LLVector4a origin_agent;
- origin_agent.load3(origin.mV);
- view[j].affineTransform(origin_agent, origin_agent);
- eye = LLVector3(origin_agent.getF32ptr());
- view[j] = look_proj(LLVector3(origin_agent.getF32ptr()),
- light_dir, -up);
- F32 fx = 1.f / tanf(fovx);
- F32 fz = 1.f / tanf(fovz);
- const F32 y1 = (yfar + ynear) / (ynear - yfar);
- const F32 y3 = 2.f * yfar * ynear / (ynear - yfar);
- proj[j].setRow<0>(LLVector4a(-fx, 0.f, 0.f, 0.f));
- proj[j].setRow<1>(LLVector4a(0.f, y1, 0.f, -1.f));
- proj[j].setRow<2>(LLVector4a(0.f, 0.f, -fz, 0.f));
- proj[j].setRow<3>(LLVector4a(0.f, y3, 0.f, 0.f));
- }
- }
- }
- #if 0
- shadow_cam.setFar(128.f);
- #endif
- if (llisnan(eye.mV[VX]) || llisnan(eye.mV[VY]) ||
- llisnan(eye.mV[VZ]))
- {
- LL_DEBUGS("Pipeline") << "NaN found in eye origin. Corresponding shadow rendering aborted. Camera ID: "
- << LLViewerCamera::sCurCameraID
- << LL_ENDL;
- continue;
- }
- shadow_cam.setOriginAndLookAt(eye, up, center);
- shadow_cam.setOrigin(0.f, 0.f, 0.f);
- gGLModelView = view[j];
- gGLProjection = proj[j];
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- // shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR);
- shadow_cam.agentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip);
- gGLModelView = view[j];
- gGLProjection = proj[j];
- gGLLastModelView = mShadowModelview[j];
- gGLLastProjection = mShadowProjection[j];
- mShadowModelview[j] = view[j];
- mShadowProjection[j] = proj[j];
- mSunShadowMatrix[j].setMul(TRANS_MAT, proj[j]);
- mSunShadowMatrix[j].mulAffine(view[j]);
- mSunShadowMatrix[j].mulAffine(inv_view);
- mShadow[j].bindTarget();
- mShadow[j].getViewport(gGLViewport);
- mShadow[j].clear();
- static LLCullResult result[4];
- renderShadow(view[j], proj[j], shadow_cam, result[j], true, false,
- mShadow[j].getWidth());
- mShadow[j].flush();
- if (no_shadow_frustra)
- {
- mShadowCamera[j + 4] = shadow_cam;
- }
- }
- }
- // HACK to disable projector shadows
- bool gen_shadow = RenderShadowDetail > 1;
- if (gen_shadow)
- {
- F32 fade_amt =
- gFrameIntervalSeconds *
- llmax(LLViewerCamera::getVelocityStat().getCurrentPerSec(), 1.f);
- // Update shadow targets
- for (U32 i = 0; i < 2; ++i)
- {
- // For each current shadow
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SPOT_SHADOW0 + i;
- if (mShadowSpotLight[i].notNull() &&
- (mShadowSpotLight[i] == mTargetShadowSpotLight[0] ||
- mShadowSpotLight[i] == mTargetShadowSpotLight[1]))
- {
- // Keep this spotlight
- mSpotLightFade[i] = llmin(mSpotLightFade[i] + fade_amt, 1.f);
- }
- else
- {
- // Fade out this light
- mSpotLightFade[i] = llmax(mSpotLightFade[i] - fade_amt, 0.f);
- if (mSpotLightFade[i] == 0.f || mShadowSpotLight[i].isNull())
- {
- // Faded out, grab one of the pending spots (whichever one
- // is not already taken)
- if (mTargetShadowSpotLight[0] != mShadowSpotLight[(i + 1) % 2])
- {
- mShadowSpotLight[i] = mTargetShadowSpotLight[0];
- }
- else
- {
- mShadowSpotLight[i] = mTargetShadowSpotLight[1];
- }
- }
- }
- }
- for (S32 i = 0; i < 2; ++i)
- {
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- if (mShadowSpotLight[i].isNull())
- {
- continue;
- }
- LLVOVolume* volp = mShadowSpotLight[i]->getVOVolume();
- if (!volp)
- {
- mShadowSpotLight[i] = NULL;
- continue;
- }
- LLDrawable* drawablep = mShadowSpotLight[i];
- LLVector3 params = volp->getSpotLightParams();
- F32 fov = params.mV[0];
- // Get agent->light space matrix (modelview)
- LLVector3 center = drawablep->getPositionAgent();
- LLQuaternion quat = volp->getRenderRotation();
- // Get near clip plane
- LLVector3 scale = volp->getScale();
- LLVector3 at_axis(0.f, 0.f, -scale.mV[2] * 0.5f);
- at_axis *= quat;
- LLVector3 np = center + at_axis;
- at_axis.normalize();
- // Get origin that has given fov for plane np, at_axis, and given
- // scale
- F32 divisor = tanf(fov * 0.5f);
- // Seen happening and causing NaNs in setOrigin() below. HB
- if (divisor == 0.f) continue;
- F32 dist = (scale.mV[1] * 0.5f) / divisor;
- LLVector3 origin = np - at_axis * dist;
- LLMatrix4 mat(quat, LLVector4(origin, 1.f));
- view[i + 4].loadu(mat.getF32ptr());
- view[i + 4].invert();
- // Get perspective matrix
- F32 near_clip = dist + 0.01f;
- F32 width = scale.mV[VX];
- F32 height = scale.mV[VY];
- F32 far_clip = dist + volp->getLightRadius() * 1.5f;
- F32 fovy = fov * RAD_TO_DEG;
- F32 aspect = width / height;
- proj[i + 4] = gl_perspective(fovy, aspect, near_clip, far_clip);
- // Translate and scale from [-1, 1] to [0, 1]
- gGLModelView = view[i + 4];
- gGLProjection = proj[i + 4];
- mSunShadowMatrix[i + 4].setMul(TRANS_MAT, proj[i + 4]);
- mSunShadowMatrix[i + 4].mulAffine(view[i + 4]);
- mSunShadowMatrix[i + 4].mulAffine(inv_view);
- gGLLastModelView = mShadowModelview[i + 4];
- gGLLastProjection = mShadowProjection[i + 4];
- mShadowModelview[i + 4] = view[i + 4];
- mShadowProjection[i + 4] = proj[i + 4];
- LLCamera shadow_cam = gViewerCamera;
- shadow_cam.setFar(far_clip);
- shadow_cam.setOrigin(origin);
- LLViewerCamera::updateFrustumPlanes(shadow_cam, false, false,
- true);
- mShadow[i + 4].bindTarget();
- mShadow[i + 4].getViewport(gGLViewport);
- mShadow[i + 4].clear();
- LLViewerCamera::sCurCameraID =
- LLViewerCamera::CAMERA_SPOT_SHADOW0 + i;
- sRenderSpotLight = drawablep;
- static LLCullResult result[2];
- renderShadow(view[i + 4], proj[i + 4], shadow_cam, result[i],
- false, false, mShadow[i + 4].getWidth());
- sRenderSpotLight = NULL;
- mShadow[i + 4].flush();
- }
- }
- else
- {
- // No spotlight shadows
- mShadowSpotLight[0] = mShadowSpotLight[1] = NULL;
- }
- if (!CameraOffset)
- {
- gGLModelView = saved_view;
- gGLProjection = saved_proj;
- }
- else
- {
- gGLModelView = view[1];
- gGLProjection = proj[1];
- gGL.loadMatrix(view[1]);
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.loadMatrix(proj[1]);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- }
- gGL.setColorMask(true, false);
- gGLLastModelView = last_modelview;
- gGLLastProjection = last_projection;
- popRenderTypeMask();
- if (!skip_avatar_update)
- {
- gAgentAvatarp->updateAttachmentVisibility(gAgent.getCameraMode());
- }
- stop_glerror();
- }
- void LLPipeline::renderGroups(LLRenderPass* passp, U32 type, U32 mask,
- bool texture)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = visible_groups[i];
- if (groupp && !groupp->isDead() &&
- (!sUseOcclusion ||
- !groupp->isOcclusionState(LLSpatialGroup::OCCLUDED)) &&
- hasRenderType(groupp->getSpatialPartition()->mDrawableType) &&
- groupp->mDrawMap.count(type))
- {
- passp->renderGroup(groupp, type, mask, texture);
- }
- }
- }
- void LLPipeline::renderRiggedGroups(LLRenderPass* passp, U32 type, U32 mask,
- bool texture)
- {
- LLCullResult::sg_list_t& visible_groups = sCull->getVisibleGroups();
- for (U32 i = 0, count = visible_groups.size(); i < count; ++i)
- {
- LLSpatialGroup* groupp = visible_groups[i];
- if (groupp && !groupp->isDead() &&
- (!sUseOcclusion ||
- !groupp->isOcclusionState(LLSpatialGroup::OCCLUDED)) &&
- hasRenderType(groupp->getSpatialPartition()->mDrawableType) &&
- groupp->mDrawMap.count(type))
- {
- passp->renderRiggedGroup(groupp, type, mask, texture);
- }
- }
- }
- void LLPipeline::generateImpostor(LLVOAvatar* avatarp)
- {
- if (!avatarp || avatarp->isDead() || !avatarp->mDrawable)
- {
- return;
- }
- LL_GL_CHECK_STATES;
- static LLCullResult result;
- result.clear();
- grabReferences(result);
- pushRenderTypeMask();
- bool visually_muted = avatarp->isVisuallyMuted();
- //MK
- bool vision_restricted = gRLenabled && gRLInterface.mVisionRestricted;
- if (vision_restricted)
- {
- // Render everything on impostors
- andRenderTypeMask(RENDER_TYPE_ALPHA,
- RENDER_TYPE_FULLBRIGHT,
- RENDER_TYPE_VOLUME,
- RENDER_TYPE_GLOW,
- RENDER_TYPE_BUMP,
- RENDER_TYPE_PASS_SIMPLE,
- RENDER_TYPE_PASS_ALPHA,
- RENDER_TYPE_PASS_ALPHA_MASK,
- RENDER_TYPE_PASS_BUMP,
- RENDER_TYPE_PASS_POST_BUMP,
- RENDER_TYPE_PASS_FULLBRIGHT,
- RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
- RENDER_TYPE_PASS_GLOW,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_PASS_SHINY,
- RENDER_TYPE_PASS_MATERIAL,
- RENDER_TYPE_PASS_MATERIAL_ALPHA,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK,
- RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE,
- RENDER_TYPE_PASS_SPECMAP,
- RENDER_TYPE_PASS_SPECMAP_BLEND,
- RENDER_TYPE_PASS_SPECMAP_MASK,
- RENDER_TYPE_PASS_SPECMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMMAP,
- RENDER_TYPE_PASS_NORMMAP_BLEND,
- RENDER_TYPE_PASS_NORMMAP_MASK,
- RENDER_TYPE_PASS_NORMMAP_EMISSIVE,
- RENDER_TYPE_PASS_NORMSPEC,
- RENDER_TYPE_PASS_NORMSPEC_BLEND,
- RENDER_TYPE_PASS_NORMSPEC_MASK,
- RENDER_TYPE_PASS_NORMSPEC_EMISSIVE,
- RENDER_TYPE_AVATAR,
- RENDER_TYPE_PUPPET,
- RENDER_TYPE_ALPHA_MASK,
- RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
- RENDER_TYPE_SIMPLE,
- RENDER_TYPE_MATERIALS,
- END_RENDER_TYPES);
- }
- else
- //mk
- if (visually_muted)
- {
- // Only show jelly doll geometry
- andRenderTypeMask(RENDER_TYPE_AVATAR, RENDER_TYPE_PUPPET,
- END_RENDER_TYPES);
- }
- else if (gUsePBRShaders)
- {
- clearRenderTypeMask(RENDER_TYPE_SKY,
- RENDER_TYPE_WL_SKY,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_PUPPET, // Animesh
- RENDER_TYPE_TREE,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_WATER,
- RENDER_TYPE_ALPHA_PRE_WATER,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_HUD,
- RENDER_TYPE_PARTICLES,
- RENDER_TYPE_CLOUDS,
- RENDER_TYPE_HUD_PARTICLES,
- END_RENDER_TYPES);
- }
- else
- {
- // Hide world geometry
- clearRenderTypeMask(RENDER_TYPE_SKY,
- RENDER_TYPE_WL_SKY,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_PUPPET, // Animesh
- RENDER_TYPE_TREE,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_WATER,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_HUD,
- RENDER_TYPE_PARTICLES,
- RENDER_TYPE_CLOUDS,
- RENDER_TYPE_HUD_PARTICLES,
- END_RENDER_TYPES);
- }
- LLDisableOcclusionCulling no_occlusion;
- sReflectionRender = !sRenderDeferred;
- sShadowRender = sImpostorRender = true;
- {
- LL_FAST_TIMER(FTM_IMPOSTOR_MARK_VISIBLE);
- markVisible(avatarp->mDrawable, gViewerCamera);
- LLVOAvatar::sUseImpostors = false;
- for (S32 i = 0, count = avatarp->mAttachedObjectsVector.size();
- i < count; ++i)
- {
- LLViewerObject* object = avatarp->mAttachedObjectsVector[i].first;
- if (object)
- {
- markVisible(object->mDrawable->getSpatialBridge(),
- gViewerCamera);
- }
- }
- }
- stateSort(gViewerCamera, result);
- LLTexUnit* unit0 = gGL.getTexUnit(0);
- LLCamera camera = gViewerCamera;
- LLVector2 tdim;
- U32 res_y = 0;
- U32 res_x = 0;
- {
- LL_FAST_TIMER(FTM_IMPOSTOR_SETUP);
- const LLVector4a* ext = avatarp->mDrawable->getSpatialExtents();
- LLVector3 pos = avatarp->getRenderPosition() +
- avatarp->getImpostorOffset();
- camera.lookAt(gViewerCamera.getOrigin(), pos,
- gViewerCamera.getUpAxis());
- LLVector4a half_height;
- half_height.setSub(ext[1], ext[0]);
- half_height.mul(0.5f);
- LLVector4a left;
- left.load3(camera.getLeftAxis().mV);
- left.mul(left);
- left.normalize3fast();
- LLVector4a up;
- up.load3(camera.getUpAxis().mV);
- up.mul(up);
- up.normalize3fast();
- tdim.mV[0] = fabsf(half_height.dot3(left).getF32());
- tdim.mV[1] = fabsf(half_height.dot3(up).getF32());
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- F32 distance = (pos - camera.getOrigin()).length();
- F32 fov = atanf(tdim.mV[1] / distance) * 2.f * RAD_TO_DEG;
- F32 aspect = tdim.mV[0] / tdim.mV[1];
- LLMatrix4a persp = gl_perspective(fov, aspect, .001f, 256.f);
- gGLProjection = persp;
- gGL.loadMatrix(persp);
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.pushMatrix();
- LLMatrix4a mat;
- camera.getOpenGLTransform(mat.getF32ptr());
- mat.setMul(OGL_TO_CFR_ROT4A, mat);
- gGL.loadMatrix(mat);
- gGLModelView = mat;
- glClearColor(0.f, 0.f, 0.f, 0.f);
- gGL.setColorMask(true, true);
- // Get the number of pixels per angle
- F32 pa = gViewerWindowp->getWindowDisplayHeight() /
- (RAD_TO_DEG * gViewerCamera.getView());
- // Get resolution based on angle width and height of impostor (double
- // desired resolution to prevent aliasing)
- res_y = llmin(nhpo2((U32)(fov * pa)), 512U);
- res_x = llmin(nhpo2((U32)(atanf(tdim.mV[0] / distance) * 2.f *
- RAD_TO_DEG * pa)),
- 512U);
- if (!avatarp->mImpostor.isComplete())
- {
- LL_FAST_TIMER(FTM_IMPOSTOR_ALLOCATE);
- if (gUsePBRShaders)
- {
- avatarp->mImpostor.allocate(res_x, res_y, GL_RGBA, true);
- }
- else
- {
- U32 format = sRenderDeferred ? GL_SRGB8_ALPHA8 : GL_RGBA;
- avatarp->mImpostor.allocate(res_x, res_y, format, true, false);
- }
- if (sRenderDeferred)
- {
- addDeferredAttachments(avatarp->mImpostor);
- }
- unit0->bind(&avatarp->mImpostor);
- unit0->setTextureFilteringOption(LLTexUnit::TFO_POINT);
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- }
- else if (res_x != avatarp->mImpostor.getWidth() ||
- res_y != avatarp->mImpostor.getHeight())
- {
- LL_FAST_TIMER(FTM_IMPOSTOR_RESIZE);
- avatarp->mImpostor.resize(res_x, res_y);
- }
- avatarp->mImpostor.bindTarget();
- stop_glerror();
- }
- F32 old_alpha = LLDrawPoolAvatar::sMinimumAlpha;
- if (visually_muted)
- {
- // Disable alpha masking for muted avatars (get whole skin silhouette)
- LLDrawPoolAvatar::sMinimumAlpha = 0.f;
- }
- if (sRenderDeferred)
- {
- avatarp->mImpostor.clear();
- renderGeomDeferred(camera);
- renderGeomPostDeferred(camera);
- // Shameless hack time: render it all again, this time writing the
- // depth values we need to generate the alpha mask below while
- // preserving the alpha-sorted color rendering from the previous pass.
- sImpostorRenderAlphaDepthPass = true;
- // Depth-only here...
- gGL.setColorMask(false, false);
- renderGeomPostDeferred(camera);
- sImpostorRenderAlphaDepthPass = false;
- }
- else
- {
- LLGLEnable scissor(GL_SCISSOR_TEST);
- glScissor(0, 0, res_x, res_y);
- avatarp->mImpostor.clear();
- renderGeom(camera);
- // Shameless hack time: render it all again, this time writing the
- // depth values we need to generate the alpha mask below while
- // preserving the alpha-sorted color rendering from the previous pass.
- sImpostorRenderAlphaDepthPass = true;
- // Depth-only here...
- gGL.setColorMask(false, false);
- renderGeom(camera);
- sImpostorRenderAlphaDepthPass = false;
- }
- LLDrawPoolAvatar::sMinimumAlpha = old_alpha;
- {
- // Create alpha mask based on depth buffer (grey out if muted)
- LL_FAST_TIMER(FTM_IMPOSTOR_BACKGROUND);
- if (sRenderDeferred)
- {
- GLuint buff = GL_COLOR_ATTACHMENT0;
- glDrawBuffers(1, &buff);
- }
- LLGLDisable blend(vision_restricted ? 0 : GL_BLEND); // mk
- if (visually_muted)
- {
- gGL.setColorMask(true, true);
- }
- else
- {
- gGL.setColorMask(false, true);
- }
- unit0->unbind(LLTexUnit::TT_TEXTURE);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
- gGL.flush();
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- constexpr F32 clip_plane = 0.99999f;
- gDebugProgram.bind();
- LLColor4 muted_color(avatarp->getMutedAVColor());
- gGL.diffuseColor4fv(muted_color.mV);
- gGL.begin(LLRender::TRIANGLES);
- {
- gGL.vertex3f(-1.f, -1.f, clip_plane);
- gGL.vertex3f(1.f, -1.f, clip_plane);
- gGL.vertex3f(1.f, 1.f, clip_plane);
- gGL.vertex3f(-1.f, -1.f, clip_plane);
- gGL.vertex3f(1.f, 1.f, clip_plane);
- gGL.vertex3f(-1.f, 1.f, clip_plane);
- }
- gGL.end(true);
- gDebugProgram.unbind();
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- stop_glerror();
- }
- avatarp->mImpostor.flush();
- avatarp->setImpostorDim(tdim);
- LLVOAvatar::sUseImpostors = LLVOAvatar::sMaxNonImpostors != 0;
- sReflectionRender = false;
- sImpostorRender = false;
- sShadowRender = false;
- popRenderTypeMask();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- avatarp->mNeedsImpostorUpdate = false;
- avatarp->cacheImpostorValues();
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- }
- void LLPipeline::previewAvatar(LLVOAvatar* avatarp)
- {
- LL_TRACY_TIMER(TRC_PREVIEW_AVATAR);
- if (!avatarp || avatarp->isDead() || !avatarp->mDrawable)
- {
- llwarns_once << "Avatar is " << (avatarp ? "not drawable" : "NULL")
- << llendl;
- return;
- }
- gGL.flush();
- stop_glerror();
- LLGLDepthTest gls_depth(GL_TRUE);
- #if 0
- LLGLSDefault gls_default;
- #endif
- gGL.setSceneBlendType(LLRender::BT_REPLACE);
- LL_GL_CHECK_STATES;
- static LLCullResult result;
- result.clear();
- grabReferences(result);
- pushRenderTypeMask();
- // Hide world geometry
- if (gUsePBRShaders)
- {
- clearRenderTypeMask(RENDER_TYPE_SKY,
- RENDER_TYPE_WL_SKY,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_PUPPET, // Animesh
- RENDER_TYPE_TREE,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_WATER,
- RENDER_TYPE_ALPHA_PRE_WATER,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_HUD,
- RENDER_TYPE_PARTICLES,
- RENDER_TYPE_CLOUDS,
- RENDER_TYPE_HUD_PARTICLES,
- END_RENDER_TYPES);
- }
- else
- {
- clearRenderTypeMask(RENDER_TYPE_SKY,
- RENDER_TYPE_WL_SKY,
- RENDER_TYPE_TERRAIN,
- RENDER_TYPE_GRASS,
- RENDER_TYPE_PUPPET, // Animesh
- RENDER_TYPE_TREE,
- RENDER_TYPE_VOIDWATER,
- RENDER_TYPE_WATER,
- RENDER_TYPE_PASS_GRASS,
- RENDER_TYPE_HUD,
- RENDER_TYPE_PARTICLES,
- RENDER_TYPE_CLOUDS,
- RENDER_TYPE_HUD_PARTICLES,
- END_RENDER_TYPES);
- }
- LLDisableOcclusionCulling no_occlusion;
- sReflectionRender = sShadowRender = false;
- sImpostorRender = true;
- markVisible(avatarp->mDrawable, gViewerCamera);
- static LLCachedControl<bool> with_rigged_meshes(gSavedSettings,
- "PreviewAvatarWithRigged");
- if (with_rigged_meshes)
- {
- // Only show rigged attachments for preview, for the sake of
- // performance, and so that static objects would not obstruct
- // previewing changes.
- for (U32 i = 0, count = avatarp->mAttachedObjectsVector.size();
- i < count; ++i)
- {
- LLViewerObject* objectp = avatarp->mAttachedObjectsVector[i].first;
- if (!objectp || objectp->isDead())
- {
- continue;
- }
- bool is_rigged_mesh = objectp->isRiggedMesh();
- if (!is_rigged_mesh)
- {
- // Sometimes object is a linkset and rigged mesh is a child
- LLViewerObject::const_child_list_t& clist =
- objectp->getChildren();
- for (LLViewerObject::const_child_list_t::const_iterator
- it = clist.begin(), end = clist.end();
- it != end; ++it)
- {
- const LLViewerObject* childp = *it;
- if (childp && childp->isRiggedMesh())
- {
- is_rigged_mesh = true;
- break;
- }
- }
- }
- if (is_rigged_mesh)
- {
- LLDrawable* drawablep = objectp->mDrawable;
- if (drawablep && !drawablep->isDead())
- {
- markVisible(drawablep->getSpatialBridge(), gViewerCamera);
- }
- }
- }
- }
- stateSort(gViewerCamera, result);
- F32 old_alpha = LLDrawPoolAvatar::sMinimumAlpha;
- LLDrawPoolAvatar::sMinimumAlpha = 0.f;
- if (sRenderDeferred)
- {
- renderGeomDeferred(gViewerCamera);
- renderGeomPostDeferred(gViewerCamera);
- }
- else
- {
- renderGeom(gViewerCamera);
- }
- LLDrawPoolAvatar::sMinimumAlpha = old_alpha;
- // Create an alpha mask based on depth buffer
- {
- if (sRenderDeferred)
- {
- GLuint buff = GL_COLOR_ATTACHMENT0;
- glDrawBuffers(1, &buff);
- }
- LLGLDisable blend(GL_BLEND);
- gGL.setColorMask(false, true);
- gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
- LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
- gGL.flush();
- gGL.pushMatrix();
- gGL.loadIdentity();
- gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.pushMatrix();
- gGL.loadIdentity();
- gDebugProgram.bind();
- gGL.begin(LLRender::TRIANGLES);
- constexpr F32 clip_plane = 0.99999f;
- gGL.vertex3f(-1.f, -1.f, clip_plane);
- gGL.vertex3f(-1.f, 1.f, clip_plane);
- gGL.vertex3f(1.f, -1.f, clip_plane);
- gGL.vertex3f(1.f, -1.f, clip_plane);
- gGL.vertex3f(-1.f, 1.f, clip_plane);
- gGL.vertex3f(1.f, 1.f, clip_plane);
- gGL.end(true);
- gDebugProgram.unbind();
- gGL.popMatrix();
- gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.popMatrix();
- }
- popRenderTypeMask();
- sImpostorRender = false;
- LLVertexBuffer::unbind();
- LL_GL_CHECK_STATES;
- gGL.setSceneBlendType(LLRender::BT_ALPHA);
- gGL.flush();
- }
- void LLPipeline::setRenderTypeMask(U32 type, ...)
- {
- va_list args;
- va_start(args, type);
- while (type < END_RENDER_TYPES)
- {
- mRenderTypeEnabled[type] = true;
- type = va_arg(args, U32);
- }
- va_end(args);
- if (type > END_RENDER_TYPES)
- {
- llerrs << "Invalid render type." << llendl;
- }
- }
- bool LLPipeline::hasAnyRenderType(U32 type, ...) const
- {
- va_list args;
- va_start(args, type);
- while (type < END_RENDER_TYPES)
- {
- if (mRenderTypeEnabled[type])
- {
- va_end(args);
- return true;
- }
- type = va_arg(args, U32);
- }
- va_end(args);
- if (type > END_RENDER_TYPES)
- {
- llerrs << "Invalid render type." << llendl;
- }
- return false;
- }
- void LLPipeline::pushRenderTypeMask()
- {
- mRenderTypeEnableStack.emplace((const char*)mRenderTypeEnabled,
- sizeof(mRenderTypeEnabled));
- }
- void LLPipeline::popRenderTypeMask()
- {
- if (mRenderTypeEnableStack.empty())
- {
- llerrs << "Depleted render type stack." << llendl;
- }
- memcpy(mRenderTypeEnabled, mRenderTypeEnableStack.top().data(),
- sizeof(mRenderTypeEnabled));
- mRenderTypeEnableStack.pop();
- }
- void LLPipeline::andRenderTypeMask(U32 type, ...)
- {
- bool tmp[NUM_RENDER_TYPES];
- for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
- {
- tmp[i] = false;
- }
- va_list args;
- va_start(args, type);
- while (type < END_RENDER_TYPES)
- {
- if (mRenderTypeEnabled[type])
- {
- tmp[type] = true;
- }
- type = va_arg(args, U32);
- }
- va_end(args);
- if (type > END_RENDER_TYPES)
- {
- llerrs << "Invalid render type." << llendl;
- }
- for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
- {
- mRenderTypeEnabled[i] = tmp[i];
- }
- }
- void LLPipeline::clearRenderTypeMask(U32 type, ...)
- {
- va_list args;
- va_start(args, type);
- while (type < END_RENDER_TYPES)
- {
- mRenderTypeEnabled[type] = false;
- type = va_arg(args, U32);
- }
- va_end(args);
- if (type > END_RENDER_TYPES)
- {
- llerrs << "Invalid render type." << llendl;
- }
- }
- void LLPipeline::setAllRenderTypes()
- {
- for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
- {
- mRenderTypeEnabled[i] = true;
- }
- }
- void LLPipeline::addDebugBlip(const LLVector3& position, const LLColor4& color)
- {
- mDebugBlips.emplace_back(position, color);
- }
- class LLOctreeDirtyInfo : public OctreeTraveler
- {
- public:
- void visit(const OctreeNode* nodep) override
- {
- LLSpatialGroup* groupp = (LLSpatialGroup*)nodep->getListener(0);
- if (groupp->getSpatialPartition()->mRenderByGroup)
- {
- groupp->setState(LLSpatialGroup::GEOM_DIRTY);
- gPipeline.markRebuild(groupp);
- LLSpatialGroup::bridge_list_t& blist = groupp->mBridgeList;
- for (U32 i = 0, count = blist.size(); i < count; ++i)
- {
- traverse(blist[i]->mOctree);
- }
- }
- }
- };
- void LLPipeline::rebuildDrawInfo()
- {
- for (LLWorld::region_list_t::const_iterator
- iter = gWorld.getRegionList().begin(),
- end = gWorld.getRegionList().end();
- iter != end; ++iter)
- {
- LLViewerRegion* regionp = *iter;
- LLOctreeDirtyInfo dirty;
- LLSpatialPartition* partp =
- regionp->getSpatialPartition(LLViewerRegion::PARTITION_VOLUME);
- dirty.traverse(partp->mOctree);
- partp = regionp->getSpatialPartition(LLViewerRegion::PARTITION_BRIDGE);
- dirty.traverse(partp->mOctree);
- }
- }
|