babylonjs.materials.js 337 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362
  1. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
  2. var babylonDependency = (globalObject && globalObject.BABYLON) || BABYLON || (typeof require !== 'undefined' && require("babylonjs"));
  3. var BABYLON = babylonDependency;
  4. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  5. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  6. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  7. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  8. return c > 3 && r && Object.defineProperty(target, key, r), r;
  9. };
  10. var __extends = (this && this.__extends) || (function () {
  11. var extendStatics = Object.setPrototypeOf ||
  12. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  13. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  14. return function (d, b) {
  15. extendStatics(d, b);
  16. function __() { this.constructor = d; }
  17. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  18. };
  19. })();
  20. var BABYLON;
  21. (function (BABYLON) {
  22. var ShadowOnlyMaterialDefines = /** @class */ (function (_super) {
  23. __extends(ShadowOnlyMaterialDefines, _super);
  24. function ShadowOnlyMaterialDefines() {
  25. var _this = _super.call(this) || this;
  26. _this.CLIPPLANE = false;
  27. _this.POINTSIZE = false;
  28. _this.FOG = false;
  29. _this.NORMAL = false;
  30. _this.NUM_BONE_INFLUENCERS = 0;
  31. _this.BonesPerMesh = 0;
  32. _this.INSTANCES = false;
  33. _this.rebuild();
  34. return _this;
  35. }
  36. return ShadowOnlyMaterialDefines;
  37. }(BABYLON.MaterialDefines));
  38. var ShadowOnlyMaterial = /** @class */ (function (_super) {
  39. __extends(ShadowOnlyMaterial, _super);
  40. function ShadowOnlyMaterial(name, scene) {
  41. return _super.call(this, name, scene) || this;
  42. }
  43. ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
  44. return true;
  45. };
  46. ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
  47. return false;
  48. };
  49. ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
  50. return null;
  51. };
  52. Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
  53. get: function () {
  54. return this._activeLight;
  55. },
  56. set: function (light) {
  57. this._activeLight = light;
  58. },
  59. enumerable: true,
  60. configurable: true
  61. });
  62. // Methods
  63. ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  64. if (this.isFrozen) {
  65. if (this._wasPreviouslyReady && subMesh.effect) {
  66. return true;
  67. }
  68. }
  69. if (!subMesh._materialDefines) {
  70. subMesh._materialDefines = new ShadowOnlyMaterialDefines();
  71. }
  72. var defines = subMesh._materialDefines;
  73. var scene = this.getScene();
  74. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  75. if (this._renderId === scene.getRenderId()) {
  76. return true;
  77. }
  78. }
  79. var engine = scene.getEngine();
  80. // Ensure that active light is the first shadow light
  81. if (this._activeLight) {
  82. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  83. var light = _a[_i];
  84. if (light.shadowEnabled) {
  85. if (this._activeLight === light) {
  86. break; // We are good
  87. }
  88. var lightPosition = mesh._lightSources.indexOf(this._activeLight);
  89. if (lightPosition !== -1) {
  90. mesh._lightSources.splice(lightPosition, 1);
  91. mesh._lightSources.splice(0, 0, this._activeLight);
  92. }
  93. break;
  94. }
  95. }
  96. }
  97. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  98. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  99. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
  100. // Attribs
  101. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  102. // Get correct effect
  103. if (defines.isDirty) {
  104. defines.markAsProcessed();
  105. scene.resetCachedMaterial();
  106. // Fallbacks
  107. var fallbacks = new BABYLON.EffectFallbacks();
  108. if (defines.FOG) {
  109. fallbacks.addFallback(1, "FOG");
  110. }
  111. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
  112. if (defines.NUM_BONE_INFLUENCERS > 0) {
  113. fallbacks.addCPUSkinningFallback(0, mesh);
  114. }
  115. //Attributes
  116. var attribs = [BABYLON.VertexBuffer.PositionKind];
  117. if (defines.NORMAL) {
  118. attribs.push(BABYLON.VertexBuffer.NormalKind);
  119. }
  120. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  121. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  122. var shaderName = "shadowOnly";
  123. var join = defines.toString();
  124. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  125. "vFogInfos", "vFogColor", "pointSize", "alpha",
  126. "mBones",
  127. "vClipPlane"
  128. ];
  129. var samplers = new Array();
  130. var uniformBuffers = new Array();
  131. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  132. uniformsNames: uniforms,
  133. uniformBuffersNames: uniformBuffers,
  134. samplers: samplers,
  135. defines: defines,
  136. maxSimultaneousLights: 1
  137. });
  138. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  139. attributes: attribs,
  140. uniformsNames: uniforms,
  141. uniformBuffersNames: uniformBuffers,
  142. samplers: samplers,
  143. defines: join,
  144. fallbacks: fallbacks,
  145. onCompiled: this.onCompiled,
  146. onError: this.onError,
  147. indexParameters: { maxSimultaneousLights: 1 }
  148. }, engine), defines);
  149. }
  150. if (!subMesh.effect || !subMesh.effect.isReady()) {
  151. return false;
  152. }
  153. this._renderId = scene.getRenderId();
  154. this._wasPreviouslyReady = true;
  155. return true;
  156. };
  157. ShadowOnlyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  158. var scene = this.getScene();
  159. var defines = subMesh._materialDefines;
  160. if (!defines) {
  161. return;
  162. }
  163. var effect = subMesh.effect;
  164. if (!effect) {
  165. return;
  166. }
  167. this._activeEffect = effect;
  168. // Matrices
  169. this.bindOnlyWorldMatrix(world);
  170. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  171. // Bones
  172. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  173. if (this._mustRebind(scene, effect)) {
  174. // Clip plane
  175. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  176. // Point size
  177. if (this.pointsCloud) {
  178. this._activeEffect.setFloat("pointSize", this.pointSize);
  179. }
  180. this._activeEffect.setFloat("alpha", this.alpha);
  181. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  182. }
  183. // Lights
  184. if (scene.lightsEnabled) {
  185. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
  186. }
  187. // View
  188. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  189. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  190. }
  191. // Fog
  192. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  193. this._afterBind(mesh, this._activeEffect);
  194. };
  195. ShadowOnlyMaterial.prototype.clone = function (name) {
  196. var _this = this;
  197. return BABYLON.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
  198. };
  199. ShadowOnlyMaterial.prototype.serialize = function () {
  200. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  201. serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
  202. return serializationObject;
  203. };
  204. ShadowOnlyMaterial.prototype.getClassName = function () {
  205. return "ShadowOnlyMaterial";
  206. };
  207. // Statics
  208. ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
  209. return BABYLON.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
  210. };
  211. return ShadowOnlyMaterial;
  212. }(BABYLON.PushMaterial));
  213. BABYLON.ShadowOnlyMaterial = ShadowOnlyMaterial;
  214. })(BABYLON || (BABYLON = {}));
  215. //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map
  216. BABYLON.Effect.ShadersStore['shadowOnlyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  217. BABYLON.Effect.ShadersStore['shadowOnlyPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform float alpha;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0..1]\n\nvec4 color=vec4(0.,0.,0.,(1.0-clamp(shadow,0.,1.))*alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  218. var BABYLON;
  219. (function (BABYLON) {
  220. var GradientMaterialDefines = /** @class */ (function (_super) {
  221. __extends(GradientMaterialDefines, _super);
  222. function GradientMaterialDefines() {
  223. var _this = _super.call(this) || this;
  224. _this.DIFFUSE = false;
  225. _this.CLIPPLANE = false;
  226. _this.ALPHATEST = false;
  227. _this.DEPTHPREPASS = false;
  228. _this.POINTSIZE = false;
  229. _this.FOG = false;
  230. _this.LIGHT0 = false;
  231. _this.LIGHT1 = false;
  232. _this.LIGHT2 = false;
  233. _this.LIGHT3 = false;
  234. _this.SPOTLIGHT0 = false;
  235. _this.SPOTLIGHT1 = false;
  236. _this.SPOTLIGHT2 = false;
  237. _this.SPOTLIGHT3 = false;
  238. _this.HEMILIGHT0 = false;
  239. _this.HEMILIGHT1 = false;
  240. _this.HEMILIGHT2 = false;
  241. _this.HEMILIGHT3 = false;
  242. _this.DIRLIGHT0 = false;
  243. _this.DIRLIGHT1 = false;
  244. _this.DIRLIGHT2 = false;
  245. _this.DIRLIGHT3 = false;
  246. _this.POINTLIGHT0 = false;
  247. _this.POINTLIGHT1 = false;
  248. _this.POINTLIGHT2 = false;
  249. _this.POINTLIGHT3 = false;
  250. _this.SHADOW0 = false;
  251. _this.SHADOW1 = false;
  252. _this.SHADOW2 = false;
  253. _this.SHADOW3 = false;
  254. _this.SHADOWS = false;
  255. _this.SHADOWESM0 = false;
  256. _this.SHADOWESM1 = false;
  257. _this.SHADOWESM2 = false;
  258. _this.SHADOWESM3 = false;
  259. _this.SHADOWPCF0 = false;
  260. _this.SHADOWPCF1 = false;
  261. _this.SHADOWPCF2 = false;
  262. _this.SHADOWPCF3 = false;
  263. _this.NORMAL = false;
  264. _this.UV1 = false;
  265. _this.UV2 = false;
  266. _this.VERTEXCOLOR = false;
  267. _this.VERTEXALPHA = false;
  268. _this.NUM_BONE_INFLUENCERS = 0;
  269. _this.BonesPerMesh = 0;
  270. _this.INSTANCES = false;
  271. _this.rebuild();
  272. return _this;
  273. }
  274. return GradientMaterialDefines;
  275. }(BABYLON.MaterialDefines));
  276. var GradientMaterial = /** @class */ (function (_super) {
  277. __extends(GradientMaterial, _super);
  278. function GradientMaterial(name, scene) {
  279. var _this = _super.call(this, name, scene) || this;
  280. _this._maxSimultaneousLights = 4;
  281. // The gradient top color, red by default
  282. _this.topColor = new BABYLON.Color3(1, 0, 0);
  283. _this.topColorAlpha = 1.0;
  284. // The gradient top color, blue by default
  285. _this.bottomColor = new BABYLON.Color3(0, 0, 1);
  286. _this.bottomColorAlpha = 1.0;
  287. // Gradient offset
  288. _this.offset = 0;
  289. _this.smoothness = 1.0;
  290. _this.disableLighting = false;
  291. _this._scaledDiffuse = new BABYLON.Color3();
  292. return _this;
  293. }
  294. GradientMaterial.prototype.needAlphaBlending = function () {
  295. return (this.alpha < 1.0 || this.topColorAlpha < 1.0 || this.bottomColorAlpha < 1.0);
  296. };
  297. GradientMaterial.prototype.needAlphaTesting = function () {
  298. return true;
  299. };
  300. GradientMaterial.prototype.getAlphaTestTexture = function () {
  301. return null;
  302. };
  303. // Methods
  304. GradientMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  305. if (this.isFrozen) {
  306. if (this._wasPreviouslyReady && subMesh.effect) {
  307. return true;
  308. }
  309. }
  310. if (!subMesh._materialDefines) {
  311. subMesh._materialDefines = new GradientMaterialDefines();
  312. }
  313. var defines = subMesh._materialDefines;
  314. var scene = this.getScene();
  315. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  316. if (this._renderId === scene.getRenderId()) {
  317. return true;
  318. }
  319. }
  320. var engine = scene.getEngine();
  321. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  322. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  323. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  324. // Attribs
  325. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  326. // Get correct effect
  327. if (defines.isDirty) {
  328. defines.markAsProcessed();
  329. scene.resetCachedMaterial();
  330. // Fallbacks
  331. var fallbacks = new BABYLON.EffectFallbacks();
  332. if (defines.FOG) {
  333. fallbacks.addFallback(1, "FOG");
  334. }
  335. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  336. if (defines.NUM_BONE_INFLUENCERS > 0) {
  337. fallbacks.addCPUSkinningFallback(0, mesh);
  338. }
  339. //Attributes
  340. var attribs = [BABYLON.VertexBuffer.PositionKind];
  341. if (defines.NORMAL) {
  342. attribs.push(BABYLON.VertexBuffer.NormalKind);
  343. }
  344. if (defines.UV1) {
  345. attribs.push(BABYLON.VertexBuffer.UVKind);
  346. }
  347. if (defines.UV2) {
  348. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  349. }
  350. if (defines.VERTEXCOLOR) {
  351. attribs.push(BABYLON.VertexBuffer.ColorKind);
  352. }
  353. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  354. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  355. // Legacy browser patch
  356. var shaderName = "gradient";
  357. var join = defines.toString();
  358. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  359. "vFogInfos", "vFogColor", "pointSize",
  360. "vDiffuseInfos",
  361. "mBones",
  362. "vClipPlane", "diffuseMatrix",
  363. "topColor", "bottomColor", "offset", "smoothness"
  364. ];
  365. var samplers = ["diffuseSampler"];
  366. var uniformBuffers = new Array();
  367. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  368. uniformsNames: uniforms,
  369. uniformBuffersNames: uniformBuffers,
  370. samplers: samplers,
  371. defines: defines,
  372. maxSimultaneousLights: 4
  373. });
  374. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  375. attributes: attribs,
  376. uniformsNames: uniforms,
  377. uniformBuffersNames: uniformBuffers,
  378. samplers: samplers,
  379. defines: join,
  380. fallbacks: fallbacks,
  381. onCompiled: this.onCompiled,
  382. onError: this.onError,
  383. indexParameters: { maxSimultaneousLights: 4 }
  384. }, engine), defines);
  385. }
  386. if (!subMesh.effect || !subMesh.effect.isReady()) {
  387. return false;
  388. }
  389. this._renderId = scene.getRenderId();
  390. this._wasPreviouslyReady = true;
  391. return true;
  392. };
  393. GradientMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  394. var scene = this.getScene();
  395. var defines = subMesh._materialDefines;
  396. if (!defines) {
  397. return;
  398. }
  399. var effect = subMesh.effect;
  400. if (!effect) {
  401. return;
  402. }
  403. this._activeEffect = effect;
  404. // Matrices
  405. this.bindOnlyWorldMatrix(world);
  406. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  407. // Bones
  408. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  409. if (this._mustRebind(scene, effect)) {
  410. // Clip plane
  411. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  412. // Point size
  413. if (this.pointsCloud) {
  414. this._activeEffect.setFloat("pointSize", this.pointSize);
  415. }
  416. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  417. }
  418. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  419. if (scene.lightsEnabled && !this.disableLighting) {
  420. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  421. }
  422. // View
  423. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  424. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  425. }
  426. // Fog
  427. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  428. this._activeEffect.setColor4("topColor", this.topColor, this.topColorAlpha);
  429. this._activeEffect.setColor4("bottomColor", this.bottomColor, this.bottomColorAlpha);
  430. this._activeEffect.setFloat("offset", this.offset);
  431. this._activeEffect.setFloat("smoothness", this.smoothness);
  432. this._afterBind(mesh, this._activeEffect);
  433. };
  434. GradientMaterial.prototype.getAnimatables = function () {
  435. return [];
  436. };
  437. GradientMaterial.prototype.dispose = function (forceDisposeEffect) {
  438. _super.prototype.dispose.call(this, forceDisposeEffect);
  439. };
  440. GradientMaterial.prototype.clone = function (name) {
  441. var _this = this;
  442. return BABYLON.SerializationHelper.Clone(function () { return new GradientMaterial(name, _this.getScene()); }, this);
  443. };
  444. GradientMaterial.prototype.serialize = function () {
  445. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  446. serializationObject.customType = "BABYLON.GradientMaterial";
  447. return serializationObject;
  448. };
  449. GradientMaterial.prototype.getClassName = function () {
  450. return "GradientMaterial";
  451. };
  452. // Statics
  453. GradientMaterial.Parse = function (source, scene, rootUrl) {
  454. return BABYLON.SerializationHelper.Parse(function () { return new GradientMaterial(source.name, scene); }, source, scene, rootUrl);
  455. };
  456. __decorate([
  457. BABYLON.serialize("maxSimultaneousLights")
  458. ], GradientMaterial.prototype, "_maxSimultaneousLights", void 0);
  459. __decorate([
  460. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  461. ], GradientMaterial.prototype, "maxSimultaneousLights", void 0);
  462. __decorate([
  463. BABYLON.serializeAsColor3()
  464. ], GradientMaterial.prototype, "topColor", void 0);
  465. __decorate([
  466. BABYLON.serialize()
  467. ], GradientMaterial.prototype, "topColorAlpha", void 0);
  468. __decorate([
  469. BABYLON.serializeAsColor3()
  470. ], GradientMaterial.prototype, "bottomColor", void 0);
  471. __decorate([
  472. BABYLON.serialize()
  473. ], GradientMaterial.prototype, "bottomColorAlpha", void 0);
  474. __decorate([
  475. BABYLON.serialize()
  476. ], GradientMaterial.prototype, "offset", void 0);
  477. __decorate([
  478. BABYLON.serialize()
  479. ], GradientMaterial.prototype, "smoothness", void 0);
  480. __decorate([
  481. BABYLON.serialize()
  482. ], GradientMaterial.prototype, "disableLighting", void 0);
  483. return GradientMaterial;
  484. }(BABYLON.PushMaterial));
  485. BABYLON.GradientMaterial = GradientMaterial;
  486. })(BABYLON || (BABYLON = {}));
  487. //# sourceMappingURL=babylon.gradientMaterial.js.map
  488. BABYLON.Effect.ShadersStore['gradientVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex> \ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  489. BABYLON.Effect.ShadersStore['gradientPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 topColor;\nuniform vec4 bottomColor;\nuniform float offset;\nuniform float smoothness;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\nfloat h=normalize(vPositionW).y+offset;\nfloat mysmoothness=clamp(smoothness,0.01,max(smoothness,10.));\nvec4 baseColor=mix(bottomColor,topColor,max(pow(max(h,0.0),mysmoothness),0.0));\n\nvec3 diffuseColor=baseColor.rgb;\n\nfloat alpha=baseColor.a;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  490. var BABYLON;
  491. (function (BABYLON) {
  492. var NormalMaterialDefines = /** @class */ (function (_super) {
  493. __extends(NormalMaterialDefines, _super);
  494. function NormalMaterialDefines() {
  495. var _this = _super.call(this) || this;
  496. _this.DIFFUSE = false;
  497. _this.CLIPPLANE = false;
  498. _this.ALPHATEST = false;
  499. _this.DEPTHPREPASS = false;
  500. _this.POINTSIZE = false;
  501. _this.FOG = false;
  502. _this.LIGHT0 = false;
  503. _this.LIGHT1 = false;
  504. _this.LIGHT2 = false;
  505. _this.LIGHT3 = false;
  506. _this.SPOTLIGHT0 = false;
  507. _this.SPOTLIGHT1 = false;
  508. _this.SPOTLIGHT2 = false;
  509. _this.SPOTLIGHT3 = false;
  510. _this.HEMILIGHT0 = false;
  511. _this.HEMILIGHT1 = false;
  512. _this.HEMILIGHT2 = false;
  513. _this.HEMILIGHT3 = false;
  514. _this.DIRLIGHT0 = false;
  515. _this.DIRLIGHT1 = false;
  516. _this.DIRLIGHT2 = false;
  517. _this.DIRLIGHT3 = false;
  518. _this.POINTLIGHT0 = false;
  519. _this.POINTLIGHT1 = false;
  520. _this.POINTLIGHT2 = false;
  521. _this.POINTLIGHT3 = false;
  522. _this.SHADOW0 = false;
  523. _this.SHADOW1 = false;
  524. _this.SHADOW2 = false;
  525. _this.SHADOW3 = false;
  526. _this.SHADOWS = false;
  527. _this.SHADOWESM0 = false;
  528. _this.SHADOWESM1 = false;
  529. _this.SHADOWESM2 = false;
  530. _this.SHADOWESM3 = false;
  531. _this.SHADOWPCF0 = false;
  532. _this.SHADOWPCF1 = false;
  533. _this.SHADOWPCF2 = false;
  534. _this.SHADOWPCF3 = false;
  535. _this.NORMAL = false;
  536. _this.UV1 = false;
  537. _this.UV2 = false;
  538. _this.VERTEXCOLOR = false;
  539. _this.VERTEXALPHA = false;
  540. _this.NUM_BONE_INFLUENCERS = 0;
  541. _this.BonesPerMesh = 0;
  542. _this.INSTANCES = false;
  543. _this.rebuild();
  544. return _this;
  545. }
  546. return NormalMaterialDefines;
  547. }(BABYLON.MaterialDefines));
  548. var NormalMaterial = /** @class */ (function (_super) {
  549. __extends(NormalMaterial, _super);
  550. function NormalMaterial(name, scene) {
  551. var _this = _super.call(this, name, scene) || this;
  552. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  553. _this._disableLighting = false;
  554. _this._maxSimultaneousLights = 4;
  555. return _this;
  556. }
  557. NormalMaterial.prototype.needAlphaBlending = function () {
  558. return (this.alpha < 1.0);
  559. };
  560. NormalMaterial.prototype.needAlphaTesting = function () {
  561. return false;
  562. };
  563. NormalMaterial.prototype.getAlphaTestTexture = function () {
  564. return null;
  565. };
  566. // Methods
  567. NormalMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  568. if (this.isFrozen) {
  569. if (this._wasPreviouslyReady && subMesh.effect) {
  570. return true;
  571. }
  572. }
  573. if (!subMesh._materialDefines) {
  574. subMesh._materialDefines = new NormalMaterialDefines();
  575. }
  576. var defines = subMesh._materialDefines;
  577. var scene = this.getScene();
  578. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  579. if (this._renderId === scene.getRenderId()) {
  580. return true;
  581. }
  582. }
  583. var engine = scene.getEngine();
  584. // Textures
  585. if (defines._areTexturesDirty) {
  586. defines._needUVs = false;
  587. if (scene.texturesEnabled) {
  588. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  589. if (!this._diffuseTexture.isReady()) {
  590. return false;
  591. }
  592. else {
  593. defines._needUVs = true;
  594. defines.DIFFUSE = true;
  595. }
  596. }
  597. }
  598. }
  599. // Misc.
  600. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  601. // Lights
  602. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  603. // Values that need to be evaluated on every frame
  604. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  605. // Attribs
  606. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  607. // Get correct effect
  608. if (defines.isDirty) {
  609. defines.markAsProcessed();
  610. scene.resetCachedMaterial();
  611. // Fallbacks
  612. var fallbacks = new BABYLON.EffectFallbacks();
  613. if (defines.FOG) {
  614. fallbacks.addFallback(1, "FOG");
  615. }
  616. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  617. if (defines.NUM_BONE_INFLUENCERS > 0) {
  618. fallbacks.addCPUSkinningFallback(0, mesh);
  619. }
  620. //Attributes
  621. var attribs = [BABYLON.VertexBuffer.PositionKind];
  622. if (defines.NORMAL) {
  623. attribs.push(BABYLON.VertexBuffer.NormalKind);
  624. }
  625. if (defines.UV1) {
  626. attribs.push(BABYLON.VertexBuffer.UVKind);
  627. }
  628. if (defines.UV2) {
  629. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  630. }
  631. if (defines.VERTEXCOLOR) {
  632. attribs.push(BABYLON.VertexBuffer.ColorKind);
  633. }
  634. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  635. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  636. var shaderName = "normal";
  637. var join = defines.toString();
  638. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  639. "vFogInfos", "vFogColor", "pointSize",
  640. "vDiffuseInfos",
  641. "mBones",
  642. "vClipPlane", "diffuseMatrix"
  643. ];
  644. var samplers = ["diffuseSampler"];
  645. var uniformBuffers = new Array();
  646. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  647. uniformsNames: uniforms,
  648. uniformBuffersNames: uniformBuffers,
  649. samplers: samplers,
  650. defines: defines,
  651. maxSimultaneousLights: 4
  652. });
  653. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  654. attributes: attribs,
  655. uniformsNames: uniforms,
  656. uniformBuffersNames: uniformBuffers,
  657. samplers: samplers,
  658. defines: join,
  659. fallbacks: fallbacks,
  660. onCompiled: this.onCompiled,
  661. onError: this.onError,
  662. indexParameters: { maxSimultaneousLights: 4 }
  663. }, engine), defines);
  664. }
  665. if (!subMesh.effect || !subMesh.effect.isReady()) {
  666. return false;
  667. }
  668. this._renderId = scene.getRenderId();
  669. this._wasPreviouslyReady = true;
  670. return true;
  671. };
  672. NormalMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  673. var scene = this.getScene();
  674. var defines = subMesh._materialDefines;
  675. if (!defines) {
  676. return;
  677. }
  678. var effect = subMesh.effect;
  679. if (!effect) {
  680. return;
  681. }
  682. this._activeEffect = effect;
  683. // Matrices
  684. this.bindOnlyWorldMatrix(world);
  685. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  686. // Bones
  687. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  688. if (this._mustRebind(scene, effect)) {
  689. // Textures
  690. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  691. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  692. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  693. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  694. }
  695. // Clip plane
  696. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  697. // Point size
  698. if (this.pointsCloud) {
  699. this._activeEffect.setFloat("pointSize", this.pointSize);
  700. }
  701. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  702. }
  703. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  704. // Lights
  705. if (scene.lightsEnabled && !this.disableLighting) {
  706. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  707. }
  708. // View
  709. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  710. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  711. }
  712. // Fog
  713. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  714. this._afterBind(mesh, this._activeEffect);
  715. };
  716. NormalMaterial.prototype.getAnimatables = function () {
  717. var results = [];
  718. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  719. results.push(this.diffuseTexture);
  720. }
  721. return results;
  722. };
  723. NormalMaterial.prototype.getActiveTextures = function () {
  724. var activeTextures = _super.prototype.getActiveTextures.call(this);
  725. if (this._diffuseTexture) {
  726. activeTextures.push(this._diffuseTexture);
  727. }
  728. return activeTextures;
  729. };
  730. NormalMaterial.prototype.hasTexture = function (texture) {
  731. if (_super.prototype.hasTexture.call(this, texture)) {
  732. return true;
  733. }
  734. if (this.diffuseTexture === texture) {
  735. return true;
  736. }
  737. return false;
  738. };
  739. NormalMaterial.prototype.dispose = function (forceDisposeEffect) {
  740. if (this.diffuseTexture) {
  741. this.diffuseTexture.dispose();
  742. }
  743. _super.prototype.dispose.call(this, forceDisposeEffect);
  744. };
  745. NormalMaterial.prototype.clone = function (name) {
  746. var _this = this;
  747. return BABYLON.SerializationHelper.Clone(function () { return new NormalMaterial(name, _this.getScene()); }, this);
  748. };
  749. NormalMaterial.prototype.serialize = function () {
  750. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  751. serializationObject.customType = "BABYLON.NormalMaterial";
  752. return serializationObject;
  753. };
  754. NormalMaterial.prototype.getClassName = function () {
  755. return "NormalMaterial";
  756. };
  757. // Statics
  758. NormalMaterial.Parse = function (source, scene, rootUrl) {
  759. return BABYLON.SerializationHelper.Parse(function () { return new NormalMaterial(source.name, scene); }, source, scene, rootUrl);
  760. };
  761. __decorate([
  762. BABYLON.serializeAsTexture("diffuseTexture")
  763. ], NormalMaterial.prototype, "_diffuseTexture", void 0);
  764. __decorate([
  765. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  766. ], NormalMaterial.prototype, "diffuseTexture", void 0);
  767. __decorate([
  768. BABYLON.serializeAsColor3()
  769. ], NormalMaterial.prototype, "diffuseColor", void 0);
  770. __decorate([
  771. BABYLON.serialize("disableLighting")
  772. ], NormalMaterial.prototype, "_disableLighting", void 0);
  773. __decorate([
  774. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  775. ], NormalMaterial.prototype, "disableLighting", void 0);
  776. __decorate([
  777. BABYLON.serialize("maxSimultaneousLights")
  778. ], NormalMaterial.prototype, "_maxSimultaneousLights", void 0);
  779. __decorate([
  780. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  781. ], NormalMaterial.prototype, "maxSimultaneousLights", void 0);
  782. return NormalMaterial;
  783. }(BABYLON.PushMaterial));
  784. BABYLON.NormalMaterial = NormalMaterial;
  785. })(BABYLON || (BABYLON = {}));
  786. //# sourceMappingURL=babylon.normalMaterial.js.map
  787. BABYLON.Effect.ShadersStore['normalVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  788. BABYLON.Effect.ShadersStore['normalPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef NORMAL\nbaseColor=mix(baseColor,vec4(vNormalW,1.0),0.5);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  789. var BABYLON;
  790. (function (BABYLON) {
  791. var LavaMaterialDefines = /** @class */ (function (_super) {
  792. __extends(LavaMaterialDefines, _super);
  793. function LavaMaterialDefines() {
  794. var _this = _super.call(this) || this;
  795. _this.DIFFUSE = false;
  796. _this.CLIPPLANE = false;
  797. _this.ALPHATEST = false;
  798. _this.DEPTHPREPASS = false;
  799. _this.POINTSIZE = false;
  800. _this.FOG = false;
  801. _this.LIGHT0 = false;
  802. _this.LIGHT1 = false;
  803. _this.LIGHT2 = false;
  804. _this.LIGHT3 = false;
  805. _this.SPOTLIGHT0 = false;
  806. _this.SPOTLIGHT1 = false;
  807. _this.SPOTLIGHT2 = false;
  808. _this.SPOTLIGHT3 = false;
  809. _this.HEMILIGHT0 = false;
  810. _this.HEMILIGHT1 = false;
  811. _this.HEMILIGHT2 = false;
  812. _this.HEMILIGHT3 = false;
  813. _this.DIRLIGHT0 = false;
  814. _this.DIRLIGHT1 = false;
  815. _this.DIRLIGHT2 = false;
  816. _this.DIRLIGHT3 = false;
  817. _this.POINTLIGHT0 = false;
  818. _this.POINTLIGHT1 = false;
  819. _this.POINTLIGHT2 = false;
  820. _this.POINTLIGHT3 = false;
  821. _this.SHADOW0 = false;
  822. _this.SHADOW1 = false;
  823. _this.SHADOW2 = false;
  824. _this.SHADOW3 = false;
  825. _this.SHADOWS = false;
  826. _this.SHADOWESM0 = false;
  827. _this.SHADOWESM1 = false;
  828. _this.SHADOWESM2 = false;
  829. _this.SHADOWESM3 = false;
  830. _this.SHADOWPCF0 = false;
  831. _this.SHADOWPCF1 = false;
  832. _this.SHADOWPCF2 = false;
  833. _this.SHADOWPCF3 = false;
  834. _this.NORMAL = false;
  835. _this.UV1 = false;
  836. _this.UV2 = false;
  837. _this.VERTEXCOLOR = false;
  838. _this.VERTEXALPHA = false;
  839. _this.NUM_BONE_INFLUENCERS = 0;
  840. _this.BonesPerMesh = 0;
  841. _this.INSTANCES = false;
  842. _this.rebuild();
  843. return _this;
  844. }
  845. return LavaMaterialDefines;
  846. }(BABYLON.MaterialDefines));
  847. var LavaMaterial = /** @class */ (function (_super) {
  848. __extends(LavaMaterial, _super);
  849. function LavaMaterial(name, scene) {
  850. var _this = _super.call(this, name, scene) || this;
  851. _this.speed = 1;
  852. _this.movingSpeed = 1;
  853. _this.lowFrequencySpeed = 1;
  854. _this.fogDensity = 0.15;
  855. _this._lastTime = 0;
  856. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  857. _this._disableLighting = false;
  858. _this._maxSimultaneousLights = 4;
  859. _this._scaledDiffuse = new BABYLON.Color3();
  860. return _this;
  861. }
  862. LavaMaterial.prototype.needAlphaBlending = function () {
  863. return (this.alpha < 1.0);
  864. };
  865. LavaMaterial.prototype.needAlphaTesting = function () {
  866. return false;
  867. };
  868. LavaMaterial.prototype.getAlphaTestTexture = function () {
  869. return null;
  870. };
  871. // Methods
  872. LavaMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  873. if (this.isFrozen) {
  874. if (this._wasPreviouslyReady && subMesh.effect) {
  875. return true;
  876. }
  877. }
  878. if (!subMesh._materialDefines) {
  879. subMesh._materialDefines = new LavaMaterialDefines();
  880. }
  881. var defines = subMesh._materialDefines;
  882. var scene = this.getScene();
  883. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  884. if (this._renderId === scene.getRenderId()) {
  885. return true;
  886. }
  887. }
  888. var engine = scene.getEngine();
  889. // Textures
  890. if (defines._areTexturesDirty) {
  891. defines._needUVs = false;
  892. if (scene.texturesEnabled) {
  893. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  894. if (!this._diffuseTexture.isReady()) {
  895. return false;
  896. }
  897. else {
  898. defines._needUVs = true;
  899. defines.DIFFUSE = true;
  900. }
  901. }
  902. }
  903. }
  904. // Misc.
  905. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  906. // Lights
  907. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  908. // Values that need to be evaluated on every frame
  909. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  910. // Attribs
  911. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  912. // Get correct effect
  913. if (defines.isDirty) {
  914. defines.markAsProcessed();
  915. scene.resetCachedMaterial();
  916. // Fallbacks
  917. var fallbacks = new BABYLON.EffectFallbacks();
  918. if (defines.FOG) {
  919. fallbacks.addFallback(1, "FOG");
  920. }
  921. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  922. if (defines.NUM_BONE_INFLUENCERS > 0) {
  923. fallbacks.addCPUSkinningFallback(0, mesh);
  924. }
  925. //Attributes
  926. var attribs = [BABYLON.VertexBuffer.PositionKind];
  927. if (defines.NORMAL) {
  928. attribs.push(BABYLON.VertexBuffer.NormalKind);
  929. }
  930. if (defines.UV1) {
  931. attribs.push(BABYLON.VertexBuffer.UVKind);
  932. }
  933. if (defines.UV2) {
  934. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  935. }
  936. if (defines.VERTEXCOLOR) {
  937. attribs.push(BABYLON.VertexBuffer.ColorKind);
  938. }
  939. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  940. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  941. // Legacy browser patch
  942. var shaderName = "lava";
  943. var join = defines.toString();
  944. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  945. "vFogInfos", "vFogColor", "pointSize",
  946. "vDiffuseInfos",
  947. "mBones",
  948. "vClipPlane", "diffuseMatrix",
  949. "time", "speed", "movingSpeed",
  950. "fogColor", "fogDensity", "lowFrequencySpeed"
  951. ];
  952. var samplers = ["diffuseSampler",
  953. "noiseTexture"
  954. ];
  955. var uniformBuffers = new Array();
  956. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  957. uniformsNames: uniforms,
  958. uniformBuffersNames: uniformBuffers,
  959. samplers: samplers,
  960. defines: defines,
  961. maxSimultaneousLights: this.maxSimultaneousLights
  962. });
  963. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  964. attributes: attribs,
  965. uniformsNames: uniforms,
  966. uniformBuffersNames: uniformBuffers,
  967. samplers: samplers,
  968. defines: join,
  969. fallbacks: fallbacks,
  970. onCompiled: this.onCompiled,
  971. onError: this.onError,
  972. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  973. }, engine), defines);
  974. }
  975. if (!subMesh.effect || !subMesh.effect.isReady()) {
  976. return false;
  977. }
  978. this._renderId = scene.getRenderId();
  979. this._wasPreviouslyReady = true;
  980. return true;
  981. };
  982. LavaMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  983. var scene = this.getScene();
  984. var defines = subMesh._materialDefines;
  985. if (!defines) {
  986. return;
  987. }
  988. var effect = subMesh.effect;
  989. if (!effect) {
  990. return;
  991. }
  992. this._activeEffect = effect;
  993. // Matrices
  994. this.bindOnlyWorldMatrix(world);
  995. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  996. // Bones
  997. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  998. if (this._mustRebind(scene, effect)) {
  999. // Textures
  1000. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1001. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  1002. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  1003. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  1004. }
  1005. if (this.noiseTexture) {
  1006. this._activeEffect.setTexture("noiseTexture", this.noiseTexture);
  1007. }
  1008. // Clip plane
  1009. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1010. // Point size
  1011. if (this.pointsCloud) {
  1012. this._activeEffect.setFloat("pointSize", this.pointSize);
  1013. }
  1014. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1015. }
  1016. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  1017. if (scene.lightsEnabled && !this.disableLighting) {
  1018. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  1019. }
  1020. // View
  1021. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1022. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1023. }
  1024. // Fog
  1025. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1026. this._lastTime += scene.getEngine().getDeltaTime();
  1027. this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
  1028. if (!this.fogColor) {
  1029. this.fogColor = BABYLON.Color3.Black();
  1030. }
  1031. this._activeEffect.setColor3("fogColor", this.fogColor);
  1032. this._activeEffect.setFloat("fogDensity", this.fogDensity);
  1033. this._activeEffect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  1034. this._activeEffect.setFloat("movingSpeed", this.movingSpeed);
  1035. this._afterBind(mesh, this._activeEffect);
  1036. };
  1037. LavaMaterial.prototype.getAnimatables = function () {
  1038. var results = [];
  1039. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  1040. results.push(this.diffuseTexture);
  1041. }
  1042. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  1043. results.push(this.noiseTexture);
  1044. }
  1045. return results;
  1046. };
  1047. LavaMaterial.prototype.getActiveTextures = function () {
  1048. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1049. if (this._diffuseTexture) {
  1050. activeTextures.push(this._diffuseTexture);
  1051. }
  1052. return activeTextures;
  1053. };
  1054. LavaMaterial.prototype.hasTexture = function (texture) {
  1055. if (_super.prototype.hasTexture.call(this, texture)) {
  1056. return true;
  1057. }
  1058. if (this.diffuseTexture === texture) {
  1059. return true;
  1060. }
  1061. return false;
  1062. };
  1063. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  1064. if (this.diffuseTexture) {
  1065. this.diffuseTexture.dispose();
  1066. }
  1067. if (this.noiseTexture) {
  1068. this.noiseTexture.dispose();
  1069. }
  1070. _super.prototype.dispose.call(this, forceDisposeEffect);
  1071. };
  1072. LavaMaterial.prototype.clone = function (name) {
  1073. var _this = this;
  1074. return BABYLON.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  1075. };
  1076. LavaMaterial.prototype.serialize = function () {
  1077. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1078. serializationObject.customType = "BABYLON.LavaMaterial";
  1079. return serializationObject;
  1080. };
  1081. LavaMaterial.prototype.getClassName = function () {
  1082. return "LavaMaterial";
  1083. };
  1084. // Statics
  1085. LavaMaterial.Parse = function (source, scene, rootUrl) {
  1086. return BABYLON.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  1087. };
  1088. __decorate([
  1089. BABYLON.serializeAsTexture("diffuseTexture")
  1090. ], LavaMaterial.prototype, "_diffuseTexture", void 0);
  1091. __decorate([
  1092. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1093. ], LavaMaterial.prototype, "diffuseTexture", void 0);
  1094. __decorate([
  1095. BABYLON.serializeAsTexture()
  1096. ], LavaMaterial.prototype, "noiseTexture", void 0);
  1097. __decorate([
  1098. BABYLON.serializeAsColor3()
  1099. ], LavaMaterial.prototype, "fogColor", void 0);
  1100. __decorate([
  1101. BABYLON.serialize()
  1102. ], LavaMaterial.prototype, "speed", void 0);
  1103. __decorate([
  1104. BABYLON.serialize()
  1105. ], LavaMaterial.prototype, "movingSpeed", void 0);
  1106. __decorate([
  1107. BABYLON.serialize()
  1108. ], LavaMaterial.prototype, "lowFrequencySpeed", void 0);
  1109. __decorate([
  1110. BABYLON.serialize()
  1111. ], LavaMaterial.prototype, "fogDensity", void 0);
  1112. __decorate([
  1113. BABYLON.serializeAsColor3()
  1114. ], LavaMaterial.prototype, "diffuseColor", void 0);
  1115. __decorate([
  1116. BABYLON.serialize("disableLighting")
  1117. ], LavaMaterial.prototype, "_disableLighting", void 0);
  1118. __decorate([
  1119. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1120. ], LavaMaterial.prototype, "disableLighting", void 0);
  1121. __decorate([
  1122. BABYLON.serialize("maxSimultaneousLights")
  1123. ], LavaMaterial.prototype, "_maxSimultaneousLights", void 0);
  1124. __decorate([
  1125. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1126. ], LavaMaterial.prototype, "maxSimultaneousLights", void 0);
  1127. return LavaMaterial;
  1128. }(BABYLON.PushMaterial));
  1129. BABYLON.LavaMaterial = LavaMaterial;
  1130. })(BABYLON || (BABYLON = {}));
  1131. //# sourceMappingURL=babylon.lavaMaterial.js.map
  1132. BABYLON.Effect.ShadersStore['lavaVertexShader'] = "precision highp float;\n\nuniform float time;\nuniform float lowFrequencySpeed;\n\nvarying float noise;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n\n\nvec3 mod289(vec3 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 mod289(vec4 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 permute(vec4 x)\n{\nreturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r)\n{\nreturn 1.79284291400159-0.85373472095314*r;\n}\nvec3 fade(vec3 t) {\nreturn t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat pnoise(vec3 P,vec3 rep)\n{\nvec3 Pi0=mod(floor(P),rep); \nvec3 Pi1=mod(Pi0+vec3(1.0),rep); \nPi0=mod289(Pi0);\nPi1=mod289(Pi1);\nvec3 Pf0=fract(P); \nvec3 Pf1=Pf0-vec3(1.0); \nvec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);\nvec4 iy=vec4(Pi0.yy,Pi1.yy);\nvec4 iz0=Pi0.zzzz;\nvec4 iz1=Pi1.zzzz;\nvec4 ixy=permute(permute(ix)+iy);\nvec4 ixy0=permute(ixy+iz0);\nvec4 ixy1=permute(ixy+iz1);\nvec4 gx0=ixy0*(1.0/7.0);\nvec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;\ngx0=fract(gx0);\nvec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);\nvec4 sz0=step(gz0,vec4(0.0));\ngx0-=sz0*(step(0.0,gx0)-0.5);\ngy0-=sz0*(step(0.0,gy0)-0.5);\nvec4 gx1=ixy1*(1.0/7.0);\nvec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;\ngx1=fract(gx1);\nvec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);\nvec4 sz1=step(gz1,vec4(0.0));\ngx1-=sz1*(step(0.0,gx1)-0.5);\ngy1-=sz1*(step(0.0,gy1)-0.5);\nvec3 g000=vec3(gx0.x,gy0.x,gz0.x);\nvec3 g100=vec3(gx0.y,gy0.y,gz0.y);\nvec3 g010=vec3(gx0.z,gy0.z,gz0.z);\nvec3 g110=vec3(gx0.w,gy0.w,gz0.w);\nvec3 g001=vec3(gx1.x,gy1.x,gz1.x);\nvec3 g101=vec3(gx1.y,gy1.y,gz1.y);\nvec3 g011=vec3(gx1.z,gy1.z,gz1.z);\nvec3 g111=vec3(gx1.w,gy1.w,gz1.w);\nvec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));\ng000*=norm0.x;\ng010*=norm0.y;\ng100*=norm0.z;\ng110*=norm0.w;\nvec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));\ng001*=norm1.x;\ng011*=norm1.y;\ng101*=norm1.z;\ng111*=norm1.w;\nfloat n000=dot(g000,Pf0);\nfloat n100=dot(g100,vec3(Pf1.x,Pf0.yz));\nfloat n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));\nfloat n110=dot(g110,vec3(Pf1.xy,Pf0.z));\nfloat n001=dot(g001,vec3(Pf0.xy,Pf1.z));\nfloat n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));\nfloat n011=dot(g011,vec3(Pf0.x,Pf1.yz));\nfloat n111=dot(g111,Pf1);\nvec3 fade_xyz=fade(Pf0);\nvec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);\nvec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);\nfloat n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);\nreturn 2.2*n_xyz;\n}\n\nfloat turbulence( vec3 p ) {\nfloat w=100.0;\nfloat t=-.5;\nfor (float f=1.0 ; f<=10.0 ; f++ ){\nfloat power=pow( 2.0,f );\nt+=abs( pnoise( vec3( power*p ),vec3( 10.0,10.0,10.0 ) )/power );\n}\nreturn t;\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef NORMAL\n\nnoise=10.0*-.10*turbulence( .5*normal+time*1.15 );\n\nfloat b=lowFrequencySpeed*5.0*pnoise( 0.05*position +vec3(time*1.025),vec3( 100.0 ) );\n\nfloat displacement =-1.5*noise+b;\n\nvec3 newPosition=position+normal*displacement;\ngl_Position=viewProjection*finalWorld*vec4( newPosition,1.0 );\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}";
  1133. BABYLON.Effect.ShadersStore['lavaPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\nvarying float noise;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\n\nvec4 noiseTex=texture2D( noiseTexture,vDiffuseUV );\nvec2 T1=vDiffuseUV+vec2( 1.5,-1.5 )*time*0.02;\nvec2 T2=vDiffuseUV+vec2( -0.5,2.0 )*time*0.01*speed;\nT1.x+=noiseTex.x*2.0;\nT1.y+=noiseTex.y*2.0;\nT2.x-=noiseTex.y*0.2+time*0.001*movingSpeed;\nT2.y+=noiseTex.z*0.2+time*0.002*movingSpeed;\nfloat p=texture2D( noiseTexture,T1*3.0 ).a;\nvec4 lavaColor=texture2D( diffuseSampler,T2*4.0);\nvec4 temp=lavaColor*( vec4( p,p,p,p )*2. )+( lavaColor*lavaColor-0.1 );\nbaseColor=temp;\nfloat depth=gl_FragCoord.z*4.0;\nconst float LOG2=1.442695;\nfloat fogFactor=exp2(-fogDensity*fogDensity*depth*depth*LOG2 );\nfogFactor=1.0-clamp( fogFactor,0.0,1.0 );\nbaseColor=mix( baseColor,vec4( fogColor,baseColor.w ),fogFactor );\ndiffuseColor=baseColor.rgb;\n\n\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1134. var BABYLON;
  1135. (function (BABYLON) {
  1136. var SimpleMaterialDefines = /** @class */ (function (_super) {
  1137. __extends(SimpleMaterialDefines, _super);
  1138. function SimpleMaterialDefines() {
  1139. var _this = _super.call(this) || this;
  1140. _this.DIFFUSE = false;
  1141. _this.CLIPPLANE = false;
  1142. _this.ALPHATEST = false;
  1143. _this.DEPTHPREPASS = false;
  1144. _this.POINTSIZE = false;
  1145. _this.FOG = false;
  1146. _this.NORMAL = false;
  1147. _this.UV1 = false;
  1148. _this.UV2 = false;
  1149. _this.VERTEXCOLOR = false;
  1150. _this.VERTEXALPHA = false;
  1151. _this.NUM_BONE_INFLUENCERS = 0;
  1152. _this.BonesPerMesh = 0;
  1153. _this.INSTANCES = false;
  1154. _this.rebuild();
  1155. return _this;
  1156. }
  1157. return SimpleMaterialDefines;
  1158. }(BABYLON.MaterialDefines));
  1159. var SimpleMaterial = /** @class */ (function (_super) {
  1160. __extends(SimpleMaterial, _super);
  1161. function SimpleMaterial(name, scene) {
  1162. var _this = _super.call(this, name, scene) || this;
  1163. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1164. _this._disableLighting = false;
  1165. _this._maxSimultaneousLights = 4;
  1166. return _this;
  1167. }
  1168. SimpleMaterial.prototype.needAlphaBlending = function () {
  1169. return (this.alpha < 1.0);
  1170. };
  1171. SimpleMaterial.prototype.needAlphaTesting = function () {
  1172. return false;
  1173. };
  1174. SimpleMaterial.prototype.getAlphaTestTexture = function () {
  1175. return null;
  1176. };
  1177. // Methods
  1178. SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1179. if (this.isFrozen) {
  1180. if (this._wasPreviouslyReady && subMesh.effect) {
  1181. return true;
  1182. }
  1183. }
  1184. if (!subMesh._materialDefines) {
  1185. subMesh._materialDefines = new SimpleMaterialDefines();
  1186. }
  1187. var defines = subMesh._materialDefines;
  1188. var scene = this.getScene();
  1189. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1190. if (this._renderId === scene.getRenderId()) {
  1191. return true;
  1192. }
  1193. }
  1194. var engine = scene.getEngine();
  1195. // Textures
  1196. if (defines._areTexturesDirty) {
  1197. defines._needUVs = false;
  1198. if (scene.texturesEnabled) {
  1199. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1200. if (!this._diffuseTexture.isReady()) {
  1201. return false;
  1202. }
  1203. else {
  1204. defines._needUVs = true;
  1205. defines.DIFFUSE = true;
  1206. }
  1207. }
  1208. }
  1209. }
  1210. // Misc.
  1211. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  1212. // Lights
  1213. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  1214. // Values that need to be evaluated on every frame
  1215. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1216. // Attribs
  1217. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1218. // Get correct effect
  1219. if (defines.isDirty) {
  1220. defines.markAsProcessed();
  1221. scene.resetCachedMaterial();
  1222. // Fallbacks
  1223. var fallbacks = new BABYLON.EffectFallbacks();
  1224. if (defines.FOG) {
  1225. fallbacks.addFallback(1, "FOG");
  1226. }
  1227. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1228. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1229. fallbacks.addCPUSkinningFallback(0, mesh);
  1230. }
  1231. //Attributes
  1232. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1233. if (defines.NORMAL) {
  1234. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1235. }
  1236. if (defines.UV1) {
  1237. attribs.push(BABYLON.VertexBuffer.UVKind);
  1238. }
  1239. if (defines.UV2) {
  1240. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1241. }
  1242. if (defines.VERTEXCOLOR) {
  1243. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1244. }
  1245. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1246. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1247. var shaderName = "simple";
  1248. var join = defines.toString();
  1249. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  1250. "vFogInfos", "vFogColor", "pointSize",
  1251. "vDiffuseInfos",
  1252. "mBones",
  1253. "vClipPlane", "diffuseMatrix"
  1254. ];
  1255. var samplers = ["diffuseSampler"];
  1256. var uniformBuffers = new Array();
  1257. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1258. uniformsNames: uniforms,
  1259. uniformBuffersNames: uniformBuffers,
  1260. samplers: samplers,
  1261. defines: defines,
  1262. maxSimultaneousLights: this.maxSimultaneousLights
  1263. });
  1264. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1265. attributes: attribs,
  1266. uniformsNames: uniforms,
  1267. uniformBuffersNames: uniformBuffers,
  1268. samplers: samplers,
  1269. defines: join,
  1270. fallbacks: fallbacks,
  1271. onCompiled: this.onCompiled,
  1272. onError: this.onError,
  1273. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 }
  1274. }, engine), defines);
  1275. }
  1276. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1277. return false;
  1278. }
  1279. this._renderId = scene.getRenderId();
  1280. this._wasPreviouslyReady = true;
  1281. return true;
  1282. };
  1283. SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1284. var scene = this.getScene();
  1285. var defines = subMesh._materialDefines;
  1286. if (!defines) {
  1287. return;
  1288. }
  1289. var effect = subMesh.effect;
  1290. if (!effect) {
  1291. return;
  1292. }
  1293. this._activeEffect = effect;
  1294. // Matrices
  1295. this.bindOnlyWorldMatrix(world);
  1296. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1297. // Bones
  1298. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1299. if (this._mustRebind(scene, effect)) {
  1300. // Textures
  1301. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1302. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  1303. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  1304. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  1305. }
  1306. // Clip plane
  1307. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1308. // Point size
  1309. if (this.pointsCloud) {
  1310. this._activeEffect.setFloat("pointSize", this.pointSize);
  1311. }
  1312. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1313. }
  1314. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1315. // Lights
  1316. if (scene.lightsEnabled && !this.disableLighting) {
  1317. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1318. }
  1319. // View
  1320. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1321. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1322. }
  1323. // Fog
  1324. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1325. this._afterBind(mesh, this._activeEffect);
  1326. };
  1327. SimpleMaterial.prototype.getAnimatables = function () {
  1328. var results = [];
  1329. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  1330. results.push(this._diffuseTexture);
  1331. }
  1332. return results;
  1333. };
  1334. SimpleMaterial.prototype.getActiveTextures = function () {
  1335. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1336. if (this._diffuseTexture) {
  1337. activeTextures.push(this._diffuseTexture);
  1338. }
  1339. return activeTextures;
  1340. };
  1341. SimpleMaterial.prototype.hasTexture = function (texture) {
  1342. if (_super.prototype.hasTexture.call(this, texture)) {
  1343. return true;
  1344. }
  1345. if (this.diffuseTexture === texture) {
  1346. return true;
  1347. }
  1348. return false;
  1349. };
  1350. SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
  1351. if (this._diffuseTexture) {
  1352. this._diffuseTexture.dispose();
  1353. }
  1354. _super.prototype.dispose.call(this, forceDisposeEffect);
  1355. };
  1356. SimpleMaterial.prototype.clone = function (name) {
  1357. var _this = this;
  1358. return BABYLON.SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
  1359. };
  1360. SimpleMaterial.prototype.serialize = function () {
  1361. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1362. serializationObject.customType = "BABYLON.SimpleMaterial";
  1363. return serializationObject;
  1364. };
  1365. SimpleMaterial.prototype.getClassName = function () {
  1366. return "SimpleMaterial";
  1367. };
  1368. // Statics
  1369. SimpleMaterial.Parse = function (source, scene, rootUrl) {
  1370. return BABYLON.SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
  1371. };
  1372. __decorate([
  1373. BABYLON.serializeAsTexture("diffuseTexture")
  1374. ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
  1375. __decorate([
  1376. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1377. ], SimpleMaterial.prototype, "diffuseTexture", void 0);
  1378. __decorate([
  1379. BABYLON.serializeAsColor3("diffuse")
  1380. ], SimpleMaterial.prototype, "diffuseColor", void 0);
  1381. __decorate([
  1382. BABYLON.serialize("disableLighting")
  1383. ], SimpleMaterial.prototype, "_disableLighting", void 0);
  1384. __decorate([
  1385. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1386. ], SimpleMaterial.prototype, "disableLighting", void 0);
  1387. __decorate([
  1388. BABYLON.serialize("maxSimultaneousLights")
  1389. ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
  1390. __decorate([
  1391. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1392. ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
  1393. return SimpleMaterial;
  1394. }(BABYLON.PushMaterial));
  1395. BABYLON.SimpleMaterial = SimpleMaterial;
  1396. })(BABYLON || (BABYLON = {}));
  1397. //# sourceMappingURL=babylon.simpleMaterial.js.map
  1398. BABYLON.Effect.ShadersStore['simpleVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  1399. BABYLON.Effect.ShadersStore['simplePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  1400. var BABYLON;
  1401. (function (BABYLON) {
  1402. var WaterMaterialDefines = /** @class */ (function (_super) {
  1403. __extends(WaterMaterialDefines, _super);
  1404. function WaterMaterialDefines() {
  1405. var _this = _super.call(this) || this;
  1406. _this.BUMP = false;
  1407. _this.REFLECTION = false;
  1408. _this.CLIPPLANE = false;
  1409. _this.ALPHATEST = false;
  1410. _this.DEPTHPREPASS = false;
  1411. _this.POINTSIZE = false;
  1412. _this.FOG = false;
  1413. _this.NORMAL = false;
  1414. _this.UV1 = false;
  1415. _this.UV2 = false;
  1416. _this.VERTEXCOLOR = false;
  1417. _this.VERTEXALPHA = false;
  1418. _this.NUM_BONE_INFLUENCERS = 0;
  1419. _this.BonesPerMesh = 0;
  1420. _this.INSTANCES = false;
  1421. _this.SPECULARTERM = false;
  1422. _this.LOGARITHMICDEPTH = false;
  1423. _this.FRESNELSEPARATE = false;
  1424. _this.BUMPSUPERIMPOSE = false;
  1425. _this.BUMPAFFECTSREFLECTION = false;
  1426. _this.rebuild();
  1427. return _this;
  1428. }
  1429. return WaterMaterialDefines;
  1430. }(BABYLON.MaterialDefines));
  1431. var WaterMaterial = /** @class */ (function (_super) {
  1432. __extends(WaterMaterial, _super);
  1433. /**
  1434. * Constructor
  1435. */
  1436. function WaterMaterial(name, scene, renderTargetSize) {
  1437. if (renderTargetSize === void 0) { renderTargetSize = new BABYLON.Vector2(512, 512); }
  1438. var _this = _super.call(this, name, scene) || this;
  1439. _this.renderTargetSize = renderTargetSize;
  1440. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  1441. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  1442. _this.specularPower = 64;
  1443. _this._disableLighting = false;
  1444. _this._maxSimultaneousLights = 4;
  1445. /**
  1446. * @param {number}: Represents the wind force
  1447. */
  1448. _this.windForce = 6;
  1449. /**
  1450. * @param {Vector2}: The direction of the wind in the plane (X, Z)
  1451. */
  1452. _this.windDirection = new BABYLON.Vector2(0, 1);
  1453. /**
  1454. * @param {number}: Wave height, represents the height of the waves
  1455. */
  1456. _this.waveHeight = 0.4;
  1457. /**
  1458. * @param {number}: Bump height, represents the bump height related to the bump map
  1459. */
  1460. _this.bumpHeight = 0.4;
  1461. /**
  1462. * @param {boolean}: Add a smaller moving bump to less steady waves.
  1463. */
  1464. _this._bumpSuperimpose = false;
  1465. /**
  1466. * @param {boolean}: Color refraction and reflection differently with .waterColor2 and .colorBlendFactor2. Non-linear (physically correct) fresnel.
  1467. */
  1468. _this._fresnelSeparate = false;
  1469. /**
  1470. * @param {boolean}: bump Waves modify the reflection.
  1471. */
  1472. _this._bumpAffectsReflection = false;
  1473. /**
  1474. * @param {number}: The water color blended with the refraction (near)
  1475. */
  1476. _this.waterColor = new BABYLON.Color3(0.1, 0.1, 0.6);
  1477. /**
  1478. * @param {number}: The blend factor related to the water color
  1479. */
  1480. _this.colorBlendFactor = 0.2;
  1481. /**
  1482. * @param {number}: The water color blended with the reflection (far)
  1483. */
  1484. _this.waterColor2 = new BABYLON.Color3(0.1, 0.1, 0.6);
  1485. /**
  1486. * @param {number}: The blend factor related to the water color (reflection, far)
  1487. */
  1488. _this.colorBlendFactor2 = 0.2;
  1489. /**
  1490. * @param {number}: Represents the maximum length of a wave
  1491. */
  1492. _this.waveLength = 0.1;
  1493. /**
  1494. * @param {number}: Defines the waves speed
  1495. */
  1496. _this.waveSpeed = 1.0;
  1497. _this._renderTargets = new BABYLON.SmartArray(16);
  1498. /*
  1499. * Private members
  1500. */
  1501. _this._mesh = null;
  1502. _this._reflectionTransform = BABYLON.Matrix.Zero();
  1503. _this._lastTime = 0;
  1504. _this._lastDeltaTime = 0;
  1505. _this._createRenderTargets(scene, renderTargetSize);
  1506. // Create render targets
  1507. _this.getRenderTargetTextures = function () {
  1508. _this._renderTargets.reset();
  1509. _this._renderTargets.push(_this._reflectionRTT);
  1510. _this._renderTargets.push(_this._refractionRTT);
  1511. return _this._renderTargets;
  1512. };
  1513. return _this;
  1514. }
  1515. Object.defineProperty(WaterMaterial.prototype, "useLogarithmicDepth", {
  1516. get: function () {
  1517. return this._useLogarithmicDepth;
  1518. },
  1519. set: function (value) {
  1520. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  1521. this._markAllSubMeshesAsMiscDirty();
  1522. },
  1523. enumerable: true,
  1524. configurable: true
  1525. });
  1526. Object.defineProperty(WaterMaterial.prototype, "refractionTexture", {
  1527. // Get / Set
  1528. get: function () {
  1529. return this._refractionRTT;
  1530. },
  1531. enumerable: true,
  1532. configurable: true
  1533. });
  1534. Object.defineProperty(WaterMaterial.prototype, "reflectionTexture", {
  1535. get: function () {
  1536. return this._reflectionRTT;
  1537. },
  1538. enumerable: true,
  1539. configurable: true
  1540. });
  1541. // Methods
  1542. WaterMaterial.prototype.addToRenderList = function (node) {
  1543. if (this._refractionRTT && this._refractionRTT.renderList) {
  1544. this._refractionRTT.renderList.push(node);
  1545. }
  1546. if (this._reflectionRTT && this._reflectionRTT.renderList) {
  1547. this._reflectionRTT.renderList.push(node);
  1548. }
  1549. };
  1550. WaterMaterial.prototype.enableRenderTargets = function (enable) {
  1551. var refreshRate = enable ? 1 : 0;
  1552. if (this._refractionRTT) {
  1553. this._refractionRTT.refreshRate = refreshRate;
  1554. }
  1555. if (this._reflectionRTT) {
  1556. this._reflectionRTT.refreshRate = refreshRate;
  1557. }
  1558. };
  1559. WaterMaterial.prototype.getRenderList = function () {
  1560. return this._refractionRTT ? this._refractionRTT.renderList : [];
  1561. };
  1562. Object.defineProperty(WaterMaterial.prototype, "renderTargetsEnabled", {
  1563. get: function () {
  1564. return !(this._refractionRTT && this._refractionRTT.refreshRate === 0);
  1565. },
  1566. enumerable: true,
  1567. configurable: true
  1568. });
  1569. WaterMaterial.prototype.needAlphaBlending = function () {
  1570. return (this.alpha < 1.0);
  1571. };
  1572. WaterMaterial.prototype.needAlphaTesting = function () {
  1573. return false;
  1574. };
  1575. WaterMaterial.prototype.getAlphaTestTexture = function () {
  1576. return null;
  1577. };
  1578. WaterMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  1579. if (this.isFrozen) {
  1580. if (this._wasPreviouslyReady && subMesh.effect) {
  1581. return true;
  1582. }
  1583. }
  1584. if (!subMesh._materialDefines) {
  1585. subMesh._materialDefines = new WaterMaterialDefines();
  1586. }
  1587. var defines = subMesh._materialDefines;
  1588. var scene = this.getScene();
  1589. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  1590. if (this._renderId === scene.getRenderId()) {
  1591. return true;
  1592. }
  1593. }
  1594. var engine = scene.getEngine();
  1595. // Textures
  1596. if (defines._areTexturesDirty) {
  1597. defines._needUVs = false;
  1598. if (scene.texturesEnabled) {
  1599. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1600. if (!this.bumpTexture.isReady()) {
  1601. return false;
  1602. }
  1603. else {
  1604. defines._needUVs = true;
  1605. defines.BUMP = true;
  1606. }
  1607. }
  1608. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1609. defines.REFLECTION = true;
  1610. }
  1611. }
  1612. }
  1613. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  1614. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  1615. if (defines._areMiscDirty) {
  1616. if (this._fresnelSeparate) {
  1617. defines.FRESNELSEPARATE = true;
  1618. }
  1619. if (this._bumpSuperimpose) {
  1620. defines.BUMPSUPERIMPOSE = true;
  1621. }
  1622. if (this._bumpAffectsReflection) {
  1623. defines.BUMPAFFECTSREFLECTION = true;
  1624. }
  1625. }
  1626. // Lights
  1627. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  1628. // Attribs
  1629. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  1630. // Configure this
  1631. this._mesh = mesh;
  1632. if (this._waitingRenderList) {
  1633. for (var i = 0; i < this._waitingRenderList.length; i++) {
  1634. this.addToRenderList(scene.getNodeByID(this._waitingRenderList[i]));
  1635. }
  1636. this._waitingRenderList = null;
  1637. }
  1638. // Get correct effect
  1639. if (defines.isDirty) {
  1640. defines.markAsProcessed();
  1641. scene.resetCachedMaterial();
  1642. // Fallbacks
  1643. var fallbacks = new BABYLON.EffectFallbacks();
  1644. if (defines.FOG) {
  1645. fallbacks.addFallback(1, "FOG");
  1646. }
  1647. if (defines.LOGARITHMICDEPTH) {
  1648. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  1649. }
  1650. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  1651. if (defines.NUM_BONE_INFLUENCERS > 0) {
  1652. fallbacks.addCPUSkinningFallback(0, mesh);
  1653. }
  1654. //Attributes
  1655. var attribs = [BABYLON.VertexBuffer.PositionKind];
  1656. if (defines.NORMAL) {
  1657. attribs.push(BABYLON.VertexBuffer.NormalKind);
  1658. }
  1659. if (defines.UV1) {
  1660. attribs.push(BABYLON.VertexBuffer.UVKind);
  1661. }
  1662. if (defines.UV2) {
  1663. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  1664. }
  1665. if (defines.VERTEXCOLOR) {
  1666. attribs.push(BABYLON.VertexBuffer.ColorKind);
  1667. }
  1668. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  1669. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  1670. // Legacy browser patch
  1671. var shaderName = "water";
  1672. var join = defines.toString();
  1673. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  1674. "vFogInfos", "vFogColor", "pointSize",
  1675. "vNormalInfos",
  1676. "mBones",
  1677. "vClipPlane", "normalMatrix",
  1678. "logarithmicDepthConstant",
  1679. // Water
  1680. "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
  1681. "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
  1682. ];
  1683. var samplers = ["normalSampler",
  1684. // Water
  1685. "refractionSampler", "reflectionSampler"
  1686. ];
  1687. var uniformBuffers = new Array();
  1688. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  1689. uniformsNames: uniforms,
  1690. uniformBuffersNames: uniformBuffers,
  1691. samplers: samplers,
  1692. defines: defines,
  1693. maxSimultaneousLights: this.maxSimultaneousLights
  1694. });
  1695. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  1696. attributes: attribs,
  1697. uniformsNames: uniforms,
  1698. uniformBuffersNames: uniformBuffers,
  1699. samplers: samplers,
  1700. defines: join,
  1701. fallbacks: fallbacks,
  1702. onCompiled: this.onCompiled,
  1703. onError: this.onError,
  1704. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  1705. }, engine), defines);
  1706. }
  1707. if (!subMesh.effect || !subMesh.effect.isReady()) {
  1708. return false;
  1709. }
  1710. this._renderId = scene.getRenderId();
  1711. this._wasPreviouslyReady = true;
  1712. return true;
  1713. };
  1714. WaterMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  1715. var scene = this.getScene();
  1716. var defines = subMesh._materialDefines;
  1717. if (!defines) {
  1718. return;
  1719. }
  1720. var effect = subMesh.effect;
  1721. if (!effect || !this._mesh) {
  1722. return;
  1723. }
  1724. this._activeEffect = effect;
  1725. // Matrices
  1726. this.bindOnlyWorldMatrix(world);
  1727. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  1728. // Bones
  1729. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  1730. if (this._mustRebind(scene, effect)) {
  1731. // Textures
  1732. if (this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled) {
  1733. this._activeEffect.setTexture("normalSampler", this.bumpTexture);
  1734. this._activeEffect.setFloat2("vNormalInfos", this.bumpTexture.coordinatesIndex, this.bumpTexture.level);
  1735. this._activeEffect.setMatrix("normalMatrix", this.bumpTexture.getTextureMatrix());
  1736. }
  1737. // Clip plane
  1738. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  1739. // Point size
  1740. if (this.pointsCloud) {
  1741. this._activeEffect.setFloat("pointSize", this.pointSize);
  1742. }
  1743. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  1744. }
  1745. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  1746. if (defines.SPECULARTERM) {
  1747. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  1748. }
  1749. if (scene.lightsEnabled && !this.disableLighting) {
  1750. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  1751. }
  1752. // View
  1753. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  1754. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  1755. }
  1756. // Fog
  1757. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  1758. // Log. depth
  1759. BABYLON.MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);
  1760. // Water
  1761. if (BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1762. this._activeEffect.setTexture("refractionSampler", this._refractionRTT);
  1763. this._activeEffect.setTexture("reflectionSampler", this._reflectionRTT);
  1764. }
  1765. var wrvp = this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(scene.getProjectionMatrix());
  1766. // Add delta time. Prevent adding delta time if it hasn't changed.
  1767. var deltaTime = scene.getEngine().getDeltaTime();
  1768. if (deltaTime !== this._lastDeltaTime) {
  1769. this._lastDeltaTime = deltaTime;
  1770. this._lastTime += this._lastDeltaTime;
  1771. }
  1772. this._activeEffect.setMatrix("worldReflectionViewProjection", wrvp);
  1773. this._activeEffect.setVector2("windDirection", this.windDirection);
  1774. this._activeEffect.setFloat("waveLength", this.waveLength);
  1775. this._activeEffect.setFloat("time", this._lastTime / 100000);
  1776. this._activeEffect.setFloat("windForce", this.windForce);
  1777. this._activeEffect.setFloat("waveHeight", this.waveHeight);
  1778. this._activeEffect.setFloat("bumpHeight", this.bumpHeight);
  1779. this._activeEffect.setColor4("waterColor", this.waterColor, 1.0);
  1780. this._activeEffect.setFloat("colorBlendFactor", this.colorBlendFactor);
  1781. this._activeEffect.setColor4("waterColor2", this.waterColor2, 1.0);
  1782. this._activeEffect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
  1783. this._activeEffect.setFloat("waveSpeed", this.waveSpeed);
  1784. this._afterBind(mesh, this._activeEffect);
  1785. };
  1786. WaterMaterial.prototype._createRenderTargets = function (scene, renderTargetSize) {
  1787. var _this = this;
  1788. // Render targets
  1789. this._refractionRTT = new BABYLON.RenderTargetTexture(name + "_refraction", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1790. this._refractionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1791. this._refractionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1792. this._refractionRTT.ignoreCameraViewport = true;
  1793. this._reflectionRTT = new BABYLON.RenderTargetTexture(name + "_reflection", { width: renderTargetSize.x, height: renderTargetSize.y }, scene, false, true);
  1794. this._reflectionRTT.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1795. this._reflectionRTT.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
  1796. this._reflectionRTT.ignoreCameraViewport = true;
  1797. var isVisible;
  1798. var clipPlane = null;
  1799. var savedViewMatrix;
  1800. var mirrorMatrix = BABYLON.Matrix.Zero();
  1801. this._refractionRTT.onBeforeRender = function () {
  1802. if (_this._mesh) {
  1803. isVisible = _this._mesh.isVisible;
  1804. _this._mesh.isVisible = false;
  1805. }
  1806. // Clip plane
  1807. clipPlane = scene.clipPlane;
  1808. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1809. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony + 0.05, 0), new BABYLON.Vector3(0, 1, 0));
  1810. };
  1811. this._refractionRTT.onAfterRender = function () {
  1812. if (_this._mesh) {
  1813. _this._mesh.isVisible = isVisible;
  1814. }
  1815. // Clip plane
  1816. scene.clipPlane = clipPlane;
  1817. };
  1818. this._reflectionRTT.onBeforeRender = function () {
  1819. if (_this._mesh) {
  1820. isVisible = _this._mesh.isVisible;
  1821. _this._mesh.isVisible = false;
  1822. }
  1823. // Clip plane
  1824. clipPlane = scene.clipPlane;
  1825. var positiony = _this._mesh ? _this._mesh.position.y : 0.0;
  1826. scene.clipPlane = BABYLON.Plane.FromPositionAndNormal(new BABYLON.Vector3(0, positiony - 0.05, 0), new BABYLON.Vector3(0, -1, 0));
  1827. // Transform
  1828. BABYLON.Matrix.ReflectionToRef(scene.clipPlane, mirrorMatrix);
  1829. savedViewMatrix = scene.getViewMatrix();
  1830. mirrorMatrix.multiplyToRef(savedViewMatrix, _this._reflectionTransform);
  1831. scene.setTransformMatrix(_this._reflectionTransform, scene.getProjectionMatrix());
  1832. scene.getEngine().cullBackFaces = false;
  1833. scene._mirroredCameraPosition = BABYLON.Vector3.TransformCoordinates(scene.activeCamera.position, mirrorMatrix);
  1834. };
  1835. this._reflectionRTT.onAfterRender = function () {
  1836. if (_this._mesh) {
  1837. _this._mesh.isVisible = isVisible;
  1838. }
  1839. // Clip plane
  1840. scene.clipPlane = clipPlane;
  1841. // Transform
  1842. scene.setTransformMatrix(savedViewMatrix, scene.getProjectionMatrix());
  1843. scene.getEngine().cullBackFaces = true;
  1844. scene._mirroredCameraPosition = null;
  1845. };
  1846. };
  1847. WaterMaterial.prototype.getAnimatables = function () {
  1848. var results = [];
  1849. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1850. results.push(this.bumpTexture);
  1851. }
  1852. if (this._reflectionRTT && this._reflectionRTT.animations && this._reflectionRTT.animations.length > 0) {
  1853. results.push(this._reflectionRTT);
  1854. }
  1855. if (this._refractionRTT && this._refractionRTT.animations && this._refractionRTT.animations.length > 0) {
  1856. results.push(this._refractionRTT);
  1857. }
  1858. return results;
  1859. };
  1860. WaterMaterial.prototype.getActiveTextures = function () {
  1861. var activeTextures = _super.prototype.getActiveTextures.call(this);
  1862. if (this._bumpTexture) {
  1863. activeTextures.push(this._bumpTexture);
  1864. }
  1865. return activeTextures;
  1866. };
  1867. WaterMaterial.prototype.hasTexture = function (texture) {
  1868. if (_super.prototype.hasTexture.call(this, texture)) {
  1869. return true;
  1870. }
  1871. if (this._bumpTexture === texture) {
  1872. return true;
  1873. }
  1874. return false;
  1875. };
  1876. WaterMaterial.prototype.dispose = function (forceDisposeEffect) {
  1877. if (this.bumpTexture) {
  1878. this.bumpTexture.dispose();
  1879. }
  1880. var index = this.getScene().customRenderTargets.indexOf(this._refractionRTT);
  1881. if (index != -1) {
  1882. this.getScene().customRenderTargets.splice(index, 1);
  1883. }
  1884. index = -1;
  1885. index = this.getScene().customRenderTargets.indexOf(this._reflectionRTT);
  1886. if (index != -1) {
  1887. this.getScene().customRenderTargets.splice(index, 1);
  1888. }
  1889. if (this._reflectionRTT) {
  1890. this._reflectionRTT.dispose();
  1891. }
  1892. if (this._refractionRTT) {
  1893. this._refractionRTT.dispose();
  1894. }
  1895. _super.prototype.dispose.call(this, forceDisposeEffect);
  1896. };
  1897. WaterMaterial.prototype.clone = function (name) {
  1898. var _this = this;
  1899. return BABYLON.SerializationHelper.Clone(function () { return new WaterMaterial(name, _this.getScene()); }, this);
  1900. };
  1901. WaterMaterial.prototype.serialize = function () {
  1902. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1903. serializationObject.customType = "BABYLON.WaterMaterial";
  1904. serializationObject.renderList = [];
  1905. if (this._refractionRTT && this._refractionRTT.renderList) {
  1906. for (var i = 0; i < this._refractionRTT.renderList.length; i++) {
  1907. serializationObject.renderList.push(this._refractionRTT.renderList[i].id);
  1908. }
  1909. }
  1910. return serializationObject;
  1911. };
  1912. WaterMaterial.prototype.getClassName = function () {
  1913. return "WaterMaterial";
  1914. };
  1915. // Statics
  1916. WaterMaterial.Parse = function (source, scene, rootUrl) {
  1917. var mat = BABYLON.SerializationHelper.Parse(function () { return new WaterMaterial(source.name, scene); }, source, scene, rootUrl);
  1918. mat._waitingRenderList = source.renderList;
  1919. return mat;
  1920. };
  1921. WaterMaterial.CreateDefaultMesh = function (name, scene) {
  1922. var mesh = BABYLON.Mesh.CreateGround(name, 512, 512, 32, scene, false);
  1923. return mesh;
  1924. };
  1925. __decorate([
  1926. BABYLON.serializeAsTexture("bumpTexture")
  1927. ], WaterMaterial.prototype, "_bumpTexture", void 0);
  1928. __decorate([
  1929. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1930. ], WaterMaterial.prototype, "bumpTexture", void 0);
  1931. __decorate([
  1932. BABYLON.serializeAsColor3()
  1933. ], WaterMaterial.prototype, "diffuseColor", void 0);
  1934. __decorate([
  1935. BABYLON.serializeAsColor3()
  1936. ], WaterMaterial.prototype, "specularColor", void 0);
  1937. __decorate([
  1938. BABYLON.serialize()
  1939. ], WaterMaterial.prototype, "specularPower", void 0);
  1940. __decorate([
  1941. BABYLON.serialize("disableLighting")
  1942. ], WaterMaterial.prototype, "_disableLighting", void 0);
  1943. __decorate([
  1944. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1945. ], WaterMaterial.prototype, "disableLighting", void 0);
  1946. __decorate([
  1947. BABYLON.serialize("maxSimultaneousLights")
  1948. ], WaterMaterial.prototype, "_maxSimultaneousLights", void 0);
  1949. __decorate([
  1950. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1951. ], WaterMaterial.prototype, "maxSimultaneousLights", void 0);
  1952. __decorate([
  1953. BABYLON.serialize()
  1954. ], WaterMaterial.prototype, "windForce", void 0);
  1955. __decorate([
  1956. BABYLON.serializeAsVector2()
  1957. ], WaterMaterial.prototype, "windDirection", void 0);
  1958. __decorate([
  1959. BABYLON.serialize()
  1960. ], WaterMaterial.prototype, "waveHeight", void 0);
  1961. __decorate([
  1962. BABYLON.serialize()
  1963. ], WaterMaterial.prototype, "bumpHeight", void 0);
  1964. __decorate([
  1965. BABYLON.serialize("bumpSuperimpose")
  1966. ], WaterMaterial.prototype, "_bumpSuperimpose", void 0);
  1967. __decorate([
  1968. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1969. ], WaterMaterial.prototype, "bumpSuperimpose", void 0);
  1970. __decorate([
  1971. BABYLON.serialize("fresnelSeparate")
  1972. ], WaterMaterial.prototype, "_fresnelSeparate", void 0);
  1973. __decorate([
  1974. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1975. ], WaterMaterial.prototype, "fresnelSeparate", void 0);
  1976. __decorate([
  1977. BABYLON.serialize("bumpAffectsReflection")
  1978. ], WaterMaterial.prototype, "_bumpAffectsReflection", void 0);
  1979. __decorate([
  1980. BABYLON.expandToProperty("_markAllSubMeshesAsMiscDirty")
  1981. ], WaterMaterial.prototype, "bumpAffectsReflection", void 0);
  1982. __decorate([
  1983. BABYLON.serializeAsColor3()
  1984. ], WaterMaterial.prototype, "waterColor", void 0);
  1985. __decorate([
  1986. BABYLON.serialize()
  1987. ], WaterMaterial.prototype, "colorBlendFactor", void 0);
  1988. __decorate([
  1989. BABYLON.serializeAsColor3()
  1990. ], WaterMaterial.prototype, "waterColor2", void 0);
  1991. __decorate([
  1992. BABYLON.serialize()
  1993. ], WaterMaterial.prototype, "colorBlendFactor2", void 0);
  1994. __decorate([
  1995. BABYLON.serialize()
  1996. ], WaterMaterial.prototype, "waveLength", void 0);
  1997. __decorate([
  1998. BABYLON.serialize()
  1999. ], WaterMaterial.prototype, "waveSpeed", void 0);
  2000. __decorate([
  2001. BABYLON.serialize()
  2002. ], WaterMaterial.prototype, "useLogarithmicDepth", null);
  2003. return WaterMaterial;
  2004. }(BABYLON.PushMaterial));
  2005. BABYLON.WaterMaterial = WaterMaterial;
  2006. })(BABYLON || (BABYLON = {}));
  2007. //# sourceMappingURL=babylon.waterMaterial.js.map
  2008. BABYLON.Effect.ShadersStore['waterVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;\nuniform vec2 vNormalInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\n\nuniform mat4 worldReflectionViewProjection;\nuniform vec2 windDirection;\nuniform float waveLength;\nuniform float time;\nuniform float windForce;\nuniform float waveHeight;\nuniform float waveSpeed;\n\nvarying vec3 vPosition;\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef BUMP\nif (vNormalInfos.x == 0.)\n{\nvNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{\nvNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\nvec3 p=position;\nfloat newY=(sin(((p.x/0.05)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+(cos(((p.z/0.05)+time*waveSpeed))*waveHeight*windDirection.y*5.0);\np.y+=abs(newY);\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#ifdef REFLECTION\nworldPos=viewProjection*finalWorld*vec4(p,1.0);\n\nvPosition=position;\nvRefractionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvRefractionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvRefractionMapTexCoord.z=worldPos.w;\nworldPos=worldReflectionViewProjection*vec4(position,1.0);\nvReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);\nvReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);\nvReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n}\n";
  2009. BABYLON.Effect.ShadersStore['waterPixelShader'] = "#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef BUMP\nvarying vec2 vNormalUV;\nvarying vec2 vNormalUV2;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\nconst float LOG2=1.442695;\nuniform vec3 cameraPosition;\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\nuniform vec4 waterColor2;\nuniform float colorBlendFactor2;\nuniform float bumpHeight;\nuniform float time;\n\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));\nif (normalW.y<0.0) {\nnormalW.y=-normalW.y;\n}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\nvec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=clamp(abs(pow(dot(eyeVector,upVector),3.0)),0.05,0.65);\nfloat IfresnelTerm=1.0-fresnelTerm;\nrefractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;\nreflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;\nbaseColor=combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\n\nvec3 eyeVector=normalize(vEyePosition-vPosition);\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);\nvec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\nvec3 upVector=vec3(0.0,1.0,0.0);\nfloat fresnelTerm=max(dot(eyeVector,upVector),0.0);\nvec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);\nbaseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  2010. var BABYLON;
  2011. (function (BABYLON) {
  2012. var FireMaterialDefines = /** @class */ (function (_super) {
  2013. __extends(FireMaterialDefines, _super);
  2014. function FireMaterialDefines() {
  2015. var _this = _super.call(this) || this;
  2016. _this.DIFFUSE = false;
  2017. _this.CLIPPLANE = false;
  2018. _this.ALPHATEST = false;
  2019. _this.DEPTHPREPASS = false;
  2020. _this.POINTSIZE = false;
  2021. _this.FOG = false;
  2022. _this.UV1 = false;
  2023. _this.VERTEXCOLOR = false;
  2024. _this.VERTEXALPHA = false;
  2025. _this.BonesPerMesh = 0;
  2026. _this.NUM_BONE_INFLUENCERS = 0;
  2027. _this.INSTANCES = false;
  2028. _this.rebuild();
  2029. return _this;
  2030. }
  2031. return FireMaterialDefines;
  2032. }(BABYLON.MaterialDefines));
  2033. var FireMaterial = /** @class */ (function (_super) {
  2034. __extends(FireMaterial, _super);
  2035. function FireMaterial(name, scene) {
  2036. var _this = _super.call(this, name, scene) || this;
  2037. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2038. _this.speed = 1.0;
  2039. _this._scaledDiffuse = new BABYLON.Color3();
  2040. _this._lastTime = 0;
  2041. return _this;
  2042. }
  2043. FireMaterial.prototype.needAlphaBlending = function () {
  2044. return false;
  2045. };
  2046. FireMaterial.prototype.needAlphaTesting = function () {
  2047. return true;
  2048. };
  2049. FireMaterial.prototype.getAlphaTestTexture = function () {
  2050. return null;
  2051. };
  2052. // Methods
  2053. FireMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2054. if (this.isFrozen) {
  2055. if (this._wasPreviouslyReady && subMesh.effect) {
  2056. return true;
  2057. }
  2058. }
  2059. if (!subMesh._materialDefines) {
  2060. subMesh._materialDefines = new FireMaterialDefines();
  2061. }
  2062. var defines = subMesh._materialDefines;
  2063. var scene = this.getScene();
  2064. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2065. if (this._renderId === scene.getRenderId()) {
  2066. return true;
  2067. }
  2068. }
  2069. var engine = scene.getEngine();
  2070. // Textures
  2071. if (defines._areTexturesDirty) {
  2072. defines._needUVs = false;
  2073. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2074. if (!this._diffuseTexture.isReady()) {
  2075. return false;
  2076. }
  2077. else {
  2078. defines._needUVs = true;
  2079. defines.DIFFUSE = true;
  2080. }
  2081. }
  2082. }
  2083. // Misc.
  2084. if (defines._areMiscDirty) {
  2085. defines.POINTSIZE = (this.pointsCloud || scene.forcePointsCloud);
  2086. defines.FOG = (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled);
  2087. }
  2088. // Values that need to be evaluated on every frame
  2089. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2090. // Attribs
  2091. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  2092. // Get correct effect
  2093. if (defines.isDirty) {
  2094. defines.markAsProcessed();
  2095. scene.resetCachedMaterial();
  2096. // Fallbacks
  2097. var fallbacks = new BABYLON.EffectFallbacks();
  2098. if (defines.FOG) {
  2099. fallbacks.addFallback(1, "FOG");
  2100. }
  2101. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2102. fallbacks.addCPUSkinningFallback(0, mesh);
  2103. }
  2104. //Attributes
  2105. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2106. if (defines.UV1) {
  2107. attribs.push(BABYLON.VertexBuffer.UVKind);
  2108. }
  2109. if (defines.VERTEXCOLOR) {
  2110. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2111. }
  2112. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2113. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2114. // Legacy browser patch
  2115. var shaderName = "fire";
  2116. var join = defines.toString();
  2117. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2118. attributes: attribs,
  2119. uniformsNames: ["world", "view", "viewProjection", "vEyePosition",
  2120. "vFogInfos", "vFogColor", "pointSize",
  2121. "vDiffuseInfos",
  2122. "mBones",
  2123. "vClipPlane", "diffuseMatrix",
  2124. // Fire
  2125. "time", "speed"
  2126. ],
  2127. uniformBuffersNames: [],
  2128. samplers: ["diffuseSampler",
  2129. // Fire
  2130. "distortionSampler", "opacitySampler"
  2131. ],
  2132. defines: join,
  2133. fallbacks: fallbacks,
  2134. onCompiled: this.onCompiled,
  2135. onError: this.onError,
  2136. indexParameters: null,
  2137. maxSimultaneousLights: 4,
  2138. transformFeedbackVaryings: null
  2139. }, engine), defines);
  2140. }
  2141. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2142. return false;
  2143. }
  2144. this._renderId = scene.getRenderId();
  2145. this._wasPreviouslyReady = true;
  2146. return true;
  2147. };
  2148. FireMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2149. var scene = this.getScene();
  2150. var defines = subMesh._materialDefines;
  2151. if (!defines) {
  2152. return;
  2153. }
  2154. var effect = subMesh.effect;
  2155. if (!effect) {
  2156. return;
  2157. }
  2158. this._activeEffect = effect;
  2159. // Matrices
  2160. this.bindOnlyWorldMatrix(world);
  2161. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2162. // Bones
  2163. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2164. if (this._mustRebind(scene, effect)) {
  2165. // Textures
  2166. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2167. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2168. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2169. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2170. this._activeEffect.setTexture("distortionSampler", this._distortionTexture);
  2171. this._activeEffect.setTexture("opacitySampler", this._opacityTexture);
  2172. }
  2173. // Clip plane
  2174. if (scene.clipPlane) {
  2175. var clipPlane = scene.clipPlane;
  2176. this._activeEffect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  2177. }
  2178. // Point size
  2179. if (this.pointsCloud) {
  2180. this._activeEffect.setFloat("pointSize", this.pointSize);
  2181. }
  2182. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2183. }
  2184. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  2185. // View
  2186. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2187. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2188. }
  2189. // Fog
  2190. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2191. // Time
  2192. this._lastTime += scene.getEngine().getDeltaTime();
  2193. this._activeEffect.setFloat("time", this._lastTime);
  2194. // Speed
  2195. this._activeEffect.setFloat("speed", this.speed);
  2196. this._afterBind(mesh, this._activeEffect);
  2197. };
  2198. FireMaterial.prototype.getAnimatables = function () {
  2199. var results = [];
  2200. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  2201. results.push(this._diffuseTexture);
  2202. }
  2203. if (this._distortionTexture && this._distortionTexture.animations && this._distortionTexture.animations.length > 0) {
  2204. results.push(this._distortionTexture);
  2205. }
  2206. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  2207. results.push(this._opacityTexture);
  2208. }
  2209. return results;
  2210. };
  2211. FireMaterial.prototype.getActiveTextures = function () {
  2212. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2213. if (this._diffuseTexture) {
  2214. activeTextures.push(this._diffuseTexture);
  2215. }
  2216. if (this._distortionTexture) {
  2217. activeTextures.push(this._distortionTexture);
  2218. }
  2219. if (this._opacityTexture) {
  2220. activeTextures.push(this._opacityTexture);
  2221. }
  2222. return activeTextures;
  2223. };
  2224. FireMaterial.prototype.hasTexture = function (texture) {
  2225. if (_super.prototype.hasTexture.call(this, texture)) {
  2226. return true;
  2227. }
  2228. if (this._diffuseTexture === texture) {
  2229. return true;
  2230. }
  2231. if (this._distortionTexture === texture) {
  2232. return true;
  2233. }
  2234. if (this._opacityTexture === texture) {
  2235. return true;
  2236. }
  2237. return false;
  2238. };
  2239. FireMaterial.prototype.getClassName = function () {
  2240. return "FireMaterial";
  2241. };
  2242. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  2243. if (this._diffuseTexture) {
  2244. this._diffuseTexture.dispose();
  2245. }
  2246. if (this._distortionTexture) {
  2247. this._distortionTexture.dispose();
  2248. }
  2249. _super.prototype.dispose.call(this, forceDisposeEffect);
  2250. };
  2251. FireMaterial.prototype.clone = function (name) {
  2252. var _this = this;
  2253. return BABYLON.SerializationHelper.Clone(function () { return new FireMaterial(name, _this.getScene()); }, this);
  2254. };
  2255. FireMaterial.prototype.serialize = function () {
  2256. var serializationObject = _super.prototype.serialize.call(this);
  2257. serializationObject.customType = "BABYLON.FireMaterial";
  2258. serializationObject.diffuseColor = this.diffuseColor.asArray();
  2259. serializationObject.speed = this.speed;
  2260. if (this._diffuseTexture) {
  2261. serializationObject._diffuseTexture = this._diffuseTexture.serialize();
  2262. }
  2263. if (this._distortionTexture) {
  2264. serializationObject._distortionTexture = this._distortionTexture.serialize();
  2265. }
  2266. if (this._opacityTexture) {
  2267. serializationObject._opacityTexture = this._opacityTexture.serialize();
  2268. }
  2269. return serializationObject;
  2270. };
  2271. FireMaterial.Parse = function (source, scene, rootUrl) {
  2272. var material = new FireMaterial(source.name, scene);
  2273. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  2274. material.speed = source.speed;
  2275. material.alpha = source.alpha;
  2276. material.id = source.id;
  2277. BABYLON.Tags.AddTagsTo(material, source.tags);
  2278. material.backFaceCulling = source.backFaceCulling;
  2279. material.wireframe = source.wireframe;
  2280. if (source._diffuseTexture) {
  2281. material._diffuseTexture = BABYLON.Texture.Parse(source._diffuseTexture, scene, rootUrl);
  2282. }
  2283. if (source._distortionTexture) {
  2284. material._distortionTexture = BABYLON.Texture.Parse(source._distortionTexture, scene, rootUrl);
  2285. }
  2286. if (source._opacityTexture) {
  2287. material._opacityTexture = BABYLON.Texture.Parse(source._opacityTexture, scene, rootUrl);
  2288. }
  2289. if (source.checkReadyOnlyOnce) {
  2290. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  2291. }
  2292. return material;
  2293. };
  2294. __decorate([
  2295. BABYLON.serializeAsTexture("diffuseTexture")
  2296. ], FireMaterial.prototype, "_diffuseTexture", void 0);
  2297. __decorate([
  2298. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2299. ], FireMaterial.prototype, "diffuseTexture", void 0);
  2300. __decorate([
  2301. BABYLON.serializeAsTexture("distortionTexture")
  2302. ], FireMaterial.prototype, "_distortionTexture", void 0);
  2303. __decorate([
  2304. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2305. ], FireMaterial.prototype, "distortionTexture", void 0);
  2306. __decorate([
  2307. BABYLON.serializeAsTexture("opacityTexture")
  2308. ], FireMaterial.prototype, "_opacityTexture", void 0);
  2309. __decorate([
  2310. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2311. ], FireMaterial.prototype, "opacityTexture", void 0);
  2312. __decorate([
  2313. BABYLON.serializeAsColor3("diffuse")
  2314. ], FireMaterial.prototype, "diffuseColor", void 0);
  2315. __decorate([
  2316. BABYLON.serialize()
  2317. ], FireMaterial.prototype, "speed", void 0);
  2318. return FireMaterial;
  2319. }(BABYLON.PushMaterial));
  2320. BABYLON.FireMaterial = FireMaterial;
  2321. })(BABYLON || (BABYLON = {}));
  2322. //# sourceMappingURL=babylon.fireMaterial.js.map
  2323. BABYLON.Effect.ShadersStore['fireVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n\nuniform float time;\nuniform float speed;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#ifdef DIFFUSE\nvDiffuseUV=uv;\nvDiffuseUV.y-=0.2;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n#ifdef DIFFUSE\n\nvec3 layerSpeed=vec3(-0.2,-0.52,-0.1)*speed;\nvDistortionCoords1.x=uv.x;\nvDistortionCoords1.y=uv.y+layerSpeed.x*time/1000.0;\nvDistortionCoords2.x=uv.x;\nvDistortionCoords2.y=uv.y+layerSpeed.y*time/1000.0;\nvDistortionCoords3.x=uv.x;\nvDistortionCoords3.y=uv.y+layerSpeed.z*time/1000.0;\n#endif\n}\n";
  2324. BABYLON.Effect.ShadersStore['firePixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\nuniform sampler2D distortionSampler;\nuniform sampler2D opacitySampler;\n#ifdef DIFFUSE\nvarying vec2 vDistortionCoords1;\nvarying vec2 vDistortionCoords2;\nvarying vec2 vDistortionCoords3;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvec4 bx2(vec4 x)\n{\nreturn vec4(2.0)*x-vec4(1.0);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\n\nfloat alpha=1.0;\n#ifdef DIFFUSE\n\nconst float distortionAmount0=0.092;\nconst float distortionAmount1=0.092;\nconst float distortionAmount2=0.092;\nvec2 heightAttenuation=vec2(0.3,0.39);\nvec4 noise0=texture2D(distortionSampler,vDistortionCoords1);\nvec4 noise1=texture2D(distortionSampler,vDistortionCoords2);\nvec4 noise2=texture2D(distortionSampler,vDistortionCoords3);\nvec4 noiseSum=bx2(noise0)*distortionAmount0+bx2(noise1)*distortionAmount1+bx2(noise2)*distortionAmount2;\nvec4 perturbedBaseCoords=vec4(vDiffuseUV,0.0,1.0)+noiseSum*(vDiffuseUV.y*heightAttenuation.x+heightAttenuation.y);\nvec4 opacityColor=texture2D(opacitySampler,perturbedBaseCoords.xy);\n#ifdef ALPHATEST\nif (opacityColor.r<0.1)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor=texture2D(diffuseSampler,perturbedBaseCoords.xy)*2.0;\nbaseColor*=opacityColor;\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(1.0,1.0,1.0);\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=vec4(baseColor.rgb,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  2325. var BABYLON;
  2326. (function (BABYLON) {
  2327. var FurMaterialDefines = /** @class */ (function (_super) {
  2328. __extends(FurMaterialDefines, _super);
  2329. function FurMaterialDefines() {
  2330. var _this = _super.call(this) || this;
  2331. _this.DIFFUSE = false;
  2332. _this.HEIGHTMAP = false;
  2333. _this.CLIPPLANE = false;
  2334. _this.ALPHATEST = false;
  2335. _this.DEPTHPREPASS = false;
  2336. _this.POINTSIZE = false;
  2337. _this.FOG = false;
  2338. _this.NORMAL = false;
  2339. _this.UV1 = false;
  2340. _this.UV2 = false;
  2341. _this.VERTEXCOLOR = false;
  2342. _this.VERTEXALPHA = false;
  2343. _this.NUM_BONE_INFLUENCERS = 0;
  2344. _this.BonesPerMesh = 0;
  2345. _this.INSTANCES = false;
  2346. _this.HIGHLEVEL = false;
  2347. _this.rebuild();
  2348. return _this;
  2349. }
  2350. return FurMaterialDefines;
  2351. }(BABYLON.MaterialDefines));
  2352. var FurMaterial = /** @class */ (function (_super) {
  2353. __extends(FurMaterial, _super);
  2354. function FurMaterial(name, scene) {
  2355. var _this = _super.call(this, name, scene) || this;
  2356. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2357. _this.furLength = 1;
  2358. _this.furAngle = 0;
  2359. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  2360. _this.furOffset = 0.0;
  2361. _this.furSpacing = 12;
  2362. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  2363. _this.furSpeed = 100;
  2364. _this.furDensity = 20;
  2365. _this._disableLighting = false;
  2366. _this._maxSimultaneousLights = 4;
  2367. _this.highLevelFur = true;
  2368. _this._furTime = 0;
  2369. return _this;
  2370. }
  2371. Object.defineProperty(FurMaterial.prototype, "furTime", {
  2372. get: function () {
  2373. return this._furTime;
  2374. },
  2375. set: function (furTime) {
  2376. this._furTime = furTime;
  2377. },
  2378. enumerable: true,
  2379. configurable: true
  2380. });
  2381. FurMaterial.prototype.needAlphaBlending = function () {
  2382. return (this.alpha < 1.0);
  2383. };
  2384. FurMaterial.prototype.needAlphaTesting = function () {
  2385. return false;
  2386. };
  2387. FurMaterial.prototype.getAlphaTestTexture = function () {
  2388. return null;
  2389. };
  2390. FurMaterial.prototype.updateFur = function () {
  2391. for (var i = 1; i < this._meshes.length; i++) {
  2392. var offsetFur = this._meshes[i].material;
  2393. offsetFur.furLength = this.furLength;
  2394. offsetFur.furAngle = this.furAngle;
  2395. offsetFur.furGravity = this.furGravity;
  2396. offsetFur.furSpacing = this.furSpacing;
  2397. offsetFur.furSpeed = this.furSpeed;
  2398. offsetFur.furColor = this.furColor;
  2399. offsetFur.diffuseTexture = this.diffuseTexture;
  2400. offsetFur.furTexture = this.furTexture;
  2401. offsetFur.highLevelFur = this.highLevelFur;
  2402. offsetFur.furTime = this.furTime;
  2403. offsetFur.furDensity = this.furDensity;
  2404. }
  2405. };
  2406. // Methods
  2407. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2408. if (this.isFrozen) {
  2409. if (this._wasPreviouslyReady && subMesh.effect) {
  2410. return true;
  2411. }
  2412. }
  2413. if (!subMesh._materialDefines) {
  2414. subMesh._materialDefines = new FurMaterialDefines();
  2415. }
  2416. var defines = subMesh._materialDefines;
  2417. var scene = this.getScene();
  2418. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2419. if (this._renderId === scene.getRenderId()) {
  2420. return true;
  2421. }
  2422. }
  2423. var engine = scene.getEngine();
  2424. // Textures
  2425. if (defines._areTexturesDirty) {
  2426. if (scene.texturesEnabled) {
  2427. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2428. if (!this.diffuseTexture.isReady()) {
  2429. return false;
  2430. }
  2431. else {
  2432. defines._needUVs = true;
  2433. defines.DIFFUSE = true;
  2434. }
  2435. }
  2436. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  2437. if (!this.heightTexture.isReady()) {
  2438. return false;
  2439. }
  2440. else {
  2441. defines._needUVs = true;
  2442. defines.HEIGHTMAP = true;
  2443. }
  2444. }
  2445. }
  2446. }
  2447. // High level
  2448. if (this.highLevelFur !== defines.HIGHLEVEL) {
  2449. defines.HIGHLEVEL = true;
  2450. defines.markAsUnprocessed();
  2451. }
  2452. // Misc.
  2453. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  2454. // Lights
  2455. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2456. // Values that need to be evaluated on every frame
  2457. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2458. // Attribs
  2459. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2460. // Get correct effect
  2461. if (defines.isDirty) {
  2462. defines.markAsProcessed();
  2463. scene.resetCachedMaterial();
  2464. // Fallbacks
  2465. var fallbacks = new BABYLON.EffectFallbacks();
  2466. if (defines.FOG) {
  2467. fallbacks.addFallback(1, "FOG");
  2468. }
  2469. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2470. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2471. fallbacks.addCPUSkinningFallback(0, mesh);
  2472. }
  2473. //Attributes
  2474. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2475. if (defines.NORMAL) {
  2476. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2477. }
  2478. if (defines.UV1) {
  2479. attribs.push(BABYLON.VertexBuffer.UVKind);
  2480. }
  2481. if (defines.UV2) {
  2482. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2483. }
  2484. if (defines.VERTEXCOLOR) {
  2485. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2486. }
  2487. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2488. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2489. // Legacy browser patch
  2490. var shaderName = "fur";
  2491. var join = defines.toString();
  2492. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  2493. "vFogInfos", "vFogColor", "pointSize",
  2494. "vDiffuseInfos",
  2495. "mBones",
  2496. "vClipPlane", "diffuseMatrix",
  2497. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
  2498. ];
  2499. var samplers = ["diffuseSampler",
  2500. "heightTexture", "furTexture"
  2501. ];
  2502. var uniformBuffers = new Array();
  2503. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2504. uniformsNames: uniforms,
  2505. uniformBuffersNames: uniformBuffers,
  2506. samplers: samplers,
  2507. defines: defines,
  2508. maxSimultaneousLights: this.maxSimultaneousLights
  2509. });
  2510. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2511. attributes: attribs,
  2512. uniformsNames: uniforms,
  2513. uniformBuffersNames: uniformBuffers,
  2514. samplers: samplers,
  2515. defines: join,
  2516. fallbacks: fallbacks,
  2517. onCompiled: this.onCompiled,
  2518. onError: this.onError,
  2519. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2520. }, engine), defines);
  2521. }
  2522. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2523. return false;
  2524. }
  2525. this._renderId = scene.getRenderId();
  2526. this._wasPreviouslyReady = true;
  2527. return true;
  2528. };
  2529. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2530. var scene = this.getScene();
  2531. var defines = subMesh._materialDefines;
  2532. if (!defines) {
  2533. return;
  2534. }
  2535. var effect = subMesh.effect;
  2536. if (!effect) {
  2537. return;
  2538. }
  2539. this._activeEffect = effect;
  2540. // Matrices
  2541. this.bindOnlyWorldMatrix(world);
  2542. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2543. // Bones
  2544. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2545. if (scene.getCachedMaterial() !== this) {
  2546. // Textures
  2547. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2548. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  2549. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  2550. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  2551. }
  2552. if (this._heightTexture) {
  2553. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  2554. }
  2555. // Clip plane
  2556. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2557. // Point size
  2558. if (this.pointsCloud) {
  2559. this._activeEffect.setFloat("pointSize", this.pointSize);
  2560. }
  2561. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2562. }
  2563. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2564. if (scene.lightsEnabled && !this.disableLighting) {
  2565. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  2566. }
  2567. // View
  2568. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  2569. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  2570. }
  2571. // Fog
  2572. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  2573. this._activeEffect.setFloat("furLength", this.furLength);
  2574. this._activeEffect.setFloat("furAngle", this.furAngle);
  2575. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  2576. if (this.highLevelFur) {
  2577. this._activeEffect.setVector3("furGravity", this.furGravity);
  2578. this._activeEffect.setFloat("furOffset", this.furOffset);
  2579. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  2580. this._activeEffect.setFloat("furDensity", this.furDensity);
  2581. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  2582. this._activeEffect.setFloat("furTime", this._furTime);
  2583. this._activeEffect.setTexture("furTexture", this.furTexture);
  2584. }
  2585. this._afterBind(mesh, this._activeEffect);
  2586. };
  2587. FurMaterial.prototype.getAnimatables = function () {
  2588. var results = [];
  2589. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  2590. results.push(this.diffuseTexture);
  2591. }
  2592. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  2593. results.push(this.heightTexture);
  2594. }
  2595. return results;
  2596. };
  2597. FurMaterial.prototype.getActiveTextures = function () {
  2598. var activeTextures = _super.prototype.getActiveTextures.call(this);
  2599. if (this._diffuseTexture) {
  2600. activeTextures.push(this._diffuseTexture);
  2601. }
  2602. if (this._heightTexture) {
  2603. activeTextures.push(this._heightTexture);
  2604. }
  2605. return activeTextures;
  2606. };
  2607. FurMaterial.prototype.hasTexture = function (texture) {
  2608. if (_super.prototype.hasTexture.call(this, texture)) {
  2609. return true;
  2610. }
  2611. if (this.diffuseTexture === texture) {
  2612. return true;
  2613. }
  2614. if (this._heightTexture === texture) {
  2615. return true;
  2616. }
  2617. return false;
  2618. };
  2619. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  2620. if (this.diffuseTexture) {
  2621. this.diffuseTexture.dispose();
  2622. }
  2623. if (this._meshes) {
  2624. for (var i = 1; i < this._meshes.length; i++) {
  2625. var mat = this._meshes[i].material;
  2626. if (mat) {
  2627. mat.dispose(forceDisposeEffect);
  2628. }
  2629. this._meshes[i].dispose();
  2630. }
  2631. }
  2632. _super.prototype.dispose.call(this, forceDisposeEffect);
  2633. };
  2634. FurMaterial.prototype.clone = function (name) {
  2635. var _this = this;
  2636. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  2637. };
  2638. FurMaterial.prototype.serialize = function () {
  2639. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  2640. serializationObject.customType = "BABYLON.FurMaterial";
  2641. if (this._meshes) {
  2642. serializationObject.sourceMeshName = this._meshes[0].name;
  2643. serializationObject.quality = this._meshes.length;
  2644. }
  2645. return serializationObject;
  2646. };
  2647. FurMaterial.prototype.getClassName = function () {
  2648. return "FurMaterial";
  2649. };
  2650. // Statics
  2651. FurMaterial.Parse = function (source, scene, rootUrl) {
  2652. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  2653. if (source.sourceMeshName && material.highLevelFur) {
  2654. scene.executeWhenReady(function () {
  2655. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  2656. if (sourceMesh) {
  2657. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  2658. material.furTexture = furTexture;
  2659. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  2660. }
  2661. });
  2662. }
  2663. return material;
  2664. };
  2665. FurMaterial.GenerateTexture = function (name, scene) {
  2666. // Generate fur textures
  2667. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  2668. var context = texture.getContext();
  2669. for (var i = 0; i < 20000; ++i) {
  2670. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  2671. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  2672. }
  2673. texture.update(false);
  2674. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  2675. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  2676. return texture;
  2677. };
  2678. // Creates and returns an array of meshes used as shells for the Fur Material
  2679. // that can be disposed later in your code
  2680. // The quality is in interval [0, 100]
  2681. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  2682. var meshes = [sourceMesh];
  2683. var mat = sourceMesh.material;
  2684. var i;
  2685. if (!(mat instanceof FurMaterial)) {
  2686. throw "The material of the source mesh must be a Fur Material";
  2687. }
  2688. for (i = 1; i < quality; i++) {
  2689. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  2690. sourceMesh.getScene().materials.pop();
  2691. BABYLON.Tags.EnableFor(offsetFur);
  2692. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  2693. offsetFur.furLength = mat.furLength;
  2694. offsetFur.furAngle = mat.furAngle;
  2695. offsetFur.furGravity = mat.furGravity;
  2696. offsetFur.furSpacing = mat.furSpacing;
  2697. offsetFur.furSpeed = mat.furSpeed;
  2698. offsetFur.furColor = mat.furColor;
  2699. offsetFur.diffuseTexture = mat.diffuseTexture;
  2700. offsetFur.furOffset = i / quality;
  2701. offsetFur.furTexture = mat.furTexture;
  2702. offsetFur.highLevelFur = mat.highLevelFur;
  2703. offsetFur.furTime = mat.furTime;
  2704. offsetFur.furDensity = mat.furDensity;
  2705. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  2706. offsetMesh.material = offsetFur;
  2707. offsetMesh.skeleton = sourceMesh.skeleton;
  2708. offsetMesh.position = BABYLON.Vector3.Zero();
  2709. meshes.push(offsetMesh);
  2710. }
  2711. for (i = 1; i < meshes.length; i++) {
  2712. meshes[i].parent = sourceMesh;
  2713. }
  2714. sourceMesh.material._meshes = meshes;
  2715. return meshes;
  2716. };
  2717. __decorate([
  2718. BABYLON.serializeAsTexture("diffuseTexture")
  2719. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  2720. __decorate([
  2721. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2722. ], FurMaterial.prototype, "diffuseTexture", void 0);
  2723. __decorate([
  2724. BABYLON.serializeAsTexture("heightTexture")
  2725. ], FurMaterial.prototype, "_heightTexture", void 0);
  2726. __decorate([
  2727. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  2728. ], FurMaterial.prototype, "heightTexture", void 0);
  2729. __decorate([
  2730. BABYLON.serializeAsColor3()
  2731. ], FurMaterial.prototype, "diffuseColor", void 0);
  2732. __decorate([
  2733. BABYLON.serialize()
  2734. ], FurMaterial.prototype, "furLength", void 0);
  2735. __decorate([
  2736. BABYLON.serialize()
  2737. ], FurMaterial.prototype, "furAngle", void 0);
  2738. __decorate([
  2739. BABYLON.serializeAsColor3()
  2740. ], FurMaterial.prototype, "furColor", void 0);
  2741. __decorate([
  2742. BABYLON.serialize()
  2743. ], FurMaterial.prototype, "furOffset", void 0);
  2744. __decorate([
  2745. BABYLON.serialize()
  2746. ], FurMaterial.prototype, "furSpacing", void 0);
  2747. __decorate([
  2748. BABYLON.serializeAsVector3()
  2749. ], FurMaterial.prototype, "furGravity", void 0);
  2750. __decorate([
  2751. BABYLON.serialize()
  2752. ], FurMaterial.prototype, "furSpeed", void 0);
  2753. __decorate([
  2754. BABYLON.serialize()
  2755. ], FurMaterial.prototype, "furDensity", void 0);
  2756. __decorate([
  2757. BABYLON.serialize("disableLighting")
  2758. ], FurMaterial.prototype, "_disableLighting", void 0);
  2759. __decorate([
  2760. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2761. ], FurMaterial.prototype, "disableLighting", void 0);
  2762. __decorate([
  2763. BABYLON.serialize("maxSimultaneousLights")
  2764. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  2765. __decorate([
  2766. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  2767. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  2768. __decorate([
  2769. BABYLON.serialize()
  2770. ], FurMaterial.prototype, "highLevelFur", void 0);
  2771. __decorate([
  2772. BABYLON.serialize()
  2773. ], FurMaterial.prototype, "furTime", null);
  2774. return FurMaterial;
  2775. }(BABYLON.PushMaterial));
  2776. BABYLON.FurMaterial = FurMaterial;
  2777. })(BABYLON || (BABYLON = {}));
  2778. //# sourceMappingURL=babylon.furMaterial.js.map
  2779. BABYLON.Effect.ShadersStore['furVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\n#ifdef HIGHLEVEL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0))*aNormal);\n#else\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  2780. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*occlusion,1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";
  2781. var BABYLON;
  2782. (function (BABYLON) {
  2783. var TerrainMaterialDefines = /** @class */ (function (_super) {
  2784. __extends(TerrainMaterialDefines, _super);
  2785. function TerrainMaterialDefines() {
  2786. var _this = _super.call(this) || this;
  2787. _this.DIFFUSE = false;
  2788. _this.BUMP = false;
  2789. _this.CLIPPLANE = false;
  2790. _this.ALPHATEST = false;
  2791. _this.DEPTHPREPASS = false;
  2792. _this.POINTSIZE = false;
  2793. _this.FOG = false;
  2794. _this.SPECULARTERM = false;
  2795. _this.NORMAL = false;
  2796. _this.UV1 = false;
  2797. _this.UV2 = false;
  2798. _this.VERTEXCOLOR = false;
  2799. _this.VERTEXALPHA = false;
  2800. _this.NUM_BONE_INFLUENCERS = 0;
  2801. _this.BonesPerMesh = 0;
  2802. _this.INSTANCES = false;
  2803. _this.rebuild();
  2804. return _this;
  2805. }
  2806. return TerrainMaterialDefines;
  2807. }(BABYLON.MaterialDefines));
  2808. var TerrainMaterial = /** @class */ (function (_super) {
  2809. __extends(TerrainMaterial, _super);
  2810. function TerrainMaterial(name, scene) {
  2811. var _this = _super.call(this, name, scene) || this;
  2812. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  2813. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  2814. _this.specularPower = 64;
  2815. _this._disableLighting = false;
  2816. _this._maxSimultaneousLights = 4;
  2817. return _this;
  2818. }
  2819. TerrainMaterial.prototype.needAlphaBlending = function () {
  2820. return (this.alpha < 1.0);
  2821. };
  2822. TerrainMaterial.prototype.needAlphaTesting = function () {
  2823. return false;
  2824. };
  2825. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  2826. return null;
  2827. };
  2828. // Methods
  2829. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  2830. if (this.isFrozen) {
  2831. if (this._wasPreviouslyReady && subMesh.effect) {
  2832. return true;
  2833. }
  2834. }
  2835. if (!subMesh._materialDefines) {
  2836. subMesh._materialDefines = new TerrainMaterialDefines();
  2837. }
  2838. var defines = subMesh._materialDefines;
  2839. var scene = this.getScene();
  2840. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  2841. if (this._renderId === scene.getRenderId()) {
  2842. return true;
  2843. }
  2844. }
  2845. var engine = scene.getEngine();
  2846. // Textures
  2847. if (scene.texturesEnabled) {
  2848. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2849. if (!this.mixTexture.isReady()) {
  2850. return false;
  2851. }
  2852. else {
  2853. defines._needUVs = true;
  2854. defines.DIFFUSE = true;
  2855. }
  2856. }
  2857. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  2858. defines._needUVs = true;
  2859. defines._needNormals = true;
  2860. defines.BUMP = true;
  2861. }
  2862. }
  2863. // Misc.
  2864. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  2865. // Lights
  2866. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  2867. // Values that need to be evaluated on every frame
  2868. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  2869. // Attribs
  2870. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  2871. // Get correct effect
  2872. if (defines.isDirty) {
  2873. defines.markAsProcessed();
  2874. scene.resetCachedMaterial();
  2875. // Fallbacks
  2876. var fallbacks = new BABYLON.EffectFallbacks();
  2877. if (defines.FOG) {
  2878. fallbacks.addFallback(1, "FOG");
  2879. }
  2880. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  2881. if (defines.NUM_BONE_INFLUENCERS > 0) {
  2882. fallbacks.addCPUSkinningFallback(0, mesh);
  2883. }
  2884. //Attributes
  2885. var attribs = [BABYLON.VertexBuffer.PositionKind];
  2886. if (defines.NORMAL) {
  2887. attribs.push(BABYLON.VertexBuffer.NormalKind);
  2888. }
  2889. if (defines.UV1) {
  2890. attribs.push(BABYLON.VertexBuffer.UVKind);
  2891. }
  2892. if (defines.UV2) {
  2893. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  2894. }
  2895. if (defines.VERTEXCOLOR) {
  2896. attribs.push(BABYLON.VertexBuffer.ColorKind);
  2897. }
  2898. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  2899. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  2900. // Legacy browser patch
  2901. var shaderName = "terrain";
  2902. var join = defines.toString();
  2903. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  2904. "vFogInfos", "vFogColor", "pointSize",
  2905. "vTextureInfos",
  2906. "mBones",
  2907. "vClipPlane", "textureMatrix",
  2908. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  2909. ];
  2910. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  2911. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  2912. ];
  2913. var uniformBuffers = new Array();
  2914. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  2915. uniformsNames: uniforms,
  2916. uniformBuffersNames: uniformBuffers,
  2917. samplers: samplers,
  2918. defines: defines,
  2919. maxSimultaneousLights: this.maxSimultaneousLights
  2920. });
  2921. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  2922. attributes: attribs,
  2923. uniformsNames: uniforms,
  2924. uniformBuffersNames: uniformBuffers,
  2925. samplers: samplers,
  2926. defines: join,
  2927. fallbacks: fallbacks,
  2928. onCompiled: this.onCompiled,
  2929. onError: this.onError,
  2930. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  2931. }, engine), defines);
  2932. }
  2933. if (!subMesh.effect || !subMesh.effect.isReady()) {
  2934. return false;
  2935. }
  2936. this._renderId = scene.getRenderId();
  2937. this._wasPreviouslyReady = true;
  2938. return true;
  2939. };
  2940. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  2941. var scene = this.getScene();
  2942. var defines = subMesh._materialDefines;
  2943. if (!defines) {
  2944. return;
  2945. }
  2946. var effect = subMesh.effect;
  2947. if (!effect) {
  2948. return;
  2949. }
  2950. this._activeEffect = effect;
  2951. // Matrices
  2952. this.bindOnlyWorldMatrix(world);
  2953. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  2954. // Bones
  2955. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  2956. if (this._mustRebind(scene, effect)) {
  2957. // Textures
  2958. if (this.mixTexture) {
  2959. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  2960. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  2961. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  2962. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  2963. if (this._diffuseTexture1) {
  2964. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  2965. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  2966. }
  2967. if (this._diffuseTexture2) {
  2968. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  2969. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  2970. }
  2971. if (this._diffuseTexture3) {
  2972. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  2973. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  2974. }
  2975. }
  2976. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  2977. if (this._bumpTexture1) {
  2978. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  2979. }
  2980. if (this._bumpTexture2) {
  2981. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  2982. }
  2983. if (this._bumpTexture3) {
  2984. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  2985. }
  2986. }
  2987. }
  2988. // Clip plane
  2989. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  2990. // Point size
  2991. if (this.pointsCloud) {
  2992. this._activeEffect.setFloat("pointSize", this.pointSize);
  2993. }
  2994. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  2995. }
  2996. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  2997. if (defines.SPECULARTERM) {
  2998. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  2999. }
  3000. if (scene.lightsEnabled && !this.disableLighting) {
  3001. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3002. }
  3003. // View
  3004. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3005. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3006. }
  3007. // Fog
  3008. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3009. this._afterBind(mesh, this._activeEffect);
  3010. };
  3011. TerrainMaterial.prototype.getAnimatables = function () {
  3012. var results = [];
  3013. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3014. results.push(this.mixTexture);
  3015. }
  3016. return results;
  3017. };
  3018. TerrainMaterial.prototype.getActiveTextures = function () {
  3019. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3020. if (this._mixTexture) {
  3021. activeTextures.push(this._mixTexture);
  3022. }
  3023. if (this._diffuseTexture1) {
  3024. activeTextures.push(this._diffuseTexture1);
  3025. }
  3026. if (this._diffuseTexture2) {
  3027. activeTextures.push(this._diffuseTexture2);
  3028. }
  3029. if (this._diffuseTexture3) {
  3030. activeTextures.push(this._diffuseTexture3);
  3031. }
  3032. if (this._bumpTexture1) {
  3033. activeTextures.push(this._bumpTexture1);
  3034. }
  3035. if (this._bumpTexture2) {
  3036. activeTextures.push(this._bumpTexture2);
  3037. }
  3038. if (this._bumpTexture3) {
  3039. activeTextures.push(this._bumpTexture3);
  3040. }
  3041. return activeTextures;
  3042. };
  3043. TerrainMaterial.prototype.hasTexture = function (texture) {
  3044. if (_super.prototype.hasTexture.call(this, texture)) {
  3045. return true;
  3046. }
  3047. if (this._mixTexture === texture) {
  3048. return true;
  3049. }
  3050. if (this._diffuseTexture1 === texture) {
  3051. return true;
  3052. }
  3053. if (this._diffuseTexture2 === texture) {
  3054. return true;
  3055. }
  3056. if (this._diffuseTexture3 === texture) {
  3057. return true;
  3058. }
  3059. if (this._bumpTexture1 === texture) {
  3060. return true;
  3061. }
  3062. if (this._bumpTexture2 === texture) {
  3063. return true;
  3064. }
  3065. if (this._bumpTexture3 === texture) {
  3066. return true;
  3067. }
  3068. return false;
  3069. };
  3070. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  3071. if (this.mixTexture) {
  3072. this.mixTexture.dispose();
  3073. }
  3074. _super.prototype.dispose.call(this, forceDisposeEffect);
  3075. };
  3076. TerrainMaterial.prototype.clone = function (name) {
  3077. var _this = this;
  3078. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  3079. };
  3080. TerrainMaterial.prototype.serialize = function () {
  3081. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3082. serializationObject.customType = "BABYLON.TerrainMaterial";
  3083. return serializationObject;
  3084. };
  3085. TerrainMaterial.prototype.getClassName = function () {
  3086. return "TerrainMaterial";
  3087. };
  3088. // Statics
  3089. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  3090. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  3091. };
  3092. __decorate([
  3093. BABYLON.serializeAsTexture("mixTexture")
  3094. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  3095. __decorate([
  3096. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3097. ], TerrainMaterial.prototype, "mixTexture", void 0);
  3098. __decorate([
  3099. BABYLON.serializeAsTexture("diffuseTexture1")
  3100. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  3101. __decorate([
  3102. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3103. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  3104. __decorate([
  3105. BABYLON.serializeAsTexture("diffuseTexture2")
  3106. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  3107. __decorate([
  3108. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3109. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  3110. __decorate([
  3111. BABYLON.serializeAsTexture("diffuseTexture3")
  3112. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  3113. __decorate([
  3114. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3115. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  3116. __decorate([
  3117. BABYLON.serializeAsTexture("bumpTexture1")
  3118. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  3119. __decorate([
  3120. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3121. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  3122. __decorate([
  3123. BABYLON.serializeAsTexture("bumpTexture2")
  3124. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  3125. __decorate([
  3126. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3127. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  3128. __decorate([
  3129. BABYLON.serializeAsTexture("bumpTexture3")
  3130. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  3131. __decorate([
  3132. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3133. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  3134. __decorate([
  3135. BABYLON.serializeAsColor3()
  3136. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  3137. __decorate([
  3138. BABYLON.serializeAsColor3()
  3139. ], TerrainMaterial.prototype, "specularColor", void 0);
  3140. __decorate([
  3141. BABYLON.serialize()
  3142. ], TerrainMaterial.prototype, "specularPower", void 0);
  3143. __decorate([
  3144. BABYLON.serialize("disableLighting")
  3145. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  3146. __decorate([
  3147. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3148. ], TerrainMaterial.prototype, "disableLighting", void 0);
  3149. __decorate([
  3150. BABYLON.serialize("maxSimultaneousLights")
  3151. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  3152. __decorate([
  3153. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3154. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  3155. return TerrainMaterial;
  3156. }(BABYLON.PushMaterial));
  3157. BABYLON.TerrainMaterial = TerrainMaterial;
  3158. })(BABYLON || (BABYLON = {}));
  3159. //# sourceMappingURL=babylon.terrainMaterial.js.map
  3160. BABYLON.Effect.ShadersStore['terrainVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  3161. BABYLON.Effect.ShadersStore['terrainPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D textureSampler;\nuniform vec2 vTextureInfos;\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\n#endif\n#ifdef BUMP\nuniform sampler2D bump1Sampler;\nuniform sampler2D bump2Sampler;\nuniform sampler2D bump3Sampler;\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));\nreturn mat3(tangent*invmax,binormal*invmax,normal);\n}\nvec3 perturbNormal(vec3 viewDir,vec3 mixColor)\n{ \nvec3 bump1Color=texture2D(bump1Sampler,vTextureUV*diffuse1Infos).xyz;\nvec3 bump2Color=texture2D(bump2Sampler,vTextureUV*diffuse2Infos).xyz;\nvec3 bump3Color=texture2D(bump3Sampler,vTextureUV*diffuse3Infos).xyz;\nbump1Color.rgb*=mixColor.r;\nbump2Color.rgb=mix(bump1Color.rgb,bump2Color.rgb,mixColor.g);\nvec3 map=mix(bump2Color.rgb,bump3Color.rgb,mixColor.b);\nmap=map*255./127.-128./127.;\nmat3 TBN=cotangent_frame(vNormalW*vTextureInfos.y,-viewDir,vTextureUV);\nreturn normalize(TBN*map);\n}\n#endif\nvoid main(void) {\n\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(textureSampler,vTextureUV);\n#if defined(BUMP) && defined(DIFFUSE)\nnormalW=perturbNormal(viewDirectionW,baseColor.rgb);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\ndiffuse1Color.rgb*=baseColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,baseColor.g);\nbaseColor.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,baseColor.b);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*baseColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  3162. var BABYLON;
  3163. (function (BABYLON) {
  3164. var TriPlanarMaterialDefines = /** @class */ (function (_super) {
  3165. __extends(TriPlanarMaterialDefines, _super);
  3166. function TriPlanarMaterialDefines() {
  3167. var _this = _super.call(this) || this;
  3168. _this.DIFFUSEX = false;
  3169. _this.DIFFUSEY = false;
  3170. _this.DIFFUSEZ = false;
  3171. _this.BUMPX = false;
  3172. _this.BUMPY = false;
  3173. _this.BUMPZ = false;
  3174. _this.CLIPPLANE = false;
  3175. _this.ALPHATEST = false;
  3176. _this.DEPTHPREPASS = false;
  3177. _this.POINTSIZE = false;
  3178. _this.FOG = false;
  3179. _this.SPECULARTERM = false;
  3180. _this.NORMAL = false;
  3181. _this.VERTEXCOLOR = false;
  3182. _this.VERTEXALPHA = false;
  3183. _this.NUM_BONE_INFLUENCERS = 0;
  3184. _this.BonesPerMesh = 0;
  3185. _this.INSTANCES = false;
  3186. _this.rebuild();
  3187. return _this;
  3188. }
  3189. return TriPlanarMaterialDefines;
  3190. }(BABYLON.MaterialDefines));
  3191. var TriPlanarMaterial = /** @class */ (function (_super) {
  3192. __extends(TriPlanarMaterial, _super);
  3193. function TriPlanarMaterial(name, scene) {
  3194. var _this = _super.call(this, name, scene) || this;
  3195. _this.tileSize = 1;
  3196. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  3197. _this.specularColor = new BABYLON.Color3(0.2, 0.2, 0.2);
  3198. _this.specularPower = 64;
  3199. _this._disableLighting = false;
  3200. _this._maxSimultaneousLights = 4;
  3201. return _this;
  3202. }
  3203. TriPlanarMaterial.prototype.needAlphaBlending = function () {
  3204. return (this.alpha < 1.0);
  3205. };
  3206. TriPlanarMaterial.prototype.needAlphaTesting = function () {
  3207. return false;
  3208. };
  3209. TriPlanarMaterial.prototype.getAlphaTestTexture = function () {
  3210. return null;
  3211. };
  3212. // Methods
  3213. TriPlanarMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3214. if (this.isFrozen) {
  3215. if (this._wasPreviouslyReady && subMesh.effect) {
  3216. return true;
  3217. }
  3218. }
  3219. if (!subMesh._materialDefines) {
  3220. subMesh._materialDefines = new TriPlanarMaterialDefines();
  3221. }
  3222. var defines = subMesh._materialDefines;
  3223. var scene = this.getScene();
  3224. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3225. if (this._renderId === scene.getRenderId()) {
  3226. return true;
  3227. }
  3228. }
  3229. var engine = scene.getEngine();
  3230. // Textures
  3231. if (defines._areTexturesDirty) {
  3232. if (scene.texturesEnabled) {
  3233. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  3234. var textures = [this.diffuseTextureX, this.diffuseTextureY, this.diffuseTextureZ];
  3235. var textureDefines = ["DIFFUSEX", "DIFFUSEY", "DIFFUSEZ"];
  3236. for (var i = 0; i < textures.length; i++) {
  3237. if (textures[i]) {
  3238. if (!textures[i].isReady()) {
  3239. return false;
  3240. }
  3241. else {
  3242. defines[textureDefines[i]] = true;
  3243. }
  3244. }
  3245. }
  3246. }
  3247. if (BABYLON.StandardMaterial.BumpTextureEnabled) {
  3248. var textures = [this.normalTextureX, this.normalTextureY, this.normalTextureZ];
  3249. var textureDefines = ["BUMPX", "BUMPY", "BUMPZ"];
  3250. for (var i = 0; i < textures.length; i++) {
  3251. if (textures[i]) {
  3252. if (!textures[i].isReady()) {
  3253. return false;
  3254. }
  3255. else {
  3256. defines[textureDefines[i]] = true;
  3257. }
  3258. }
  3259. }
  3260. }
  3261. }
  3262. }
  3263. // Misc.
  3264. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  3265. // Lights
  3266. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  3267. // Values that need to be evaluated on every frame
  3268. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  3269. // Attribs
  3270. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  3271. // Get correct effect
  3272. if (defines.isDirty) {
  3273. defines.markAsProcessed();
  3274. scene.resetCachedMaterial();
  3275. // Fallbacks
  3276. var fallbacks = new BABYLON.EffectFallbacks();
  3277. if (defines.FOG) {
  3278. fallbacks.addFallback(1, "FOG");
  3279. }
  3280. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  3281. if (defines.NUM_BONE_INFLUENCERS > 0) {
  3282. fallbacks.addCPUSkinningFallback(0, mesh);
  3283. }
  3284. //Attributes
  3285. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3286. if (defines.NORMAL) {
  3287. attribs.push(BABYLON.VertexBuffer.NormalKind);
  3288. }
  3289. if (defines.VERTEXCOLOR) {
  3290. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3291. }
  3292. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  3293. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  3294. // Legacy browser patch
  3295. var shaderName = "triplanar";
  3296. var join = defines.toString();
  3297. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  3298. "vFogInfos", "vFogColor", "pointSize",
  3299. "mBones",
  3300. "vClipPlane",
  3301. "tileSize"
  3302. ];
  3303. var samplers = ["diffuseSamplerX", "diffuseSamplerY", "diffuseSamplerZ",
  3304. "normalSamplerX", "normalSamplerY", "normalSamplerZ"
  3305. ];
  3306. var uniformBuffers = new Array();
  3307. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  3308. uniformsNames: uniforms,
  3309. uniformBuffersNames: uniformBuffers,
  3310. samplers: samplers,
  3311. defines: defines,
  3312. maxSimultaneousLights: this.maxSimultaneousLights
  3313. });
  3314. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  3315. attributes: attribs,
  3316. uniformsNames: uniforms,
  3317. uniformBuffersNames: uniformBuffers,
  3318. samplers: samplers,
  3319. defines: join,
  3320. fallbacks: fallbacks,
  3321. onCompiled: this.onCompiled,
  3322. onError: this.onError,
  3323. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  3324. }, engine), defines);
  3325. }
  3326. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3327. return false;
  3328. }
  3329. this._renderId = scene.getRenderId();
  3330. this._wasPreviouslyReady = true;
  3331. return true;
  3332. };
  3333. TriPlanarMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3334. var scene = this.getScene();
  3335. var defines = subMesh._materialDefines;
  3336. if (!defines) {
  3337. return;
  3338. }
  3339. var effect = subMesh.effect;
  3340. if (!effect) {
  3341. return;
  3342. }
  3343. this._activeEffect = effect;
  3344. // Matrices
  3345. this.bindOnlyWorldMatrix(world);
  3346. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3347. // Bones
  3348. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  3349. this._activeEffect.setFloat("tileSize", this.tileSize);
  3350. if (scene.getCachedMaterial() !== this) {
  3351. // Textures
  3352. if (this.diffuseTextureX) {
  3353. this._activeEffect.setTexture("diffuseSamplerX", this.diffuseTextureX);
  3354. }
  3355. if (this.diffuseTextureY) {
  3356. this._activeEffect.setTexture("diffuseSamplerY", this.diffuseTextureY);
  3357. }
  3358. if (this.diffuseTextureZ) {
  3359. this._activeEffect.setTexture("diffuseSamplerZ", this.diffuseTextureZ);
  3360. }
  3361. if (this.normalTextureX) {
  3362. this._activeEffect.setTexture("normalSamplerX", this.normalTextureX);
  3363. }
  3364. if (this.normalTextureY) {
  3365. this._activeEffect.setTexture("normalSamplerY", this.normalTextureY);
  3366. }
  3367. if (this.normalTextureZ) {
  3368. this._activeEffect.setTexture("normalSamplerZ", this.normalTextureZ);
  3369. }
  3370. // Clip plane
  3371. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  3372. // Point size
  3373. if (this.pointsCloud) {
  3374. this._activeEffect.setFloat("pointSize", this.pointSize);
  3375. }
  3376. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  3377. }
  3378. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  3379. if (defines.SPECULARTERM) {
  3380. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  3381. }
  3382. if (scene.lightsEnabled && !this.disableLighting) {
  3383. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  3384. }
  3385. // View
  3386. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3387. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3388. }
  3389. // Fog
  3390. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3391. this._afterBind(mesh, this._activeEffect);
  3392. };
  3393. TriPlanarMaterial.prototype.getAnimatables = function () {
  3394. var results = [];
  3395. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  3396. results.push(this.mixTexture);
  3397. }
  3398. return results;
  3399. };
  3400. TriPlanarMaterial.prototype.getActiveTextures = function () {
  3401. var activeTextures = _super.prototype.getActiveTextures.call(this);
  3402. if (this._diffuseTextureX) {
  3403. activeTextures.push(this._diffuseTextureX);
  3404. }
  3405. if (this._diffuseTextureY) {
  3406. activeTextures.push(this._diffuseTextureY);
  3407. }
  3408. if (this._diffuseTextureZ) {
  3409. activeTextures.push(this._diffuseTextureZ);
  3410. }
  3411. if (this._normalTextureX) {
  3412. activeTextures.push(this._normalTextureX);
  3413. }
  3414. if (this._normalTextureY) {
  3415. activeTextures.push(this._normalTextureY);
  3416. }
  3417. if (this._normalTextureZ) {
  3418. activeTextures.push(this._normalTextureZ);
  3419. }
  3420. return activeTextures;
  3421. };
  3422. TriPlanarMaterial.prototype.hasTexture = function (texture) {
  3423. if (_super.prototype.hasTexture.call(this, texture)) {
  3424. return true;
  3425. }
  3426. if (this._diffuseTextureX === texture) {
  3427. return true;
  3428. }
  3429. if (this._diffuseTextureY === texture) {
  3430. return true;
  3431. }
  3432. if (this._diffuseTextureZ === texture) {
  3433. return true;
  3434. }
  3435. if (this._normalTextureX === texture) {
  3436. return true;
  3437. }
  3438. if (this._normalTextureY === texture) {
  3439. return true;
  3440. }
  3441. if (this._normalTextureZ === texture) {
  3442. return true;
  3443. }
  3444. return false;
  3445. };
  3446. TriPlanarMaterial.prototype.dispose = function (forceDisposeEffect) {
  3447. if (this.mixTexture) {
  3448. this.mixTexture.dispose();
  3449. }
  3450. _super.prototype.dispose.call(this, forceDisposeEffect);
  3451. };
  3452. TriPlanarMaterial.prototype.clone = function (name) {
  3453. var _this = this;
  3454. return BABYLON.SerializationHelper.Clone(function () { return new TriPlanarMaterial(name, _this.getScene()); }, this);
  3455. };
  3456. TriPlanarMaterial.prototype.serialize = function () {
  3457. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3458. serializationObject.customType = "BABYLON.TriPlanarMaterial";
  3459. return serializationObject;
  3460. };
  3461. TriPlanarMaterial.prototype.getClassName = function () {
  3462. return "TriPlanarMaterial";
  3463. };
  3464. // Statics
  3465. TriPlanarMaterial.Parse = function (source, scene, rootUrl) {
  3466. return BABYLON.SerializationHelper.Parse(function () { return new TriPlanarMaterial(source.name, scene); }, source, scene, rootUrl);
  3467. };
  3468. __decorate([
  3469. BABYLON.serializeAsTexture()
  3470. ], TriPlanarMaterial.prototype, "mixTexture", void 0);
  3471. __decorate([
  3472. BABYLON.serializeAsTexture("diffuseTextureX")
  3473. ], TriPlanarMaterial.prototype, "_diffuseTextureX", void 0);
  3474. __decorate([
  3475. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3476. ], TriPlanarMaterial.prototype, "diffuseTextureX", void 0);
  3477. __decorate([
  3478. BABYLON.serializeAsTexture("diffuseTexturY")
  3479. ], TriPlanarMaterial.prototype, "_diffuseTextureY", void 0);
  3480. __decorate([
  3481. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3482. ], TriPlanarMaterial.prototype, "diffuseTextureY", void 0);
  3483. __decorate([
  3484. BABYLON.serializeAsTexture("diffuseTextureZ")
  3485. ], TriPlanarMaterial.prototype, "_diffuseTextureZ", void 0);
  3486. __decorate([
  3487. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3488. ], TriPlanarMaterial.prototype, "diffuseTextureZ", void 0);
  3489. __decorate([
  3490. BABYLON.serializeAsTexture("normalTextureX")
  3491. ], TriPlanarMaterial.prototype, "_normalTextureX", void 0);
  3492. __decorate([
  3493. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3494. ], TriPlanarMaterial.prototype, "normalTextureX", void 0);
  3495. __decorate([
  3496. BABYLON.serializeAsTexture("normalTextureY")
  3497. ], TriPlanarMaterial.prototype, "_normalTextureY", void 0);
  3498. __decorate([
  3499. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3500. ], TriPlanarMaterial.prototype, "normalTextureY", void 0);
  3501. __decorate([
  3502. BABYLON.serializeAsTexture("normalTextureZ")
  3503. ], TriPlanarMaterial.prototype, "_normalTextureZ", void 0);
  3504. __decorate([
  3505. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  3506. ], TriPlanarMaterial.prototype, "normalTextureZ", void 0);
  3507. __decorate([
  3508. BABYLON.serialize()
  3509. ], TriPlanarMaterial.prototype, "tileSize", void 0);
  3510. __decorate([
  3511. BABYLON.serializeAsColor3()
  3512. ], TriPlanarMaterial.prototype, "diffuseColor", void 0);
  3513. __decorate([
  3514. BABYLON.serializeAsColor3()
  3515. ], TriPlanarMaterial.prototype, "specularColor", void 0);
  3516. __decorate([
  3517. BABYLON.serialize()
  3518. ], TriPlanarMaterial.prototype, "specularPower", void 0);
  3519. __decorate([
  3520. BABYLON.serialize("disableLighting")
  3521. ], TriPlanarMaterial.prototype, "_disableLighting", void 0);
  3522. __decorate([
  3523. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3524. ], TriPlanarMaterial.prototype, "disableLighting", void 0);
  3525. __decorate([
  3526. BABYLON.serialize("maxSimultaneousLights")
  3527. ], TriPlanarMaterial.prototype, "_maxSimultaneousLights", void 0);
  3528. __decorate([
  3529. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  3530. ], TriPlanarMaterial.prototype, "maxSimultaneousLights", void 0);
  3531. return TriPlanarMaterial;
  3532. }(BABYLON.PushMaterial));
  3533. BABYLON.TriPlanarMaterial = TriPlanarMaterial;
  3534. })(BABYLON || (BABYLON = {}));
  3535. //# sourceMappingURL=babylon.triPlanarMaterial.js.map
  3536. BABYLON.Effect.ShadersStore['triplanarVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\n#endif\nuniform float tileSize;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef DIFFUSEX\nvTextureUVX=worldPos.zy/tileSize;\n#endif\n#ifdef DIFFUSEY\nvTextureUVY=worldPos.xz/tileSize;\n#endif\n#ifdef DIFFUSEZ\nvTextureUVZ=worldPos.xy/tileSize;\n#endif\n#ifdef NORMAL\n\nvec3 xtan=vec3(0,0,1);\nvec3 xbin=vec3(0,1,0);\nvec3 ytan=vec3(1,0,0);\nvec3 ybin=vec3(0,0,1);\nvec3 ztan=vec3(1,0,0);\nvec3 zbin=vec3(0,1,0);\nvec3 normalizedNormal=normalize(normal);\nnormalizedNormal*=normalizedNormal;\nvec3 worldBinormal=normalize(xbin*normalizedNormal.x+ybin*normalizedNormal.y+zbin*normalizedNormal.z);\nvec3 worldTangent=normalize(xtan*normalizedNormal.x+ytan*normalizedNormal.y+ztan*normalizedNormal.z);\nworldTangent=(world*vec4(worldTangent,1.0)).xyz;\nworldBinormal=(world*vec4(worldBinormal,1.0)).xyz;\nvec3 worldNormal=normalize(cross(worldTangent,worldBinormal));\ntangentSpace[0]=worldTangent;\ntangentSpace[1]=worldBinormal;\ntangentSpace[2]=worldNormal;\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  3537. BABYLON.Effect.ShadersStore['triplanarPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSEX\nvarying vec2 vTextureUVX;\nuniform sampler2D diffuseSamplerX;\n#ifdef BUMPX\nuniform sampler2D normalSamplerX;\n#endif\n#endif\n#ifdef DIFFUSEY\nvarying vec2 vTextureUVY;\nuniform sampler2D diffuseSamplerY;\n#ifdef BUMPY\nuniform sampler2D normalSamplerY;\n#endif\n#endif\n#ifdef DIFFUSEZ\nvarying vec2 vTextureUVZ;\nuniform sampler2D diffuseSamplerZ;\n#ifdef BUMPZ\nuniform sampler2D normalSamplerZ;\n#endif\n#endif\n#ifdef NORMAL\nvarying mat3 tangentSpace;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<fogFragmentDeclaration>\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(0.,0.,0.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=tangentSpace[2];\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\nvec4 baseNormal=vec4(0.0,0.0,0.0,1.0);\nnormalW*=normalW;\n#ifdef DIFFUSEX\nbaseColor+=texture2D(diffuseSamplerX,vTextureUVX)*normalW.x;\n#ifdef BUMPX\nbaseNormal+=texture2D(normalSamplerX,vTextureUVX)*normalW.x;\n#endif\n#endif\n#ifdef DIFFUSEY\nbaseColor+=texture2D(diffuseSamplerY,vTextureUVY)*normalW.y;\n#ifdef BUMPY\nbaseNormal+=texture2D(normalSamplerY,vTextureUVY)*normalW.y;\n#endif\n#endif\n#ifdef DIFFUSEZ\nbaseColor+=texture2D(diffuseSamplerZ,vTextureUVZ)*normalW.z;\n#ifdef BUMPZ\nbaseNormal+=texture2D(normalSamplerZ,vTextureUVZ)*normalW.z;\n#endif\n#endif\n#ifdef NORMAL\nnormalW=normalize((2.0*baseNormal.xyz-1.0)*tangentSpace);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularBase=vec3(0.,0.,0.);\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  3538. var BABYLON;
  3539. (function (BABYLON) {
  3540. var SkyMaterialDefines = /** @class */ (function (_super) {
  3541. __extends(SkyMaterialDefines, _super);
  3542. function SkyMaterialDefines() {
  3543. var _this = _super.call(this) || this;
  3544. _this.CLIPPLANE = false;
  3545. _this.POINTSIZE = false;
  3546. _this.FOG = false;
  3547. _this.VERTEXCOLOR = false;
  3548. _this.VERTEXALPHA = false;
  3549. _this.rebuild();
  3550. return _this;
  3551. }
  3552. return SkyMaterialDefines;
  3553. }(BABYLON.MaterialDefines));
  3554. var SkyMaterial = /** @class */ (function (_super) {
  3555. __extends(SkyMaterial, _super);
  3556. function SkyMaterial(name, scene) {
  3557. var _this = _super.call(this, name, scene) || this;
  3558. // Public members
  3559. _this.luminance = 1.0;
  3560. _this.turbidity = 10.0;
  3561. _this.rayleigh = 2.0;
  3562. _this.mieCoefficient = 0.005;
  3563. _this.mieDirectionalG = 0.8;
  3564. _this.distance = 500;
  3565. _this.inclination = 0.49;
  3566. _this.azimuth = 0.25;
  3567. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  3568. _this.useSunPosition = false;
  3569. // Private members
  3570. _this._cameraPosition = BABYLON.Vector3.Zero();
  3571. return _this;
  3572. }
  3573. SkyMaterial.prototype.needAlphaBlending = function () {
  3574. return (this.alpha < 1.0);
  3575. };
  3576. SkyMaterial.prototype.needAlphaTesting = function () {
  3577. return false;
  3578. };
  3579. SkyMaterial.prototype.getAlphaTestTexture = function () {
  3580. return null;
  3581. };
  3582. // Methods
  3583. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3584. if (this.isFrozen) {
  3585. if (this._wasPreviouslyReady && subMesh.effect) {
  3586. return true;
  3587. }
  3588. }
  3589. if (!subMesh._materialDefines) {
  3590. subMesh._materialDefines = new SkyMaterialDefines();
  3591. }
  3592. var defines = subMesh._materialDefines;
  3593. var scene = this.getScene();
  3594. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3595. if (this._renderId === scene.getRenderId()) {
  3596. return true;
  3597. }
  3598. }
  3599. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  3600. // Attribs
  3601. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  3602. // Get correct effect
  3603. if (defines.isDirty) {
  3604. defines.markAsProcessed();
  3605. scene.resetCachedMaterial();
  3606. // Fallbacks
  3607. var fallbacks = new BABYLON.EffectFallbacks();
  3608. if (defines.FOG) {
  3609. fallbacks.addFallback(1, "FOG");
  3610. }
  3611. //Attributes
  3612. var attribs = [BABYLON.VertexBuffer.PositionKind];
  3613. if (defines.VERTEXCOLOR) {
  3614. attribs.push(BABYLON.VertexBuffer.ColorKind);
  3615. }
  3616. var shaderName = "sky";
  3617. var join = defines.toString();
  3618. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  3619. "vFogInfos", "vFogColor", "pointSize", "vClipPlane",
  3620. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  3621. "cameraPosition"
  3622. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  3623. }
  3624. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3625. return false;
  3626. }
  3627. this._renderId = scene.getRenderId();
  3628. this._wasPreviouslyReady = true;
  3629. return true;
  3630. };
  3631. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3632. var scene = this.getScene();
  3633. var defines = subMesh._materialDefines;
  3634. if (!defines) {
  3635. return;
  3636. }
  3637. var effect = subMesh.effect;
  3638. if (!effect) {
  3639. return;
  3640. }
  3641. this._activeEffect = effect;
  3642. // Matrices
  3643. this.bindOnlyWorldMatrix(world);
  3644. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  3645. if (this._mustRebind(scene, effect)) {
  3646. // Clip plane
  3647. if (scene.clipPlane) {
  3648. var clipPlane = scene.clipPlane;
  3649. this._activeEffect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  3650. }
  3651. // Point size
  3652. if (this.pointsCloud) {
  3653. this._activeEffect.setFloat("pointSize", this.pointSize);
  3654. }
  3655. }
  3656. // View
  3657. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  3658. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3659. }
  3660. // Fog
  3661. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3662. // Sky
  3663. var camera = scene.activeCamera;
  3664. if (camera) {
  3665. var cameraWorldMatrix = camera.getWorldMatrix();
  3666. this._cameraPosition.x = cameraWorldMatrix.m[12];
  3667. this._cameraPosition.y = cameraWorldMatrix.m[13];
  3668. this._cameraPosition.z = cameraWorldMatrix.m[14];
  3669. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  3670. }
  3671. if (this.luminance > 0) {
  3672. this._activeEffect.setFloat("luminance", this.luminance);
  3673. }
  3674. this._activeEffect.setFloat("turbidity", this.turbidity);
  3675. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  3676. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  3677. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  3678. if (!this.useSunPosition) {
  3679. var theta = Math.PI * (this.inclination - 0.5);
  3680. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  3681. this.sunPosition.x = this.distance * Math.cos(phi);
  3682. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  3683. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  3684. }
  3685. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  3686. this._afterBind(mesh, this._activeEffect);
  3687. };
  3688. SkyMaterial.prototype.getAnimatables = function () {
  3689. return [];
  3690. };
  3691. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  3692. _super.prototype.dispose.call(this, forceDisposeEffect);
  3693. };
  3694. SkyMaterial.prototype.clone = function (name) {
  3695. var _this = this;
  3696. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  3697. };
  3698. SkyMaterial.prototype.serialize = function () {
  3699. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3700. serializationObject.customType = "BABYLON.SkyMaterial";
  3701. return serializationObject;
  3702. };
  3703. SkyMaterial.prototype.getClassName = function () {
  3704. return "SkyMaterial";
  3705. };
  3706. // Statics
  3707. SkyMaterial.Parse = function (source, scene, rootUrl) {
  3708. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  3709. };
  3710. __decorate([
  3711. BABYLON.serialize()
  3712. ], SkyMaterial.prototype, "luminance", void 0);
  3713. __decorate([
  3714. BABYLON.serialize()
  3715. ], SkyMaterial.prototype, "turbidity", void 0);
  3716. __decorate([
  3717. BABYLON.serialize()
  3718. ], SkyMaterial.prototype, "rayleigh", void 0);
  3719. __decorate([
  3720. BABYLON.serialize()
  3721. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  3722. __decorate([
  3723. BABYLON.serialize()
  3724. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  3725. __decorate([
  3726. BABYLON.serialize()
  3727. ], SkyMaterial.prototype, "distance", void 0);
  3728. __decorate([
  3729. BABYLON.serialize()
  3730. ], SkyMaterial.prototype, "inclination", void 0);
  3731. __decorate([
  3732. BABYLON.serialize()
  3733. ], SkyMaterial.prototype, "azimuth", void 0);
  3734. __decorate([
  3735. BABYLON.serializeAsVector3()
  3736. ], SkyMaterial.prototype, "sunPosition", void 0);
  3737. __decorate([
  3738. BABYLON.serialize()
  3739. ], SkyMaterial.prototype, "useSunPosition", void 0);
  3740. return SkyMaterial;
  3741. }(BABYLON.PushMaterial));
  3742. BABYLON.SkyMaterial = SkyMaterial;
  3743. })(BABYLON || (BABYLON = {}));
  3744. //# sourceMappingURL=babylon.skyMaterial.js.map
  3745. BABYLON.Effect.ShadersStore['skyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  3746. BABYLON.Effect.ShadersStore['skyPixelShader'] = "precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nuniform vec3 cameraPosition;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include<fogFragmentDeclaration>\n\nconst float e=2.71828182845904523536028747135266249775724709369995957;\nconst float pi=3.141592653589793238462643383279502884197169;\nconst float n=1.0003;\nconst float N=2.545E25;\nconst float pn=0.035;\nconst vec3 lambda=vec3(680E-9,550E-9,450E-9);\nconst vec3 K=vec3(0.686,0.678,0.666);\nconst float v=4.0;\nconst float rayleighZenithLength=8.4E3;\nconst float mieZenithLength=1.25E3;\nconst vec3 up=vec3(0.0,1.0,0.0);\nconst float EE=1000.0;\nconst float sunAngularDiameterCos=0.999956676946448443553574619906976478926848692873900859324;\nconst float cutoffAngle=pi/1.95;\nconst float steepness=1.5;\nvec3 totalRayleigh(vec3 lambda)\n{\nreturn (8.0*pow(pi,3.0)*pow(pow(n,2.0)-1.0,2.0)*(6.0+3.0*pn))/(3.0*N*pow(lambda,vec3(4.0))*(6.0-7.0*pn));\n}\nvec3 simplifiedRayleigh()\n{\nreturn 0.0005/vec3(94,40,18);\n}\nfloat rayleighPhase(float cosTheta)\n{ \nreturn (3.0/(16.0*pi))*(1.0+pow(cosTheta,2.0));\n}\nvec3 totalMie(vec3 lambda,vec3 K,float T)\n{\nfloat c=(0.2*T )*10E-18;\nreturn 0.434*c*pi*pow((2.0*pi)/lambda,vec3(v-2.0))*K;\n}\nfloat hgPhase(float cosTheta,float g)\n{\nreturn (1.0/(4.0*pi))*((1.0-pow(g,2.0))/pow(1.0-2.0*g*cosTheta+pow(g,2.0),1.5));\n}\nfloat sunIntensity(float zenithAngleCos)\n{\nreturn EE*max(0.0,1.0-exp((-(cutoffAngle-acos(zenithAngleCos))/steepness)));\n}\nfloat A=0.15;\nfloat B=0.50;\nfloat C=0.10;\nfloat D=0.20;\nfloat EEE=0.02;\nfloat F=0.30;\nfloat W=1000.0;\nvec3 Uncharted2Tonemap(vec3 x)\n{\nreturn ((x*(A*x+C*B)+D*EEE)/(x*(A*x+B)+D*F))-EEE/F;\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\n\nfloat sunfade=1.0-clamp(1.0-exp((sunPosition.y/450000.0)),0.0,1.0);\nfloat rayleighCoefficient=rayleigh-(1.0*(1.0-sunfade));\nvec3 sunDirection=normalize(sunPosition);\nfloat sunE=sunIntensity(dot(sunDirection,up));\nvec3 betaR=simplifiedRayleigh()*rayleighCoefficient;\nvec3 betaM=totalMie(lambda,K,turbidity)*mieCoefficient;\nfloat zenithAngle=acos(max(0.0,dot(up,normalize(vPositionW-cameraPosition))));\nfloat sR=rayleighZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nfloat sM=mieZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nvec3 Fex=exp(-(betaR*sR+betaM*sM));\nfloat cosTheta=dot(normalize(vPositionW-cameraPosition),sunDirection);\nfloat rPhase=rayleighPhase(cosTheta*0.5+0.5);\nvec3 betaRTheta=betaR*rPhase;\nfloat mPhase=hgPhase(cosTheta,mieDirectionalG);\nvec3 betaMTheta=betaM*mPhase;\nvec3 Lin=pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*(1.0-Fex),vec3(1.5));\nLin*=mix(vec3(1.0),pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*Fex,vec3(1.0/2.0)),clamp(pow(1.0-dot(up,sunDirection),5.0),0.0,1.0));\nvec3 direction=normalize(vPositionW-cameraPosition);\nfloat theta=acos(direction.y);\nfloat phi=atan(direction.z,direction.x);\nvec2 uv=vec2(phi,theta)/vec2(2.0*pi,pi)+vec2(0.5,0.0);\nvec3 L0=vec3(0.1)*Fex;\nfloat sundisk=smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);\nL0+=(sunE*19000.0*Fex)*sundisk;\nvec3 whiteScale=1.0/Uncharted2Tonemap(vec3(W));\nvec3 texColor=(Lin+L0); \ntexColor*=0.04 ;\ntexColor+=vec3(0.0,0.001,0.0025)*0.3;\nfloat g_fMaxLuminance=1.0;\nfloat fLumScaled=0.1/luminance; \nfloat fLumCompressed=(fLumScaled*(1.0+(fLumScaled/(g_fMaxLuminance*g_fMaxLuminance))))/(1.0+fLumScaled); \nfloat ExposureBias=fLumCompressed;\nvec3 curr=Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);\n\n\n\nvec3 retColor=curr*whiteScale;\n\n\nfloat alpha=1.0;\n#ifdef VERTEXCOLOR\nretColor.rgb*=vColor.rgb;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=clamp(vec4(retColor.rgb,alpha),0.0,1.0);\n\n#include<fogFragment>\ngl_FragColor=color;\n}\n";
  3747. var BABYLON;
  3748. (function (BABYLON) {
  3749. var GridMaterialDefines = /** @class */ (function (_super) {
  3750. __extends(GridMaterialDefines, _super);
  3751. function GridMaterialDefines() {
  3752. var _this = _super.call(this) || this;
  3753. _this.TRANSPARENT = false;
  3754. _this.FOG = false;
  3755. _this.PREMULTIPLYALPHA = false;
  3756. _this.rebuild();
  3757. return _this;
  3758. }
  3759. return GridMaterialDefines;
  3760. }(BABYLON.MaterialDefines));
  3761. /**
  3762. * The grid materials allows you to wrap any shape with a grid.
  3763. * Colors are customizable.
  3764. */
  3765. var GridMaterial = /** @class */ (function (_super) {
  3766. __extends(GridMaterial, _super);
  3767. /**
  3768. * constructor
  3769. * @param name The name given to the material in order to identify it afterwards.
  3770. * @param scene The scene the material is used in.
  3771. */
  3772. function GridMaterial(name, scene) {
  3773. var _this = _super.call(this, name, scene) || this;
  3774. /**
  3775. * Main color of the grid (e.g. between lines)
  3776. */
  3777. _this.mainColor = BABYLON.Color3.Black();
  3778. /**
  3779. * Color of the grid lines.
  3780. */
  3781. _this.lineColor = BABYLON.Color3.Teal();
  3782. /**
  3783. * The scale of the grid compared to unit.
  3784. */
  3785. _this.gridRatio = 1.0;
  3786. /**
  3787. * Allows setting an offset for the grid lines.
  3788. */
  3789. _this.gridOffset = BABYLON.Vector3.Zero();
  3790. /**
  3791. * The frequency of thicker lines.
  3792. */
  3793. _this.majorUnitFrequency = 10;
  3794. /**
  3795. * The visibility of minor units in the grid.
  3796. */
  3797. _this.minorUnitVisibility = 0.33;
  3798. /**
  3799. * The grid opacity outside of the lines.
  3800. */
  3801. _this.opacity = 1.0;
  3802. /**
  3803. * Determine RBG output is premultiplied by alpha value.
  3804. */
  3805. _this.preMultiplyAlpha = false;
  3806. _this._gridControl = new BABYLON.Vector4(_this.gridRatio, _this.majorUnitFrequency, _this.minorUnitVisibility, _this.opacity);
  3807. return _this;
  3808. }
  3809. /**
  3810. * Returns wehter or not the grid requires alpha blending.
  3811. */
  3812. GridMaterial.prototype.needAlphaBlending = function () {
  3813. return this.opacity < 1.0;
  3814. };
  3815. GridMaterial.prototype.needAlphaBlendingForMesh = function (mesh) {
  3816. return this.needAlphaBlending();
  3817. };
  3818. GridMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  3819. if (this.isFrozen) {
  3820. if (this._wasPreviouslyReady && subMesh.effect) {
  3821. return true;
  3822. }
  3823. }
  3824. if (!subMesh._materialDefines) {
  3825. subMesh._materialDefines = new GridMaterialDefines();
  3826. }
  3827. var defines = subMesh._materialDefines;
  3828. var scene = this.getScene();
  3829. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  3830. if (this._renderId === scene.getRenderId()) {
  3831. return true;
  3832. }
  3833. }
  3834. if (defines.TRANSPARENT !== (this.opacity < 1.0)) {
  3835. defines.TRANSPARENT = !defines.TRANSPARENT;
  3836. defines.markAsUnprocessed();
  3837. }
  3838. if (defines.PREMULTIPLYALPHA != this.preMultiplyAlpha) {
  3839. defines.PREMULTIPLYALPHA = !defines.PREMULTIPLYALPHA;
  3840. defines.markAsUnprocessed();
  3841. }
  3842. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, false, this.fogEnabled, defines);
  3843. // Get correct effect
  3844. if (defines.isDirty) {
  3845. defines.markAsProcessed();
  3846. scene.resetCachedMaterial();
  3847. // Attributes
  3848. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  3849. // Defines
  3850. var join = defines.toString();
  3851. subMesh.setEffect(scene.getEngine().createEffect("grid", attribs, ["projection", "worldView", "mainColor", "lineColor", "gridControl", "gridOffset", "vFogInfos", "vFogColor", "world", "view"], [], join, undefined, this.onCompiled, this.onError), defines);
  3852. }
  3853. if (!subMesh.effect || !subMesh.effect.isReady()) {
  3854. return false;
  3855. }
  3856. this._renderId = scene.getRenderId();
  3857. this._wasPreviouslyReady = true;
  3858. return true;
  3859. };
  3860. GridMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  3861. var scene = this.getScene();
  3862. var defines = subMesh._materialDefines;
  3863. if (!defines) {
  3864. return;
  3865. }
  3866. var effect = subMesh.effect;
  3867. if (!effect) {
  3868. return;
  3869. }
  3870. this._activeEffect = effect;
  3871. // Matrices
  3872. this.bindOnlyWorldMatrix(world);
  3873. this._activeEffect.setMatrix("worldView", world.multiply(scene.getViewMatrix()));
  3874. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  3875. this._activeEffect.setMatrix("projection", scene.getProjectionMatrix());
  3876. // Uniforms
  3877. if (this._mustRebind(scene, effect)) {
  3878. this._activeEffect.setColor3("mainColor", this.mainColor);
  3879. this._activeEffect.setColor3("lineColor", this.lineColor);
  3880. this._activeEffect.setVector3("gridOffset", this.gridOffset);
  3881. this._gridControl.x = this.gridRatio;
  3882. this._gridControl.y = Math.round(this.majorUnitFrequency);
  3883. this._gridControl.z = this.minorUnitVisibility;
  3884. this._gridControl.w = this.opacity;
  3885. this._activeEffect.setVector4("gridControl", this._gridControl);
  3886. }
  3887. // Fog
  3888. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  3889. this._afterBind(mesh, this._activeEffect);
  3890. };
  3891. GridMaterial.prototype.dispose = function (forceDisposeEffect) {
  3892. _super.prototype.dispose.call(this, forceDisposeEffect);
  3893. };
  3894. GridMaterial.prototype.clone = function (name) {
  3895. var _this = this;
  3896. return BABYLON.SerializationHelper.Clone(function () { return new GridMaterial(name, _this.getScene()); }, this);
  3897. };
  3898. GridMaterial.prototype.serialize = function () {
  3899. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  3900. serializationObject.customType = "BABYLON.GridMaterial";
  3901. return serializationObject;
  3902. };
  3903. GridMaterial.prototype.getClassName = function () {
  3904. return "GridMaterial";
  3905. };
  3906. GridMaterial.Parse = function (source, scene, rootUrl) {
  3907. return BABYLON.SerializationHelper.Parse(function () { return new GridMaterial(source.name, scene); }, source, scene, rootUrl);
  3908. };
  3909. __decorate([
  3910. BABYLON.serializeAsColor3()
  3911. ], GridMaterial.prototype, "mainColor", void 0);
  3912. __decorate([
  3913. BABYLON.serializeAsColor3()
  3914. ], GridMaterial.prototype, "lineColor", void 0);
  3915. __decorate([
  3916. BABYLON.serialize()
  3917. ], GridMaterial.prototype, "gridRatio", void 0);
  3918. __decorate([
  3919. BABYLON.serializeAsColor3()
  3920. ], GridMaterial.prototype, "gridOffset", void 0);
  3921. __decorate([
  3922. BABYLON.serialize()
  3923. ], GridMaterial.prototype, "majorUnitFrequency", void 0);
  3924. __decorate([
  3925. BABYLON.serialize()
  3926. ], GridMaterial.prototype, "minorUnitVisibility", void 0);
  3927. __decorate([
  3928. BABYLON.serialize()
  3929. ], GridMaterial.prototype, "opacity", void 0);
  3930. __decorate([
  3931. BABYLON.serialize()
  3932. ], GridMaterial.prototype, "preMultiplyAlpha", void 0);
  3933. return GridMaterial;
  3934. }(BABYLON.PushMaterial));
  3935. BABYLON.GridMaterial = GridMaterial;
  3936. })(BABYLON || (BABYLON = {}));
  3937. //# sourceMappingURL=babylon.gridmaterial.js.map
  3938. BABYLON.Effect.ShadersStore['gridVertexShader'] = "precision highp float;\n\nattribute vec3 position;\nattribute vec3 normal;\n\nuniform mat4 projection;\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 worldView;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogVertexDeclaration>\nvoid main(void) {\n#ifdef FOG\nvec4 worldPos=world*vec4(position,1.0);\n#endif\n#include<fogVertex>\nvec4 cameraSpacePosition=worldView*vec4(position,1.0);\ngl_Position=projection*cameraSpacePosition;\n#ifdef TRANSPARENT\nvCameraSpacePosition=cameraSpacePosition;\n#endif\nvPosition=position;\nvNormal=normal;\n}";
  3939. BABYLON.Effect.ShadersStore['gridPixelShader'] = "#extension GL_OES_standard_derivatives : enable\n#define SQRT2 1.41421356\n#define PI 3.14159\nprecision highp float;\nuniform vec3 mainColor;\nuniform vec3 lineColor;\nuniform vec4 gridControl;\nuniform vec3 gridOffset;\n\n#ifdef TRANSPARENT\nvarying vec4 vCameraSpacePosition;\n#endif\nvarying vec3 vPosition;\nvarying vec3 vNormal;\n#include<fogFragmentDeclaration>\nfloat getVisibility(float position) {\n\nfloat majorGridFrequency=gridControl.y;\nif (floor(position+0.5) == floor(position/majorGridFrequency+0.5)*majorGridFrequency)\n{\nreturn 1.0;\n} \nreturn gridControl.z;\n}\nfloat getAnisotropicAttenuation(float differentialLength) {\nconst float maxNumberOfLines=10.0;\nreturn clamp(1.0/(differentialLength+1.0)-1.0/maxNumberOfLines,0.0,1.0);\n}\nfloat isPointOnLine(float position,float differentialLength) {\nfloat fractionPartOfPosition=position-floor(position+0.5); \nfractionPartOfPosition/=differentialLength; \nfractionPartOfPosition=clamp(fractionPartOfPosition,-1.,1.);\nfloat result=0.5+0.5*cos(fractionPartOfPosition*PI); \nreturn result; \n}\nfloat contributionOnAxis(float position) {\nfloat differentialLength=length(vec2(dFdx(position),dFdy(position)));\ndifferentialLength*=SQRT2; \n\nfloat result=isPointOnLine(position,differentialLength);\n\nfloat visibility=getVisibility(position);\nresult*=visibility;\n\nfloat anisotropicAttenuation=getAnisotropicAttenuation(differentialLength);\nresult*=anisotropicAttenuation;\nreturn result;\n}\nfloat normalImpactOnAxis(float x) {\nfloat normalImpact=clamp(1.0-3.0*abs(x*x*x),0.0,1.0);\nreturn normalImpact;\n}\nvoid main(void) {\n\nfloat gridRatio=gridControl.x;\nvec3 gridPos=(vPosition+gridOffset)/gridRatio;\n\nfloat x=contributionOnAxis(gridPos.x);\nfloat y=contributionOnAxis(gridPos.y);\nfloat z=contributionOnAxis(gridPos.z);\n\nvec3 normal=normalize(vNormal);\nx*=normalImpactOnAxis(normal.x);\ny*=normalImpactOnAxis(normal.y);\nz*=normalImpactOnAxis(normal.z);\n\nfloat grid=clamp(x+y+z,0.,1.);\n\nvec3 color=mix(mainColor,lineColor,grid);\n#ifdef FOG\n#include<fogFragment>\n#endif\n#ifdef TRANSPARENT\nfloat distanceToFragment=length(vCameraSpacePosition.xyz);\nfloat cameraPassThrough=clamp(distanceToFragment-0.25,0.0,1.0);\nfloat opacity=clamp(grid,0.08,cameraPassThrough*gridControl.w*grid);\ngl_FragColor=vec4(color.rgb,opacity);\n#ifdef PREMULTIPLYALPHA\ngl_FragColor.rgb*=opacity;\n#endif\n#else\n\ngl_FragColor=vec4(color.rgb,1.0);\n#endif\n}";
  3940. var BABYLON;
  3941. (function (BABYLON) {
  3942. // old version of standard material updated every 3 months
  3943. var StandardMaterialDefines_OldVer = /** @class */ (function (_super) {
  3944. __extends(StandardMaterialDefines_OldVer, _super);
  3945. function StandardMaterialDefines_OldVer() {
  3946. var _this = _super.call(this) || this;
  3947. _this.DIFFUSE = false;
  3948. _this.AMBIENT = false;
  3949. _this.OPACITY = false;
  3950. _this.OPACITYRGB = false;
  3951. _this.REFLECTION = false;
  3952. _this.EMISSIVE = false;
  3953. _this.SPECULAR = false;
  3954. _this.BUMP = false;
  3955. _this.PARALLAX = false;
  3956. _this.PARALLAXOCCLUSION = false;
  3957. _this.SPECULAROVERALPHA = false;
  3958. _this.CLIPPLANE = false;
  3959. _this.ALPHATEST = false;
  3960. _this.ALPHAFROMDIFFUSE = false;
  3961. _this.POINTSIZE = false;
  3962. _this.FOG = false;
  3963. _this.SPECULARTERM = false;
  3964. _this.DIFFUSEFRESNEL = false;
  3965. _this.OPACITYFRESNEL = false;
  3966. _this.REFLECTIONFRESNEL = false;
  3967. _this.REFRACTIONFRESNEL = false;
  3968. _this.EMISSIVEFRESNEL = false;
  3969. _this.FRESNEL = false;
  3970. _this.NORMAL = false;
  3971. _this.UV1 = false;
  3972. _this.UV2 = false;
  3973. _this.VERTEXCOLOR = false;
  3974. _this.VERTEXALPHA = false;
  3975. _this.NUM_BONE_INFLUENCERS = 0;
  3976. _this.BonesPerMesh = 0;
  3977. _this.INSTANCES = false;
  3978. _this.GLOSSINESS = false;
  3979. _this.ROUGHNESS = false;
  3980. _this.EMISSIVEASILLUMINATION = false;
  3981. _this.LINKEMISSIVEWITHDIFFUSE = false;
  3982. _this.REFLECTIONFRESNELFROMSPECULAR = false;
  3983. _this.LIGHTMAP = false;
  3984. _this.USELIGHTMAPASSHADOWMAP = false;
  3985. _this.REFLECTIONMAP_3D = false;
  3986. _this.REFLECTIONMAP_SPHERICAL = false;
  3987. _this.REFLECTIONMAP_PLANAR = false;
  3988. _this.REFLECTIONMAP_CUBIC = false;
  3989. _this.REFLECTIONMAP_PROJECTION = false;
  3990. _this.REFLECTIONMAP_SKYBOX = false;
  3991. _this.REFLECTIONMAP_EXPLICIT = false;
  3992. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  3993. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  3994. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  3995. _this.INVERTCUBICMAP = false;
  3996. _this.LOGARITHMICDEPTH = false;
  3997. _this.REFRACTION = false;
  3998. _this.REFRACTIONMAP_3D = false;
  3999. _this.REFLECTIONOVERALPHA = false;
  4000. _this.TWOSIDEDLIGHTING = false;
  4001. _this.SHADOWFLOAT = false;
  4002. _this.MORPHTARGETS = false;
  4003. _this.MORPHTARGETS_NORMAL = false;
  4004. _this.MORPHTARGETS_TANGENT = false;
  4005. _this.NUM_MORPH_INFLUENCERS = 0;
  4006. _this.IMAGEPROCESSING = false;
  4007. _this.VIGNETTE = false;
  4008. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  4009. _this.VIGNETTEBLENDMODEOPAQUE = false;
  4010. _this.TONEMAPPING = false;
  4011. _this.CONTRAST = false;
  4012. _this.COLORCURVES = false;
  4013. _this.COLORGRADING = false;
  4014. _this.COLORGRADING3D = false;
  4015. _this.SAMPLER3DGREENDEPTH = false;
  4016. _this.SAMPLER3DBGRMAP = false;
  4017. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  4018. _this.EXPOSURE = false;
  4019. _this.rebuild();
  4020. return _this;
  4021. }
  4022. StandardMaterialDefines_OldVer.prototype.setReflectionMode = function (modeToEnable) {
  4023. var modes = [
  4024. "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
  4025. "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
  4026. "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
  4027. "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
  4028. ];
  4029. for (var _i = 0, modes_1 = modes; _i < modes_1.length; _i++) {
  4030. var mode = modes_1[_i];
  4031. this[mode] = (mode === modeToEnable);
  4032. }
  4033. };
  4034. return StandardMaterialDefines_OldVer;
  4035. }(BABYLON.MaterialDefines));
  4036. BABYLON.StandardMaterialDefines_OldVer = StandardMaterialDefines_OldVer;
  4037. var StandardMaterial_OldVer = /** @class */ (function (_super) {
  4038. __extends(StandardMaterial_OldVer, _super);
  4039. function StandardMaterial_OldVer(name, scene) {
  4040. var _this = _super.call(this, name, scene) || this;
  4041. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  4042. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  4043. _this.specularColor = new BABYLON.Color3(1, 1, 1);
  4044. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  4045. _this.specularPower = 64;
  4046. _this._useAlphaFromDiffuseTexture = false;
  4047. _this._useEmissiveAsIllumination = false;
  4048. _this._linkEmissiveWithDiffuse = false;
  4049. _this._useSpecularOverAlpha = false;
  4050. _this._useReflectionOverAlpha = false;
  4051. _this._disableLighting = false;
  4052. _this._useParallax = false;
  4053. _this._useParallaxOcclusion = false;
  4054. _this.parallaxScaleBias = 0.05;
  4055. _this._roughness = 0;
  4056. _this.indexOfRefraction = 0.98;
  4057. _this.invertRefractionY = true;
  4058. _this._useLightmapAsShadowmap = false;
  4059. _this._useReflectionFresnelFromSpecular = false;
  4060. _this._useGlossinessFromSpecularMapAlpha = false;
  4061. _this._maxSimultaneousLights = 4;
  4062. /**
  4063. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  4064. */
  4065. _this._invertNormalMapX = false;
  4066. /**
  4067. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  4068. */
  4069. _this._invertNormalMapY = false;
  4070. /**
  4071. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  4072. */
  4073. _this._twoSidedLighting = false;
  4074. _this._renderTargets = new BABYLON.SmartArray(16);
  4075. _this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  4076. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  4077. // Setup the default processing configuration to the scene.
  4078. _this._attachImageProcessingConfiguration(null);
  4079. _this.getRenderTargetTextures = function () {
  4080. _this._renderTargets.reset();
  4081. if (StandardMaterial_OldVer.ReflectionTextureEnabled && _this._reflectionTexture && _this._reflectionTexture.isRenderTarget) {
  4082. _this._renderTargets.push(_this._reflectionTexture);
  4083. }
  4084. if (StandardMaterial_OldVer.RefractionTextureEnabled && _this._refractionTexture && _this._refractionTexture.isRenderTarget) {
  4085. _this._renderTargets.push(_this._refractionTexture);
  4086. }
  4087. return _this._renderTargets;
  4088. };
  4089. return _this;
  4090. }
  4091. Object.defineProperty(StandardMaterial_OldVer.prototype, "imageProcessingConfiguration", {
  4092. /**
  4093. * Gets the image processing configuration used either in this material.
  4094. */
  4095. get: function () {
  4096. return this._imageProcessingConfiguration;
  4097. },
  4098. /**
  4099. * Sets the Default image processing configuration used either in the this material.
  4100. *
  4101. * If sets to null, the scene one is in use.
  4102. */
  4103. set: function (value) {
  4104. this._attachImageProcessingConfiguration(value);
  4105. // Ensure the effect will be rebuilt.
  4106. this._markAllSubMeshesAsTexturesDirty();
  4107. },
  4108. enumerable: true,
  4109. configurable: true
  4110. });
  4111. /**
  4112. * Attaches a new image processing configuration to the Standard Material.
  4113. * @param configuration
  4114. */
  4115. StandardMaterial_OldVer.prototype._attachImageProcessingConfiguration = function (configuration) {
  4116. var _this = this;
  4117. if (configuration === this._imageProcessingConfiguration) {
  4118. return;
  4119. }
  4120. // Detaches observer.
  4121. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  4122. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  4123. }
  4124. // Pick the scene configuration if needed.
  4125. if (!configuration) {
  4126. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  4127. }
  4128. else {
  4129. this._imageProcessingConfiguration = configuration;
  4130. }
  4131. // Attaches observer.
  4132. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  4133. _this._markAllSubMeshesAsImageProcessingDirty();
  4134. });
  4135. };
  4136. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorCurvesEnabled", {
  4137. /**
  4138. * Gets wether the color curves effect is enabled.
  4139. */
  4140. get: function () {
  4141. return this.imageProcessingConfiguration.colorCurvesEnabled;
  4142. },
  4143. /**
  4144. * Sets wether the color curves effect is enabled.
  4145. */
  4146. set: function (value) {
  4147. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  4148. },
  4149. enumerable: true,
  4150. configurable: true
  4151. });
  4152. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingEnabled", {
  4153. /**
  4154. * Gets wether the color grading effect is enabled.
  4155. */
  4156. get: function () {
  4157. return this.imageProcessingConfiguration.colorGradingEnabled;
  4158. },
  4159. /**
  4160. * Gets wether the color grading effect is enabled.
  4161. */
  4162. set: function (value) {
  4163. this.imageProcessingConfiguration.colorGradingEnabled = value;
  4164. },
  4165. enumerable: true,
  4166. configurable: true
  4167. });
  4168. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraToneMappingEnabled", {
  4169. /**
  4170. * Gets wether tonemapping is enabled or not.
  4171. */
  4172. get: function () {
  4173. return this._imageProcessingConfiguration.toneMappingEnabled;
  4174. },
  4175. /**
  4176. * Sets wether tonemapping is enabled or not
  4177. */
  4178. set: function (value) {
  4179. this._imageProcessingConfiguration.toneMappingEnabled = value;
  4180. },
  4181. enumerable: true,
  4182. configurable: true
  4183. });
  4184. ;
  4185. ;
  4186. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraExposure", {
  4187. /**
  4188. * The camera exposure used on this material.
  4189. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  4190. * This corresponds to a photographic exposure.
  4191. */
  4192. get: function () {
  4193. return this._imageProcessingConfiguration.exposure;
  4194. },
  4195. /**
  4196. * The camera exposure used on this material.
  4197. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  4198. * This corresponds to a photographic exposure.
  4199. */
  4200. set: function (value) {
  4201. this._imageProcessingConfiguration.exposure = value;
  4202. },
  4203. enumerable: true,
  4204. configurable: true
  4205. });
  4206. ;
  4207. ;
  4208. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraContrast", {
  4209. /**
  4210. * Gets The camera contrast used on this material.
  4211. */
  4212. get: function () {
  4213. return this._imageProcessingConfiguration.contrast;
  4214. },
  4215. /**
  4216. * Sets The camera contrast used on this material.
  4217. */
  4218. set: function (value) {
  4219. this._imageProcessingConfiguration.contrast = value;
  4220. },
  4221. enumerable: true,
  4222. configurable: true
  4223. });
  4224. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingTexture", {
  4225. /**
  4226. * Gets the Color Grading 2D Lookup Texture.
  4227. */
  4228. get: function () {
  4229. return this._imageProcessingConfiguration.colorGradingTexture;
  4230. },
  4231. /**
  4232. * Sets the Color Grading 2D Lookup Texture.
  4233. */
  4234. set: function (value) {
  4235. this._imageProcessingConfiguration.colorGradingTexture = value;
  4236. },
  4237. enumerable: true,
  4238. configurable: true
  4239. });
  4240. StandardMaterial_OldVer.prototype.getClassName = function () {
  4241. return "StandardMaterial_OldVer";
  4242. };
  4243. Object.defineProperty(StandardMaterial_OldVer.prototype, "useLogarithmicDepth", {
  4244. get: function () {
  4245. return this._useLogarithmicDepth;
  4246. },
  4247. set: function (value) {
  4248. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  4249. this._markAllSubMeshesAsMiscDirty();
  4250. },
  4251. enumerable: true,
  4252. configurable: true
  4253. });
  4254. StandardMaterial_OldVer.prototype.needAlphaBlending = function () {
  4255. return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
  4256. };
  4257. StandardMaterial_OldVer.prototype.needAlphaTesting = function () {
  4258. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
  4259. };
  4260. StandardMaterial_OldVer.prototype._shouldUseAlphaFromDiffuseTexture = function () {
  4261. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
  4262. };
  4263. StandardMaterial_OldVer.prototype.getAlphaTestTexture = function () {
  4264. return this._diffuseTexture;
  4265. };
  4266. /**
  4267. * Child classes can use it to update shaders
  4268. */
  4269. StandardMaterial_OldVer.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  4270. if (this.isFrozen) {
  4271. if (this._wasPreviouslyReady && subMesh.effect) {
  4272. return true;
  4273. }
  4274. }
  4275. if (!subMesh._materialDefines) {
  4276. subMesh._materialDefines = new StandardMaterialDefines_OldVer();
  4277. }
  4278. var scene = this.getScene();
  4279. var defines = subMesh._materialDefines;
  4280. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  4281. if (defines._renderId === scene.getRenderId()) {
  4282. return true;
  4283. }
  4284. }
  4285. var engine = scene.getEngine();
  4286. // Lights
  4287. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  4288. // Textures
  4289. if (defines._areTexturesDirty) {
  4290. defines._needUVs = false;
  4291. if (scene.texturesEnabled) {
  4292. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4293. if (!this._diffuseTexture.isReadyOrNotBlocking()) {
  4294. return false;
  4295. }
  4296. else {
  4297. defines._needUVs = true;
  4298. defines.DIFFUSE = true;
  4299. }
  4300. }
  4301. else {
  4302. defines.DIFFUSE = false;
  4303. }
  4304. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4305. if (!this._ambientTexture.isReadyOrNotBlocking()) {
  4306. return false;
  4307. }
  4308. else {
  4309. defines._needUVs = true;
  4310. defines.AMBIENT = true;
  4311. }
  4312. }
  4313. else {
  4314. defines.AMBIENT = false;
  4315. }
  4316. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4317. if (!this._opacityTexture.isReadyOrNotBlocking()) {
  4318. return false;
  4319. }
  4320. else {
  4321. defines._needUVs = true;
  4322. defines.OPACITY = true;
  4323. defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
  4324. }
  4325. }
  4326. else {
  4327. defines.OPACITY = false;
  4328. }
  4329. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4330. if (!this._reflectionTexture.isReadyOrNotBlocking()) {
  4331. return false;
  4332. }
  4333. else {
  4334. defines._needNormals = true;
  4335. defines.REFLECTION = true;
  4336. defines.ROUGHNESS = (this._roughness > 0);
  4337. defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;
  4338. defines.INVERTCUBICMAP = (this._reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE);
  4339. defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
  4340. switch (this._reflectionTexture.coordinatesMode) {
  4341. case BABYLON.Texture.CUBIC_MODE:
  4342. case BABYLON.Texture.INVCUBIC_MODE:
  4343. defines.setReflectionMode("REFLECTIONMAP_CUBIC");
  4344. break;
  4345. case BABYLON.Texture.EXPLICIT_MODE:
  4346. defines.setReflectionMode("REFLECTIONMAP_EXPLICIT");
  4347. break;
  4348. case BABYLON.Texture.PLANAR_MODE:
  4349. defines.setReflectionMode("REFLECTIONMAP_PLANAR");
  4350. break;
  4351. case BABYLON.Texture.PROJECTION_MODE:
  4352. defines.setReflectionMode("REFLECTIONMAP_PROJECTION");
  4353. break;
  4354. case BABYLON.Texture.SKYBOX_MODE:
  4355. defines.setReflectionMode("REFLECTIONMAP_SKYBOX");
  4356. break;
  4357. case BABYLON.Texture.SPHERICAL_MODE:
  4358. defines.setReflectionMode("REFLECTIONMAP_SPHERICAL");
  4359. break;
  4360. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  4361. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");
  4362. break;
  4363. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  4364. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");
  4365. break;
  4366. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  4367. defines.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED");
  4368. break;
  4369. }
  4370. }
  4371. }
  4372. else {
  4373. defines.REFLECTION = false;
  4374. }
  4375. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4376. if (!this._emissiveTexture.isReadyOrNotBlocking()) {
  4377. return false;
  4378. }
  4379. else {
  4380. defines._needUVs = true;
  4381. defines.EMISSIVE = true;
  4382. }
  4383. }
  4384. else {
  4385. defines.EMISSIVE = false;
  4386. }
  4387. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4388. if (!this._lightmapTexture.isReadyOrNotBlocking()) {
  4389. return false;
  4390. }
  4391. else {
  4392. defines._needUVs = true;
  4393. defines.LIGHTMAP = true;
  4394. defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;
  4395. }
  4396. }
  4397. else {
  4398. defines.LIGHTMAP = false;
  4399. }
  4400. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4401. if (!this._specularTexture.isReadyOrNotBlocking()) {
  4402. return false;
  4403. }
  4404. else {
  4405. defines._needUVs = true;
  4406. defines.SPECULAR = true;
  4407. defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;
  4408. }
  4409. }
  4410. else {
  4411. defines.SPECULAR = false;
  4412. }
  4413. if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial_OldVer.BumpTextureEnabled) {
  4414. // Bump texure can not be not blocking.
  4415. if (!this._bumpTexture.isReady()) {
  4416. return false;
  4417. }
  4418. else {
  4419. defines._needUVs = true;
  4420. defines.BUMP = true;
  4421. defines.PARALLAX = this._useParallax;
  4422. defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
  4423. }
  4424. }
  4425. else {
  4426. defines.BUMP = false;
  4427. }
  4428. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4429. if (!this._refractionTexture.isReadyOrNotBlocking()) {
  4430. return false;
  4431. }
  4432. else {
  4433. defines._needUVs = true;
  4434. defines.REFRACTION = true;
  4435. defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;
  4436. }
  4437. }
  4438. else {
  4439. defines.REFRACTION = false;
  4440. }
  4441. defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;
  4442. }
  4443. else {
  4444. defines.DIFFUSE = false;
  4445. defines.AMBIENT = false;
  4446. defines.OPACITY = false;
  4447. defines.REFLECTION = false;
  4448. defines.EMISSIVE = false;
  4449. defines.LIGHTMAP = false;
  4450. defines.BUMP = false;
  4451. defines.REFRACTION = false;
  4452. }
  4453. defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();
  4454. defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
  4455. defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
  4456. defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
  4457. }
  4458. if (defines._areImageProcessingDirty) {
  4459. if (!this._imageProcessingConfiguration.isReady()) {
  4460. return false;
  4461. }
  4462. this._imageProcessingConfiguration.prepareDefines(defines);
  4463. }
  4464. if (defines._areFresnelDirty) {
  4465. if (StandardMaterial_OldVer.FresnelEnabled) {
  4466. // Fresnel
  4467. if (this._diffuseFresnelParameters || this._opacityFresnelParameters ||
  4468. this._emissiveFresnelParameters || this._refractionFresnelParameters ||
  4469. this._reflectionFresnelParameters) {
  4470. defines.DIFFUSEFRESNEL = (this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled);
  4471. defines.OPACITYFRESNEL = (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled);
  4472. defines.REFLECTIONFRESNEL = (this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled);
  4473. defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
  4474. defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled);
  4475. defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled);
  4476. defines._needNormals = true;
  4477. defines.FRESNEL = true;
  4478. }
  4479. }
  4480. else {
  4481. defines.FRESNEL = false;
  4482. }
  4483. }
  4484. // Misc.
  4485. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  4486. // Attribs
  4487. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
  4488. // Values that need to be evaluated on every frame
  4489. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  4490. // Get correct effect
  4491. if (defines.isDirty) {
  4492. defines.markAsProcessed();
  4493. scene.resetCachedMaterial();
  4494. // Fallbacks
  4495. var fallbacks = new BABYLON.EffectFallbacks();
  4496. if (defines.REFLECTION) {
  4497. fallbacks.addFallback(0, "REFLECTION");
  4498. }
  4499. if (defines.SPECULAR) {
  4500. fallbacks.addFallback(0, "SPECULAR");
  4501. }
  4502. if (defines.BUMP) {
  4503. fallbacks.addFallback(0, "BUMP");
  4504. }
  4505. if (defines.PARALLAX) {
  4506. fallbacks.addFallback(1, "PARALLAX");
  4507. }
  4508. if (defines.PARALLAXOCCLUSION) {
  4509. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  4510. }
  4511. if (defines.SPECULAROVERALPHA) {
  4512. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  4513. }
  4514. if (defines.FOG) {
  4515. fallbacks.addFallback(1, "FOG");
  4516. }
  4517. if (defines.POINTSIZE) {
  4518. fallbacks.addFallback(0, "POINTSIZE");
  4519. }
  4520. if (defines.LOGARITHMICDEPTH) {
  4521. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  4522. }
  4523. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  4524. if (defines.SPECULARTERM) {
  4525. fallbacks.addFallback(0, "SPECULARTERM");
  4526. }
  4527. if (defines.DIFFUSEFRESNEL) {
  4528. fallbacks.addFallback(1, "DIFFUSEFRESNEL");
  4529. }
  4530. if (defines.OPACITYFRESNEL) {
  4531. fallbacks.addFallback(2, "OPACITYFRESNEL");
  4532. }
  4533. if (defines.REFLECTIONFRESNEL) {
  4534. fallbacks.addFallback(3, "REFLECTIONFRESNEL");
  4535. }
  4536. if (defines.EMISSIVEFRESNEL) {
  4537. fallbacks.addFallback(4, "EMISSIVEFRESNEL");
  4538. }
  4539. if (defines.FRESNEL) {
  4540. fallbacks.addFallback(4, "FRESNEL");
  4541. }
  4542. //Attributes
  4543. var attribs = [BABYLON.VertexBuffer.PositionKind];
  4544. if (defines.NORMAL) {
  4545. attribs.push(BABYLON.VertexBuffer.NormalKind);
  4546. }
  4547. if (defines.UV1) {
  4548. attribs.push(BABYLON.VertexBuffer.UVKind);
  4549. }
  4550. if (defines.UV2) {
  4551. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  4552. }
  4553. if (defines.VERTEXCOLOR) {
  4554. attribs.push(BABYLON.VertexBuffer.ColorKind);
  4555. }
  4556. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  4557. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  4558. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
  4559. var shaderName = "default";
  4560. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
  4561. "vFogInfos", "vFogColor", "pointSize",
  4562. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  4563. "mBones",
  4564. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  4565. "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
  4566. "logarithmicDepthConstant", "vTangentSpaceParams"
  4567. ];
  4568. var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  4569. var uniformBuffers = ["Material", "Scene"];
  4570. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  4571. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  4572. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  4573. uniformsNames: uniforms,
  4574. uniformBuffersNames: uniformBuffers,
  4575. samplers: samplers,
  4576. defines: defines,
  4577. maxSimultaneousLights: this._maxSimultaneousLights
  4578. });
  4579. if (this.customShaderNameResolve) {
  4580. shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines);
  4581. }
  4582. var join = defines.toString();
  4583. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  4584. attributes: attribs,
  4585. uniformsNames: uniforms,
  4586. uniformBuffersNames: uniformBuffers,
  4587. samplers: samplers,
  4588. defines: join,
  4589. fallbacks: fallbacks,
  4590. onCompiled: this.onCompiled,
  4591. onError: this.onError,
  4592. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
  4593. }, engine), defines);
  4594. this.buildUniformLayout();
  4595. }
  4596. if (!subMesh.effect || !subMesh.effect.isReady()) {
  4597. return false;
  4598. }
  4599. defines._renderId = scene.getRenderId();
  4600. this._wasPreviouslyReady = true;
  4601. return true;
  4602. };
  4603. StandardMaterial_OldVer.prototype.buildUniformLayout = function () {
  4604. // Order is important !
  4605. this._uniformBuffer.addUniform("diffuseLeftColor", 4);
  4606. this._uniformBuffer.addUniform("diffuseRightColor", 4);
  4607. this._uniformBuffer.addUniform("opacityParts", 4);
  4608. this._uniformBuffer.addUniform("reflectionLeftColor", 4);
  4609. this._uniformBuffer.addUniform("reflectionRightColor", 4);
  4610. this._uniformBuffer.addUniform("refractionLeftColor", 4);
  4611. this._uniformBuffer.addUniform("refractionRightColor", 4);
  4612. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  4613. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  4614. this._uniformBuffer.addUniform("vDiffuseInfos", 2);
  4615. this._uniformBuffer.addUniform("vAmbientInfos", 2);
  4616. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  4617. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  4618. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  4619. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  4620. this._uniformBuffer.addUniform("vSpecularInfos", 2);
  4621. this._uniformBuffer.addUniform("vBumpInfos", 3);
  4622. this._uniformBuffer.addUniform("diffuseMatrix", 16);
  4623. this._uniformBuffer.addUniform("ambientMatrix", 16);
  4624. this._uniformBuffer.addUniform("opacityMatrix", 16);
  4625. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  4626. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  4627. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  4628. this._uniformBuffer.addUniform("specularMatrix", 16);
  4629. this._uniformBuffer.addUniform("bumpMatrix", 16);
  4630. this._uniformBuffer.addUniform("vTangentSpaceParams", 2);
  4631. this._uniformBuffer.addUniform("refractionMatrix", 16);
  4632. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  4633. this._uniformBuffer.addUniform("vSpecularColor", 4);
  4634. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  4635. this._uniformBuffer.addUniform("vDiffuseColor", 4);
  4636. this._uniformBuffer.addUniform("pointSize", 1);
  4637. this._uniformBuffer.create();
  4638. };
  4639. StandardMaterial_OldVer.prototype.unbind = function () {
  4640. if (this._activeEffect) {
  4641. if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
  4642. this._activeEffect.setTexture("reflection2DSampler", null);
  4643. }
  4644. if (this._refractionTexture && this._refractionTexture.isRenderTarget) {
  4645. this._activeEffect.setTexture("refraction2DSampler", null);
  4646. }
  4647. }
  4648. _super.prototype.unbind.call(this);
  4649. };
  4650. StandardMaterial_OldVer.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  4651. var scene = this.getScene();
  4652. var defines = subMesh._materialDefines;
  4653. if (!defines) {
  4654. return;
  4655. }
  4656. var effect = subMesh.effect;
  4657. if (!effect) {
  4658. return;
  4659. }
  4660. this._activeEffect = effect;
  4661. // Matrices
  4662. this.bindOnlyWorldMatrix(world);
  4663. // Bones
  4664. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  4665. if (this._mustRebind(scene, effect, mesh.visibility)) {
  4666. this._uniformBuffer.bindToEffect(effect, "Material");
  4667. this.bindViewProjection(effect);
  4668. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  4669. if (StandardMaterial_OldVer.FresnelEnabled && defines.FRESNEL) {
  4670. // Fresnel
  4671. if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
  4672. this._uniformBuffer.updateColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
  4673. this._uniformBuffer.updateColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
  4674. }
  4675. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  4676. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  4677. }
  4678. if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
  4679. this._uniformBuffer.updateColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
  4680. this._uniformBuffer.updateColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
  4681. }
  4682. if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {
  4683. this._uniformBuffer.updateColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
  4684. this._uniformBuffer.updateColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
  4685. }
  4686. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  4687. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  4688. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  4689. }
  4690. }
  4691. // Textures
  4692. if (scene.texturesEnabled) {
  4693. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4694. this._uniformBuffer.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  4695. this._uniformBuffer.updateMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  4696. }
  4697. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4698. this._uniformBuffer.updateFloat2("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);
  4699. this._uniformBuffer.updateMatrix("ambientMatrix", this._ambientTexture.getTextureMatrix());
  4700. }
  4701. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4702. this._uniformBuffer.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  4703. this._uniformBuffer.updateMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
  4704. }
  4705. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4706. this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, this.roughness);
  4707. this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
  4708. }
  4709. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4710. this._uniformBuffer.updateFloat2("vEmissiveInfos", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);
  4711. this._uniformBuffer.updateMatrix("emissiveMatrix", this._emissiveTexture.getTextureMatrix());
  4712. }
  4713. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4714. this._uniformBuffer.updateFloat2("vLightmapInfos", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);
  4715. this._uniformBuffer.updateMatrix("lightmapMatrix", this._lightmapTexture.getTextureMatrix());
  4716. }
  4717. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4718. this._uniformBuffer.updateFloat2("vSpecularInfos", this._specularTexture.coordinatesIndex, this._specularTexture.level);
  4719. this._uniformBuffer.updateMatrix("specularMatrix", this._specularTexture.getTextureMatrix());
  4720. }
  4721. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  4722. this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
  4723. this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
  4724. if (scene._mirroredCameraPosition) {
  4725. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);
  4726. }
  4727. else {
  4728. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);
  4729. }
  4730. }
  4731. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4732. var depth = 1.0;
  4733. if (!this._refractionTexture.isCube) {
  4734. this._uniformBuffer.updateMatrix("refractionMatrix", this._refractionTexture.getReflectionTextureMatrix());
  4735. if (this._refractionTexture.depth) {
  4736. depth = this._refractionTexture.depth;
  4737. }
  4738. }
  4739. this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  4740. }
  4741. }
  4742. // Point size
  4743. if (this.pointsCloud) {
  4744. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  4745. }
  4746. if (defines.SPECULARTERM) {
  4747. this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
  4748. }
  4749. this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
  4750. // Diffuse
  4751. this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  4752. }
  4753. // Textures
  4754. if (scene.texturesEnabled) {
  4755. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  4756. effect.setTexture("diffuseSampler", this._diffuseTexture);
  4757. }
  4758. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  4759. effect.setTexture("ambientSampler", this._ambientTexture);
  4760. }
  4761. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  4762. effect.setTexture("opacitySampler", this._opacityTexture);
  4763. }
  4764. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  4765. if (this._reflectionTexture.isCube) {
  4766. effect.setTexture("reflectionCubeSampler", this._reflectionTexture);
  4767. }
  4768. else {
  4769. effect.setTexture("reflection2DSampler", this._reflectionTexture);
  4770. }
  4771. }
  4772. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  4773. effect.setTexture("emissiveSampler", this._emissiveTexture);
  4774. }
  4775. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  4776. effect.setTexture("lightmapSampler", this._lightmapTexture);
  4777. }
  4778. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  4779. effect.setTexture("specularSampler", this._specularTexture);
  4780. }
  4781. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  4782. effect.setTexture("bumpSampler", this._bumpTexture);
  4783. }
  4784. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  4785. var depth = 1.0;
  4786. if (this._refractionTexture.isCube) {
  4787. effect.setTexture("refractionCubeSampler", this._refractionTexture);
  4788. }
  4789. else {
  4790. effect.setTexture("refraction2DSampler", this._refractionTexture);
  4791. }
  4792. }
  4793. }
  4794. // Clip plane
  4795. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  4796. // Colors
  4797. scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  4798. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  4799. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  4800. }
  4801. if (this._mustRebind(scene, effect) || !this.isFrozen) {
  4802. // Lights
  4803. if (scene.lightsEnabled && !this._disableLighting) {
  4804. BABYLON.MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);
  4805. }
  4806. // View
  4807. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
  4808. this.bindView(effect);
  4809. }
  4810. // Fog
  4811. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, effect);
  4812. // Morph targets
  4813. if (defines.NUM_MORPH_INFLUENCERS) {
  4814. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
  4815. }
  4816. // Log. depth
  4817. BABYLON.MaterialHelper.BindLogDepth(defines, effect, scene);
  4818. // image processing
  4819. this._imageProcessingConfiguration.bind(this._activeEffect);
  4820. }
  4821. this._uniformBuffer.update();
  4822. this._afterBind(mesh, this._activeEffect);
  4823. };
  4824. StandardMaterial_OldVer.prototype.getAnimatables = function () {
  4825. var results = [];
  4826. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  4827. results.push(this._diffuseTexture);
  4828. }
  4829. if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {
  4830. results.push(this._ambientTexture);
  4831. }
  4832. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  4833. results.push(this._opacityTexture);
  4834. }
  4835. if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {
  4836. results.push(this._reflectionTexture);
  4837. }
  4838. if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {
  4839. results.push(this._emissiveTexture);
  4840. }
  4841. if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {
  4842. results.push(this._specularTexture);
  4843. }
  4844. if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
  4845. results.push(this._bumpTexture);
  4846. }
  4847. if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {
  4848. results.push(this._lightmapTexture);
  4849. }
  4850. if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {
  4851. results.push(this._refractionTexture);
  4852. }
  4853. return results;
  4854. };
  4855. StandardMaterial_OldVer.prototype.getActiveTextures = function () {
  4856. var activeTextures = _super.prototype.getActiveTextures.call(this);
  4857. if (this._diffuseTexture) {
  4858. activeTextures.push(this._diffuseTexture);
  4859. }
  4860. if (this._ambientTexture) {
  4861. activeTextures.push(this._ambientTexture);
  4862. }
  4863. if (this._opacityTexture) {
  4864. activeTextures.push(this._opacityTexture);
  4865. }
  4866. if (this._reflectionTexture) {
  4867. activeTextures.push(this._reflectionTexture);
  4868. }
  4869. if (this._emissiveTexture) {
  4870. activeTextures.push(this._emissiveTexture);
  4871. }
  4872. if (this._specularTexture) {
  4873. activeTextures.push(this._specularTexture);
  4874. }
  4875. if (this._bumpTexture) {
  4876. activeTextures.push(this._bumpTexture);
  4877. }
  4878. if (this._lightmapTexture) {
  4879. activeTextures.push(this._lightmapTexture);
  4880. }
  4881. if (this._refractionTexture) {
  4882. activeTextures.push(this._refractionTexture);
  4883. }
  4884. return activeTextures;
  4885. };
  4886. StandardMaterial_OldVer.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  4887. if (forceDisposeTextures) {
  4888. if (this._diffuseTexture) {
  4889. this._diffuseTexture.dispose();
  4890. }
  4891. if (this._ambientTexture) {
  4892. this._ambientTexture.dispose();
  4893. }
  4894. if (this._opacityTexture) {
  4895. this._opacityTexture.dispose();
  4896. }
  4897. if (this._reflectionTexture) {
  4898. this._reflectionTexture.dispose();
  4899. }
  4900. if (this._emissiveTexture) {
  4901. this._emissiveTexture.dispose();
  4902. }
  4903. if (this._specularTexture) {
  4904. this._specularTexture.dispose();
  4905. }
  4906. if (this._bumpTexture) {
  4907. this._bumpTexture.dispose();
  4908. }
  4909. if (this._lightmapTexture) {
  4910. this._lightmapTexture.dispose();
  4911. }
  4912. if (this._refractionTexture) {
  4913. this._refractionTexture.dispose();
  4914. }
  4915. }
  4916. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  4917. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  4918. }
  4919. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  4920. };
  4921. StandardMaterial_OldVer.prototype.clone = function (name) {
  4922. var _this = this;
  4923. var result = BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial_OldVer(name, _this.getScene()); }, this);
  4924. result.name = name;
  4925. result.id = name;
  4926. return result;
  4927. };
  4928. StandardMaterial_OldVer.prototype.serialize = function () {
  4929. return BABYLON.SerializationHelper.Serialize(this);
  4930. };
  4931. // Statics
  4932. StandardMaterial_OldVer.Parse = function (source, scene, rootUrl) {
  4933. return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial_OldVer(source.name, scene); }, source, scene, rootUrl);
  4934. };
  4935. Object.defineProperty(StandardMaterial_OldVer, "DiffuseTextureEnabled", {
  4936. get: function () {
  4937. return StandardMaterial_OldVer._DiffuseTextureEnabled;
  4938. },
  4939. set: function (value) {
  4940. if (StandardMaterial_OldVer._DiffuseTextureEnabled === value) {
  4941. return;
  4942. }
  4943. StandardMaterial_OldVer._DiffuseTextureEnabled = value;
  4944. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4945. },
  4946. enumerable: true,
  4947. configurable: true
  4948. });
  4949. Object.defineProperty(StandardMaterial_OldVer, "AmbientTextureEnabled", {
  4950. get: function () {
  4951. return StandardMaterial_OldVer._AmbientTextureEnabled;
  4952. },
  4953. set: function (value) {
  4954. if (StandardMaterial_OldVer._AmbientTextureEnabled === value) {
  4955. return;
  4956. }
  4957. StandardMaterial_OldVer._AmbientTextureEnabled = value;
  4958. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4959. },
  4960. enumerable: true,
  4961. configurable: true
  4962. });
  4963. Object.defineProperty(StandardMaterial_OldVer, "OpacityTextureEnabled", {
  4964. get: function () {
  4965. return StandardMaterial_OldVer._OpacityTextureEnabled;
  4966. },
  4967. set: function (value) {
  4968. if (StandardMaterial_OldVer._OpacityTextureEnabled === value) {
  4969. return;
  4970. }
  4971. StandardMaterial_OldVer._OpacityTextureEnabled = value;
  4972. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4973. },
  4974. enumerable: true,
  4975. configurable: true
  4976. });
  4977. Object.defineProperty(StandardMaterial_OldVer, "ReflectionTextureEnabled", {
  4978. get: function () {
  4979. return StandardMaterial_OldVer._ReflectionTextureEnabled;
  4980. },
  4981. set: function (value) {
  4982. if (StandardMaterial_OldVer._ReflectionTextureEnabled === value) {
  4983. return;
  4984. }
  4985. StandardMaterial_OldVer._ReflectionTextureEnabled = value;
  4986. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  4987. },
  4988. enumerable: true,
  4989. configurable: true
  4990. });
  4991. Object.defineProperty(StandardMaterial_OldVer, "EmissiveTextureEnabled", {
  4992. get: function () {
  4993. return StandardMaterial_OldVer._EmissiveTextureEnabled;
  4994. },
  4995. set: function (value) {
  4996. if (StandardMaterial_OldVer._EmissiveTextureEnabled === value) {
  4997. return;
  4998. }
  4999. StandardMaterial_OldVer._EmissiveTextureEnabled = value;
  5000. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5001. },
  5002. enumerable: true,
  5003. configurable: true
  5004. });
  5005. Object.defineProperty(StandardMaterial_OldVer, "SpecularTextureEnabled", {
  5006. get: function () {
  5007. return StandardMaterial_OldVer._SpecularTextureEnabled;
  5008. },
  5009. set: function (value) {
  5010. if (StandardMaterial_OldVer._SpecularTextureEnabled === value) {
  5011. return;
  5012. }
  5013. StandardMaterial_OldVer._SpecularTextureEnabled = value;
  5014. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5015. },
  5016. enumerable: true,
  5017. configurable: true
  5018. });
  5019. Object.defineProperty(StandardMaterial_OldVer, "BumpTextureEnabled", {
  5020. get: function () {
  5021. return StandardMaterial_OldVer._BumpTextureEnabled;
  5022. },
  5023. set: function (value) {
  5024. if (StandardMaterial_OldVer._BumpTextureEnabled === value) {
  5025. return;
  5026. }
  5027. StandardMaterial_OldVer._BumpTextureEnabled = value;
  5028. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5029. },
  5030. enumerable: true,
  5031. configurable: true
  5032. });
  5033. Object.defineProperty(StandardMaterial_OldVer, "LightmapTextureEnabled", {
  5034. get: function () {
  5035. return StandardMaterial_OldVer._LightmapTextureEnabled;
  5036. },
  5037. set: function (value) {
  5038. if (StandardMaterial_OldVer._LightmapTextureEnabled === value) {
  5039. return;
  5040. }
  5041. StandardMaterial_OldVer._LightmapTextureEnabled = value;
  5042. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5043. },
  5044. enumerable: true,
  5045. configurable: true
  5046. });
  5047. Object.defineProperty(StandardMaterial_OldVer, "RefractionTextureEnabled", {
  5048. get: function () {
  5049. return StandardMaterial_OldVer._RefractionTextureEnabled;
  5050. },
  5051. set: function (value) {
  5052. if (StandardMaterial_OldVer._RefractionTextureEnabled === value) {
  5053. return;
  5054. }
  5055. StandardMaterial_OldVer._RefractionTextureEnabled = value;
  5056. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5057. },
  5058. enumerable: true,
  5059. configurable: true
  5060. });
  5061. Object.defineProperty(StandardMaterial_OldVer, "ColorGradingTextureEnabled", {
  5062. get: function () {
  5063. return StandardMaterial_OldVer._ColorGradingTextureEnabled;
  5064. },
  5065. set: function (value) {
  5066. if (StandardMaterial_OldVer._ColorGradingTextureEnabled === value) {
  5067. return;
  5068. }
  5069. StandardMaterial_OldVer._ColorGradingTextureEnabled = value;
  5070. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  5071. },
  5072. enumerable: true,
  5073. configurable: true
  5074. });
  5075. Object.defineProperty(StandardMaterial_OldVer, "FresnelEnabled", {
  5076. get: function () {
  5077. return StandardMaterial_OldVer._FresnelEnabled;
  5078. },
  5079. set: function (value) {
  5080. if (StandardMaterial_OldVer._FresnelEnabled === value) {
  5081. return;
  5082. }
  5083. StandardMaterial_OldVer._FresnelEnabled = value;
  5084. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.FresnelDirtyFlag);
  5085. },
  5086. enumerable: true,
  5087. configurable: true
  5088. });
  5089. // Flags used to enable or disable a type of texture for all Standard Materials
  5090. StandardMaterial_OldVer._DiffuseTextureEnabled = true;
  5091. StandardMaterial_OldVer._AmbientTextureEnabled = true;
  5092. StandardMaterial_OldVer._OpacityTextureEnabled = true;
  5093. StandardMaterial_OldVer._ReflectionTextureEnabled = true;
  5094. StandardMaterial_OldVer._EmissiveTextureEnabled = true;
  5095. StandardMaterial_OldVer._SpecularTextureEnabled = true;
  5096. StandardMaterial_OldVer._BumpTextureEnabled = true;
  5097. StandardMaterial_OldVer._LightmapTextureEnabled = true;
  5098. StandardMaterial_OldVer._RefractionTextureEnabled = true;
  5099. StandardMaterial_OldVer._ColorGradingTextureEnabled = true;
  5100. StandardMaterial_OldVer._FresnelEnabled = true;
  5101. __decorate([
  5102. BABYLON.serializeAsTexture("diffuseTexture")
  5103. ], StandardMaterial_OldVer.prototype, "_diffuseTexture", void 0);
  5104. __decorate([
  5105. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5106. ], StandardMaterial_OldVer.prototype, "diffuseTexture", void 0);
  5107. __decorate([
  5108. BABYLON.serializeAsTexture("ambientTexture")
  5109. ], StandardMaterial_OldVer.prototype, "_ambientTexture", void 0);
  5110. __decorate([
  5111. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5112. ], StandardMaterial_OldVer.prototype, "ambientTexture", void 0);
  5113. __decorate([
  5114. BABYLON.serializeAsTexture("opacityTexture")
  5115. ], StandardMaterial_OldVer.prototype, "_opacityTexture", void 0);
  5116. __decorate([
  5117. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5118. ], StandardMaterial_OldVer.prototype, "opacityTexture", void 0);
  5119. __decorate([
  5120. BABYLON.serializeAsTexture("reflectionTexture")
  5121. ], StandardMaterial_OldVer.prototype, "_reflectionTexture", void 0);
  5122. __decorate([
  5123. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5124. ], StandardMaterial_OldVer.prototype, "reflectionTexture", void 0);
  5125. __decorate([
  5126. BABYLON.serializeAsTexture("emissiveTexture")
  5127. ], StandardMaterial_OldVer.prototype, "_emissiveTexture", void 0);
  5128. __decorate([
  5129. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5130. ], StandardMaterial_OldVer.prototype, "emissiveTexture", void 0);
  5131. __decorate([
  5132. BABYLON.serializeAsTexture("specularTexture")
  5133. ], StandardMaterial_OldVer.prototype, "_specularTexture", void 0);
  5134. __decorate([
  5135. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5136. ], StandardMaterial_OldVer.prototype, "specularTexture", void 0);
  5137. __decorate([
  5138. BABYLON.serializeAsTexture("bumpTexture")
  5139. ], StandardMaterial_OldVer.prototype, "_bumpTexture", void 0);
  5140. __decorate([
  5141. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5142. ], StandardMaterial_OldVer.prototype, "bumpTexture", void 0);
  5143. __decorate([
  5144. BABYLON.serializeAsTexture("lightmapTexture")
  5145. ], StandardMaterial_OldVer.prototype, "_lightmapTexture", void 0);
  5146. __decorate([
  5147. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5148. ], StandardMaterial_OldVer.prototype, "lightmapTexture", void 0);
  5149. __decorate([
  5150. BABYLON.serializeAsTexture("refractionTexture")
  5151. ], StandardMaterial_OldVer.prototype, "_refractionTexture", void 0);
  5152. __decorate([
  5153. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5154. ], StandardMaterial_OldVer.prototype, "refractionTexture", void 0);
  5155. __decorate([
  5156. BABYLON.serializeAsColor3("ambient")
  5157. ], StandardMaterial_OldVer.prototype, "ambientColor", void 0);
  5158. __decorate([
  5159. BABYLON.serializeAsColor3("diffuse")
  5160. ], StandardMaterial_OldVer.prototype, "diffuseColor", void 0);
  5161. __decorate([
  5162. BABYLON.serializeAsColor3("specular")
  5163. ], StandardMaterial_OldVer.prototype, "specularColor", void 0);
  5164. __decorate([
  5165. BABYLON.serializeAsColor3("emissive")
  5166. ], StandardMaterial_OldVer.prototype, "emissiveColor", void 0);
  5167. __decorate([
  5168. BABYLON.serialize()
  5169. ], StandardMaterial_OldVer.prototype, "specularPower", void 0);
  5170. __decorate([
  5171. BABYLON.serialize("useAlphaFromDiffuseTexture")
  5172. ], StandardMaterial_OldVer.prototype, "_useAlphaFromDiffuseTexture", void 0);
  5173. __decorate([
  5174. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5175. ], StandardMaterial_OldVer.prototype, "useAlphaFromDiffuseTexture", void 0);
  5176. __decorate([
  5177. BABYLON.serialize("useEmissiveAsIllumination")
  5178. ], StandardMaterial_OldVer.prototype, "_useEmissiveAsIllumination", void 0);
  5179. __decorate([
  5180. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5181. ], StandardMaterial_OldVer.prototype, "useEmissiveAsIllumination", void 0);
  5182. __decorate([
  5183. BABYLON.serialize("linkEmissiveWithDiffuse")
  5184. ], StandardMaterial_OldVer.prototype, "_linkEmissiveWithDiffuse", void 0);
  5185. __decorate([
  5186. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5187. ], StandardMaterial_OldVer.prototype, "linkEmissiveWithDiffuse", void 0);
  5188. __decorate([
  5189. BABYLON.serialize("useSpecularOverAlpha")
  5190. ], StandardMaterial_OldVer.prototype, "_useSpecularOverAlpha", void 0);
  5191. __decorate([
  5192. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5193. ], StandardMaterial_OldVer.prototype, "useSpecularOverAlpha", void 0);
  5194. __decorate([
  5195. BABYLON.serialize("useReflectionOverAlpha")
  5196. ], StandardMaterial_OldVer.prototype, "_useReflectionOverAlpha", void 0);
  5197. __decorate([
  5198. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5199. ], StandardMaterial_OldVer.prototype, "useReflectionOverAlpha", void 0);
  5200. __decorate([
  5201. BABYLON.serialize("disableLighting")
  5202. ], StandardMaterial_OldVer.prototype, "_disableLighting", void 0);
  5203. __decorate([
  5204. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  5205. ], StandardMaterial_OldVer.prototype, "disableLighting", void 0);
  5206. __decorate([
  5207. BABYLON.serialize("useParallax")
  5208. ], StandardMaterial_OldVer.prototype, "_useParallax", void 0);
  5209. __decorate([
  5210. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5211. ], StandardMaterial_OldVer.prototype, "useParallax", void 0);
  5212. __decorate([
  5213. BABYLON.serialize("useParallaxOcclusion")
  5214. ], StandardMaterial_OldVer.prototype, "_useParallaxOcclusion", void 0);
  5215. __decorate([
  5216. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5217. ], StandardMaterial_OldVer.prototype, "useParallaxOcclusion", void 0);
  5218. __decorate([
  5219. BABYLON.serialize()
  5220. ], StandardMaterial_OldVer.prototype, "parallaxScaleBias", void 0);
  5221. __decorate([
  5222. BABYLON.serialize("roughness")
  5223. ], StandardMaterial_OldVer.prototype, "_roughness", void 0);
  5224. __decorate([
  5225. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5226. ], StandardMaterial_OldVer.prototype, "roughness", void 0);
  5227. __decorate([
  5228. BABYLON.serialize()
  5229. ], StandardMaterial_OldVer.prototype, "indexOfRefraction", void 0);
  5230. __decorate([
  5231. BABYLON.serialize()
  5232. ], StandardMaterial_OldVer.prototype, "invertRefractionY", void 0);
  5233. __decorate([
  5234. BABYLON.serialize("useLightmapAsShadowmap")
  5235. ], StandardMaterial_OldVer.prototype, "_useLightmapAsShadowmap", void 0);
  5236. __decorate([
  5237. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5238. ], StandardMaterial_OldVer.prototype, "useLightmapAsShadowmap", void 0);
  5239. __decorate([
  5240. BABYLON.serializeAsFresnelParameters("diffuseFresnelParameters")
  5241. ], StandardMaterial_OldVer.prototype, "_diffuseFresnelParameters", void 0);
  5242. __decorate([
  5243. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5244. ], StandardMaterial_OldVer.prototype, "diffuseFresnelParameters", void 0);
  5245. __decorate([
  5246. BABYLON.serializeAsFresnelParameters("opacityFresnelParameters")
  5247. ], StandardMaterial_OldVer.prototype, "_opacityFresnelParameters", void 0);
  5248. __decorate([
  5249. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5250. ], StandardMaterial_OldVer.prototype, "opacityFresnelParameters", void 0);
  5251. __decorate([
  5252. BABYLON.serializeAsFresnelParameters("reflectionFresnelParameters")
  5253. ], StandardMaterial_OldVer.prototype, "_reflectionFresnelParameters", void 0);
  5254. __decorate([
  5255. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5256. ], StandardMaterial_OldVer.prototype, "reflectionFresnelParameters", void 0);
  5257. __decorate([
  5258. BABYLON.serializeAsFresnelParameters("refractionFresnelParameters")
  5259. ], StandardMaterial_OldVer.prototype, "_refractionFresnelParameters", void 0);
  5260. __decorate([
  5261. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5262. ], StandardMaterial_OldVer.prototype, "refractionFresnelParameters", void 0);
  5263. __decorate([
  5264. BABYLON.serializeAsFresnelParameters("emissiveFresnelParameters")
  5265. ], StandardMaterial_OldVer.prototype, "_emissiveFresnelParameters", void 0);
  5266. __decorate([
  5267. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5268. ], StandardMaterial_OldVer.prototype, "emissiveFresnelParameters", void 0);
  5269. __decorate([
  5270. BABYLON.serialize("useReflectionFresnelFromSpecular")
  5271. ], StandardMaterial_OldVer.prototype, "_useReflectionFresnelFromSpecular", void 0);
  5272. __decorate([
  5273. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  5274. ], StandardMaterial_OldVer.prototype, "useReflectionFresnelFromSpecular", void 0);
  5275. __decorate([
  5276. BABYLON.serialize("useGlossinessFromSpecularMapAlpha")
  5277. ], StandardMaterial_OldVer.prototype, "_useGlossinessFromSpecularMapAlpha", void 0);
  5278. __decorate([
  5279. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5280. ], StandardMaterial_OldVer.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
  5281. __decorate([
  5282. BABYLON.serialize("maxSimultaneousLights")
  5283. ], StandardMaterial_OldVer.prototype, "_maxSimultaneousLights", void 0);
  5284. __decorate([
  5285. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  5286. ], StandardMaterial_OldVer.prototype, "maxSimultaneousLights", void 0);
  5287. __decorate([
  5288. BABYLON.serialize("invertNormalMapX")
  5289. ], StandardMaterial_OldVer.prototype, "_invertNormalMapX", void 0);
  5290. __decorate([
  5291. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5292. ], StandardMaterial_OldVer.prototype, "invertNormalMapX", void 0);
  5293. __decorate([
  5294. BABYLON.serialize("invertNormalMapY")
  5295. ], StandardMaterial_OldVer.prototype, "_invertNormalMapY", void 0);
  5296. __decorate([
  5297. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5298. ], StandardMaterial_OldVer.prototype, "invertNormalMapY", void 0);
  5299. __decorate([
  5300. BABYLON.serialize("twoSidedLighting")
  5301. ], StandardMaterial_OldVer.prototype, "_twoSidedLighting", void 0);
  5302. __decorate([
  5303. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  5304. ], StandardMaterial_OldVer.prototype, "twoSidedLighting", void 0);
  5305. __decorate([
  5306. BABYLON.serialize()
  5307. ], StandardMaterial_OldVer.prototype, "useLogarithmicDepth", null);
  5308. return StandardMaterial_OldVer;
  5309. }(BABYLON.PushMaterial));
  5310. BABYLON.StandardMaterial_OldVer = StandardMaterial_OldVer;
  5311. var CustomShaderStructure = /** @class */ (function () {
  5312. function CustomShaderStructure() {
  5313. }
  5314. return CustomShaderStructure;
  5315. }());
  5316. BABYLON.CustomShaderStructure = CustomShaderStructure;
  5317. var ShaderSpecialParts = /** @class */ (function () {
  5318. function ShaderSpecialParts() {
  5319. }
  5320. return ShaderSpecialParts;
  5321. }());
  5322. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  5323. var ShaderForVer3_0 = /** @class */ (function (_super) {
  5324. __extends(ShaderForVer3_0, _super);
  5325. function ShaderForVer3_0() {
  5326. var _this = _super.call(this) || this;
  5327. _this.VertexStore = "";
  5328. _this.FragmentStore = "#include<__decl__defaultFragment>\n\
  5329. #[Fragment_Begin]\n\
  5330. #extension GL_OES_standard_derivatives : enable\n\
  5331. #ifdef LOGARITHMICDEPTH\n\
  5332. #extension GL_EXT_frag_depth : enable\n\
  5333. #endif\n\
  5334. \n\
  5335. #define RECIPROCAL_PI2 0.15915494\n\
  5336. uniform vec3 vEyePosition;\n\
  5337. uniform vec3 vAmbientColor;\n\
  5338. \n\
  5339. varying vec3 vPositionW;\n\
  5340. #ifdef NORMAL\n\
  5341. varying vec3 vNormalW_helper;\n\
  5342. varying vec3 localNormal;\n\
  5343. varying vec3 localPosition;\n\
  5344. vec3 vNormalW;\n\
  5345. #endif\n\
  5346. #ifdef VERTEXCOLOR\n\
  5347. varying vec4 vColor;\n\
  5348. #endif\n\
  5349. \n\
  5350. #include<helperFunctions>\n\
  5351. \n\
  5352. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  5353. #include<lightsFragmentFunctions>\n\
  5354. #include<shadowsFragmentFunctions>\n\
  5355. \n\
  5356. #ifdef DIFFUSE\n\
  5357. varying vec2 vDiffuseUV;\n\
  5358. uniform sampler2D diffuseSampler;\n\
  5359. #endif\n\
  5360. #ifdef AMBIENT\n\
  5361. varying vec2 vAmbientUV;\n\
  5362. uniform sampler2D ambientSampler;\n\
  5363. #endif\n\
  5364. #ifdef OPACITY\n\
  5365. varying vec2 vOpacityUV;\n\
  5366. uniform sampler2D opacitySampler;\n\
  5367. #endif\n\
  5368. #ifdef EMISSIVE\n\
  5369. varying vec2 vEmissiveUV;\n\
  5370. uniform sampler2D emissiveSampler;\n\
  5371. #endif\n\
  5372. #ifdef LIGHTMAP\n\
  5373. varying vec2 vLightmapUV;\n\
  5374. uniform sampler2D lightmapSampler;\n\
  5375. #endif\n\
  5376. #ifdef REFRACTION\n\
  5377. #ifdef REFRACTIONMAP_3D\n\
  5378. uniform samplerCube refractionCubeSampler;\n\
  5379. #else\n\
  5380. uniform sampler2D refraction2DSampler;\n\
  5381. #endif\n\
  5382. #endif\n\
  5383. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5384. varying vec2 vSpecularUV;\n\
  5385. uniform sampler2D specularSampler;\n\
  5386. #endif\n\
  5387. \n\
  5388. #include<fresnelFunction>\n\
  5389. \n\
  5390. #ifdef REFLECTION\n\
  5391. #ifdef REFLECTIONMAP_3D\n\
  5392. uniform samplerCube reflectionCubeSampler;\n\
  5393. #else\n\
  5394. uniform sampler2D reflection2DSampler;\n\
  5395. #endif\n\
  5396. #ifdef REFLECTIONMAP_SKYBOX\n\
  5397. varying vec3 vPositionUVW;\n\
  5398. #else\n\
  5399. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5400. varying vec3 vDirectionW;\n\
  5401. #endif\n\
  5402. #endif\n\
  5403. #include<reflectionFunction>\n\
  5404. #endif\n\
  5405. #include<imageProcessingDeclaration>\n\
  5406. #include<imageProcessingFunctions>\n\
  5407. \n\
  5408. #include<bumpFragmentFunctions>\n\
  5409. #include<clipPlaneFragmentDeclaration>\n\
  5410. #include<logDepthDeclaration>\n\
  5411. #include<fogFragmentDeclaration>\n\
  5412. \n\
  5413. #[Fragment_Definitions]\n\
  5414. \n\
  5415. void main(void) {\n\
  5416. \n\
  5417. vNormalW = vNormalW_helper;\n\
  5418. #[Fragment_MainBegin]\n\
  5419. \n\
  5420. #include<clipPlaneFragment>\n\
  5421. vec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\
  5422. \n\
  5423. vec4 baseColor=vec4(1.,1.,1.,1.);\n\
  5424. vec3 diffuseColor=vDiffuseColor.rgb;\n\
  5425. #[Fragment_Custom_Diffuse]\n\
  5426. \n\
  5427. float alpha=vDiffuseColor.a;\n\
  5428. #[Fragment_Custom_Alpha]\n\
  5429. \n\
  5430. #ifdef NORMAL\n\
  5431. vec3 normalW=normalize(vNormalW);\n\
  5432. #else\n\
  5433. vec3 normalW=vec3(1.0,1.0,1.0);\n\
  5434. #endif\n\
  5435. #include<bumpFragment>\n\
  5436. #ifdef TWOSIDEDLIGHTING\n\
  5437. normalW=gl_FrontFacing ? normalW : -normalW;\n\
  5438. #endif\n\
  5439. #ifdef DIFFUSE\n\
  5440. baseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n\
  5441. #ifdef ALPHATEST\n\
  5442. if (baseColor.a<0.4)\n\
  5443. discard;\n\
  5444. #endif\n\
  5445. #ifdef ALPHAFROMDIFFUSE\n\
  5446. alpha*=baseColor.a;\n\
  5447. #endif\n\
  5448. baseColor.rgb*=vDiffuseInfos.y;\n\
  5449. #endif\n\
  5450. #ifdef VERTEXCOLOR\n\
  5451. baseColor.rgb*=vColor.rgb;\n\
  5452. #endif\n\
  5453. \n\
  5454. vec3 baseAmbientColor=vec3(1.,1.,1.);\n\
  5455. #ifdef AMBIENT\n\
  5456. baseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n\
  5457. #endif\n\
  5458. \n\
  5459. #ifdef SPECULARTERM\n\
  5460. float glossiness=vSpecularColor.a;\n\
  5461. vec3 specularColor=vSpecularColor.rgb;\n\
  5462. #ifdef SPECULAR\n\
  5463. vec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\n\
  5464. specularColor=specularMapColor.rgb;\n\
  5465. #ifdef GLOSSINESS\n\
  5466. glossiness=glossiness*specularMapColor.a;\n\
  5467. #endif\n\
  5468. #endif\n\
  5469. #else\n\
  5470. float glossiness=0.;\n\
  5471. #endif\n\
  5472. \n\
  5473. vec3 diffuseBase=vec3(0.,0.,0.);\n\
  5474. lightingInfo info;\n\
  5475. #ifdef SPECULARTERM\n\
  5476. vec3 specularBase=vec3(0.,0.,0.);\n\
  5477. #endif\n\
  5478. float shadow=1.;\n\
  5479. #ifdef LIGHTMAP\n\
  5480. vec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n\
  5481. #endif\n\
  5482. #include<lightFragment>[0..maxSimultaneousLights]\n\
  5483. \n\
  5484. vec3 refractionColor=vec3(0.,0.,0.);\n\
  5485. #ifdef REFRACTION\n\
  5486. vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n\
  5487. #ifdef REFRACTIONMAP_3D\n\
  5488. refractionVector.y=refractionVector.y*vRefractionInfos.w;\n\
  5489. if (dot(refractionVector,viewDirectionW)<1.0)\n\
  5490. {\n\
  5491. refractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n\
  5492. }\n\
  5493. #else\n\
  5494. vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n\
  5495. vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\n\
  5496. refractionCoords.y=1.0-refractionCoords.y;\n\
  5497. refractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n\
  5498. #endif\n\
  5499. #endif\n\
  5500. \n\
  5501. vec3 reflectionColor=vec3(0.,0.,0.);\n\
  5502. #ifdef REFLECTION\n\
  5503. vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n\
  5504. #ifdef REFLECTIONMAP_3D\n\
  5505. #ifdef ROUGHNESS\n\
  5506. float bias=vReflectionInfos.y;\n\
  5507. #ifdef SPECULARTERM\n\
  5508. #ifdef SPECULAR\n\
  5509. #ifdef GLOSSINESS\n\
  5510. bias*=(1.0-specularMapColor.a);\n\
  5511. #endif\n\
  5512. #endif\n\
  5513. #endif\n\
  5514. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n\
  5515. #else\n\
  5516. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n\
  5517. #endif\n\
  5518. #else\n\
  5519. vec2 coords=vReflectionUVW.xy;\n\
  5520. #ifdef REFLECTIONMAP_PROJECTION\n\
  5521. coords/=vReflectionUVW.z;\n\
  5522. #endif\n\
  5523. coords.y=1.0-coords.y;\n\
  5524. reflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n\
  5525. #endif\n\
  5526. #ifdef REFLECTIONFRESNEL\n\
  5527. float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n\
  5528. #ifdef REFLECTIONFRESNELFROMSPECULAR\n\
  5529. #ifdef SPECULARTERM\n\
  5530. reflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5531. #else\n\
  5532. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5533. #endif\n\
  5534. #else\n\
  5535. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  5536. #endif\n\
  5537. #endif\n\
  5538. #endif\n\
  5539. #ifdef REFRACTIONFRESNEL\n\
  5540. float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\n\
  5541. refractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n\
  5542. #endif\n\
  5543. #ifdef OPACITY\n\
  5544. vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n\
  5545. #ifdef OPACITYRGB\n\
  5546. opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\n\
  5547. alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n\
  5548. #else\n\
  5549. alpha*=opacityMap.a*vOpacityInfos.y;\n\
  5550. #endif\n\
  5551. #endif\n\
  5552. #ifdef VERTEXALPHA\n\
  5553. alpha*=vColor.a;\n\
  5554. #endif\n\
  5555. #ifdef OPACITYFRESNEL\n\
  5556. float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\n\
  5557. alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n\
  5558. #endif\n\
  5559. \n\
  5560. vec3 emissiveColor=vEmissiveColor;\n\
  5561. #ifdef EMISSIVE\n\
  5562. emissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n\
  5563. #endif\n\
  5564. #ifdef EMISSIVEFRESNEL\n\
  5565. float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\n\
  5566. emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n\
  5567. #endif\n\
  5568. \n\
  5569. #ifdef DIFFUSEFRESNEL\n\
  5570. float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\n\
  5571. diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n\
  5572. #endif\n\
  5573. \n\
  5574. #ifdef EMISSIVEASILLUMINATION\n\
  5575. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5576. #else\n\
  5577. #ifdef LINKEMISSIVEWITHDIFFUSE\n\
  5578. vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5579. #else\n\
  5580. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  5581. #endif\n\
  5582. #endif\n\
  5583. #ifdef SPECULARTERM\n\
  5584. vec3 finalSpecular=specularBase*specularColor;\n\
  5585. #ifdef SPECULAROVERALPHA\n\
  5586. alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n\
  5587. #endif\n\
  5588. #else\n\
  5589. vec3 finalSpecular=vec3(0.0);\n\
  5590. #endif\n\
  5591. #ifdef REFLECTIONOVERALPHA\n\
  5592. alpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n\
  5593. #endif\n\
  5594. \n\
  5595. #ifdef EMISSIVEASILLUMINATION\n\
  5596. vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n\
  5597. #else\n\
  5598. vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n\
  5599. #endif\n\
  5600. \n\
  5601. #ifdef LIGHTMAP\n\
  5602. #ifndef LIGHTMAPEXCLUDED\n\
  5603. #ifdef USELIGHTMAPASSHADOWMAP\n\
  5604. color.rgb*=lightmapColor;\n\
  5605. #else\n\
  5606. color.rgb+=lightmapColor;\n\
  5607. #endif\n\
  5608. #endif\n\
  5609. #endif\n\
  5610. #include<logDepthFragment>\n\
  5611. #include<fogFragment>\n\
  5612. \n\
  5613. // Apply image processing if relevant. As this applies in linear space, \n\
  5614. // We first move from gamma to linear.\n\
  5615. #ifdef IMAGEPROCESSINGPOSTPROCESS\n\
  5616. color.rgb = toLinearSpace(color.rgb);\n\
  5617. #else\n\
  5618. #ifdef IMAGEPROCESSING\n\
  5619. color.rgb = toLinearSpace(color.rgb);\n\
  5620. color = applyImageProcessing(color);\n\
  5621. #endif\n\
  5622. #endif\n\
  5623. \n\
  5624. #[Fragment_Before_FragColor]\n\
  5625. gl_FragColor=color;\n\
  5626. }";
  5627. _this.VertexStore = "#include<__decl__defaultVertex>\n\
  5628. \n\
  5629. #[Vertex_Begin]\n\
  5630. \n\
  5631. attribute vec3 position;\n\
  5632. #ifdef NORMAL\n\
  5633. attribute vec3 normal;\n\
  5634. #endif\n\
  5635. #ifdef TANGENT\n\
  5636. attribute vec4 tangent;\n\
  5637. #endif\n\
  5638. #ifdef UV1\n\
  5639. attribute vec2 uv;\n\
  5640. #endif\n\
  5641. #ifdef UV2\n\
  5642. attribute vec2 uv2;\n\
  5643. #endif\n\
  5644. #ifdef VERTEXCOLOR\n\
  5645. attribute vec4 color;\n\
  5646. #endif\n\
  5647. #include<bonesDeclaration>\n\
  5648. \n\
  5649. #include<instancesDeclaration>\n\
  5650. #ifdef DIFFUSE\n\
  5651. varying vec2 vDiffuseUV;\n\
  5652. #endif\n\
  5653. #ifdef AMBIENT\n\
  5654. varying vec2 vAmbientUV;\n\
  5655. #endif\n\
  5656. #ifdef OPACITY\n\
  5657. varying vec2 vOpacityUV;\n\
  5658. #endif\n\
  5659. #ifdef EMISSIVE\n\
  5660. varying vec2 vEmissiveUV;\n\
  5661. #endif\n\
  5662. #ifdef LIGHTMAP\n\
  5663. varying vec2 vLightmapUV;\n\
  5664. #endif\n\
  5665. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5666. varying vec2 vSpecularUV;\n\
  5667. #endif\n\
  5668. #ifdef BUMP\n\
  5669. varying vec2 vBumpUV;\n\
  5670. #endif\n\
  5671. \n\
  5672. varying vec3 localPosition;\n\
  5673. varying vec3 vPositionW;\n\
  5674. #ifdef NORMAL\n\
  5675. varying vec3 vNormalW_helper;\n\
  5676. varying vec3 localNormal;\n\
  5677. #endif\n\
  5678. #ifdef VERTEXCOLOR\n\
  5679. varying vec4 vColor;\n\
  5680. #endif\n\
  5681. #include<bumpVertexDeclaration>\n\
  5682. #include<clipPlaneVertexDeclaration>\n\
  5683. #include<fogVertexDeclaration>\n\
  5684. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  5685. #include<morphTargetsVertexGlobalDeclaration>\n\
  5686. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n\
  5687. #ifdef REFLECTIONMAP_SKYBOX\n\
  5688. varying vec3 vPositionUVW;\n\
  5689. #endif\n\
  5690. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5691. varying vec3 vDirectionW;\n\
  5692. #endif\n\
  5693. #include<logDepthDeclaration>\n\
  5694. \n\
  5695. #[Vertex_Definitions]\n\
  5696. \n\
  5697. void main(void) {\n\
  5698. \n\
  5699. #[Vertex_MainBegin]\n\
  5700. \n\
  5701. vec3 positionUpdated=position;\n\
  5702. #ifdef NORMAL \n\
  5703. vec3 normalUpdated=normal;\n\
  5704. #endif\n\
  5705. #ifdef TANGENT\n\
  5706. vec4 tangentUpdated=tangent;\n\
  5707. #endif\n\
  5708. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n\
  5709. #ifdef REFLECTIONMAP_SKYBOX\n\
  5710. vPositionUVW=positionUpdated;\n\
  5711. #endif \n\
  5712. #include<instancesVertex>\n\
  5713. #include<bonesVertex>\n\
  5714. \n\
  5715. localPosition = positionUpdated;\n\
  5716. #[Vertex_Before_PositionUpdated]\n\
  5717. \n\
  5718. gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n\
  5719. vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n\
  5720. vPositionW=vec3(worldPos);\n\
  5721. #ifdef NORMAL\n\
  5722. \n\
  5723. #[Vertex_Before_NormalUpdated]\n\
  5724. \n\
  5725. localNormal = normalUpdated;\n\
  5726. vNormalW_helper=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n\
  5727. #endif\n\
  5728. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  5729. vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n\
  5730. #endif\n\
  5731. \n\
  5732. #ifndef UV1\n\
  5733. vec2 uv=vec2(0.,0.);\n\
  5734. #endif\n\
  5735. #ifndef UV2\n\
  5736. vec2 uv2=vec2(0.,0.);\n\
  5737. #endif\n\
  5738. #ifdef DIFFUSE\n\
  5739. if (vDiffuseInfos.x == 0.)\n\
  5740. {\n\
  5741. vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n\
  5742. }\n\
  5743. else\n\
  5744. {\n\
  5745. vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n\
  5746. }\n\
  5747. #endif\n\
  5748. #ifdef AMBIENT\n\
  5749. if (vAmbientInfos.x == 0.)\n\
  5750. {\n\
  5751. vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n\
  5752. }\n\
  5753. else\n\
  5754. {\n\
  5755. vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n\
  5756. }\n\
  5757. #endif\n\
  5758. #ifdef OPACITY\n\
  5759. if (vOpacityInfos.x == 0.)\n\
  5760. {\n\
  5761. vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n\
  5762. }\n\
  5763. else\n\
  5764. {\n\
  5765. vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n\
  5766. }\n\
  5767. #endif\n\
  5768. #ifdef EMISSIVE\n\
  5769. if (vEmissiveInfos.x == 0.)\n\
  5770. {\n\
  5771. vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n\
  5772. }\n\
  5773. else\n\
  5774. {\n\
  5775. vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n\
  5776. }\n\
  5777. #endif\n\
  5778. #ifdef LIGHTMAP\n\
  5779. if (vLightmapInfos.x == 0.)\n\
  5780. {\n\
  5781. vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n\
  5782. }\n\
  5783. else\n\
  5784. {\n\
  5785. vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n\
  5786. }\n\
  5787. #endif\n\
  5788. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  5789. if (vSpecularInfos.x == 0.)\n\
  5790. {\n\
  5791. vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n\
  5792. }\n\
  5793. else\n\
  5794. {\n\
  5795. vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n\
  5796. }\n\
  5797. #endif\n\
  5798. #ifdef BUMP\n\
  5799. if (vBumpInfos.x == 0.)\n\
  5800. {\n\
  5801. vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n\
  5802. }\n\
  5803. else\n\
  5804. {\n\
  5805. vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n\
  5806. }\n\
  5807. #endif\n\
  5808. #include<bumpVertex>\n\
  5809. #include<clipPlaneVertex>\n\
  5810. #include<fogVertex>\n\
  5811. #include<shadowsVertex>[0..maxSimultaneousLights]\n\
  5812. #ifdef VERTEXCOLOR\n\
  5813. \n\
  5814. vColor=color;\n\
  5815. #endif\n\
  5816. #include<pointCloudVertex>\n\
  5817. #include<logDepthVertex>\n\
  5818. }";
  5819. return _this;
  5820. }
  5821. return ShaderForVer3_0;
  5822. }(CustomShaderStructure));
  5823. BABYLON.ShaderForVer3_0 = ShaderForVer3_0;
  5824. var StandardShaderVersions = /** @class */ (function () {
  5825. function StandardShaderVersions() {
  5826. }
  5827. StandardShaderVersions.Ver3_0 = "3.0.0";
  5828. return StandardShaderVersions;
  5829. }());
  5830. BABYLON.StandardShaderVersions = StandardShaderVersions;
  5831. var CustomMaterial = /** @class */ (function (_super) {
  5832. __extends(CustomMaterial, _super);
  5833. function CustomMaterial(name, scene) {
  5834. var _this = _super.call(this, name, scene) || this;
  5835. _this.CustomParts = new ShaderSpecialParts();
  5836. _this.customShaderNameResolve = _this.Builder;
  5837. _this.SelectVersion("3.0.0");
  5838. return _this;
  5839. }
  5840. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  5841. for (var el in this._newUniformInstances) {
  5842. var ea = el.toString().split('-');
  5843. if (ea[0] == 'vec2')
  5844. effect.setVector2(ea[1], this._newUniformInstances[el]);
  5845. else if (ea[0] == 'vec3')
  5846. effect.setVector3(ea[1], this._newUniformInstances[el]);
  5847. else if (ea[0] == 'vec4')
  5848. effect.setVector4(ea[1], this._newUniformInstances[el]);
  5849. else if (ea[0] == 'mat4')
  5850. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  5851. else if (ea[0] == 'float')
  5852. effect.setFloat(ea[1], this._newUniformInstances[el]);
  5853. }
  5854. for (var el in this._newSamplerInstances) {
  5855. var ea = el.toString().split('-');
  5856. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
  5857. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  5858. }
  5859. };
  5860. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  5861. if (name == "uniform") {
  5862. for (var ind in this._newUniforms)
  5863. if (this._customUniform[ind].indexOf('sampler') == -1)
  5864. arr.push(this._newUniforms[ind]);
  5865. }
  5866. if (name == "sampler") {
  5867. for (var ind in this._newUniforms)
  5868. if (this._customUniform[ind].indexOf('sampler') != -1)
  5869. arr.push(this._newUniforms[ind]);
  5870. }
  5871. return arr;
  5872. };
  5873. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  5874. var _this = this;
  5875. if (this._isCreatedShader)
  5876. return this._createdShaderName;
  5877. this._isCreatedShader = false;
  5878. CustomMaterial.ShaderIndexer++;
  5879. var name = "custom_" + CustomMaterial.ShaderIndexer;
  5880. this.ReviewUniform("uniform", uniforms);
  5881. this.ReviewUniform("sampler", samplers);
  5882. var fn_afterBind = this._afterBind.bind(this);
  5883. this._afterBind = function (m, e) {
  5884. if (!e) {
  5885. return;
  5886. }
  5887. _this.AttachAfterBind(m, e);
  5888. try {
  5889. fn_afterBind(m, e);
  5890. }
  5891. catch (e) { }
  5892. ;
  5893. };
  5894. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.ShaderVersion.VertexStore
  5895. .replace('#[Vertex_Begin]', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  5896. .replace('#[Vertex_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  5897. .replace('#[Vertex_MainBegin]', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  5898. .replace('#[Vertex_Before_PositionUpdated]', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  5899. .replace('#[Vertex_Before_NormalUpdated]', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  5900. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.ShaderVersion.FragmentStore
  5901. .replace('#[Fragment_Begin]', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  5902. .replace('#[Fragment_MainBegin]', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  5903. .replace('#[Fragment_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  5904. .replace('#[Fragment_Custom_Diffuse]', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  5905. .replace('#[Fragment_Custom_Alpha]', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  5906. .replace('#[Fragment_Before_FragColor]', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  5907. this._isCreatedShader = true;
  5908. this._createdShaderName = name;
  5909. return name;
  5910. };
  5911. CustomMaterial.prototype.SelectVersion = function (ver) {
  5912. switch (ver) {
  5913. case "3.0.0":
  5914. this.ShaderVersion = new ShaderForVer3_0();
  5915. break;
  5916. }
  5917. };
  5918. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  5919. if (!this._customUniform) {
  5920. this._customUniform = new Array();
  5921. this._newUniforms = new Array();
  5922. this._newSamplerInstances = new Array();
  5923. this._newUniformInstances = new Array();
  5924. }
  5925. if (param) {
  5926. if (kind.indexOf("sampler") == -1) {
  5927. this._newUniformInstances[kind + "-" + name] = param;
  5928. }
  5929. else {
  5930. this._newUniformInstances[kind + "-" + name] = param;
  5931. }
  5932. }
  5933. this._customUniform.push("uniform " + kind + " " + name + ";");
  5934. this._newUniforms.push(name);
  5935. return this;
  5936. };
  5937. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  5938. this.CustomParts.Fragment_Begin = shaderPart;
  5939. return this;
  5940. };
  5941. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  5942. this.CustomParts.Fragment_Definitions = shaderPart;
  5943. return this;
  5944. };
  5945. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  5946. this.CustomParts.Fragment_MainBegin = shaderPart;
  5947. return this;
  5948. };
  5949. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  5950. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  5951. return this;
  5952. };
  5953. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  5954. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  5955. return this;
  5956. };
  5957. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  5958. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  5959. return this;
  5960. };
  5961. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  5962. this.CustomParts.Vertex_Begin = shaderPart;
  5963. return this;
  5964. };
  5965. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  5966. this.CustomParts.Vertex_Definitions = shaderPart;
  5967. return this;
  5968. };
  5969. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  5970. this.CustomParts.Vertex_MainBegin = shaderPart;
  5971. return this;
  5972. };
  5973. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  5974. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  5975. return this;
  5976. };
  5977. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  5978. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  5979. return this;
  5980. };
  5981. CustomMaterial.ShaderIndexer = 1;
  5982. return CustomMaterial;
  5983. }(StandardMaterial_OldVer));
  5984. BABYLON.CustomMaterial = CustomMaterial;
  5985. })(BABYLON || (BABYLON = {}));
  5986. //# sourceMappingURL=babylon.customMaterial.js.map
  5987. var BABYLON;
  5988. (function (BABYLON) {
  5989. var CellMaterialDefines = /** @class */ (function (_super) {
  5990. __extends(CellMaterialDefines, _super);
  5991. function CellMaterialDefines() {
  5992. var _this = _super.call(this) || this;
  5993. _this.DIFFUSE = false;
  5994. _this.CLIPPLANE = false;
  5995. _this.ALPHATEST = false;
  5996. _this.POINTSIZE = false;
  5997. _this.FOG = false;
  5998. _this.NORMAL = false;
  5999. _this.UV1 = false;
  6000. _this.UV2 = false;
  6001. _this.VERTEXCOLOR = false;
  6002. _this.VERTEXALPHA = false;
  6003. _this.NUM_BONE_INFLUENCERS = 0;
  6004. _this.BonesPerMesh = 0;
  6005. _this.INSTANCES = false;
  6006. _this.NDOTL = true;
  6007. _this.CUSTOMUSERLIGHTING = true;
  6008. _this.CELLBASIC = true;
  6009. _this.DEPTHPREPASS = false;
  6010. _this.rebuild();
  6011. return _this;
  6012. }
  6013. return CellMaterialDefines;
  6014. }(BABYLON.MaterialDefines));
  6015. var CellMaterial = /** @class */ (function (_super) {
  6016. __extends(CellMaterial, _super);
  6017. function CellMaterial(name, scene) {
  6018. var _this = _super.call(this, name, scene) || this;
  6019. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  6020. _this._computeHighLevel = false;
  6021. _this._disableLighting = false;
  6022. _this._maxSimultaneousLights = 4;
  6023. return _this;
  6024. }
  6025. CellMaterial.prototype.needAlphaBlending = function () {
  6026. return (this.alpha < 1.0);
  6027. };
  6028. CellMaterial.prototype.needAlphaTesting = function () {
  6029. return false;
  6030. };
  6031. CellMaterial.prototype.getAlphaTestTexture = function () {
  6032. return null;
  6033. };
  6034. // Methods
  6035. CellMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  6036. if (this.isFrozen) {
  6037. if (this._wasPreviouslyReady && subMesh.effect) {
  6038. return true;
  6039. }
  6040. }
  6041. if (!subMesh._materialDefines) {
  6042. subMesh._materialDefines = new CellMaterialDefines();
  6043. }
  6044. var defines = subMesh._materialDefines;
  6045. var scene = this.getScene();
  6046. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  6047. if (this._renderId === scene.getRenderId()) {
  6048. return true;
  6049. }
  6050. }
  6051. var engine = scene.getEngine();
  6052. // Textures
  6053. if (defines._areTexturesDirty) {
  6054. defines._needUVs = false;
  6055. if (scene.texturesEnabled) {
  6056. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6057. if (!this._diffuseTexture.isReady()) {
  6058. return false;
  6059. }
  6060. else {
  6061. defines._needUVs = true;
  6062. defines.DIFFUSE = true;
  6063. }
  6064. }
  6065. }
  6066. }
  6067. // High level
  6068. defines.CELLBASIC = !this.computeHighLevel;
  6069. // Misc.
  6070. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  6071. // Lights
  6072. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  6073. // Values that need to be evaluated on every frame
  6074. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  6075. // Attribs
  6076. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  6077. // Get correct effect
  6078. if (defines.isDirty) {
  6079. defines.markAsProcessed();
  6080. scene.resetCachedMaterial();
  6081. // Fallbacks
  6082. var fallbacks = new BABYLON.EffectFallbacks();
  6083. if (defines.FOG) {
  6084. fallbacks.addFallback(1, "FOG");
  6085. }
  6086. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  6087. if (defines.NUM_BONE_INFLUENCERS > 0) {
  6088. fallbacks.addCPUSkinningFallback(0, mesh);
  6089. }
  6090. //Attributes
  6091. var attribs = [BABYLON.VertexBuffer.PositionKind];
  6092. if (defines.NORMAL) {
  6093. attribs.push(BABYLON.VertexBuffer.NormalKind);
  6094. }
  6095. if (defines.UV1) {
  6096. attribs.push(BABYLON.VertexBuffer.UVKind);
  6097. }
  6098. if (defines.UV2) {
  6099. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  6100. }
  6101. if (defines.VERTEXCOLOR) {
  6102. attribs.push(BABYLON.VertexBuffer.ColorKind);
  6103. }
  6104. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  6105. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  6106. var shaderName = "cell";
  6107. var join = defines.toString();
  6108. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  6109. "vFogInfos", "vFogColor", "pointSize",
  6110. "vDiffuseInfos",
  6111. "mBones",
  6112. "vClipPlane", "diffuseMatrix"
  6113. ];
  6114. var samplers = ["diffuseSampler"];
  6115. var uniformBuffers = new Array();
  6116. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  6117. uniformsNames: uniforms,
  6118. uniformBuffersNames: uniformBuffers,
  6119. samplers: samplers,
  6120. defines: defines,
  6121. maxSimultaneousLights: this.maxSimultaneousLights
  6122. });
  6123. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  6124. attributes: attribs,
  6125. uniformsNames: uniforms,
  6126. uniformBuffersNames: uniformBuffers,
  6127. samplers: samplers,
  6128. defines: join,
  6129. fallbacks: fallbacks,
  6130. onCompiled: this.onCompiled,
  6131. onError: this.onError,
  6132. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights - 1 }
  6133. }, engine), defines);
  6134. }
  6135. if (!subMesh.effect || !subMesh.effect.isReady()) {
  6136. return false;
  6137. }
  6138. this._renderId = scene.getRenderId();
  6139. this._wasPreviouslyReady = true;
  6140. return true;
  6141. };
  6142. CellMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  6143. var scene = this.getScene();
  6144. var defines = subMesh._materialDefines;
  6145. if (!defines) {
  6146. return;
  6147. }
  6148. var effect = subMesh.effect;
  6149. if (!effect) {
  6150. return;
  6151. }
  6152. this._activeEffect = effect;
  6153. // Matrices
  6154. this.bindOnlyWorldMatrix(world);
  6155. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  6156. // Bones
  6157. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  6158. if (this._mustRebind(scene, effect)) {
  6159. // Textures
  6160. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  6161. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  6162. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  6163. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  6164. }
  6165. // Clip plane
  6166. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  6167. // Point size
  6168. if (this.pointsCloud) {
  6169. this._activeEffect.setFloat("pointSize", this.pointSize);
  6170. }
  6171. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  6172. }
  6173. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  6174. // Lights
  6175. if (scene.lightsEnabled && !this.disableLighting) {
  6176. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
  6177. }
  6178. // View
  6179. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  6180. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  6181. }
  6182. // Fog
  6183. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  6184. this._afterBind(mesh, this._activeEffect);
  6185. };
  6186. CellMaterial.prototype.getAnimatables = function () {
  6187. var results = [];
  6188. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  6189. results.push(this._diffuseTexture);
  6190. }
  6191. return results;
  6192. };
  6193. CellMaterial.prototype.getActiveTextures = function () {
  6194. var activeTextures = _super.prototype.getActiveTextures.call(this);
  6195. if (this._diffuseTexture) {
  6196. activeTextures.push(this._diffuseTexture);
  6197. }
  6198. return activeTextures;
  6199. };
  6200. CellMaterial.prototype.hasTexture = function (texture) {
  6201. if (_super.prototype.hasTexture.call(this, texture)) {
  6202. return true;
  6203. }
  6204. return this._diffuseTexture === texture;
  6205. };
  6206. CellMaterial.prototype.dispose = function (forceDisposeEffect) {
  6207. if (this._diffuseTexture) {
  6208. this._diffuseTexture.dispose();
  6209. }
  6210. _super.prototype.dispose.call(this, forceDisposeEffect);
  6211. };
  6212. CellMaterial.prototype.getClassName = function () {
  6213. return "CellMaterial";
  6214. };
  6215. CellMaterial.prototype.clone = function (name) {
  6216. var _this = this;
  6217. return BABYLON.SerializationHelper.Clone(function () { return new CellMaterial(name, _this.getScene()); }, this);
  6218. };
  6219. CellMaterial.prototype.serialize = function () {
  6220. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  6221. serializationObject.customType = "BABYLON.CellMaterial";
  6222. return serializationObject;
  6223. };
  6224. // Statics
  6225. CellMaterial.Parse = function (source, scene, rootUrl) {
  6226. return BABYLON.SerializationHelper.Parse(function () { return new CellMaterial(source.name, scene); }, source, scene, rootUrl);
  6227. };
  6228. __decorate([
  6229. BABYLON.serializeAsTexture("diffuseTexture")
  6230. ], CellMaterial.prototype, "_diffuseTexture", void 0);
  6231. __decorate([
  6232. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6233. ], CellMaterial.prototype, "diffuseTexture", void 0);
  6234. __decorate([
  6235. BABYLON.serializeAsColor3("diffuse")
  6236. ], CellMaterial.prototype, "diffuseColor", void 0);
  6237. __decorate([
  6238. BABYLON.serialize("computeHighLevel")
  6239. ], CellMaterial.prototype, "_computeHighLevel", void 0);
  6240. __decorate([
  6241. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  6242. ], CellMaterial.prototype, "computeHighLevel", void 0);
  6243. __decorate([
  6244. BABYLON.serialize("disableLighting")
  6245. ], CellMaterial.prototype, "_disableLighting", void 0);
  6246. __decorate([
  6247. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  6248. ], CellMaterial.prototype, "disableLighting", void 0);
  6249. __decorate([
  6250. BABYLON.serialize("maxSimultaneousLights")
  6251. ], CellMaterial.prototype, "_maxSimultaneousLights", void 0);
  6252. __decorate([
  6253. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  6254. ], CellMaterial.prototype, "maxSimultaneousLights", void 0);
  6255. return CellMaterial;
  6256. }(BABYLON.PushMaterial));
  6257. BABYLON.CellMaterial = CellMaterial;
  6258. })(BABYLON || (BABYLON = {}));
  6259. //# sourceMappingURL=babylon.cellMaterial.js.map
  6260. BABYLON.Effect.ShadersStore['cellVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  6261. BABYLON.Effect.ShadersStore['cellPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{\ndiffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;\nif (info.ndl<0.5)\nlevel=0.5;\ndiffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];\nToonThresholds[0]=0.95;\nToonThresholds[1]=0.5;\nToonThresholds[2]=0.2;\nToonThresholds[3]=0.03;\nfloat ToonBrightnessLevels[5];\nToonBrightnessLevels[0]=1.0;\nToonBrightnessLevels[1]=0.8;\nToonBrightnessLevels[2]=0.6;\nToonBrightnessLevels[3]=0.35;\nToonBrightnessLevels[4]=0.2;\nif (info.ndl>ToonThresholds[0])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[0];\n}\nelse if (info.ndl>ToonThresholds[1])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[1];\n}\nelse if (info.ndl>ToonThresholds[2])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[2];\n}\nelse if (info.ndl>ToonThresholds[3])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[3];\n}\nelse\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[4];\n}\n#endif\nreturn max(diffuseBase,vec3(0.2));\n}\nvoid main(void)\n{\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nlightingInfo info;\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  6262. (function universalModuleDefinition(root, factory) {
  6263. var f = factory();
  6264. if (root && root["BABYLON"]) {
  6265. return;
  6266. }
  6267. if(typeof exports === 'object' && typeof module === 'object')
  6268. module.exports = f;
  6269. else if(typeof define === 'function' && define.amd)
  6270. define(["BJSMaterials"], factory);
  6271. else if(typeof exports === 'object')
  6272. exports["BJSMaterials"] = f;
  6273. else {
  6274. root["BABYLON"] = f;
  6275. }
  6276. })(this, function() {
  6277. return BABYLON;
  6278. });