Particles.shader 328 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237
  1. //<HASH>-1197523745</HASH>
  2. ////////////////////////////////////////
  3. // Generated with Better Shaders
  4. //
  5. // Auto-generated shader code, don't hand edit!
  6. //
  7. // Unity Version: 2021.3.0f1
  8. // Render Pipeline: URP2021
  9. // Platform: WindowsEditor
  10. ////////////////////////////////////////
  11. Shader "FLOW/Particles"
  12. {
  13. Properties
  14. {
  15. [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0
  16. [HideInInspector]_QueueControl("_QueueControl", Float) = -1
  17. [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
  18. [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
  19. [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
  20. [NoScaleOffset]_MainTex("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  21. [NoScaleOffset][Normal]_BumpMap("Normal (RGBA)", 2D) = "bump" {}
  22. [Header(SCALE)]
  23. _ScaleBase (" Base", Float) = 1
  24. _ScaleVolume (" Volume", Float) = 1
  25. [Header(STRETCH)]
  26. [Toggle(_STRETCH_ON)] _HasStretch (" Enabled", Float) = 0
  27. _StretchScale (" Scale", Float) = 5
  28. [Header(UNITY FOG)]
  29. [Toggle(DISABLEFOG)] _CW_DisableFog(" Disable", Float) = 0
  30. }
  31. SubShader
  32. {
  33. Tags { "RenderPipeline"="UniversalPipeline" "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" }
  34. Pass
  35. {
  36. Name "Universal Forward"
  37. Tags
  38. {
  39. "LightMode" = "UniversalForward"
  40. }
  41. Cull Back
  42. Blend One Zero
  43. ZTest LEqual
  44. ZWrite On
  45. Blend One Zero, One Zero
  46. Cull Back
  47. ZTest LEqual
  48. ZWrite On
  49. HLSLPROGRAM
  50. #pragma vertex Vert
  51. #pragma fragment Frag
  52. #pragma target 3.0
  53. #pragma prefer_hlslcc gles
  54. #pragma exclude_renderers d3d11_9x
  55. #pragma multi_compile_fog
  56. #pragma multi_compile_instancing
  57. #pragma instancing_options renderinglayer
  58. #pragma multi_compile _ DOTS_INSTANCING_ON
  59. // Keywords
  60. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  61. #pragma multi_compile _ LIGHTMAP_ON
  62. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  63. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  64. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  65. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  66. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  67. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  68. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
  69. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  70. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  71. #pragma multi_compile _ SHADOWS_SHADOWMASK
  72. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  73. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  74. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  75. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  76. #pragma multi_compile _ _CLUSTERED_RENDERING
  77. // GraphKeywords: <None>
  78. #define SHADER_PASS SHADERPASS_FORWARD
  79. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  80. #define _PASSFORWARD 1
  81. #define _FOG_FRAGMENT 1
  82. #include "Flow.cginc"
  83. #pragma shader_feature_local _ _STRETCH_ON
  84. #pragma shader_feature_local DISABLEFOG
  85. #define _URP 1
  86. #define _USINGTEXCOORD1 1
  87. #define _USINGTEXCOORD2 1
  88. // this has to be here or specular color will be ignored. Not in SG code
  89. #if _SIMPLELIT
  90. #define _SPECULAR_COLOR
  91. #endif
  92. // Includes
  93. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  94. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  95. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  96. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  97. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  98. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  99. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  100. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  101. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  102. #undef WorldNormalVector
  103. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  104. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  105. #define _WorldSpaceLightPos0 _MainLightPosition
  106. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  107. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  108. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  109. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  110. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  111. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  112. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  113. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  114. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  115. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  116. #if defined(UNITY_COMPILER_HLSL)
  117. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  118. #else
  119. #define UNITY_INITIALIZE_OUTPUT(type,name)
  120. #endif
  121. #define sampler2D_float sampler2D
  122. #define sampler2D_half sampler2D
  123. // data across stages, stripped like the above.
  124. struct VertexToPixel
  125. {
  126. float4 pos : SV_POSITION;
  127. float3 worldPos : TEXCOORD0;
  128. float3 worldNormal : TEXCOORD1;
  129. float4 worldTangent : TEXCOORD2;
  130. float4 texcoord0 : TEXCOORD3;
  131. float4 texcoord1 : TEXCOORD4;
  132. float4 texcoord2 : TEXCOORD5;
  133. // #if %TEXCOORD3REQUIREKEY%
  134. float4 texcoord3 : TEXCOORD6;
  135. // #endif
  136. // #if %SCREENPOSREQUIREKEY%
  137. float4 screenPos : TEXCOORD7;
  138. // #endif
  139. // #if %VERTEXCOLORREQUIREKEY%
  140. // half4 vertexColor : COLOR;
  141. // #endif
  142. #if defined(LIGHTMAP_ON)
  143. float2 lightmapUV : TEXCOORD8;
  144. #endif
  145. #if defined(DYNAMICLIGHTMAP_ON)
  146. float2 dynamicLightmapUV : TEXCOORD9;
  147. #endif
  148. #if !defined(LIGHTMAP_ON)
  149. float3 sh : TEXCOORD10;
  150. #endif
  151. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  152. float4 fogFactorAndVertexLight : TEXCOORD11;
  153. #endif
  154. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  155. float4 shadowCoord : TEXCOORD12;
  156. #endif
  157. // #if %EXTRAV2F0REQUIREKEY%
  158. // float4 extraV2F0 : TEXCOORD13;
  159. // #endif
  160. // #if %EXTRAV2F1REQUIREKEY%
  161. // float4 extraV2F1 : TEXCOORD14;
  162. // #endif
  163. // #if %EXTRAV2F2REQUIREKEY%
  164. // float4 extraV2F2 : TEXCOORD15;
  165. // #endif
  166. // #if %EXTRAV2F3REQUIREKEY%
  167. // float4 extraV2F3 : TEXCOORD16;
  168. // #endif
  169. // #if %EXTRAV2F4REQUIREKEY%
  170. // float4 extraV2F4 : TEXCOORD17;
  171. // #endif
  172. // #if %EXTRAV2F5REQUIREKEY%
  173. // float4 extraV2F5 : TEXCOORD18;
  174. // #endif
  175. // #if %EXTRAV2F6REQUIREKEY%
  176. // float4 extraV2F6 : TEXCOORD19;
  177. // #endif
  178. // #if %EXTRAV2F7REQUIREKEY%
  179. // float4 extraV2F7 : TEXCOORD20;
  180. // #endif
  181. #if UNITY_ANY_INSTANCING_ENABLED
  182. uint instanceID : CUSTOM_INSTANCE_ID;
  183. #endif
  184. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  185. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  186. #endif
  187. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  188. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  189. #endif
  190. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  191. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  192. #endif
  193. };
  194. // data describing the user output of a pixel
  195. struct Surface
  196. {
  197. half3 Albedo;
  198. half Height;
  199. half3 Normal;
  200. half Smoothness;
  201. half3 Emission;
  202. half Metallic;
  203. half3 Specular;
  204. half Occlusion;
  205. half SpecularPower; // for simple lighting
  206. half Alpha;
  207. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  208. // HDRP Only
  209. half SpecularOcclusion;
  210. half SubsurfaceMask;
  211. half Thickness;
  212. half CoatMask;
  213. half CoatSmoothness;
  214. half Anisotropy;
  215. half IridescenceMask;
  216. half IridescenceThickness;
  217. int DiffusionProfileHash;
  218. float SpecularAAThreshold;
  219. float SpecularAAScreenSpaceVariance;
  220. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  221. float3 DiffuseGI;
  222. float3 BackDiffuseGI;
  223. float3 SpecularGI;
  224. float ior;
  225. float3 transmittanceColor;
  226. float atDistance;
  227. float transmittanceMask;
  228. // requires _OVERRIDE_SHADOWMASK to be defines
  229. float4 ShadowMask;
  230. // for decals
  231. float NormalAlpha;
  232. float MAOSAlpha;
  233. };
  234. // Data the user declares in blackboard blocks
  235. struct Blackboard
  236. {
  237. float groundHeight;
  238. float surfaceHeight;
  239. float3 surfaceNormal;
  240. Fluid fluid;
  241. float blackboardDummyData;
  242. };
  243. // data the user might need, this will grow to be big. But easy to strip
  244. struct ShaderData
  245. {
  246. float4 clipPos; // SV_POSITION
  247. float3 localSpacePosition;
  248. float3 localSpaceNormal;
  249. float3 localSpaceTangent;
  250. float3 worldSpacePosition;
  251. float3 worldSpaceNormal;
  252. float3 worldSpaceTangent;
  253. float tangentSign;
  254. float3 worldSpaceViewDir;
  255. float3 tangentSpaceViewDir;
  256. float4 texcoord0;
  257. float4 texcoord1;
  258. float4 texcoord2;
  259. float4 texcoord3;
  260. float2 screenUV;
  261. float4 screenPos;
  262. float4 vertexColor;
  263. bool isFrontFace;
  264. float4 extraV2F0;
  265. float4 extraV2F1;
  266. float4 extraV2F2;
  267. float4 extraV2F3;
  268. float4 extraV2F4;
  269. float4 extraV2F5;
  270. float4 extraV2F6;
  271. float4 extraV2F7;
  272. float3x3 TBNMatrix;
  273. Blackboard blackboard;
  274. };
  275. struct VertexData
  276. {
  277. #if SHADER_TARGET > 30
  278. // uint vertexID : SV_VertexID;
  279. #endif
  280. float4 vertex : POSITION;
  281. float3 normal : NORMAL;
  282. float4 tangent : TANGENT;
  283. float4 texcoord0 : TEXCOORD0;
  284. // optimize out mesh coords when not in use by user or lighting system
  285. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  286. float4 texcoord1 : TEXCOORD1;
  287. #endif
  288. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  289. float4 texcoord2 : TEXCOORD2;
  290. #endif
  291. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  292. float4 texcoord1 : TEXCOORD1;
  293. #endif
  294. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  295. float4 texcoord2 : TEXCOORD2;
  296. #endif
  297. #if _HDRP
  298. float4 texcoord1 : TEXCOORD1;
  299. float4 texcoord2 : TEXCOORD2;
  300. #endif
  301. // #if %TEXCOORD3REQUIREKEY%
  302. float4 texcoord3 : TEXCOORD3;
  303. // #endif
  304. // #if %VERTEXCOLORREQUIREKEY%
  305. // float4 vertexColor : COLOR;
  306. // #endif
  307. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  308. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  309. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  310. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  311. #endif
  312. #endif
  313. UNITY_VERTEX_INPUT_INSTANCE_ID
  314. };
  315. struct TessVertex
  316. {
  317. float4 vertex : INTERNALTESSPOS;
  318. float3 normal : NORMAL;
  319. float4 tangent : TANGENT;
  320. float4 texcoord0 : TEXCOORD0;
  321. float4 texcoord1 : TEXCOORD1;
  322. float4 texcoord2 : TEXCOORD2;
  323. // #if %TEXCOORD3REQUIREKEY%
  324. float4 texcoord3 : TEXCOORD3;
  325. // #endif
  326. // #if %VERTEXCOLORREQUIREKEY%
  327. // float4 vertexColor : COLOR;
  328. // #endif
  329. // #if %EXTRAV2F0REQUIREKEY%
  330. // float4 extraV2F0 : TEXCOORD5;
  331. // #endif
  332. // #if %EXTRAV2F1REQUIREKEY%
  333. // float4 extraV2F1 : TEXCOORD6;
  334. // #endif
  335. // #if %EXTRAV2F2REQUIREKEY%
  336. // float4 extraV2F2 : TEXCOORD7;
  337. // #endif
  338. // #if %EXTRAV2F3REQUIREKEY%
  339. // float4 extraV2F3 : TEXCOORD8;
  340. // #endif
  341. // #if %EXTRAV2F4REQUIREKEY%
  342. // float4 extraV2F4 : TEXCOORD9;
  343. // #endif
  344. // #if %EXTRAV2F5REQUIREKEY%
  345. // float4 extraV2F5 : TEXCOORD10;
  346. // #endif
  347. // #if %EXTRAV2F6REQUIREKEY%
  348. // float4 extraV2F6 : TEXCOORD11;
  349. // #endif
  350. // #if %EXTRAV2F7REQUIREKEY%
  351. // float4 extraV2F7 : TEXCOORD12;
  352. // #endif
  353. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  354. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  355. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  356. float3 precomputedVelocity : TEXCOORD14;
  357. #endif
  358. #endif
  359. UNITY_VERTEX_INPUT_INSTANCE_ID
  360. UNITY_VERTEX_OUTPUT_STEREO
  361. };
  362. struct ExtraV2F
  363. {
  364. float4 extraV2F0;
  365. float4 extraV2F1;
  366. float4 extraV2F2;
  367. float4 extraV2F3;
  368. float4 extraV2F4;
  369. float4 extraV2F5;
  370. float4 extraV2F6;
  371. float4 extraV2F7;
  372. Blackboard blackboard;
  373. float4 time;
  374. };
  375. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  376. {
  377. return mul(d.TBNMatrix, normal);
  378. }
  379. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  380. {
  381. return mul(normal, d.TBNMatrix);
  382. }
  383. // in this case, make standard more like SRPs, because we can't fix
  384. // unity_WorldToObject in HDRP, since it already does macro-fu there
  385. #if _STANDARD
  386. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  387. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  388. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  389. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  390. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  391. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  392. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  393. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  394. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  395. #else
  396. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  397. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  398. #endif
  399. #undef GetWorldToObjectMatrix()
  400. #define GetWorldToObjectMatrix() unity_WorldToObject
  401. #endif
  402. float3 GetCameraWorldPosition()
  403. {
  404. #if _HDRP
  405. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  406. #else
  407. return _WorldSpaceCameraPos;
  408. #endif
  409. }
  410. #if _GRABPASSUSED
  411. #if _STANDARD
  412. TEXTURE2D(%GRABTEXTURE%);
  413. SAMPLER(sampler_%GRABTEXTURE%);
  414. #endif
  415. half3 GetSceneColor(float2 uv)
  416. {
  417. #if _STANDARD
  418. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  419. #else
  420. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  421. #endif
  422. }
  423. #endif
  424. #if _STANDARD
  425. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  426. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  427. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  428. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  429. #else
  430. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  431. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  432. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  433. #endif
  434. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  435. {
  436. float eye = GetLinearEyeDepth(uv);
  437. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  438. float dt = dot(worldSpaceViewDir, camView);
  439. float3 div = worldSpaceViewDir/dt;
  440. float3 wpos = (eye * div) + GetCameraWorldPosition();
  441. return wpos;
  442. }
  443. #if _HDRP
  444. float3 ObjectToWorldSpacePosition(float3 pos)
  445. {
  446. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  447. }
  448. #else
  449. float3 ObjectToWorldSpacePosition(float3 pos)
  450. {
  451. return TransformObjectToWorld(pos);
  452. }
  453. #endif
  454. #if _STANDARD
  455. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  456. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  457. {
  458. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  459. float3 norms = DecodeViewNormalStereo(depthNorms);
  460. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  461. return norms;
  462. }
  463. #elif _HDRP && !_DECALSHADER
  464. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  465. {
  466. NormalData nd;
  467. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  468. return nd.normalWS;
  469. }
  470. #elif _URP
  471. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  472. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  473. #endif
  474. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  475. {
  476. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  477. return SampleSceneNormals(uv);
  478. #else
  479. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  480. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  481. #endif
  482. }
  483. #endif
  484. #if _HDRP
  485. half3 UnpackNormalmapRGorAG(half4 packednormal)
  486. {
  487. // This do the trick
  488. packednormal.x *= packednormal.w;
  489. half3 normal;
  490. normal.xy = packednormal.xy * 2 - 1;
  491. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  492. return normal;
  493. }
  494. half3 UnpackNormal(half4 packednormal)
  495. {
  496. #if defined(UNITY_NO_DXT5nm)
  497. return packednormal.xyz * 2 - 1;
  498. #else
  499. return UnpackNormalmapRGorAG(packednormal);
  500. #endif
  501. }
  502. #endif
  503. #if _HDRP || _URP
  504. half3 UnpackScaleNormal(half4 packednormal, half scale)
  505. {
  506. #ifndef UNITY_NO_DXT5nm
  507. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  508. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  509. packednormal.x *= packednormal.w;
  510. #endif
  511. half3 normal;
  512. normal.xy = (packednormal.xy * 2 - 1) * scale;
  513. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  514. return normal;
  515. }
  516. #endif
  517. void GetSun(out float3 lightDir, out float3 color)
  518. {
  519. lightDir = float3(0.5, 0.5, 0);
  520. color = 1;
  521. #if _HDRP
  522. if (_DirectionalLightCount > 0)
  523. {
  524. DirectionalLightData light = _DirectionalLightDatas[0];
  525. lightDir = -light.forward.xyz;
  526. color = light.color;
  527. }
  528. #elif _STANDARD
  529. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  530. color = _LightColor0.rgb;
  531. #elif _URP
  532. Light light = GetMainLight();
  533. lightDir = light.direction;
  534. color = light.color;
  535. #endif
  536. }
  537. CBUFFER_START(UnityPerMaterial)
  538. float _FlowDensity;
  539. float2 _FlowSeparationXZ;
  540. float _FlowSimulationHeight;
  541. float _FlowCameraHeight;
  542. float2 _FlowCountXZ;
  543. float4 _FlowCoordU000;
  544. float4 _FlowCoord0V00;
  545. float _FlowSpeed;
  546. float4x4 _FlowMatrix;
  547. float _Sink;
  548. int2 _PartCountXY;
  549. float _FlowDelta;
  550. float _ScaleBase;
  551. float _ScaleVolume;
  552. float _StretchScale;
  553. CBUFFER_END
  554. #ifdef unity_WorldToObject
  555. #undef unity_WorldToObject
  556. #endif
  557. #ifdef unity_ObjectToWorld
  558. #undef unity_ObjectToWorld
  559. #endif
  560. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  561. #define unity_WorldToObject GetWorldToObjectMatrix()
  562. TEXTURE2D(_FlowDataA);
  563. SAMPLER(sampler_FlowDataA);
  564. TEXTURE2D(_FlowDataB);
  565. SAMPLER(sampler_FlowDataB);
  566. TEXTURE2D(_FlowDataC);
  567. SAMPLER(sampler_FlowDataC);
  568. TEXTURE2D(_FlowDataD);
  569. SAMPLER(sampler_FlowDataD);
  570. TEXTURE2D(_FlowDataE);
  571. SAMPLER(sampler_FlowDataE);
  572. TEXTURE2D(_FlowDataF);
  573. SAMPLER(sampler_FlowDataF);
  574. float4 SGT_O2W(float4 v)
  575. {
  576. v = mul(GetObjectToWorldMatrix(), v);
  577. #if _HDRP
  578. v.xyz = GetAbsolutePositionWS(v.xyz);
  579. #endif
  580. return v;
  581. }
  582. float4 SGT_W2O(float4 v)
  583. {
  584. #if _HDRP
  585. v.xyz = GetCameraRelativePositionWS(v.xyz);
  586. #endif
  587. return mul(GetWorldToObjectMatrix(), v);
  588. }
  589. float4 SGT_O2V(float4 v)
  590. {
  591. #if _STANDARD
  592. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  593. #else
  594. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  595. #endif
  596. }
  597. float GetFluidHeight(float2 uv)
  598. {
  599. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  600. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  601. return groundHeight + fluidDepth;
  602. }
  603. float2 GetHeightAndDepth(float2 uv)
  604. {
  605. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  606. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  607. return float2(groundHeight, fluidDepth);
  608. }
  609. Column GetColumn(float2 uv)
  610. {
  611. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  612. }
  613. Fluid GetColumnFluid(float2 uv)
  614. {
  615. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  616. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  617. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  618. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  619. return DecodeFluid(c, d, e, f);
  620. }
  621. bool InsideFluid(float3 wpos)
  622. {
  623. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  624. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  625. float2 columnHAD = GetHeightAndDepth(columnCoord);
  626. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  627. }
  628. bool UnderFluid(float3 wpos)
  629. {
  630. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  631. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  632. float2 columnHAD = GetHeightAndDepth(columnCoord);
  633. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  634. }
  635. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  636. {
  637. float epsi = step * 0.01f;
  638. float dist = 0.0f;
  639. for (int i = 0; i < maxs && step > epsi; i++)
  640. {
  641. dist += step;
  642. float3 pos = wpos + wdir * dist;
  643. if (InsideFluid(pos) == false)
  644. {
  645. dist -= step;
  646. step *= 0.5f;
  647. }
  648. if (dist > maxd)
  649. {
  650. return maxd;
  651. }
  652. }
  653. return dist;
  654. }
  655. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  656. {
  657. float epsi = step * 0.01f;
  658. float dist = 0.0f;
  659. for (int i = 0; i < maxs && step > epsi; i++)
  660. {
  661. dist += step;
  662. float3 pos = wpos + wdir * dist;
  663. if (UnderFluid(pos) == false)
  664. {
  665. dist -= step;
  666. step *= 0.5f;
  667. }
  668. if (dist > maxd)
  669. {
  670. return maxd;
  671. }
  672. }
  673. return dist;
  674. }
  675. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  676. {
  677. float4 wpos = SGT_O2W(v.vertex);
  678. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  679. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  680. Column column0 = GetColumn(columnCoord);
  681. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  682. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  683. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  684. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  685. Fluid fluid0 = GetColumnFluid(columnCoord);
  686. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  687. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  688. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  689. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  690. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  691. float wL = fluidL.Depth / ww;
  692. float wR = fluidR.Depth / ww;
  693. float wB = fluidB.Depth / ww;
  694. float wT = fluidT.Depth / ww;
  695. float w0 = saturate(fluid0.Depth * 10);
  696. float hL = columnL.GroundHeight + fluidL.Depth;
  697. float hR = columnR.GroundHeight + fluidR.Depth;
  698. float hB = columnB.GroundHeight + fluidB.Depth;
  699. float hT = columnT.GroundHeight + fluidT.Depth;
  700. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  701. float h0 = column0.GroundHeight + fluid0.Depth;
  702. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  703. Fluid fluid = fluid0;
  704. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  705. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  706. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  707. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  708. e.blackboard.groundHeight = column0.GroundHeight;
  709. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  710. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  711. e.blackboard.fluid = fluid;
  712. }
  713. TEXTURE2D(_MainTex);
  714. SAMPLER(sampler_MainTex);
  715. TEXTURE2D(_BumpMap);
  716. SAMPLER(sampler_BumpMap);
  717. TEXTURE2D(_PartDataA);
  718. SAMPLER(sampler_PartDataA);
  719. TEXTURE2D(_PartDataB);
  720. SAMPLER(sampler_PartDataB);
  721. TEXTURE2D(_PartDataC);
  722. SAMPLER(sampler_PartDataC);
  723. TEXTURE2D(_PartDataD);
  724. SAMPLER(sampler_PartDataD);
  725. TEXTURE2D(_PartDataE);
  726. SAMPLER(sampler_PartDataE);
  727. TEXTURE2D(_PartDataF);
  728. SAMPLER(sampler_PartDataF);
  729. Particle GetParticle(float2 uv)
  730. {
  731. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  732. }
  733. Fluid GetParticleFluid(float2 uv)
  734. {
  735. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  736. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  737. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  738. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  739. return DecodeFluid(c, d, e, f);
  740. }
  741. float2 Rotate(float2 v, float a)
  742. {
  743. float s = sin(a);
  744. float c = cos(a);
  745. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  746. }
  747. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  748. {
  749. float2 particlePixel = v.texcoord1.xy;
  750. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  751. Particle particle = GetParticle(particleCoord);
  752. Fluid fluid = GetParticleFluid(particleCoord);
  753. float size = particle.Age < particle.Life;
  754. float4 wpos = float4(particle.Position, 1.0f);
  755. float2 rvec = v.texcoord0.xy * size;
  756. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  757. #if _STRETCH_ON
  758. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  759. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  760. float2 posV = posB.xy - posA.xy;
  761. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  762. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  763. #endif
  764. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  765. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  766. v.vertex = SGT_W2O(wpos);
  767. v.normal = GetWorldToViewMatrix()[2].xyz;
  768. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  769. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  770. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  771. v.texcoord0 += 0.5f;
  772. v.texcoord1 = fluid.RGBA;
  773. v.texcoord2 = fluid.ESMV;
  774. }
  775. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  776. {
  777. Fluid fluid;
  778. fluid.RGBA = d.texcoord1;
  779. fluid.ESMV = d.texcoord2;
  780. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  781. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  782. //clip(texMain.a - 0.5f);
  783. float DITHER_THRESHOLDS[16] =
  784. {
  785. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  786. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  787. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  788. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  789. };
  790. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  791. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  792. clip(texMain.a - DITHER_THRESHOLDS[index]);
  793. o.Albedo = fluid.RGBA.xyz;
  794. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  795. o.Smoothness = fluid.ESMV.y;
  796. o.Metallic = fluid.ESMV.z;
  797. o.Normal = UnpackScaleNormal(bump, 1.0f);
  798. }
  799. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  800. {
  801. // Ext_SurfaceFunction0(l, d);
  802. Ext_SurfaceFunction1(l, d);
  803. // Ext_SurfaceFunction2(l, d);
  804. // Ext_SurfaceFunction3(l, d);
  805. // Ext_SurfaceFunction4(l, d);
  806. // Ext_SurfaceFunction5(l, d);
  807. // Ext_SurfaceFunction6(l, d);
  808. // Ext_SurfaceFunction7(l, d);
  809. // Ext_SurfaceFunction8(l, d);
  810. // Ext_SurfaceFunction9(l, d);
  811. // Ext_SurfaceFunction10(l, d);
  812. // Ext_SurfaceFunction11(l, d);
  813. // Ext_SurfaceFunction12(l, d);
  814. // Ext_SurfaceFunction13(l, d);
  815. // Ext_SurfaceFunction14(l, d);
  816. // Ext_SurfaceFunction15(l, d);
  817. // Ext_SurfaceFunction16(l, d);
  818. // Ext_SurfaceFunction17(l, d);
  819. // Ext_SurfaceFunction18(l, d);
  820. // Ext_SurfaceFunction19(l, d);
  821. // Ext_SurfaceFunction20(l, d);
  822. // Ext_SurfaceFunction21(l, d);
  823. // Ext_SurfaceFunction22(l, d);
  824. // Ext_SurfaceFunction23(l, d);
  825. // Ext_SurfaceFunction24(l, d);
  826. // Ext_SurfaceFunction25(l, d);
  827. // Ext_SurfaceFunction26(l, d);
  828. // Ext_SurfaceFunction27(l, d);
  829. // Ext_SurfaceFunction28(l, d);
  830. // Ext_SurfaceFunction29(l, d);
  831. }
  832. #if !_DECALSHADER
  833. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  834. {
  835. ExtraV2F d;
  836. ZERO_INITIALIZE(ExtraV2F, d);
  837. ZERO_INITIALIZE(Blackboard, d.blackboard);
  838. // due to motion vectors in HDRP, we need to use the last
  839. // time in certain spots. So if you are going to use _Time to adjust vertices,
  840. // you need to use this time or motion vectors will break.
  841. d.time = time;
  842. Ext_ModifyVertex0(v, d);
  843. Ext_ModifyVertex1(v, d);
  844. // Ext_ModifyVertex2(v, d);
  845. // Ext_ModifyVertex3(v, d);
  846. // Ext_ModifyVertex4(v, d);
  847. // Ext_ModifyVertex5(v, d);
  848. // Ext_ModifyVertex6(v, d);
  849. // Ext_ModifyVertex7(v, d);
  850. // Ext_ModifyVertex8(v, d);
  851. // Ext_ModifyVertex9(v, d);
  852. // Ext_ModifyVertex10(v, d);
  853. // Ext_ModifyVertex11(v, d);
  854. // Ext_ModifyVertex12(v, d);
  855. // Ext_ModifyVertex13(v, d);
  856. // Ext_ModifyVertex14(v, d);
  857. // Ext_ModifyVertex15(v, d);
  858. // Ext_ModifyVertex16(v, d);
  859. // Ext_ModifyVertex17(v, d);
  860. // Ext_ModifyVertex18(v, d);
  861. // Ext_ModifyVertex19(v, d);
  862. // Ext_ModifyVertex20(v, d);
  863. // Ext_ModifyVertex21(v, d);
  864. // Ext_ModifyVertex22(v, d);
  865. // Ext_ModifyVertex23(v, d);
  866. // Ext_ModifyVertex24(v, d);
  867. // Ext_ModifyVertex25(v, d);
  868. // Ext_ModifyVertex26(v, d);
  869. // Ext_ModifyVertex27(v, d);
  870. // Ext_ModifyVertex28(v, d);
  871. // Ext_ModifyVertex29(v, d);
  872. // #if %EXTRAV2F0REQUIREKEY%
  873. // v2p.extraV2F0 = d.extraV2F0;
  874. // #endif
  875. // #if %EXTRAV2F1REQUIREKEY%
  876. // v2p.extraV2F1 = d.extraV2F1;
  877. // #endif
  878. // #if %EXTRAV2F2REQUIREKEY%
  879. // v2p.extraV2F2 = d.extraV2F2;
  880. // #endif
  881. // #if %EXTRAV2F3REQUIREKEY%
  882. // v2p.extraV2F3 = d.extraV2F3;
  883. // #endif
  884. // #if %EXTRAV2F4REQUIREKEY%
  885. // v2p.extraV2F4 = d.extraV2F4;
  886. // #endif
  887. // #if %EXTRAV2F5REQUIREKEY%
  888. // v2p.extraV2F5 = d.extraV2F5;
  889. // #endif
  890. // #if %EXTRAV2F6REQUIREKEY%
  891. // v2p.extraV2F6 = d.extraV2F6;
  892. // #endif
  893. // #if %EXTRAV2F7REQUIREKEY%
  894. // v2p.extraV2F7 = d.extraV2F7;
  895. // #endif
  896. }
  897. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  898. {
  899. ExtraV2F d;
  900. ZERO_INITIALIZE(ExtraV2F, d);
  901. ZERO_INITIALIZE(Blackboard, d.blackboard);
  902. // #if %EXTRAV2F0REQUIREKEY%
  903. // d.extraV2F0 = v2p.extraV2F0;
  904. // #endif
  905. // #if %EXTRAV2F1REQUIREKEY%
  906. // d.extraV2F1 = v2p.extraV2F1;
  907. // #endif
  908. // #if %EXTRAV2F2REQUIREKEY%
  909. // d.extraV2F2 = v2p.extraV2F2;
  910. // #endif
  911. // #if %EXTRAV2F3REQUIREKEY%
  912. // d.extraV2F3 = v2p.extraV2F3;
  913. // #endif
  914. // #if %EXTRAV2F4REQUIREKEY%
  915. // d.extraV2F4 = v2p.extraV2F4;
  916. // #endif
  917. // #if %EXTRAV2F5REQUIREKEY%
  918. // d.extraV2F5 = v2p.extraV2F5;
  919. // #endif
  920. // #if %EXTRAV2F6REQUIREKEY%
  921. // d.extraV2F6 = v2p.extraV2F6;
  922. // #endif
  923. // #if %EXTRAV2F7REQUIREKEY%
  924. // d.extraV2F7 = v2p.extraV2F7;
  925. // #endif
  926. // Ext_ModifyTessellatedVertex0(v, d);
  927. // Ext_ModifyTessellatedVertex1(v, d);
  928. // Ext_ModifyTessellatedVertex2(v, d);
  929. // Ext_ModifyTessellatedVertex3(v, d);
  930. // Ext_ModifyTessellatedVertex4(v, d);
  931. // Ext_ModifyTessellatedVertex5(v, d);
  932. // Ext_ModifyTessellatedVertex6(v, d);
  933. // Ext_ModifyTessellatedVertex7(v, d);
  934. // Ext_ModifyTessellatedVertex8(v, d);
  935. // Ext_ModifyTessellatedVertex9(v, d);
  936. // Ext_ModifyTessellatedVertex10(v, d);
  937. // Ext_ModifyTessellatedVertex11(v, d);
  938. // Ext_ModifyTessellatedVertex12(v, d);
  939. // Ext_ModifyTessellatedVertex13(v, d);
  940. // Ext_ModifyTessellatedVertex14(v, d);
  941. // Ext_ModifyTessellatedVertex15(v, d);
  942. // Ext_ModifyTessellatedVertex16(v, d);
  943. // Ext_ModifyTessellatedVertex17(v, d);
  944. // Ext_ModifyTessellatedVertex18(v, d);
  945. // Ext_ModifyTessellatedVertex19(v, d);
  946. // Ext_ModifyTessellatedVertex20(v, d);
  947. // Ext_ModifyTessellatedVertex21(v, d);
  948. // Ext_ModifyTessellatedVertex22(v, d);
  949. // Ext_ModifyTessellatedVertex23(v, d);
  950. // Ext_ModifyTessellatedVertex24(v, d);
  951. // Ext_ModifyTessellatedVertex25(v, d);
  952. // Ext_ModifyTessellatedVertex26(v, d);
  953. // Ext_ModifyTessellatedVertex27(v, d);
  954. // Ext_ModifyTessellatedVertex28(v, d);
  955. // Ext_ModifyTessellatedVertex29(v, d);
  956. // #if %EXTRAV2F0REQUIREKEY%
  957. // v2p.extraV2F0 = d.extraV2F0;
  958. // #endif
  959. // #if %EXTRAV2F1REQUIREKEY%
  960. // v2p.extraV2F1 = d.extraV2F1;
  961. // #endif
  962. // #if %EXTRAV2F2REQUIREKEY%
  963. // v2p.extraV2F2 = d.extraV2F2;
  964. // #endif
  965. // #if %EXTRAV2F3REQUIREKEY%
  966. // v2p.extraV2F3 = d.extraV2F3;
  967. // #endif
  968. // #if %EXTRAV2F4REQUIREKEY%
  969. // v2p.extraV2F4 = d.extraV2F4;
  970. // #endif
  971. // #if %EXTRAV2F5REQUIREKEY%
  972. // v2p.extraV2F5 = d.extraV2F5;
  973. // #endif
  974. // #if %EXTRAV2F6REQUIREKEY%
  975. // v2p.extraV2F6 = d.extraV2F6;
  976. // #endif
  977. // #if %EXTRAV2F7REQUIREKEY%
  978. // v2p.extraV2F7 = d.extraV2F7;
  979. // #endif
  980. }
  981. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  982. {
  983. // Ext_FinalColorForward0(l, d, color);
  984. // Ext_FinalColorForward1(l, d, color);
  985. // Ext_FinalColorForward2(l, d, color);
  986. // Ext_FinalColorForward3(l, d, color);
  987. // Ext_FinalColorForward4(l, d, color);
  988. // Ext_FinalColorForward5(l, d, color);
  989. // Ext_FinalColorForward6(l, d, color);
  990. // Ext_FinalColorForward7(l, d, color);
  991. // Ext_FinalColorForward8(l, d, color);
  992. // Ext_FinalColorForward9(l, d, color);
  993. // Ext_FinalColorForward10(l, d, color);
  994. // Ext_FinalColorForward11(l, d, color);
  995. // Ext_FinalColorForward12(l, d, color);
  996. // Ext_FinalColorForward13(l, d, color);
  997. // Ext_FinalColorForward14(l, d, color);
  998. // Ext_FinalColorForward15(l, d, color);
  999. // Ext_FinalColorForward16(l, d, color);
  1000. // Ext_FinalColorForward17(l, d, color);
  1001. // Ext_FinalColorForward18(l, d, color);
  1002. // Ext_FinalColorForward19(l, d, color);
  1003. // Ext_FinalColorForward20(l, d, color);
  1004. // Ext_FinalColorForward21(l, d, color);
  1005. // Ext_FinalColorForward22(l, d, color);
  1006. // Ext_FinalColorForward23(l, d, color);
  1007. // Ext_FinalColorForward24(l, d, color);
  1008. // Ext_FinalColorForward25(l, d, color);
  1009. // Ext_FinalColorForward26(l, d, color);
  1010. // Ext_FinalColorForward27(l, d, color);
  1011. // Ext_FinalColorForward28(l, d, color);
  1012. // Ext_FinalColorForward29(l, d, color);
  1013. }
  1014. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  1015. {
  1016. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1017. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1018. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1019. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1020. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1021. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1022. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1023. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1024. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1025. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1026. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1027. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1028. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1029. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1030. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1031. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1032. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1033. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1034. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1035. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1036. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1037. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1038. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1039. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1040. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1041. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1042. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1043. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1044. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1045. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1046. }
  1047. #endif
  1048. #if _DECALSHADER
  1049. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  1050. {
  1051. ShaderData d = (ShaderData)0;
  1052. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  1053. d.worldSpaceNormal = IN.WorldSpaceNormal;
  1054. d.worldSpaceTangent = IN.WorldSpaceTangent;
  1055. d.worldSpacePosition = IN.WorldSpacePosition;
  1056. d.texcoord0 = IN.uv0.xyxy;
  1057. d.screenPos = IN.ScreenPosition;
  1058. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  1059. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  1060. // these rarely get used, so we back transform them. Usually will be stripped.
  1061. #if _HDRP
  1062. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  1063. #else
  1064. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  1065. #endif
  1066. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  1067. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  1068. // #if %SCREENPOSREQUIREKEY%
  1069. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  1070. // #endif
  1071. return d;
  1072. }
  1073. #else
  1074. ShaderData CreateShaderData(VertexToPixel i
  1075. #if NEED_FACING
  1076. , bool facing
  1077. #endif
  1078. )
  1079. {
  1080. ShaderData d = (ShaderData)0;
  1081. d.clipPos = i.pos;
  1082. d.worldSpacePosition = i.worldPos;
  1083. d.worldSpaceNormal = normalize(i.worldNormal);
  1084. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  1085. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  1086. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  1087. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  1088. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  1089. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  1090. d.texcoord0 = i.texcoord0;
  1091. d.texcoord1 = i.texcoord1;
  1092. d.texcoord2 = i.texcoord2;
  1093. // #if %TEXCOORD3REQUIREKEY%
  1094. d.texcoord3 = i.texcoord3;
  1095. // #endif
  1096. // d.isFrontFace = facing;
  1097. // #if %VERTEXCOLORREQUIREKEY%
  1098. // d.vertexColor = i.vertexColor;
  1099. // #endif
  1100. // these rarely get used, so we back transform them. Usually will be stripped.
  1101. #if _HDRP
  1102. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  1103. #else
  1104. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  1105. #endif
  1106. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  1107. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  1108. // #if %SCREENPOSREQUIREKEY%
  1109. d.screenPos = i.screenPos;
  1110. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  1111. // #endif
  1112. // #if %EXTRAV2F0REQUIREKEY%
  1113. // d.extraV2F0 = i.extraV2F0;
  1114. // #endif
  1115. // #if %EXTRAV2F1REQUIREKEY%
  1116. // d.extraV2F1 = i.extraV2F1;
  1117. // #endif
  1118. // #if %EXTRAV2F2REQUIREKEY%
  1119. // d.extraV2F2 = i.extraV2F2;
  1120. // #endif
  1121. // #if %EXTRAV2F3REQUIREKEY%
  1122. // d.extraV2F3 = i.extraV2F3;
  1123. // #endif
  1124. // #if %EXTRAV2F4REQUIREKEY%
  1125. // d.extraV2F4 = i.extraV2F4;
  1126. // #endif
  1127. // #if %EXTRAV2F5REQUIREKEY%
  1128. // d.extraV2F5 = i.extraV2F5;
  1129. // #endif
  1130. // #if %EXTRAV2F6REQUIREKEY%
  1131. // d.extraV2F6 = i.extraV2F6;
  1132. // #endif
  1133. // #if %EXTRAV2F7REQUIREKEY%
  1134. // d.extraV2F7 = i.extraV2F7;
  1135. // #endif
  1136. return d;
  1137. }
  1138. #endif
  1139. #if defined(_PASSSHADOW)
  1140. float3 _LightDirection;
  1141. float3 _LightPosition;
  1142. #endif
  1143. // vertex shader
  1144. VertexToPixel Vert (VertexData v)
  1145. {
  1146. VertexToPixel o = (VertexToPixel)0;
  1147. UNITY_SETUP_INSTANCE_ID(v);
  1148. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1149. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  1150. #if !_TESSELLATION_ON
  1151. ChainModifyVertex(v, o, _Time);
  1152. #endif
  1153. o.texcoord0 = v.texcoord0;
  1154. o.texcoord1 = v.texcoord1;
  1155. o.texcoord2 = v.texcoord2;
  1156. // #if %TEXCOORD3REQUIREKEY%
  1157. o.texcoord3 = v.texcoord3;
  1158. // #endif
  1159. // #if %VERTEXCOLORREQUIREKEY%
  1160. // o.vertexColor = v.vertexColor;
  1161. // #endif
  1162. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  1163. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  1164. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  1165. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  1166. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  1167. #if _PASSSHADOW
  1168. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  1169. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  1170. #else
  1171. float3 lightDirectionWS = _LightDirection;
  1172. #endif
  1173. // Define shadow pass specific clip position for Universal
  1174. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  1175. #if UNITY_REVERSED_Z
  1176. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  1177. #else
  1178. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  1179. #endif
  1180. #elif _PASSMETA
  1181. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  1182. #else
  1183. o.pos = TransformWorldToHClip(o.worldPos);
  1184. #endif
  1185. // #if %SCREENPOSREQUIREKEY%
  1186. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  1187. // #endif
  1188. #if _PASSFORWARD || _PASSGBUFFER
  1189. float2 uv1 = v.texcoord1.xy;
  1190. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  1191. o.texcoord1.xy = uv1;
  1192. OUTPUT_SH(o.worldNormal, o.sh);
  1193. #if defined(DYNAMICLIGHTMAP_ON)
  1194. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  1195. #endif
  1196. #endif
  1197. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  1198. half fogFactor = 0;
  1199. #if defined(_FOG_FRAGMENT)
  1200. fogFactor = ComputeFogFactor(o.pos.z);
  1201. #endif
  1202. #if _BAKEDLIT
  1203. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  1204. #else
  1205. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  1206. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  1207. #endif
  1208. #endif
  1209. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1210. o.shadowCoord = GetShadowCoord(vertexInput);
  1211. #endif
  1212. return o;
  1213. }
  1214. #if _UNLIT
  1215. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl"
  1216. #endif
  1217. // fragment shader
  1218. half4 Frag (VertexToPixel IN
  1219. #ifdef _DEPTHOFFSET_ON
  1220. , out float outputDepth : SV_Depth
  1221. #endif
  1222. #if NEED_FACING
  1223. , bool facing : SV_IsFrontFace
  1224. #endif
  1225. ) : SV_Target
  1226. {
  1227. UNITY_SETUP_INSTANCE_ID(IN);
  1228. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  1229. ShaderData d = CreateShaderData(IN
  1230. #if NEED_FACING
  1231. , facing
  1232. #endif
  1233. );
  1234. Surface l = (Surface)0;
  1235. #ifdef _DEPTHOFFSET_ON
  1236. l.outputDepth = outputDepth;
  1237. #endif
  1238. l.Albedo = half3(0.5, 0.5, 0.5);
  1239. l.Normal = float3(0,0,1);
  1240. l.Occlusion = 1;
  1241. l.Alpha = 1;
  1242. ChainSurfaceFunction(l, d);
  1243. #ifdef _DEPTHOFFSET_ON
  1244. outputDepth = l.outputDepth;
  1245. #endif
  1246. #if _USESPECULAR || _SIMPLELIT
  1247. float3 specular = l.Specular;
  1248. float metallic = 1;
  1249. #else
  1250. float3 specular = 0;
  1251. float metallic = l.Metallic;
  1252. #endif
  1253. InputData inputData = (InputData)0;
  1254. inputData.positionWS = IN.worldPos;
  1255. #if _WORLDSPACENORMAL
  1256. inputData.normalWS = l.Normal;
  1257. #else
  1258. inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal));
  1259. #endif
  1260. inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir);
  1261. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1262. inputData.shadowCoord = IN.shadowCoord;
  1263. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1264. inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos);
  1265. #else
  1266. inputData.shadowCoord = float4(0, 0, 0, 0);
  1267. #endif
  1268. #if _BAKEDLIT
  1269. inputData.fogCoord = IN.fogFactorAndVertexLight.x;
  1270. inputData.vertexLighting = 0;
  1271. #else
  1272. inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x);
  1273. inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  1274. #endif
  1275. #if defined(_OVERRIDE_BAKEDGI)
  1276. inputData.bakedGI = l.DiffuseGI;
  1277. l.Emission += l.SpecularGI;
  1278. #elif _BAKEDLIT
  1279. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
  1280. #else
  1281. #if defined(DYNAMICLIGHTMAP_ON)
  1282. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS);
  1283. #else
  1284. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
  1285. #endif
  1286. #endif
  1287. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos);
  1288. #if !_BAKEDLIT
  1289. inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV);
  1290. #if defined(_OVERRIDE_SHADOWMASK)
  1291. float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector));
  1292. inputData.shadowMask = mulColor;
  1293. #endif
  1294. #else
  1295. inputData.shadowMask = float4(1,1,1,1);
  1296. #endif
  1297. #if defined(DEBUG_DISPLAY)
  1298. #if defined(DYNAMICLIGHTMAP_ON)
  1299. inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy;
  1300. #endif
  1301. #if defined(LIGHTMAP_ON)
  1302. inputData.staticLightmapUV = IN.lightmapUV;
  1303. #else
  1304. inputData.vertexSH = IN.sh;
  1305. #endif
  1306. #endif
  1307. #if _WORLDSPACENORMAL
  1308. float3 normalTS = WorldToTangentSpace(d, l.Normal);
  1309. #else
  1310. float3 normalTS = l.Normal;
  1311. #endif
  1312. SurfaceData surface = (SurfaceData)0;
  1313. surface.albedo = l.Albedo;
  1314. surface.metallic = saturate(metallic);
  1315. surface.specular = specular;
  1316. surface.smoothness = saturate(l.Smoothness),
  1317. surface.occlusion = l.Occlusion,
  1318. surface.emission = l.Emission,
  1319. surface.alpha = saturate(l.Alpha);
  1320. surface.clearCoatMask = 0;
  1321. surface.clearCoatSmoothness = 1;
  1322. #ifdef _CLEARCOAT
  1323. surface.clearCoatMask = saturate(l.CoatMask);
  1324. surface.clearCoatSmoothness = saturate(l.CoatSmoothness);
  1325. #endif
  1326. #if !_UNLIT
  1327. half4 color = half4(l.Albedo, l.Alpha);
  1328. #ifdef _DBUFFER
  1329. #if _BAKEDLIT
  1330. half3 bakeColor = color.rgb;
  1331. float3 bakeNormal = inputData.normalWS.xyz;
  1332. ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal);
  1333. color.rgb = bakeColor;
  1334. inputData.normalWS.xyz = bakeNormal;
  1335. #else
  1336. ApplyDecalToSurfaceData(IN.pos, surface, inputData);
  1337. #endif
  1338. #endif
  1339. #if _SIMPLELIT
  1340. color = UniversalFragmentBlinnPhong(
  1341. inputData,
  1342. surface);
  1343. #elif _BAKEDLIT
  1344. color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS);
  1345. #else
  1346. color = UniversalFragmentPBR(inputData, surface);
  1347. #endif
  1348. #if !DISABLEFOG
  1349. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  1350. #endif
  1351. #else // unlit
  1352. #ifdef _DBUFFER
  1353. ApplyDecalToSurfaceData(IN.pos, surface, inputData);
  1354. #endif
  1355. half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha);
  1356. #if !DISABLEFOG
  1357. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  1358. #endif
  1359. #endif
  1360. ChainFinalColorForward(l, d, color);
  1361. return color;
  1362. }
  1363. ENDHLSL
  1364. }
  1365. Pass
  1366. {
  1367. Name "GBuffer"
  1368. Tags
  1369. {
  1370. "LightMode" = "UniversalGBuffer"
  1371. }
  1372. Blend One Zero
  1373. ZTest LEqual
  1374. ZWrite On
  1375. HLSLPROGRAM
  1376. #pragma vertex Vert
  1377. #pragma fragment Frag
  1378. #pragma target 3.0
  1379. #pragma prefer_hlslcc gles
  1380. #pragma exclude_renderers d3d11_9x
  1381. #pragma multi_compile_instancing
  1382. #pragma multi_compile_fog
  1383. #pragma instancing_options renderinglayer
  1384. #pragma multi_compile _ DOTS_INSTANCING_ON
  1385. #pragma multi_compile _ LIGHTMAP_ON
  1386. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  1387. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  1388. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  1389. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  1390. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
  1391. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  1392. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  1393. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  1394. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  1395. #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
  1396. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  1397. #pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
  1398. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  1399. #pragma multi_compile _ SHADOWS_SHADOWMASK
  1400. #define _FOG_FRAGMENT 1
  1401. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  1402. #define SHADERPASS SHADERPASS_GBUFFER
  1403. #define _PASSGBUFFER 1
  1404. #include "Flow.cginc"
  1405. #pragma shader_feature_local _ _STRETCH_ON
  1406. #pragma shader_feature_local DISABLEFOG
  1407. #define _URP 1
  1408. #define _USINGTEXCOORD1 1
  1409. #define _USINGTEXCOORD2 1
  1410. // Includes
  1411. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1412. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1413. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1414. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1415. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  1416. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  1417. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1418. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  1419. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  1420. #undef WorldNormalVector
  1421. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  1422. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  1423. #define _WorldSpaceLightPos0 _MainLightPosition
  1424. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  1425. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  1426. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  1427. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  1428. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  1429. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  1430. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  1431. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  1432. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  1433. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  1434. #if defined(UNITY_COMPILER_HLSL)
  1435. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  1436. #else
  1437. #define UNITY_INITIALIZE_OUTPUT(type,name)
  1438. #endif
  1439. #define sampler2D_float sampler2D
  1440. #define sampler2D_half sampler2D
  1441. // data across stages, stripped like the above.
  1442. struct VertexToPixel
  1443. {
  1444. float4 pos : SV_POSITION;
  1445. float3 worldPos : TEXCOORD0;
  1446. float3 worldNormal : TEXCOORD1;
  1447. float4 worldTangent : TEXCOORD2;
  1448. float4 texcoord0 : TEXCOORD3;
  1449. float4 texcoord1 : TEXCOORD4;
  1450. float4 texcoord2 : TEXCOORD5;
  1451. // #if %TEXCOORD3REQUIREKEY%
  1452. float4 texcoord3 : TEXCOORD6;
  1453. // #endif
  1454. // #if %SCREENPOSREQUIREKEY%
  1455. float4 screenPos : TEXCOORD7;
  1456. // #endif
  1457. // #if %VERTEXCOLORREQUIREKEY%
  1458. // half4 vertexColor : COLOR;
  1459. // #endif
  1460. #if defined(LIGHTMAP_ON)
  1461. float2 lightmapUV : TEXCOORD8;
  1462. #endif
  1463. #if defined(DYNAMICLIGHTMAP_ON)
  1464. float2 dynamicLightmapUV : TEXCOORD9;
  1465. #endif
  1466. #if !defined(LIGHTMAP_ON)
  1467. float3 sh : TEXCOORD10;
  1468. #endif
  1469. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  1470. float4 fogFactorAndVertexLight : TEXCOORD11;
  1471. #endif
  1472. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1473. float4 shadowCoord : TEXCOORD12;
  1474. #endif
  1475. // #if %EXTRAV2F0REQUIREKEY%
  1476. // float4 extraV2F0 : TEXCOORD13;
  1477. // #endif
  1478. // #if %EXTRAV2F1REQUIREKEY%
  1479. // float4 extraV2F1 : TEXCOORD14;
  1480. // #endif
  1481. // #if %EXTRAV2F2REQUIREKEY%
  1482. // float4 extraV2F2 : TEXCOORD15;
  1483. // #endif
  1484. // #if %EXTRAV2F3REQUIREKEY%
  1485. // float4 extraV2F3 : TEXCOORD16;
  1486. // #endif
  1487. // #if %EXTRAV2F4REQUIREKEY%
  1488. // float4 extraV2F4 : TEXCOORD17;
  1489. // #endif
  1490. // #if %EXTRAV2F5REQUIREKEY%
  1491. // float4 extraV2F5 : TEXCOORD18;
  1492. // #endif
  1493. // #if %EXTRAV2F6REQUIREKEY%
  1494. // float4 extraV2F6 : TEXCOORD19;
  1495. // #endif
  1496. // #if %EXTRAV2F7REQUIREKEY%
  1497. // float4 extraV2F7 : TEXCOORD20;
  1498. // #endif
  1499. #if UNITY_ANY_INSTANCING_ENABLED
  1500. uint instanceID : CUSTOM_INSTANCE_ID;
  1501. #endif
  1502. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  1503. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  1504. #endif
  1505. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  1506. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  1507. #endif
  1508. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  1509. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  1510. #endif
  1511. };
  1512. // data describing the user output of a pixel
  1513. struct Surface
  1514. {
  1515. half3 Albedo;
  1516. half Height;
  1517. half3 Normal;
  1518. half Smoothness;
  1519. half3 Emission;
  1520. half Metallic;
  1521. half3 Specular;
  1522. half Occlusion;
  1523. half SpecularPower; // for simple lighting
  1524. half Alpha;
  1525. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  1526. // HDRP Only
  1527. half SpecularOcclusion;
  1528. half SubsurfaceMask;
  1529. half Thickness;
  1530. half CoatMask;
  1531. half CoatSmoothness;
  1532. half Anisotropy;
  1533. half IridescenceMask;
  1534. half IridescenceThickness;
  1535. int DiffusionProfileHash;
  1536. float SpecularAAThreshold;
  1537. float SpecularAAScreenSpaceVariance;
  1538. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  1539. float3 DiffuseGI;
  1540. float3 BackDiffuseGI;
  1541. float3 SpecularGI;
  1542. float ior;
  1543. float3 transmittanceColor;
  1544. float atDistance;
  1545. float transmittanceMask;
  1546. // requires _OVERRIDE_SHADOWMASK to be defines
  1547. float4 ShadowMask;
  1548. // for decals
  1549. float NormalAlpha;
  1550. float MAOSAlpha;
  1551. };
  1552. // Data the user declares in blackboard blocks
  1553. struct Blackboard
  1554. {
  1555. float groundHeight;
  1556. float surfaceHeight;
  1557. float3 surfaceNormal;
  1558. Fluid fluid;
  1559. float blackboardDummyData;
  1560. };
  1561. // data the user might need, this will grow to be big. But easy to strip
  1562. struct ShaderData
  1563. {
  1564. float4 clipPos; // SV_POSITION
  1565. float3 localSpacePosition;
  1566. float3 localSpaceNormal;
  1567. float3 localSpaceTangent;
  1568. float3 worldSpacePosition;
  1569. float3 worldSpaceNormal;
  1570. float3 worldSpaceTangent;
  1571. float tangentSign;
  1572. float3 worldSpaceViewDir;
  1573. float3 tangentSpaceViewDir;
  1574. float4 texcoord0;
  1575. float4 texcoord1;
  1576. float4 texcoord2;
  1577. float4 texcoord3;
  1578. float2 screenUV;
  1579. float4 screenPos;
  1580. float4 vertexColor;
  1581. bool isFrontFace;
  1582. float4 extraV2F0;
  1583. float4 extraV2F1;
  1584. float4 extraV2F2;
  1585. float4 extraV2F3;
  1586. float4 extraV2F4;
  1587. float4 extraV2F5;
  1588. float4 extraV2F6;
  1589. float4 extraV2F7;
  1590. float3x3 TBNMatrix;
  1591. Blackboard blackboard;
  1592. };
  1593. struct VertexData
  1594. {
  1595. #if SHADER_TARGET > 30
  1596. // uint vertexID : SV_VertexID;
  1597. #endif
  1598. float4 vertex : POSITION;
  1599. float3 normal : NORMAL;
  1600. float4 tangent : TANGENT;
  1601. float4 texcoord0 : TEXCOORD0;
  1602. // optimize out mesh coords when not in use by user or lighting system
  1603. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  1604. float4 texcoord1 : TEXCOORD1;
  1605. #endif
  1606. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  1607. float4 texcoord2 : TEXCOORD2;
  1608. #endif
  1609. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  1610. float4 texcoord1 : TEXCOORD1;
  1611. #endif
  1612. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  1613. float4 texcoord2 : TEXCOORD2;
  1614. #endif
  1615. #if _HDRP
  1616. float4 texcoord1 : TEXCOORD1;
  1617. float4 texcoord2 : TEXCOORD2;
  1618. #endif
  1619. // #if %TEXCOORD3REQUIREKEY%
  1620. float4 texcoord3 : TEXCOORD3;
  1621. // #endif
  1622. // #if %VERTEXCOLORREQUIREKEY%
  1623. // float4 vertexColor : COLOR;
  1624. // #endif
  1625. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  1626. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  1627. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  1628. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  1629. #endif
  1630. #endif
  1631. UNITY_VERTEX_INPUT_INSTANCE_ID
  1632. };
  1633. struct TessVertex
  1634. {
  1635. float4 vertex : INTERNALTESSPOS;
  1636. float3 normal : NORMAL;
  1637. float4 tangent : TANGENT;
  1638. float4 texcoord0 : TEXCOORD0;
  1639. float4 texcoord1 : TEXCOORD1;
  1640. float4 texcoord2 : TEXCOORD2;
  1641. // #if %TEXCOORD3REQUIREKEY%
  1642. float4 texcoord3 : TEXCOORD3;
  1643. // #endif
  1644. // #if %VERTEXCOLORREQUIREKEY%
  1645. // float4 vertexColor : COLOR;
  1646. // #endif
  1647. // #if %EXTRAV2F0REQUIREKEY%
  1648. // float4 extraV2F0 : TEXCOORD5;
  1649. // #endif
  1650. // #if %EXTRAV2F1REQUIREKEY%
  1651. // float4 extraV2F1 : TEXCOORD6;
  1652. // #endif
  1653. // #if %EXTRAV2F2REQUIREKEY%
  1654. // float4 extraV2F2 : TEXCOORD7;
  1655. // #endif
  1656. // #if %EXTRAV2F3REQUIREKEY%
  1657. // float4 extraV2F3 : TEXCOORD8;
  1658. // #endif
  1659. // #if %EXTRAV2F4REQUIREKEY%
  1660. // float4 extraV2F4 : TEXCOORD9;
  1661. // #endif
  1662. // #if %EXTRAV2F5REQUIREKEY%
  1663. // float4 extraV2F5 : TEXCOORD10;
  1664. // #endif
  1665. // #if %EXTRAV2F6REQUIREKEY%
  1666. // float4 extraV2F6 : TEXCOORD11;
  1667. // #endif
  1668. // #if %EXTRAV2F7REQUIREKEY%
  1669. // float4 extraV2F7 : TEXCOORD12;
  1670. // #endif
  1671. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  1672. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  1673. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  1674. float3 precomputedVelocity : TEXCOORD14;
  1675. #endif
  1676. #endif
  1677. UNITY_VERTEX_INPUT_INSTANCE_ID
  1678. UNITY_VERTEX_OUTPUT_STEREO
  1679. };
  1680. struct ExtraV2F
  1681. {
  1682. float4 extraV2F0;
  1683. float4 extraV2F1;
  1684. float4 extraV2F2;
  1685. float4 extraV2F3;
  1686. float4 extraV2F4;
  1687. float4 extraV2F5;
  1688. float4 extraV2F6;
  1689. float4 extraV2F7;
  1690. Blackboard blackboard;
  1691. float4 time;
  1692. };
  1693. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  1694. {
  1695. return mul(d.TBNMatrix, normal);
  1696. }
  1697. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  1698. {
  1699. return mul(normal, d.TBNMatrix);
  1700. }
  1701. // in this case, make standard more like SRPs, because we can't fix
  1702. // unity_WorldToObject in HDRP, since it already does macro-fu there
  1703. #if _STANDARD
  1704. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  1705. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  1706. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  1707. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  1708. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  1709. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  1710. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  1711. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  1712. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  1713. #else
  1714. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  1715. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  1716. #endif
  1717. #undef GetWorldToObjectMatrix()
  1718. #define GetWorldToObjectMatrix() unity_WorldToObject
  1719. #endif
  1720. float3 GetCameraWorldPosition()
  1721. {
  1722. #if _HDRP
  1723. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  1724. #else
  1725. return _WorldSpaceCameraPos;
  1726. #endif
  1727. }
  1728. #if _GRABPASSUSED
  1729. #if _STANDARD
  1730. TEXTURE2D(%GRABTEXTURE%);
  1731. SAMPLER(sampler_%GRABTEXTURE%);
  1732. #endif
  1733. half3 GetSceneColor(float2 uv)
  1734. {
  1735. #if _STANDARD
  1736. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  1737. #else
  1738. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  1739. #endif
  1740. }
  1741. #endif
  1742. #if _STANDARD
  1743. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  1744. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  1745. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  1746. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  1747. #else
  1748. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  1749. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  1750. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  1751. #endif
  1752. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  1753. {
  1754. float eye = GetLinearEyeDepth(uv);
  1755. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  1756. float dt = dot(worldSpaceViewDir, camView);
  1757. float3 div = worldSpaceViewDir/dt;
  1758. float3 wpos = (eye * div) + GetCameraWorldPosition();
  1759. return wpos;
  1760. }
  1761. #if _HDRP
  1762. float3 ObjectToWorldSpacePosition(float3 pos)
  1763. {
  1764. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  1765. }
  1766. #else
  1767. float3 ObjectToWorldSpacePosition(float3 pos)
  1768. {
  1769. return TransformObjectToWorld(pos);
  1770. }
  1771. #endif
  1772. #if _STANDARD
  1773. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  1774. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1775. {
  1776. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  1777. float3 norms = DecodeViewNormalStereo(depthNorms);
  1778. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  1779. return norms;
  1780. }
  1781. #elif _HDRP && !_DECALSHADER
  1782. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1783. {
  1784. NormalData nd;
  1785. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  1786. return nd.normalWS;
  1787. }
  1788. #elif _URP
  1789. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  1790. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  1791. #endif
  1792. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1793. {
  1794. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  1795. return SampleSceneNormals(uv);
  1796. #else
  1797. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  1798. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  1799. #endif
  1800. }
  1801. #endif
  1802. #if _HDRP
  1803. half3 UnpackNormalmapRGorAG(half4 packednormal)
  1804. {
  1805. // This do the trick
  1806. packednormal.x *= packednormal.w;
  1807. half3 normal;
  1808. normal.xy = packednormal.xy * 2 - 1;
  1809. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  1810. return normal;
  1811. }
  1812. half3 UnpackNormal(half4 packednormal)
  1813. {
  1814. #if defined(UNITY_NO_DXT5nm)
  1815. return packednormal.xyz * 2 - 1;
  1816. #else
  1817. return UnpackNormalmapRGorAG(packednormal);
  1818. #endif
  1819. }
  1820. #endif
  1821. #if _HDRP || _URP
  1822. half3 UnpackScaleNormal(half4 packednormal, half scale)
  1823. {
  1824. #ifndef UNITY_NO_DXT5nm
  1825. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  1826. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  1827. packednormal.x *= packednormal.w;
  1828. #endif
  1829. half3 normal;
  1830. normal.xy = (packednormal.xy * 2 - 1) * scale;
  1831. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  1832. return normal;
  1833. }
  1834. #endif
  1835. void GetSun(out float3 lightDir, out float3 color)
  1836. {
  1837. lightDir = float3(0.5, 0.5, 0);
  1838. color = 1;
  1839. #if _HDRP
  1840. if (_DirectionalLightCount > 0)
  1841. {
  1842. DirectionalLightData light = _DirectionalLightDatas[0];
  1843. lightDir = -light.forward.xyz;
  1844. color = light.color;
  1845. }
  1846. #elif _STANDARD
  1847. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  1848. color = _LightColor0.rgb;
  1849. #elif _URP
  1850. Light light = GetMainLight();
  1851. lightDir = light.direction;
  1852. color = light.color;
  1853. #endif
  1854. }
  1855. CBUFFER_START(UnityPerMaterial)
  1856. float _FlowDensity;
  1857. float2 _FlowSeparationXZ;
  1858. float _FlowSimulationHeight;
  1859. float _FlowCameraHeight;
  1860. float2 _FlowCountXZ;
  1861. float4 _FlowCoordU000;
  1862. float4 _FlowCoord0V00;
  1863. float _FlowSpeed;
  1864. float4x4 _FlowMatrix;
  1865. float _Sink;
  1866. int2 _PartCountXY;
  1867. float _FlowDelta;
  1868. float _ScaleBase;
  1869. float _ScaleVolume;
  1870. float _StretchScale;
  1871. CBUFFER_END
  1872. #ifdef unity_WorldToObject
  1873. #undef unity_WorldToObject
  1874. #endif
  1875. #ifdef unity_ObjectToWorld
  1876. #undef unity_ObjectToWorld
  1877. #endif
  1878. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  1879. #define unity_WorldToObject GetWorldToObjectMatrix()
  1880. TEXTURE2D(_FlowDataA);
  1881. SAMPLER(sampler_FlowDataA);
  1882. TEXTURE2D(_FlowDataB);
  1883. SAMPLER(sampler_FlowDataB);
  1884. TEXTURE2D(_FlowDataC);
  1885. SAMPLER(sampler_FlowDataC);
  1886. TEXTURE2D(_FlowDataD);
  1887. SAMPLER(sampler_FlowDataD);
  1888. TEXTURE2D(_FlowDataE);
  1889. SAMPLER(sampler_FlowDataE);
  1890. TEXTURE2D(_FlowDataF);
  1891. SAMPLER(sampler_FlowDataF);
  1892. float4 SGT_O2W(float4 v)
  1893. {
  1894. v = mul(GetObjectToWorldMatrix(), v);
  1895. #if _HDRP
  1896. v.xyz = GetAbsolutePositionWS(v.xyz);
  1897. #endif
  1898. return v;
  1899. }
  1900. float4 SGT_W2O(float4 v)
  1901. {
  1902. #if _HDRP
  1903. v.xyz = GetCameraRelativePositionWS(v.xyz);
  1904. #endif
  1905. return mul(GetWorldToObjectMatrix(), v);
  1906. }
  1907. float4 SGT_O2V(float4 v)
  1908. {
  1909. #if _STANDARD
  1910. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  1911. #else
  1912. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  1913. #endif
  1914. }
  1915. float GetFluidHeight(float2 uv)
  1916. {
  1917. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  1918. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  1919. return groundHeight + fluidDepth;
  1920. }
  1921. float2 GetHeightAndDepth(float2 uv)
  1922. {
  1923. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  1924. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  1925. return float2(groundHeight, fluidDepth);
  1926. }
  1927. Column GetColumn(float2 uv)
  1928. {
  1929. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  1930. }
  1931. Fluid GetColumnFluid(float2 uv)
  1932. {
  1933. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  1934. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  1935. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  1936. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  1937. return DecodeFluid(c, d, e, f);
  1938. }
  1939. bool InsideFluid(float3 wpos)
  1940. {
  1941. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  1942. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  1943. float2 columnHAD = GetHeightAndDepth(columnCoord);
  1944. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  1945. }
  1946. bool UnderFluid(float3 wpos)
  1947. {
  1948. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  1949. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  1950. float2 columnHAD = GetHeightAndDepth(columnCoord);
  1951. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  1952. }
  1953. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  1954. {
  1955. float epsi = step * 0.01f;
  1956. float dist = 0.0f;
  1957. for (int i = 0; i < maxs && step > epsi; i++)
  1958. {
  1959. dist += step;
  1960. float3 pos = wpos + wdir * dist;
  1961. if (InsideFluid(pos) == false)
  1962. {
  1963. dist -= step;
  1964. step *= 0.5f;
  1965. }
  1966. if (dist > maxd)
  1967. {
  1968. return maxd;
  1969. }
  1970. }
  1971. return dist;
  1972. }
  1973. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  1974. {
  1975. float epsi = step * 0.01f;
  1976. float dist = 0.0f;
  1977. for (int i = 0; i < maxs && step > epsi; i++)
  1978. {
  1979. dist += step;
  1980. float3 pos = wpos + wdir * dist;
  1981. if (UnderFluid(pos) == false)
  1982. {
  1983. dist -= step;
  1984. step *= 0.5f;
  1985. }
  1986. if (dist > maxd)
  1987. {
  1988. return maxd;
  1989. }
  1990. }
  1991. return dist;
  1992. }
  1993. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  1994. {
  1995. float4 wpos = SGT_O2W(v.vertex);
  1996. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  1997. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  1998. Column column0 = GetColumn(columnCoord);
  1999. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  2000. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  2001. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  2002. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  2003. Fluid fluid0 = GetColumnFluid(columnCoord);
  2004. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  2005. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  2006. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  2007. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  2008. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  2009. float wL = fluidL.Depth / ww;
  2010. float wR = fluidR.Depth / ww;
  2011. float wB = fluidB.Depth / ww;
  2012. float wT = fluidT.Depth / ww;
  2013. float w0 = saturate(fluid0.Depth * 10);
  2014. float hL = columnL.GroundHeight + fluidL.Depth;
  2015. float hR = columnR.GroundHeight + fluidR.Depth;
  2016. float hB = columnB.GroundHeight + fluidB.Depth;
  2017. float hT = columnT.GroundHeight + fluidT.Depth;
  2018. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  2019. float h0 = column0.GroundHeight + fluid0.Depth;
  2020. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  2021. Fluid fluid = fluid0;
  2022. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  2023. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  2024. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  2025. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  2026. e.blackboard.groundHeight = column0.GroundHeight;
  2027. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  2028. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  2029. e.blackboard.fluid = fluid;
  2030. }
  2031. TEXTURE2D(_MainTex);
  2032. SAMPLER(sampler_MainTex);
  2033. TEXTURE2D(_BumpMap);
  2034. SAMPLER(sampler_BumpMap);
  2035. TEXTURE2D(_PartDataA);
  2036. SAMPLER(sampler_PartDataA);
  2037. TEXTURE2D(_PartDataB);
  2038. SAMPLER(sampler_PartDataB);
  2039. TEXTURE2D(_PartDataC);
  2040. SAMPLER(sampler_PartDataC);
  2041. TEXTURE2D(_PartDataD);
  2042. SAMPLER(sampler_PartDataD);
  2043. TEXTURE2D(_PartDataE);
  2044. SAMPLER(sampler_PartDataE);
  2045. TEXTURE2D(_PartDataF);
  2046. SAMPLER(sampler_PartDataF);
  2047. Particle GetParticle(float2 uv)
  2048. {
  2049. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  2050. }
  2051. Fluid GetParticleFluid(float2 uv)
  2052. {
  2053. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  2054. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  2055. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  2056. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  2057. return DecodeFluid(c, d, e, f);
  2058. }
  2059. float2 Rotate(float2 v, float a)
  2060. {
  2061. float s = sin(a);
  2062. float c = cos(a);
  2063. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  2064. }
  2065. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  2066. {
  2067. float2 particlePixel = v.texcoord1.xy;
  2068. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  2069. Particle particle = GetParticle(particleCoord);
  2070. Fluid fluid = GetParticleFluid(particleCoord);
  2071. float size = particle.Age < particle.Life;
  2072. float4 wpos = float4(particle.Position, 1.0f);
  2073. float2 rvec = v.texcoord0.xy * size;
  2074. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  2075. #if _STRETCH_ON
  2076. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  2077. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  2078. float2 posV = posB.xy - posA.xy;
  2079. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  2080. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  2081. #endif
  2082. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  2083. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  2084. v.vertex = SGT_W2O(wpos);
  2085. v.normal = GetWorldToViewMatrix()[2].xyz;
  2086. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  2087. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  2088. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  2089. v.texcoord0 += 0.5f;
  2090. v.texcoord1 = fluid.RGBA;
  2091. v.texcoord2 = fluid.ESMV;
  2092. }
  2093. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  2094. {
  2095. Fluid fluid;
  2096. fluid.RGBA = d.texcoord1;
  2097. fluid.ESMV = d.texcoord2;
  2098. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  2099. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  2100. //clip(texMain.a - 0.5f);
  2101. float DITHER_THRESHOLDS[16] =
  2102. {
  2103. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  2104. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  2105. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  2106. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  2107. };
  2108. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  2109. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  2110. clip(texMain.a - DITHER_THRESHOLDS[index]);
  2111. o.Albedo = fluid.RGBA.xyz;
  2112. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  2113. o.Smoothness = fluid.ESMV.y;
  2114. o.Metallic = fluid.ESMV.z;
  2115. o.Normal = UnpackScaleNormal(bump, 1.0f);
  2116. }
  2117. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  2118. {
  2119. // Ext_SurfaceFunction0(l, d);
  2120. Ext_SurfaceFunction1(l, d);
  2121. // Ext_SurfaceFunction2(l, d);
  2122. // Ext_SurfaceFunction3(l, d);
  2123. // Ext_SurfaceFunction4(l, d);
  2124. // Ext_SurfaceFunction5(l, d);
  2125. // Ext_SurfaceFunction6(l, d);
  2126. // Ext_SurfaceFunction7(l, d);
  2127. // Ext_SurfaceFunction8(l, d);
  2128. // Ext_SurfaceFunction9(l, d);
  2129. // Ext_SurfaceFunction10(l, d);
  2130. // Ext_SurfaceFunction11(l, d);
  2131. // Ext_SurfaceFunction12(l, d);
  2132. // Ext_SurfaceFunction13(l, d);
  2133. // Ext_SurfaceFunction14(l, d);
  2134. // Ext_SurfaceFunction15(l, d);
  2135. // Ext_SurfaceFunction16(l, d);
  2136. // Ext_SurfaceFunction17(l, d);
  2137. // Ext_SurfaceFunction18(l, d);
  2138. // Ext_SurfaceFunction19(l, d);
  2139. // Ext_SurfaceFunction20(l, d);
  2140. // Ext_SurfaceFunction21(l, d);
  2141. // Ext_SurfaceFunction22(l, d);
  2142. // Ext_SurfaceFunction23(l, d);
  2143. // Ext_SurfaceFunction24(l, d);
  2144. // Ext_SurfaceFunction25(l, d);
  2145. // Ext_SurfaceFunction26(l, d);
  2146. // Ext_SurfaceFunction27(l, d);
  2147. // Ext_SurfaceFunction28(l, d);
  2148. // Ext_SurfaceFunction29(l, d);
  2149. }
  2150. #if !_DECALSHADER
  2151. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  2152. {
  2153. ExtraV2F d;
  2154. ZERO_INITIALIZE(ExtraV2F, d);
  2155. ZERO_INITIALIZE(Blackboard, d.blackboard);
  2156. // due to motion vectors in HDRP, we need to use the last
  2157. // time in certain spots. So if you are going to use _Time to adjust vertices,
  2158. // you need to use this time or motion vectors will break.
  2159. d.time = time;
  2160. Ext_ModifyVertex0(v, d);
  2161. Ext_ModifyVertex1(v, d);
  2162. // Ext_ModifyVertex2(v, d);
  2163. // Ext_ModifyVertex3(v, d);
  2164. // Ext_ModifyVertex4(v, d);
  2165. // Ext_ModifyVertex5(v, d);
  2166. // Ext_ModifyVertex6(v, d);
  2167. // Ext_ModifyVertex7(v, d);
  2168. // Ext_ModifyVertex8(v, d);
  2169. // Ext_ModifyVertex9(v, d);
  2170. // Ext_ModifyVertex10(v, d);
  2171. // Ext_ModifyVertex11(v, d);
  2172. // Ext_ModifyVertex12(v, d);
  2173. // Ext_ModifyVertex13(v, d);
  2174. // Ext_ModifyVertex14(v, d);
  2175. // Ext_ModifyVertex15(v, d);
  2176. // Ext_ModifyVertex16(v, d);
  2177. // Ext_ModifyVertex17(v, d);
  2178. // Ext_ModifyVertex18(v, d);
  2179. // Ext_ModifyVertex19(v, d);
  2180. // Ext_ModifyVertex20(v, d);
  2181. // Ext_ModifyVertex21(v, d);
  2182. // Ext_ModifyVertex22(v, d);
  2183. // Ext_ModifyVertex23(v, d);
  2184. // Ext_ModifyVertex24(v, d);
  2185. // Ext_ModifyVertex25(v, d);
  2186. // Ext_ModifyVertex26(v, d);
  2187. // Ext_ModifyVertex27(v, d);
  2188. // Ext_ModifyVertex28(v, d);
  2189. // Ext_ModifyVertex29(v, d);
  2190. // #if %EXTRAV2F0REQUIREKEY%
  2191. // v2p.extraV2F0 = d.extraV2F0;
  2192. // #endif
  2193. // #if %EXTRAV2F1REQUIREKEY%
  2194. // v2p.extraV2F1 = d.extraV2F1;
  2195. // #endif
  2196. // #if %EXTRAV2F2REQUIREKEY%
  2197. // v2p.extraV2F2 = d.extraV2F2;
  2198. // #endif
  2199. // #if %EXTRAV2F3REQUIREKEY%
  2200. // v2p.extraV2F3 = d.extraV2F3;
  2201. // #endif
  2202. // #if %EXTRAV2F4REQUIREKEY%
  2203. // v2p.extraV2F4 = d.extraV2F4;
  2204. // #endif
  2205. // #if %EXTRAV2F5REQUIREKEY%
  2206. // v2p.extraV2F5 = d.extraV2F5;
  2207. // #endif
  2208. // #if %EXTRAV2F6REQUIREKEY%
  2209. // v2p.extraV2F6 = d.extraV2F6;
  2210. // #endif
  2211. // #if %EXTRAV2F7REQUIREKEY%
  2212. // v2p.extraV2F7 = d.extraV2F7;
  2213. // #endif
  2214. }
  2215. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  2216. {
  2217. ExtraV2F d;
  2218. ZERO_INITIALIZE(ExtraV2F, d);
  2219. ZERO_INITIALIZE(Blackboard, d.blackboard);
  2220. // #if %EXTRAV2F0REQUIREKEY%
  2221. // d.extraV2F0 = v2p.extraV2F0;
  2222. // #endif
  2223. // #if %EXTRAV2F1REQUIREKEY%
  2224. // d.extraV2F1 = v2p.extraV2F1;
  2225. // #endif
  2226. // #if %EXTRAV2F2REQUIREKEY%
  2227. // d.extraV2F2 = v2p.extraV2F2;
  2228. // #endif
  2229. // #if %EXTRAV2F3REQUIREKEY%
  2230. // d.extraV2F3 = v2p.extraV2F3;
  2231. // #endif
  2232. // #if %EXTRAV2F4REQUIREKEY%
  2233. // d.extraV2F4 = v2p.extraV2F4;
  2234. // #endif
  2235. // #if %EXTRAV2F5REQUIREKEY%
  2236. // d.extraV2F5 = v2p.extraV2F5;
  2237. // #endif
  2238. // #if %EXTRAV2F6REQUIREKEY%
  2239. // d.extraV2F6 = v2p.extraV2F6;
  2240. // #endif
  2241. // #if %EXTRAV2F7REQUIREKEY%
  2242. // d.extraV2F7 = v2p.extraV2F7;
  2243. // #endif
  2244. // Ext_ModifyTessellatedVertex0(v, d);
  2245. // Ext_ModifyTessellatedVertex1(v, d);
  2246. // Ext_ModifyTessellatedVertex2(v, d);
  2247. // Ext_ModifyTessellatedVertex3(v, d);
  2248. // Ext_ModifyTessellatedVertex4(v, d);
  2249. // Ext_ModifyTessellatedVertex5(v, d);
  2250. // Ext_ModifyTessellatedVertex6(v, d);
  2251. // Ext_ModifyTessellatedVertex7(v, d);
  2252. // Ext_ModifyTessellatedVertex8(v, d);
  2253. // Ext_ModifyTessellatedVertex9(v, d);
  2254. // Ext_ModifyTessellatedVertex10(v, d);
  2255. // Ext_ModifyTessellatedVertex11(v, d);
  2256. // Ext_ModifyTessellatedVertex12(v, d);
  2257. // Ext_ModifyTessellatedVertex13(v, d);
  2258. // Ext_ModifyTessellatedVertex14(v, d);
  2259. // Ext_ModifyTessellatedVertex15(v, d);
  2260. // Ext_ModifyTessellatedVertex16(v, d);
  2261. // Ext_ModifyTessellatedVertex17(v, d);
  2262. // Ext_ModifyTessellatedVertex18(v, d);
  2263. // Ext_ModifyTessellatedVertex19(v, d);
  2264. // Ext_ModifyTessellatedVertex20(v, d);
  2265. // Ext_ModifyTessellatedVertex21(v, d);
  2266. // Ext_ModifyTessellatedVertex22(v, d);
  2267. // Ext_ModifyTessellatedVertex23(v, d);
  2268. // Ext_ModifyTessellatedVertex24(v, d);
  2269. // Ext_ModifyTessellatedVertex25(v, d);
  2270. // Ext_ModifyTessellatedVertex26(v, d);
  2271. // Ext_ModifyTessellatedVertex27(v, d);
  2272. // Ext_ModifyTessellatedVertex28(v, d);
  2273. // Ext_ModifyTessellatedVertex29(v, d);
  2274. // #if %EXTRAV2F0REQUIREKEY%
  2275. // v2p.extraV2F0 = d.extraV2F0;
  2276. // #endif
  2277. // #if %EXTRAV2F1REQUIREKEY%
  2278. // v2p.extraV2F1 = d.extraV2F1;
  2279. // #endif
  2280. // #if %EXTRAV2F2REQUIREKEY%
  2281. // v2p.extraV2F2 = d.extraV2F2;
  2282. // #endif
  2283. // #if %EXTRAV2F3REQUIREKEY%
  2284. // v2p.extraV2F3 = d.extraV2F3;
  2285. // #endif
  2286. // #if %EXTRAV2F4REQUIREKEY%
  2287. // v2p.extraV2F4 = d.extraV2F4;
  2288. // #endif
  2289. // #if %EXTRAV2F5REQUIREKEY%
  2290. // v2p.extraV2F5 = d.extraV2F5;
  2291. // #endif
  2292. // #if %EXTRAV2F6REQUIREKEY%
  2293. // v2p.extraV2F6 = d.extraV2F6;
  2294. // #endif
  2295. // #if %EXTRAV2F7REQUIREKEY%
  2296. // v2p.extraV2F7 = d.extraV2F7;
  2297. // #endif
  2298. }
  2299. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  2300. {
  2301. // Ext_FinalColorForward0(l, d, color);
  2302. // Ext_FinalColorForward1(l, d, color);
  2303. // Ext_FinalColorForward2(l, d, color);
  2304. // Ext_FinalColorForward3(l, d, color);
  2305. // Ext_FinalColorForward4(l, d, color);
  2306. // Ext_FinalColorForward5(l, d, color);
  2307. // Ext_FinalColorForward6(l, d, color);
  2308. // Ext_FinalColorForward7(l, d, color);
  2309. // Ext_FinalColorForward8(l, d, color);
  2310. // Ext_FinalColorForward9(l, d, color);
  2311. // Ext_FinalColorForward10(l, d, color);
  2312. // Ext_FinalColorForward11(l, d, color);
  2313. // Ext_FinalColorForward12(l, d, color);
  2314. // Ext_FinalColorForward13(l, d, color);
  2315. // Ext_FinalColorForward14(l, d, color);
  2316. // Ext_FinalColorForward15(l, d, color);
  2317. // Ext_FinalColorForward16(l, d, color);
  2318. // Ext_FinalColorForward17(l, d, color);
  2319. // Ext_FinalColorForward18(l, d, color);
  2320. // Ext_FinalColorForward19(l, d, color);
  2321. // Ext_FinalColorForward20(l, d, color);
  2322. // Ext_FinalColorForward21(l, d, color);
  2323. // Ext_FinalColorForward22(l, d, color);
  2324. // Ext_FinalColorForward23(l, d, color);
  2325. // Ext_FinalColorForward24(l, d, color);
  2326. // Ext_FinalColorForward25(l, d, color);
  2327. // Ext_FinalColorForward26(l, d, color);
  2328. // Ext_FinalColorForward27(l, d, color);
  2329. // Ext_FinalColorForward28(l, d, color);
  2330. // Ext_FinalColorForward29(l, d, color);
  2331. }
  2332. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  2333. {
  2334. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2335. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2336. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2337. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2338. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2339. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2340. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2341. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2342. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2343. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2344. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2345. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2346. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2347. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2348. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2349. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2350. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2351. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2352. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2353. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2354. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2355. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2356. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2357. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2358. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2359. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2360. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2361. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2362. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2363. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2364. }
  2365. #endif
  2366. #if _DECALSHADER
  2367. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  2368. {
  2369. ShaderData d = (ShaderData)0;
  2370. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  2371. d.worldSpaceNormal = IN.WorldSpaceNormal;
  2372. d.worldSpaceTangent = IN.WorldSpaceTangent;
  2373. d.worldSpacePosition = IN.WorldSpacePosition;
  2374. d.texcoord0 = IN.uv0.xyxy;
  2375. d.screenPos = IN.ScreenPosition;
  2376. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  2377. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  2378. // these rarely get used, so we back transform them. Usually will be stripped.
  2379. #if _HDRP
  2380. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  2381. #else
  2382. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  2383. #endif
  2384. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  2385. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  2386. // #if %SCREENPOSREQUIREKEY%
  2387. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  2388. // #endif
  2389. return d;
  2390. }
  2391. #else
  2392. ShaderData CreateShaderData(VertexToPixel i
  2393. #if NEED_FACING
  2394. , bool facing
  2395. #endif
  2396. )
  2397. {
  2398. ShaderData d = (ShaderData)0;
  2399. d.clipPos = i.pos;
  2400. d.worldSpacePosition = i.worldPos;
  2401. d.worldSpaceNormal = normalize(i.worldNormal);
  2402. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  2403. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  2404. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  2405. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  2406. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  2407. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  2408. d.texcoord0 = i.texcoord0;
  2409. d.texcoord1 = i.texcoord1;
  2410. d.texcoord2 = i.texcoord2;
  2411. // #if %TEXCOORD3REQUIREKEY%
  2412. d.texcoord3 = i.texcoord3;
  2413. // #endif
  2414. // d.isFrontFace = facing;
  2415. // #if %VERTEXCOLORREQUIREKEY%
  2416. // d.vertexColor = i.vertexColor;
  2417. // #endif
  2418. // these rarely get used, so we back transform them. Usually will be stripped.
  2419. #if _HDRP
  2420. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  2421. #else
  2422. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  2423. #endif
  2424. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  2425. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  2426. // #if %SCREENPOSREQUIREKEY%
  2427. d.screenPos = i.screenPos;
  2428. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  2429. // #endif
  2430. // #if %EXTRAV2F0REQUIREKEY%
  2431. // d.extraV2F0 = i.extraV2F0;
  2432. // #endif
  2433. // #if %EXTRAV2F1REQUIREKEY%
  2434. // d.extraV2F1 = i.extraV2F1;
  2435. // #endif
  2436. // #if %EXTRAV2F2REQUIREKEY%
  2437. // d.extraV2F2 = i.extraV2F2;
  2438. // #endif
  2439. // #if %EXTRAV2F3REQUIREKEY%
  2440. // d.extraV2F3 = i.extraV2F3;
  2441. // #endif
  2442. // #if %EXTRAV2F4REQUIREKEY%
  2443. // d.extraV2F4 = i.extraV2F4;
  2444. // #endif
  2445. // #if %EXTRAV2F5REQUIREKEY%
  2446. // d.extraV2F5 = i.extraV2F5;
  2447. // #endif
  2448. // #if %EXTRAV2F6REQUIREKEY%
  2449. // d.extraV2F6 = i.extraV2F6;
  2450. // #endif
  2451. // #if %EXTRAV2F7REQUIREKEY%
  2452. // d.extraV2F7 = i.extraV2F7;
  2453. // #endif
  2454. return d;
  2455. }
  2456. #endif
  2457. #if defined(_PASSSHADOW)
  2458. float3 _LightDirection;
  2459. float3 _LightPosition;
  2460. #endif
  2461. // vertex shader
  2462. VertexToPixel Vert (VertexData v)
  2463. {
  2464. VertexToPixel o = (VertexToPixel)0;
  2465. UNITY_SETUP_INSTANCE_ID(v);
  2466. UNITY_TRANSFER_INSTANCE_ID(v, o);
  2467. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  2468. #if !_TESSELLATION_ON
  2469. ChainModifyVertex(v, o, _Time);
  2470. #endif
  2471. o.texcoord0 = v.texcoord0;
  2472. o.texcoord1 = v.texcoord1;
  2473. o.texcoord2 = v.texcoord2;
  2474. // #if %TEXCOORD3REQUIREKEY%
  2475. o.texcoord3 = v.texcoord3;
  2476. // #endif
  2477. // #if %VERTEXCOLORREQUIREKEY%
  2478. // o.vertexColor = v.vertexColor;
  2479. // #endif
  2480. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  2481. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  2482. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  2483. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  2484. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  2485. #if _PASSSHADOW
  2486. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  2487. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  2488. #else
  2489. float3 lightDirectionWS = _LightDirection;
  2490. #endif
  2491. // Define shadow pass specific clip position for Universal
  2492. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  2493. #if UNITY_REVERSED_Z
  2494. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  2495. #else
  2496. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  2497. #endif
  2498. #elif _PASSMETA
  2499. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  2500. #else
  2501. o.pos = TransformWorldToHClip(o.worldPos);
  2502. #endif
  2503. // #if %SCREENPOSREQUIREKEY%
  2504. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  2505. // #endif
  2506. #if _PASSFORWARD || _PASSGBUFFER
  2507. float2 uv1 = v.texcoord1.xy;
  2508. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  2509. o.texcoord1.xy = uv1;
  2510. OUTPUT_SH(o.worldNormal, o.sh);
  2511. #if defined(DYNAMICLIGHTMAP_ON)
  2512. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  2513. #endif
  2514. #endif
  2515. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2516. half fogFactor = 0;
  2517. #if defined(_FOG_FRAGMENT)
  2518. fogFactor = ComputeFogFactor(o.pos.z);
  2519. #endif
  2520. #if _BAKEDLIT
  2521. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  2522. #else
  2523. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  2524. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  2525. #endif
  2526. #endif
  2527. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  2528. o.shadowCoord = GetShadowCoord(vertexInput);
  2529. #endif
  2530. return o;
  2531. }
  2532. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
  2533. // fragment shader
  2534. FragmentOutput Frag (VertexToPixel IN
  2535. #ifdef _DEPTHOFFSET_ON
  2536. , out float outputDepth : SV_Depth
  2537. #endif
  2538. #if NEED_FACING
  2539. , bool facing : SV_IsFrontFace
  2540. #endif
  2541. )
  2542. {
  2543. UNITY_SETUP_INSTANCE_ID(IN);
  2544. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  2545. ShaderData d = CreateShaderData(IN
  2546. #if NEED_FACING
  2547. , facing
  2548. #endif
  2549. );
  2550. Surface l = (Surface)0;
  2551. #ifdef _DEPTHOFFSET_ON
  2552. l.outputDepth = outputDepth;
  2553. #endif
  2554. l.Albedo = half3(0.5, 0.5, 0.5);
  2555. l.Normal = float3(0,0,1);
  2556. l.Occlusion = 1;
  2557. l.Alpha = 1;
  2558. ChainSurfaceFunction(l, d);
  2559. #ifdef _DEPTHOFFSET_ON
  2560. outputDepth = l.outputDepth;
  2561. #endif
  2562. #if _USESPECULAR || _SIMPLELIT
  2563. float3 specular = l.Specular;
  2564. float metallic = 0;
  2565. #else
  2566. float3 specular = 0;
  2567. float metallic = l.Metallic;
  2568. #endif
  2569. InputData inputData = (InputData)0;
  2570. inputData.positionWS = IN.worldPos;
  2571. #if _WORLDSPACENORMAL
  2572. inputData.normalWS = l.Normal;
  2573. #else
  2574. inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal));
  2575. #endif
  2576. inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir);
  2577. #if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  2578. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  2579. #else
  2580. inputData.shadowCoord = float4(0, 0, 0, 0);
  2581. #endif
  2582. //inputData.fogCoord = IN.fogFactorAndVertexLight.x;
  2583. InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x);
  2584. inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  2585. #if defined(_OVERRIDE_BAKEDGI)
  2586. inputData.bakedGI = l.DiffuseGI;
  2587. l.Emission += l.SpecularGI;
  2588. #else
  2589. #if defined(DYNAMICLIGHTMAP_ON)
  2590. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS);
  2591. #else
  2592. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
  2593. #endif
  2594. #endif
  2595. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos);
  2596. inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV);
  2597. #if defined(DEBUG_DISPLAY)
  2598. #if defined(DYNAMICLIGHTMAP_ON)
  2599. inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy;
  2600. #endif
  2601. #if defined(LIGHTMAP_ON)
  2602. inputData.staticLightmapUV = IN.lightmapUV;
  2603. #else
  2604. inputData.vertexSH = IN.sh;
  2605. #endif
  2606. #endif
  2607. #ifdef _DBUFFER
  2608. ApplyDecal(IN.pos,
  2609. l.Albedo,
  2610. specular,
  2611. inputData.normalWS,
  2612. metallic,
  2613. l.Occlusion,
  2614. l.Smoothness);
  2615. #endif
  2616. BRDFData brdfData;
  2617. InitializeBRDFData(l.Albedo, metallic, specular, l.Smoothness, l.Alpha, brdfData);
  2618. Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
  2619. MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, inputData.shadowMask);
  2620. half3 color = GlobalIllumination(brdfData, inputData.bakedGI, l.Occlusion, inputData.positionWS, inputData.normalWS, inputData.viewDirectionWS);
  2621. return BRDFDataToGbuffer(brdfData, inputData, l.Smoothness, l.Emission + color, l.Occlusion);
  2622. }
  2623. ENDHLSL
  2624. }
  2625. Pass
  2626. {
  2627. Name "ShadowCaster"
  2628. Tags
  2629. {
  2630. "LightMode" = "ShadowCaster"
  2631. }
  2632. // Render State
  2633. Blend One Zero, One Zero
  2634. Cull Back
  2635. ZTest LEqual
  2636. ZWrite On
  2637. // ColorMask: <None>
  2638. HLSLPROGRAM
  2639. #pragma vertex Vert
  2640. #pragma fragment Frag
  2641. #pragma target 3.0
  2642. #pragma prefer_hlslcc gles
  2643. #pragma exclude_renderers d3d11_9x
  2644. #pragma multi_compile_instancing
  2645. #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
  2646. #define _NORMAL_DROPOFF_TS 1
  2647. #define ATTRIBUTES_NEED_NORMAL
  2648. #define ATTRIBUTES_NEED_TANGENT
  2649. #define _PASSSHADOW 1
  2650. #include "Flow.cginc"
  2651. #pragma shader_feature_local _ _STRETCH_ON
  2652. #pragma shader_feature_local DISABLEFOG
  2653. #define _URP 1
  2654. #define _USINGTEXCOORD1 1
  2655. #define _USINGTEXCOORD2 1
  2656. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  2657. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  2658. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2659. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  2660. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  2661. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  2662. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  2663. #undef WorldNormalVector
  2664. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  2665. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  2666. #define _WorldSpaceLightPos0 _MainLightPosition
  2667. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  2668. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  2669. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  2670. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  2671. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  2672. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  2673. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  2674. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  2675. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  2676. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  2677. #if defined(UNITY_COMPILER_HLSL)
  2678. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  2679. #else
  2680. #define UNITY_INITIALIZE_OUTPUT(type,name)
  2681. #endif
  2682. #define sampler2D_float sampler2D
  2683. #define sampler2D_half sampler2D
  2684. // data across stages, stripped like the above.
  2685. struct VertexToPixel
  2686. {
  2687. float4 pos : SV_POSITION;
  2688. float3 worldPos : TEXCOORD0;
  2689. float3 worldNormal : TEXCOORD1;
  2690. float4 worldTangent : TEXCOORD2;
  2691. float4 texcoord0 : TEXCOORD3;
  2692. float4 texcoord1 : TEXCOORD4;
  2693. float4 texcoord2 : TEXCOORD5;
  2694. // #if %TEXCOORD3REQUIREKEY%
  2695. float4 texcoord3 : TEXCOORD6;
  2696. // #endif
  2697. // #if %SCREENPOSREQUIREKEY%
  2698. float4 screenPos : TEXCOORD7;
  2699. // #endif
  2700. // #if %VERTEXCOLORREQUIREKEY%
  2701. // half4 vertexColor : COLOR;
  2702. // #endif
  2703. #if defined(LIGHTMAP_ON)
  2704. float2 lightmapUV : TEXCOORD8;
  2705. #endif
  2706. #if defined(DYNAMICLIGHTMAP_ON)
  2707. float2 dynamicLightmapUV : TEXCOORD9;
  2708. #endif
  2709. #if !defined(LIGHTMAP_ON)
  2710. float3 sh : TEXCOORD10;
  2711. #endif
  2712. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  2713. float4 fogFactorAndVertexLight : TEXCOORD11;
  2714. #endif
  2715. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  2716. float4 shadowCoord : TEXCOORD12;
  2717. #endif
  2718. // #if %EXTRAV2F0REQUIREKEY%
  2719. // float4 extraV2F0 : TEXCOORD13;
  2720. // #endif
  2721. // #if %EXTRAV2F1REQUIREKEY%
  2722. // float4 extraV2F1 : TEXCOORD14;
  2723. // #endif
  2724. // #if %EXTRAV2F2REQUIREKEY%
  2725. // float4 extraV2F2 : TEXCOORD15;
  2726. // #endif
  2727. // #if %EXTRAV2F3REQUIREKEY%
  2728. // float4 extraV2F3 : TEXCOORD16;
  2729. // #endif
  2730. // #if %EXTRAV2F4REQUIREKEY%
  2731. // float4 extraV2F4 : TEXCOORD17;
  2732. // #endif
  2733. // #if %EXTRAV2F5REQUIREKEY%
  2734. // float4 extraV2F5 : TEXCOORD18;
  2735. // #endif
  2736. // #if %EXTRAV2F6REQUIREKEY%
  2737. // float4 extraV2F6 : TEXCOORD19;
  2738. // #endif
  2739. // #if %EXTRAV2F7REQUIREKEY%
  2740. // float4 extraV2F7 : TEXCOORD20;
  2741. // #endif
  2742. #if UNITY_ANY_INSTANCING_ENABLED
  2743. uint instanceID : CUSTOM_INSTANCE_ID;
  2744. #endif
  2745. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  2746. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  2747. #endif
  2748. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  2749. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  2750. #endif
  2751. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  2752. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  2753. #endif
  2754. };
  2755. // data describing the user output of a pixel
  2756. struct Surface
  2757. {
  2758. half3 Albedo;
  2759. half Height;
  2760. half3 Normal;
  2761. half Smoothness;
  2762. half3 Emission;
  2763. half Metallic;
  2764. half3 Specular;
  2765. half Occlusion;
  2766. half SpecularPower; // for simple lighting
  2767. half Alpha;
  2768. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  2769. // HDRP Only
  2770. half SpecularOcclusion;
  2771. half SubsurfaceMask;
  2772. half Thickness;
  2773. half CoatMask;
  2774. half CoatSmoothness;
  2775. half Anisotropy;
  2776. half IridescenceMask;
  2777. half IridescenceThickness;
  2778. int DiffusionProfileHash;
  2779. float SpecularAAThreshold;
  2780. float SpecularAAScreenSpaceVariance;
  2781. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  2782. float3 DiffuseGI;
  2783. float3 BackDiffuseGI;
  2784. float3 SpecularGI;
  2785. float ior;
  2786. float3 transmittanceColor;
  2787. float atDistance;
  2788. float transmittanceMask;
  2789. // requires _OVERRIDE_SHADOWMASK to be defines
  2790. float4 ShadowMask;
  2791. // for decals
  2792. float NormalAlpha;
  2793. float MAOSAlpha;
  2794. };
  2795. // Data the user declares in blackboard blocks
  2796. struct Blackboard
  2797. {
  2798. float groundHeight;
  2799. float surfaceHeight;
  2800. float3 surfaceNormal;
  2801. Fluid fluid;
  2802. float blackboardDummyData;
  2803. };
  2804. // data the user might need, this will grow to be big. But easy to strip
  2805. struct ShaderData
  2806. {
  2807. float4 clipPos; // SV_POSITION
  2808. float3 localSpacePosition;
  2809. float3 localSpaceNormal;
  2810. float3 localSpaceTangent;
  2811. float3 worldSpacePosition;
  2812. float3 worldSpaceNormal;
  2813. float3 worldSpaceTangent;
  2814. float tangentSign;
  2815. float3 worldSpaceViewDir;
  2816. float3 tangentSpaceViewDir;
  2817. float4 texcoord0;
  2818. float4 texcoord1;
  2819. float4 texcoord2;
  2820. float4 texcoord3;
  2821. float2 screenUV;
  2822. float4 screenPos;
  2823. float4 vertexColor;
  2824. bool isFrontFace;
  2825. float4 extraV2F0;
  2826. float4 extraV2F1;
  2827. float4 extraV2F2;
  2828. float4 extraV2F3;
  2829. float4 extraV2F4;
  2830. float4 extraV2F5;
  2831. float4 extraV2F6;
  2832. float4 extraV2F7;
  2833. float3x3 TBNMatrix;
  2834. Blackboard blackboard;
  2835. };
  2836. struct VertexData
  2837. {
  2838. #if SHADER_TARGET > 30
  2839. // uint vertexID : SV_VertexID;
  2840. #endif
  2841. float4 vertex : POSITION;
  2842. float3 normal : NORMAL;
  2843. float4 tangent : TANGENT;
  2844. float4 texcoord0 : TEXCOORD0;
  2845. // optimize out mesh coords when not in use by user or lighting system
  2846. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  2847. float4 texcoord1 : TEXCOORD1;
  2848. #endif
  2849. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  2850. float4 texcoord2 : TEXCOORD2;
  2851. #endif
  2852. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  2853. float4 texcoord1 : TEXCOORD1;
  2854. #endif
  2855. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  2856. float4 texcoord2 : TEXCOORD2;
  2857. #endif
  2858. #if _HDRP
  2859. float4 texcoord1 : TEXCOORD1;
  2860. float4 texcoord2 : TEXCOORD2;
  2861. #endif
  2862. // #if %TEXCOORD3REQUIREKEY%
  2863. float4 texcoord3 : TEXCOORD3;
  2864. // #endif
  2865. // #if %VERTEXCOLORREQUIREKEY%
  2866. // float4 vertexColor : COLOR;
  2867. // #endif
  2868. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  2869. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  2870. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  2871. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  2872. #endif
  2873. #endif
  2874. UNITY_VERTEX_INPUT_INSTANCE_ID
  2875. };
  2876. struct TessVertex
  2877. {
  2878. float4 vertex : INTERNALTESSPOS;
  2879. float3 normal : NORMAL;
  2880. float4 tangent : TANGENT;
  2881. float4 texcoord0 : TEXCOORD0;
  2882. float4 texcoord1 : TEXCOORD1;
  2883. float4 texcoord2 : TEXCOORD2;
  2884. // #if %TEXCOORD3REQUIREKEY%
  2885. float4 texcoord3 : TEXCOORD3;
  2886. // #endif
  2887. // #if %VERTEXCOLORREQUIREKEY%
  2888. // float4 vertexColor : COLOR;
  2889. // #endif
  2890. // #if %EXTRAV2F0REQUIREKEY%
  2891. // float4 extraV2F0 : TEXCOORD5;
  2892. // #endif
  2893. // #if %EXTRAV2F1REQUIREKEY%
  2894. // float4 extraV2F1 : TEXCOORD6;
  2895. // #endif
  2896. // #if %EXTRAV2F2REQUIREKEY%
  2897. // float4 extraV2F2 : TEXCOORD7;
  2898. // #endif
  2899. // #if %EXTRAV2F3REQUIREKEY%
  2900. // float4 extraV2F3 : TEXCOORD8;
  2901. // #endif
  2902. // #if %EXTRAV2F4REQUIREKEY%
  2903. // float4 extraV2F4 : TEXCOORD9;
  2904. // #endif
  2905. // #if %EXTRAV2F5REQUIREKEY%
  2906. // float4 extraV2F5 : TEXCOORD10;
  2907. // #endif
  2908. // #if %EXTRAV2F6REQUIREKEY%
  2909. // float4 extraV2F6 : TEXCOORD11;
  2910. // #endif
  2911. // #if %EXTRAV2F7REQUIREKEY%
  2912. // float4 extraV2F7 : TEXCOORD12;
  2913. // #endif
  2914. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  2915. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  2916. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  2917. float3 precomputedVelocity : TEXCOORD14;
  2918. #endif
  2919. #endif
  2920. UNITY_VERTEX_INPUT_INSTANCE_ID
  2921. UNITY_VERTEX_OUTPUT_STEREO
  2922. };
  2923. struct ExtraV2F
  2924. {
  2925. float4 extraV2F0;
  2926. float4 extraV2F1;
  2927. float4 extraV2F2;
  2928. float4 extraV2F3;
  2929. float4 extraV2F4;
  2930. float4 extraV2F5;
  2931. float4 extraV2F6;
  2932. float4 extraV2F7;
  2933. Blackboard blackboard;
  2934. float4 time;
  2935. };
  2936. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  2937. {
  2938. return mul(d.TBNMatrix, normal);
  2939. }
  2940. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  2941. {
  2942. return mul(normal, d.TBNMatrix);
  2943. }
  2944. // in this case, make standard more like SRPs, because we can't fix
  2945. // unity_WorldToObject in HDRP, since it already does macro-fu there
  2946. #if _STANDARD
  2947. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  2948. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  2949. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  2950. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  2951. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  2952. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  2953. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  2954. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  2955. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  2956. #else
  2957. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  2958. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  2959. #endif
  2960. #undef GetWorldToObjectMatrix()
  2961. #define GetWorldToObjectMatrix() unity_WorldToObject
  2962. #endif
  2963. float3 GetCameraWorldPosition()
  2964. {
  2965. #if _HDRP
  2966. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  2967. #else
  2968. return _WorldSpaceCameraPos;
  2969. #endif
  2970. }
  2971. #if _GRABPASSUSED
  2972. #if _STANDARD
  2973. TEXTURE2D(%GRABTEXTURE%);
  2974. SAMPLER(sampler_%GRABTEXTURE%);
  2975. #endif
  2976. half3 GetSceneColor(float2 uv)
  2977. {
  2978. #if _STANDARD
  2979. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  2980. #else
  2981. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  2982. #endif
  2983. }
  2984. #endif
  2985. #if _STANDARD
  2986. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  2987. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  2988. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  2989. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  2990. #else
  2991. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  2992. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  2993. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  2994. #endif
  2995. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  2996. {
  2997. float eye = GetLinearEyeDepth(uv);
  2998. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  2999. float dt = dot(worldSpaceViewDir, camView);
  3000. float3 div = worldSpaceViewDir/dt;
  3001. float3 wpos = (eye * div) + GetCameraWorldPosition();
  3002. return wpos;
  3003. }
  3004. #if _HDRP
  3005. float3 ObjectToWorldSpacePosition(float3 pos)
  3006. {
  3007. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  3008. }
  3009. #else
  3010. float3 ObjectToWorldSpacePosition(float3 pos)
  3011. {
  3012. return TransformObjectToWorld(pos);
  3013. }
  3014. #endif
  3015. #if _STANDARD
  3016. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  3017. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3018. {
  3019. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  3020. float3 norms = DecodeViewNormalStereo(depthNorms);
  3021. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  3022. return norms;
  3023. }
  3024. #elif _HDRP && !_DECALSHADER
  3025. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3026. {
  3027. NormalData nd;
  3028. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  3029. return nd.normalWS;
  3030. }
  3031. #elif _URP
  3032. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  3033. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  3034. #endif
  3035. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3036. {
  3037. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  3038. return SampleSceneNormals(uv);
  3039. #else
  3040. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  3041. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  3042. #endif
  3043. }
  3044. #endif
  3045. #if _HDRP
  3046. half3 UnpackNormalmapRGorAG(half4 packednormal)
  3047. {
  3048. // This do the trick
  3049. packednormal.x *= packednormal.w;
  3050. half3 normal;
  3051. normal.xy = packednormal.xy * 2 - 1;
  3052. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  3053. return normal;
  3054. }
  3055. half3 UnpackNormal(half4 packednormal)
  3056. {
  3057. #if defined(UNITY_NO_DXT5nm)
  3058. return packednormal.xyz * 2 - 1;
  3059. #else
  3060. return UnpackNormalmapRGorAG(packednormal);
  3061. #endif
  3062. }
  3063. #endif
  3064. #if _HDRP || _URP
  3065. half3 UnpackScaleNormal(half4 packednormal, half scale)
  3066. {
  3067. #ifndef UNITY_NO_DXT5nm
  3068. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  3069. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  3070. packednormal.x *= packednormal.w;
  3071. #endif
  3072. half3 normal;
  3073. normal.xy = (packednormal.xy * 2 - 1) * scale;
  3074. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  3075. return normal;
  3076. }
  3077. #endif
  3078. void GetSun(out float3 lightDir, out float3 color)
  3079. {
  3080. lightDir = float3(0.5, 0.5, 0);
  3081. color = 1;
  3082. #if _HDRP
  3083. if (_DirectionalLightCount > 0)
  3084. {
  3085. DirectionalLightData light = _DirectionalLightDatas[0];
  3086. lightDir = -light.forward.xyz;
  3087. color = light.color;
  3088. }
  3089. #elif _STANDARD
  3090. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  3091. color = _LightColor0.rgb;
  3092. #elif _URP
  3093. Light light = GetMainLight();
  3094. lightDir = light.direction;
  3095. color = light.color;
  3096. #endif
  3097. }
  3098. CBUFFER_START(UnityPerMaterial)
  3099. float _FlowDensity;
  3100. float2 _FlowSeparationXZ;
  3101. float _FlowSimulationHeight;
  3102. float _FlowCameraHeight;
  3103. float2 _FlowCountXZ;
  3104. float4 _FlowCoordU000;
  3105. float4 _FlowCoord0V00;
  3106. float _FlowSpeed;
  3107. float4x4 _FlowMatrix;
  3108. float _Sink;
  3109. int2 _PartCountXY;
  3110. float _FlowDelta;
  3111. float _ScaleBase;
  3112. float _ScaleVolume;
  3113. float _StretchScale;
  3114. CBUFFER_END
  3115. #ifdef unity_WorldToObject
  3116. #undef unity_WorldToObject
  3117. #endif
  3118. #ifdef unity_ObjectToWorld
  3119. #undef unity_ObjectToWorld
  3120. #endif
  3121. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  3122. #define unity_WorldToObject GetWorldToObjectMatrix()
  3123. TEXTURE2D(_FlowDataA);
  3124. SAMPLER(sampler_FlowDataA);
  3125. TEXTURE2D(_FlowDataB);
  3126. SAMPLER(sampler_FlowDataB);
  3127. TEXTURE2D(_FlowDataC);
  3128. SAMPLER(sampler_FlowDataC);
  3129. TEXTURE2D(_FlowDataD);
  3130. SAMPLER(sampler_FlowDataD);
  3131. TEXTURE2D(_FlowDataE);
  3132. SAMPLER(sampler_FlowDataE);
  3133. TEXTURE2D(_FlowDataF);
  3134. SAMPLER(sampler_FlowDataF);
  3135. float4 SGT_O2W(float4 v)
  3136. {
  3137. v = mul(GetObjectToWorldMatrix(), v);
  3138. #if _HDRP
  3139. v.xyz = GetAbsolutePositionWS(v.xyz);
  3140. #endif
  3141. return v;
  3142. }
  3143. float4 SGT_W2O(float4 v)
  3144. {
  3145. #if _HDRP
  3146. v.xyz = GetCameraRelativePositionWS(v.xyz);
  3147. #endif
  3148. return mul(GetWorldToObjectMatrix(), v);
  3149. }
  3150. float4 SGT_O2V(float4 v)
  3151. {
  3152. #if _STANDARD
  3153. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  3154. #else
  3155. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  3156. #endif
  3157. }
  3158. float GetFluidHeight(float2 uv)
  3159. {
  3160. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  3161. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  3162. return groundHeight + fluidDepth;
  3163. }
  3164. float2 GetHeightAndDepth(float2 uv)
  3165. {
  3166. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  3167. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  3168. return float2(groundHeight, fluidDepth);
  3169. }
  3170. Column GetColumn(float2 uv)
  3171. {
  3172. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  3173. }
  3174. Fluid GetColumnFluid(float2 uv)
  3175. {
  3176. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  3177. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  3178. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  3179. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  3180. return DecodeFluid(c, d, e, f);
  3181. }
  3182. bool InsideFluid(float3 wpos)
  3183. {
  3184. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  3185. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  3186. float2 columnHAD = GetHeightAndDepth(columnCoord);
  3187. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  3188. }
  3189. bool UnderFluid(float3 wpos)
  3190. {
  3191. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  3192. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  3193. float2 columnHAD = GetHeightAndDepth(columnCoord);
  3194. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  3195. }
  3196. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  3197. {
  3198. float epsi = step * 0.01f;
  3199. float dist = 0.0f;
  3200. for (int i = 0; i < maxs && step > epsi; i++)
  3201. {
  3202. dist += step;
  3203. float3 pos = wpos + wdir * dist;
  3204. if (InsideFluid(pos) == false)
  3205. {
  3206. dist -= step;
  3207. step *= 0.5f;
  3208. }
  3209. if (dist > maxd)
  3210. {
  3211. return maxd;
  3212. }
  3213. }
  3214. return dist;
  3215. }
  3216. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  3217. {
  3218. float epsi = step * 0.01f;
  3219. float dist = 0.0f;
  3220. for (int i = 0; i < maxs && step > epsi; i++)
  3221. {
  3222. dist += step;
  3223. float3 pos = wpos + wdir * dist;
  3224. if (UnderFluid(pos) == false)
  3225. {
  3226. dist -= step;
  3227. step *= 0.5f;
  3228. }
  3229. if (dist > maxd)
  3230. {
  3231. return maxd;
  3232. }
  3233. }
  3234. return dist;
  3235. }
  3236. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  3237. {
  3238. float4 wpos = SGT_O2W(v.vertex);
  3239. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  3240. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  3241. Column column0 = GetColumn(columnCoord);
  3242. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  3243. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  3244. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  3245. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  3246. Fluid fluid0 = GetColumnFluid(columnCoord);
  3247. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  3248. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  3249. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  3250. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  3251. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  3252. float wL = fluidL.Depth / ww;
  3253. float wR = fluidR.Depth / ww;
  3254. float wB = fluidB.Depth / ww;
  3255. float wT = fluidT.Depth / ww;
  3256. float w0 = saturate(fluid0.Depth * 10);
  3257. float hL = columnL.GroundHeight + fluidL.Depth;
  3258. float hR = columnR.GroundHeight + fluidR.Depth;
  3259. float hB = columnB.GroundHeight + fluidB.Depth;
  3260. float hT = columnT.GroundHeight + fluidT.Depth;
  3261. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  3262. float h0 = column0.GroundHeight + fluid0.Depth;
  3263. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  3264. Fluid fluid = fluid0;
  3265. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  3266. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  3267. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  3268. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  3269. e.blackboard.groundHeight = column0.GroundHeight;
  3270. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  3271. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  3272. e.blackboard.fluid = fluid;
  3273. }
  3274. TEXTURE2D(_MainTex);
  3275. SAMPLER(sampler_MainTex);
  3276. TEXTURE2D(_BumpMap);
  3277. SAMPLER(sampler_BumpMap);
  3278. TEXTURE2D(_PartDataA);
  3279. SAMPLER(sampler_PartDataA);
  3280. TEXTURE2D(_PartDataB);
  3281. SAMPLER(sampler_PartDataB);
  3282. TEXTURE2D(_PartDataC);
  3283. SAMPLER(sampler_PartDataC);
  3284. TEXTURE2D(_PartDataD);
  3285. SAMPLER(sampler_PartDataD);
  3286. TEXTURE2D(_PartDataE);
  3287. SAMPLER(sampler_PartDataE);
  3288. TEXTURE2D(_PartDataF);
  3289. SAMPLER(sampler_PartDataF);
  3290. Particle GetParticle(float2 uv)
  3291. {
  3292. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  3293. }
  3294. Fluid GetParticleFluid(float2 uv)
  3295. {
  3296. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  3297. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  3298. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  3299. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  3300. return DecodeFluid(c, d, e, f);
  3301. }
  3302. float2 Rotate(float2 v, float a)
  3303. {
  3304. float s = sin(a);
  3305. float c = cos(a);
  3306. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  3307. }
  3308. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  3309. {
  3310. float2 particlePixel = v.texcoord1.xy;
  3311. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  3312. Particle particle = GetParticle(particleCoord);
  3313. Fluid fluid = GetParticleFluid(particleCoord);
  3314. float size = particle.Age < particle.Life;
  3315. float4 wpos = float4(particle.Position, 1.0f);
  3316. float2 rvec = v.texcoord0.xy * size;
  3317. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  3318. #if _STRETCH_ON
  3319. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  3320. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  3321. float2 posV = posB.xy - posA.xy;
  3322. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  3323. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  3324. #endif
  3325. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  3326. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  3327. v.vertex = SGT_W2O(wpos);
  3328. v.normal = GetWorldToViewMatrix()[2].xyz;
  3329. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  3330. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  3331. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  3332. v.texcoord0 += 0.5f;
  3333. v.texcoord1 = fluid.RGBA;
  3334. v.texcoord2 = fluid.ESMV;
  3335. }
  3336. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  3337. {
  3338. Fluid fluid;
  3339. fluid.RGBA = d.texcoord1;
  3340. fluid.ESMV = d.texcoord2;
  3341. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  3342. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  3343. //clip(texMain.a - 0.5f);
  3344. float DITHER_THRESHOLDS[16] =
  3345. {
  3346. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  3347. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  3348. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  3349. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  3350. };
  3351. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  3352. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  3353. clip(texMain.a - DITHER_THRESHOLDS[index]);
  3354. o.Albedo = fluid.RGBA.xyz;
  3355. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  3356. o.Smoothness = fluid.ESMV.y;
  3357. o.Metallic = fluid.ESMV.z;
  3358. o.Normal = UnpackScaleNormal(bump, 1.0f);
  3359. }
  3360. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  3361. {
  3362. // Ext_SurfaceFunction0(l, d);
  3363. Ext_SurfaceFunction1(l, d);
  3364. // Ext_SurfaceFunction2(l, d);
  3365. // Ext_SurfaceFunction3(l, d);
  3366. // Ext_SurfaceFunction4(l, d);
  3367. // Ext_SurfaceFunction5(l, d);
  3368. // Ext_SurfaceFunction6(l, d);
  3369. // Ext_SurfaceFunction7(l, d);
  3370. // Ext_SurfaceFunction8(l, d);
  3371. // Ext_SurfaceFunction9(l, d);
  3372. // Ext_SurfaceFunction10(l, d);
  3373. // Ext_SurfaceFunction11(l, d);
  3374. // Ext_SurfaceFunction12(l, d);
  3375. // Ext_SurfaceFunction13(l, d);
  3376. // Ext_SurfaceFunction14(l, d);
  3377. // Ext_SurfaceFunction15(l, d);
  3378. // Ext_SurfaceFunction16(l, d);
  3379. // Ext_SurfaceFunction17(l, d);
  3380. // Ext_SurfaceFunction18(l, d);
  3381. // Ext_SurfaceFunction19(l, d);
  3382. // Ext_SurfaceFunction20(l, d);
  3383. // Ext_SurfaceFunction21(l, d);
  3384. // Ext_SurfaceFunction22(l, d);
  3385. // Ext_SurfaceFunction23(l, d);
  3386. // Ext_SurfaceFunction24(l, d);
  3387. // Ext_SurfaceFunction25(l, d);
  3388. // Ext_SurfaceFunction26(l, d);
  3389. // Ext_SurfaceFunction27(l, d);
  3390. // Ext_SurfaceFunction28(l, d);
  3391. // Ext_SurfaceFunction29(l, d);
  3392. }
  3393. #if !_DECALSHADER
  3394. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  3395. {
  3396. ExtraV2F d;
  3397. ZERO_INITIALIZE(ExtraV2F, d);
  3398. ZERO_INITIALIZE(Blackboard, d.blackboard);
  3399. // due to motion vectors in HDRP, we need to use the last
  3400. // time in certain spots. So if you are going to use _Time to adjust vertices,
  3401. // you need to use this time or motion vectors will break.
  3402. d.time = time;
  3403. Ext_ModifyVertex0(v, d);
  3404. Ext_ModifyVertex1(v, d);
  3405. // Ext_ModifyVertex2(v, d);
  3406. // Ext_ModifyVertex3(v, d);
  3407. // Ext_ModifyVertex4(v, d);
  3408. // Ext_ModifyVertex5(v, d);
  3409. // Ext_ModifyVertex6(v, d);
  3410. // Ext_ModifyVertex7(v, d);
  3411. // Ext_ModifyVertex8(v, d);
  3412. // Ext_ModifyVertex9(v, d);
  3413. // Ext_ModifyVertex10(v, d);
  3414. // Ext_ModifyVertex11(v, d);
  3415. // Ext_ModifyVertex12(v, d);
  3416. // Ext_ModifyVertex13(v, d);
  3417. // Ext_ModifyVertex14(v, d);
  3418. // Ext_ModifyVertex15(v, d);
  3419. // Ext_ModifyVertex16(v, d);
  3420. // Ext_ModifyVertex17(v, d);
  3421. // Ext_ModifyVertex18(v, d);
  3422. // Ext_ModifyVertex19(v, d);
  3423. // Ext_ModifyVertex20(v, d);
  3424. // Ext_ModifyVertex21(v, d);
  3425. // Ext_ModifyVertex22(v, d);
  3426. // Ext_ModifyVertex23(v, d);
  3427. // Ext_ModifyVertex24(v, d);
  3428. // Ext_ModifyVertex25(v, d);
  3429. // Ext_ModifyVertex26(v, d);
  3430. // Ext_ModifyVertex27(v, d);
  3431. // Ext_ModifyVertex28(v, d);
  3432. // Ext_ModifyVertex29(v, d);
  3433. // #if %EXTRAV2F0REQUIREKEY%
  3434. // v2p.extraV2F0 = d.extraV2F0;
  3435. // #endif
  3436. // #if %EXTRAV2F1REQUIREKEY%
  3437. // v2p.extraV2F1 = d.extraV2F1;
  3438. // #endif
  3439. // #if %EXTRAV2F2REQUIREKEY%
  3440. // v2p.extraV2F2 = d.extraV2F2;
  3441. // #endif
  3442. // #if %EXTRAV2F3REQUIREKEY%
  3443. // v2p.extraV2F3 = d.extraV2F3;
  3444. // #endif
  3445. // #if %EXTRAV2F4REQUIREKEY%
  3446. // v2p.extraV2F4 = d.extraV2F4;
  3447. // #endif
  3448. // #if %EXTRAV2F5REQUIREKEY%
  3449. // v2p.extraV2F5 = d.extraV2F5;
  3450. // #endif
  3451. // #if %EXTRAV2F6REQUIREKEY%
  3452. // v2p.extraV2F6 = d.extraV2F6;
  3453. // #endif
  3454. // #if %EXTRAV2F7REQUIREKEY%
  3455. // v2p.extraV2F7 = d.extraV2F7;
  3456. // #endif
  3457. }
  3458. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  3459. {
  3460. ExtraV2F d;
  3461. ZERO_INITIALIZE(ExtraV2F, d);
  3462. ZERO_INITIALIZE(Blackboard, d.blackboard);
  3463. // #if %EXTRAV2F0REQUIREKEY%
  3464. // d.extraV2F0 = v2p.extraV2F0;
  3465. // #endif
  3466. // #if %EXTRAV2F1REQUIREKEY%
  3467. // d.extraV2F1 = v2p.extraV2F1;
  3468. // #endif
  3469. // #if %EXTRAV2F2REQUIREKEY%
  3470. // d.extraV2F2 = v2p.extraV2F2;
  3471. // #endif
  3472. // #if %EXTRAV2F3REQUIREKEY%
  3473. // d.extraV2F3 = v2p.extraV2F3;
  3474. // #endif
  3475. // #if %EXTRAV2F4REQUIREKEY%
  3476. // d.extraV2F4 = v2p.extraV2F4;
  3477. // #endif
  3478. // #if %EXTRAV2F5REQUIREKEY%
  3479. // d.extraV2F5 = v2p.extraV2F5;
  3480. // #endif
  3481. // #if %EXTRAV2F6REQUIREKEY%
  3482. // d.extraV2F6 = v2p.extraV2F6;
  3483. // #endif
  3484. // #if %EXTRAV2F7REQUIREKEY%
  3485. // d.extraV2F7 = v2p.extraV2F7;
  3486. // #endif
  3487. // Ext_ModifyTessellatedVertex0(v, d);
  3488. // Ext_ModifyTessellatedVertex1(v, d);
  3489. // Ext_ModifyTessellatedVertex2(v, d);
  3490. // Ext_ModifyTessellatedVertex3(v, d);
  3491. // Ext_ModifyTessellatedVertex4(v, d);
  3492. // Ext_ModifyTessellatedVertex5(v, d);
  3493. // Ext_ModifyTessellatedVertex6(v, d);
  3494. // Ext_ModifyTessellatedVertex7(v, d);
  3495. // Ext_ModifyTessellatedVertex8(v, d);
  3496. // Ext_ModifyTessellatedVertex9(v, d);
  3497. // Ext_ModifyTessellatedVertex10(v, d);
  3498. // Ext_ModifyTessellatedVertex11(v, d);
  3499. // Ext_ModifyTessellatedVertex12(v, d);
  3500. // Ext_ModifyTessellatedVertex13(v, d);
  3501. // Ext_ModifyTessellatedVertex14(v, d);
  3502. // Ext_ModifyTessellatedVertex15(v, d);
  3503. // Ext_ModifyTessellatedVertex16(v, d);
  3504. // Ext_ModifyTessellatedVertex17(v, d);
  3505. // Ext_ModifyTessellatedVertex18(v, d);
  3506. // Ext_ModifyTessellatedVertex19(v, d);
  3507. // Ext_ModifyTessellatedVertex20(v, d);
  3508. // Ext_ModifyTessellatedVertex21(v, d);
  3509. // Ext_ModifyTessellatedVertex22(v, d);
  3510. // Ext_ModifyTessellatedVertex23(v, d);
  3511. // Ext_ModifyTessellatedVertex24(v, d);
  3512. // Ext_ModifyTessellatedVertex25(v, d);
  3513. // Ext_ModifyTessellatedVertex26(v, d);
  3514. // Ext_ModifyTessellatedVertex27(v, d);
  3515. // Ext_ModifyTessellatedVertex28(v, d);
  3516. // Ext_ModifyTessellatedVertex29(v, d);
  3517. // #if %EXTRAV2F0REQUIREKEY%
  3518. // v2p.extraV2F0 = d.extraV2F0;
  3519. // #endif
  3520. // #if %EXTRAV2F1REQUIREKEY%
  3521. // v2p.extraV2F1 = d.extraV2F1;
  3522. // #endif
  3523. // #if %EXTRAV2F2REQUIREKEY%
  3524. // v2p.extraV2F2 = d.extraV2F2;
  3525. // #endif
  3526. // #if %EXTRAV2F3REQUIREKEY%
  3527. // v2p.extraV2F3 = d.extraV2F3;
  3528. // #endif
  3529. // #if %EXTRAV2F4REQUIREKEY%
  3530. // v2p.extraV2F4 = d.extraV2F4;
  3531. // #endif
  3532. // #if %EXTRAV2F5REQUIREKEY%
  3533. // v2p.extraV2F5 = d.extraV2F5;
  3534. // #endif
  3535. // #if %EXTRAV2F6REQUIREKEY%
  3536. // v2p.extraV2F6 = d.extraV2F6;
  3537. // #endif
  3538. // #if %EXTRAV2F7REQUIREKEY%
  3539. // v2p.extraV2F7 = d.extraV2F7;
  3540. // #endif
  3541. }
  3542. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  3543. {
  3544. // Ext_FinalColorForward0(l, d, color);
  3545. // Ext_FinalColorForward1(l, d, color);
  3546. // Ext_FinalColorForward2(l, d, color);
  3547. // Ext_FinalColorForward3(l, d, color);
  3548. // Ext_FinalColorForward4(l, d, color);
  3549. // Ext_FinalColorForward5(l, d, color);
  3550. // Ext_FinalColorForward6(l, d, color);
  3551. // Ext_FinalColorForward7(l, d, color);
  3552. // Ext_FinalColorForward8(l, d, color);
  3553. // Ext_FinalColorForward9(l, d, color);
  3554. // Ext_FinalColorForward10(l, d, color);
  3555. // Ext_FinalColorForward11(l, d, color);
  3556. // Ext_FinalColorForward12(l, d, color);
  3557. // Ext_FinalColorForward13(l, d, color);
  3558. // Ext_FinalColorForward14(l, d, color);
  3559. // Ext_FinalColorForward15(l, d, color);
  3560. // Ext_FinalColorForward16(l, d, color);
  3561. // Ext_FinalColorForward17(l, d, color);
  3562. // Ext_FinalColorForward18(l, d, color);
  3563. // Ext_FinalColorForward19(l, d, color);
  3564. // Ext_FinalColorForward20(l, d, color);
  3565. // Ext_FinalColorForward21(l, d, color);
  3566. // Ext_FinalColorForward22(l, d, color);
  3567. // Ext_FinalColorForward23(l, d, color);
  3568. // Ext_FinalColorForward24(l, d, color);
  3569. // Ext_FinalColorForward25(l, d, color);
  3570. // Ext_FinalColorForward26(l, d, color);
  3571. // Ext_FinalColorForward27(l, d, color);
  3572. // Ext_FinalColorForward28(l, d, color);
  3573. // Ext_FinalColorForward29(l, d, color);
  3574. }
  3575. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  3576. {
  3577. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3578. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3579. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3580. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3581. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3582. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3583. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3584. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3585. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3586. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3587. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3588. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3589. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3590. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3591. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3592. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3593. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3594. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3595. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3596. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3597. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3598. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3599. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3600. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3601. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3602. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3603. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3604. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3605. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3606. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3607. }
  3608. #endif
  3609. #if _DECALSHADER
  3610. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  3611. {
  3612. ShaderData d = (ShaderData)0;
  3613. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  3614. d.worldSpaceNormal = IN.WorldSpaceNormal;
  3615. d.worldSpaceTangent = IN.WorldSpaceTangent;
  3616. d.worldSpacePosition = IN.WorldSpacePosition;
  3617. d.texcoord0 = IN.uv0.xyxy;
  3618. d.screenPos = IN.ScreenPosition;
  3619. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  3620. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  3621. // these rarely get used, so we back transform them. Usually will be stripped.
  3622. #if _HDRP
  3623. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  3624. #else
  3625. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  3626. #endif
  3627. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  3628. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  3629. // #if %SCREENPOSREQUIREKEY%
  3630. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  3631. // #endif
  3632. return d;
  3633. }
  3634. #else
  3635. ShaderData CreateShaderData(VertexToPixel i
  3636. #if NEED_FACING
  3637. , bool facing
  3638. #endif
  3639. )
  3640. {
  3641. ShaderData d = (ShaderData)0;
  3642. d.clipPos = i.pos;
  3643. d.worldSpacePosition = i.worldPos;
  3644. d.worldSpaceNormal = normalize(i.worldNormal);
  3645. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  3646. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  3647. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  3648. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  3649. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  3650. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  3651. d.texcoord0 = i.texcoord0;
  3652. d.texcoord1 = i.texcoord1;
  3653. d.texcoord2 = i.texcoord2;
  3654. // #if %TEXCOORD3REQUIREKEY%
  3655. d.texcoord3 = i.texcoord3;
  3656. // #endif
  3657. // d.isFrontFace = facing;
  3658. // #if %VERTEXCOLORREQUIREKEY%
  3659. // d.vertexColor = i.vertexColor;
  3660. // #endif
  3661. // these rarely get used, so we back transform them. Usually will be stripped.
  3662. #if _HDRP
  3663. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  3664. #else
  3665. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  3666. #endif
  3667. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  3668. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  3669. // #if %SCREENPOSREQUIREKEY%
  3670. d.screenPos = i.screenPos;
  3671. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  3672. // #endif
  3673. // #if %EXTRAV2F0REQUIREKEY%
  3674. // d.extraV2F0 = i.extraV2F0;
  3675. // #endif
  3676. // #if %EXTRAV2F1REQUIREKEY%
  3677. // d.extraV2F1 = i.extraV2F1;
  3678. // #endif
  3679. // #if %EXTRAV2F2REQUIREKEY%
  3680. // d.extraV2F2 = i.extraV2F2;
  3681. // #endif
  3682. // #if %EXTRAV2F3REQUIREKEY%
  3683. // d.extraV2F3 = i.extraV2F3;
  3684. // #endif
  3685. // #if %EXTRAV2F4REQUIREKEY%
  3686. // d.extraV2F4 = i.extraV2F4;
  3687. // #endif
  3688. // #if %EXTRAV2F5REQUIREKEY%
  3689. // d.extraV2F5 = i.extraV2F5;
  3690. // #endif
  3691. // #if %EXTRAV2F6REQUIREKEY%
  3692. // d.extraV2F6 = i.extraV2F6;
  3693. // #endif
  3694. // #if %EXTRAV2F7REQUIREKEY%
  3695. // d.extraV2F7 = i.extraV2F7;
  3696. // #endif
  3697. return d;
  3698. }
  3699. #endif
  3700. #if defined(_PASSSHADOW)
  3701. float3 _LightDirection;
  3702. float3 _LightPosition;
  3703. #endif
  3704. // vertex shader
  3705. VertexToPixel Vert (VertexData v)
  3706. {
  3707. VertexToPixel o = (VertexToPixel)0;
  3708. UNITY_SETUP_INSTANCE_ID(v);
  3709. UNITY_TRANSFER_INSTANCE_ID(v, o);
  3710. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  3711. #if !_TESSELLATION_ON
  3712. ChainModifyVertex(v, o, _Time);
  3713. #endif
  3714. o.texcoord0 = v.texcoord0;
  3715. o.texcoord1 = v.texcoord1;
  3716. o.texcoord2 = v.texcoord2;
  3717. // #if %TEXCOORD3REQUIREKEY%
  3718. o.texcoord3 = v.texcoord3;
  3719. // #endif
  3720. // #if %VERTEXCOLORREQUIREKEY%
  3721. // o.vertexColor = v.vertexColor;
  3722. // #endif
  3723. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  3724. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  3725. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  3726. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  3727. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  3728. #if _PASSSHADOW
  3729. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  3730. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  3731. #else
  3732. float3 lightDirectionWS = _LightDirection;
  3733. #endif
  3734. // Define shadow pass specific clip position for Universal
  3735. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  3736. #if UNITY_REVERSED_Z
  3737. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  3738. #else
  3739. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  3740. #endif
  3741. #elif _PASSMETA
  3742. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  3743. #else
  3744. o.pos = TransformWorldToHClip(o.worldPos);
  3745. #endif
  3746. // #if %SCREENPOSREQUIREKEY%
  3747. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  3748. // #endif
  3749. #if _PASSFORWARD || _PASSGBUFFER
  3750. float2 uv1 = v.texcoord1.xy;
  3751. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  3752. o.texcoord1.xy = uv1;
  3753. OUTPUT_SH(o.worldNormal, o.sh);
  3754. #if defined(DYNAMICLIGHTMAP_ON)
  3755. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  3756. #endif
  3757. #endif
  3758. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  3759. half fogFactor = 0;
  3760. #if defined(_FOG_FRAGMENT)
  3761. fogFactor = ComputeFogFactor(o.pos.z);
  3762. #endif
  3763. #if _BAKEDLIT
  3764. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  3765. #else
  3766. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  3767. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  3768. #endif
  3769. #endif
  3770. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  3771. o.shadowCoord = GetShadowCoord(vertexInput);
  3772. #endif
  3773. return o;
  3774. }
  3775. // fragment shader
  3776. half4 Frag (VertexToPixel IN
  3777. #ifdef _DEPTHOFFSET_ON
  3778. , out float outputDepth : SV_Depth
  3779. #endif
  3780. #if NEED_FACING
  3781. , bool facing : SV_IsFrontFace
  3782. #endif
  3783. ) : SV_Target
  3784. {
  3785. UNITY_SETUP_INSTANCE_ID(IN);
  3786. ShaderData d = CreateShaderData(IN
  3787. #if NEED_FACING
  3788. , facing
  3789. #endif
  3790. );
  3791. Surface l = (Surface)0;
  3792. #ifdef _DEPTHOFFSET_ON
  3793. l.outputDepth = outputDepth;
  3794. #endif
  3795. l.Albedo = half3(0.5, 0.5, 0.5);
  3796. l.Normal = float3(0,0,1);
  3797. l.Occlusion = 1;
  3798. l.Alpha = 1;
  3799. ChainSurfaceFunction(l, d);
  3800. #ifdef _DEPTHOFFSET_ON
  3801. outputDepth = l.outputDepth;
  3802. #endif
  3803. return 0;
  3804. }
  3805. ENDHLSL
  3806. }
  3807. Pass
  3808. {
  3809. Name "DepthOnly"
  3810. Tags
  3811. {
  3812. "LightMode" = "DepthOnly"
  3813. }
  3814. // Render State
  3815. Blend One Zero, One Zero
  3816. Cull Back
  3817. ZTest LEqual
  3818. ZWrite On
  3819. ColorMask 0
  3820. HLSLPROGRAM
  3821. #pragma vertex Vert
  3822. #pragma fragment Frag
  3823. #define _PASSDEPTH 1
  3824. #pragma target 3.0
  3825. #pragma prefer_hlslcc gles
  3826. #pragma exclude_renderers d3d11_9x
  3827. #pragma multi_compile_instancing
  3828. #pragma multi_compile _ DOTS_INSTANCING_ON
  3829. #include "Flow.cginc"
  3830. #pragma shader_feature_local _ _STRETCH_ON
  3831. #pragma shader_feature_local DISABLEFOG
  3832. #define _URP 1
  3833. #define _USINGTEXCOORD1 1
  3834. #define _USINGTEXCOORD2 1
  3835. // Includes
  3836. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  3837. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  3838. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  3839. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  3840. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  3841. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  3842. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  3843. #undef WorldNormalVector
  3844. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  3845. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  3846. #define _WorldSpaceLightPos0 _MainLightPosition
  3847. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  3848. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  3849. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  3850. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  3851. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  3852. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  3853. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  3854. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  3855. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  3856. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  3857. #if defined(UNITY_COMPILER_HLSL)
  3858. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  3859. #else
  3860. #define UNITY_INITIALIZE_OUTPUT(type,name)
  3861. #endif
  3862. #define sampler2D_float sampler2D
  3863. #define sampler2D_half sampler2D
  3864. // data across stages, stripped like the above.
  3865. struct VertexToPixel
  3866. {
  3867. float4 pos : SV_POSITION;
  3868. float3 worldPos : TEXCOORD0;
  3869. float3 worldNormal : TEXCOORD1;
  3870. float4 worldTangent : TEXCOORD2;
  3871. float4 texcoord0 : TEXCOORD3;
  3872. float4 texcoord1 : TEXCOORD4;
  3873. float4 texcoord2 : TEXCOORD5;
  3874. // #if %TEXCOORD3REQUIREKEY%
  3875. float4 texcoord3 : TEXCOORD6;
  3876. // #endif
  3877. // #if %SCREENPOSREQUIREKEY%
  3878. float4 screenPos : TEXCOORD7;
  3879. // #endif
  3880. // #if %VERTEXCOLORREQUIREKEY%
  3881. // half4 vertexColor : COLOR;
  3882. // #endif
  3883. #if defined(LIGHTMAP_ON)
  3884. float2 lightmapUV : TEXCOORD8;
  3885. #endif
  3886. #if defined(DYNAMICLIGHTMAP_ON)
  3887. float2 dynamicLightmapUV : TEXCOORD9;
  3888. #endif
  3889. #if !defined(LIGHTMAP_ON)
  3890. float3 sh : TEXCOORD10;
  3891. #endif
  3892. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  3893. float4 fogFactorAndVertexLight : TEXCOORD11;
  3894. #endif
  3895. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  3896. float4 shadowCoord : TEXCOORD12;
  3897. #endif
  3898. // #if %EXTRAV2F0REQUIREKEY%
  3899. // float4 extraV2F0 : TEXCOORD13;
  3900. // #endif
  3901. // #if %EXTRAV2F1REQUIREKEY%
  3902. // float4 extraV2F1 : TEXCOORD14;
  3903. // #endif
  3904. // #if %EXTRAV2F2REQUIREKEY%
  3905. // float4 extraV2F2 : TEXCOORD15;
  3906. // #endif
  3907. // #if %EXTRAV2F3REQUIREKEY%
  3908. // float4 extraV2F3 : TEXCOORD16;
  3909. // #endif
  3910. // #if %EXTRAV2F4REQUIREKEY%
  3911. // float4 extraV2F4 : TEXCOORD17;
  3912. // #endif
  3913. // #if %EXTRAV2F5REQUIREKEY%
  3914. // float4 extraV2F5 : TEXCOORD18;
  3915. // #endif
  3916. // #if %EXTRAV2F6REQUIREKEY%
  3917. // float4 extraV2F6 : TEXCOORD19;
  3918. // #endif
  3919. // #if %EXTRAV2F7REQUIREKEY%
  3920. // float4 extraV2F7 : TEXCOORD20;
  3921. // #endif
  3922. #if UNITY_ANY_INSTANCING_ENABLED
  3923. uint instanceID : CUSTOM_INSTANCE_ID;
  3924. #endif
  3925. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  3926. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  3927. #endif
  3928. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  3929. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  3930. #endif
  3931. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  3932. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  3933. #endif
  3934. };
  3935. // data describing the user output of a pixel
  3936. struct Surface
  3937. {
  3938. half3 Albedo;
  3939. half Height;
  3940. half3 Normal;
  3941. half Smoothness;
  3942. half3 Emission;
  3943. half Metallic;
  3944. half3 Specular;
  3945. half Occlusion;
  3946. half SpecularPower; // for simple lighting
  3947. half Alpha;
  3948. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  3949. // HDRP Only
  3950. half SpecularOcclusion;
  3951. half SubsurfaceMask;
  3952. half Thickness;
  3953. half CoatMask;
  3954. half CoatSmoothness;
  3955. half Anisotropy;
  3956. half IridescenceMask;
  3957. half IridescenceThickness;
  3958. int DiffusionProfileHash;
  3959. float SpecularAAThreshold;
  3960. float SpecularAAScreenSpaceVariance;
  3961. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  3962. float3 DiffuseGI;
  3963. float3 BackDiffuseGI;
  3964. float3 SpecularGI;
  3965. float ior;
  3966. float3 transmittanceColor;
  3967. float atDistance;
  3968. float transmittanceMask;
  3969. // requires _OVERRIDE_SHADOWMASK to be defines
  3970. float4 ShadowMask;
  3971. // for decals
  3972. float NormalAlpha;
  3973. float MAOSAlpha;
  3974. };
  3975. // Data the user declares in blackboard blocks
  3976. struct Blackboard
  3977. {
  3978. float groundHeight;
  3979. float surfaceHeight;
  3980. float3 surfaceNormal;
  3981. Fluid fluid;
  3982. float blackboardDummyData;
  3983. };
  3984. // data the user might need, this will grow to be big. But easy to strip
  3985. struct ShaderData
  3986. {
  3987. float4 clipPos; // SV_POSITION
  3988. float3 localSpacePosition;
  3989. float3 localSpaceNormal;
  3990. float3 localSpaceTangent;
  3991. float3 worldSpacePosition;
  3992. float3 worldSpaceNormal;
  3993. float3 worldSpaceTangent;
  3994. float tangentSign;
  3995. float3 worldSpaceViewDir;
  3996. float3 tangentSpaceViewDir;
  3997. float4 texcoord0;
  3998. float4 texcoord1;
  3999. float4 texcoord2;
  4000. float4 texcoord3;
  4001. float2 screenUV;
  4002. float4 screenPos;
  4003. float4 vertexColor;
  4004. bool isFrontFace;
  4005. float4 extraV2F0;
  4006. float4 extraV2F1;
  4007. float4 extraV2F2;
  4008. float4 extraV2F3;
  4009. float4 extraV2F4;
  4010. float4 extraV2F5;
  4011. float4 extraV2F6;
  4012. float4 extraV2F7;
  4013. float3x3 TBNMatrix;
  4014. Blackboard blackboard;
  4015. };
  4016. struct VertexData
  4017. {
  4018. #if SHADER_TARGET > 30
  4019. // uint vertexID : SV_VertexID;
  4020. #endif
  4021. float4 vertex : POSITION;
  4022. float3 normal : NORMAL;
  4023. float4 tangent : TANGENT;
  4024. float4 texcoord0 : TEXCOORD0;
  4025. // optimize out mesh coords when not in use by user or lighting system
  4026. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  4027. float4 texcoord1 : TEXCOORD1;
  4028. #endif
  4029. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  4030. float4 texcoord2 : TEXCOORD2;
  4031. #endif
  4032. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  4033. float4 texcoord1 : TEXCOORD1;
  4034. #endif
  4035. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  4036. float4 texcoord2 : TEXCOORD2;
  4037. #endif
  4038. #if _HDRP
  4039. float4 texcoord1 : TEXCOORD1;
  4040. float4 texcoord2 : TEXCOORD2;
  4041. #endif
  4042. // #if %TEXCOORD3REQUIREKEY%
  4043. float4 texcoord3 : TEXCOORD3;
  4044. // #endif
  4045. // #if %VERTEXCOLORREQUIREKEY%
  4046. // float4 vertexColor : COLOR;
  4047. // #endif
  4048. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  4049. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  4050. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  4051. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  4052. #endif
  4053. #endif
  4054. UNITY_VERTEX_INPUT_INSTANCE_ID
  4055. };
  4056. struct TessVertex
  4057. {
  4058. float4 vertex : INTERNALTESSPOS;
  4059. float3 normal : NORMAL;
  4060. float4 tangent : TANGENT;
  4061. float4 texcoord0 : TEXCOORD0;
  4062. float4 texcoord1 : TEXCOORD1;
  4063. float4 texcoord2 : TEXCOORD2;
  4064. // #if %TEXCOORD3REQUIREKEY%
  4065. float4 texcoord3 : TEXCOORD3;
  4066. // #endif
  4067. // #if %VERTEXCOLORREQUIREKEY%
  4068. // float4 vertexColor : COLOR;
  4069. // #endif
  4070. // #if %EXTRAV2F0REQUIREKEY%
  4071. // float4 extraV2F0 : TEXCOORD5;
  4072. // #endif
  4073. // #if %EXTRAV2F1REQUIREKEY%
  4074. // float4 extraV2F1 : TEXCOORD6;
  4075. // #endif
  4076. // #if %EXTRAV2F2REQUIREKEY%
  4077. // float4 extraV2F2 : TEXCOORD7;
  4078. // #endif
  4079. // #if %EXTRAV2F3REQUIREKEY%
  4080. // float4 extraV2F3 : TEXCOORD8;
  4081. // #endif
  4082. // #if %EXTRAV2F4REQUIREKEY%
  4083. // float4 extraV2F4 : TEXCOORD9;
  4084. // #endif
  4085. // #if %EXTRAV2F5REQUIREKEY%
  4086. // float4 extraV2F5 : TEXCOORD10;
  4087. // #endif
  4088. // #if %EXTRAV2F6REQUIREKEY%
  4089. // float4 extraV2F6 : TEXCOORD11;
  4090. // #endif
  4091. // #if %EXTRAV2F7REQUIREKEY%
  4092. // float4 extraV2F7 : TEXCOORD12;
  4093. // #endif
  4094. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  4095. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  4096. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  4097. float3 precomputedVelocity : TEXCOORD14;
  4098. #endif
  4099. #endif
  4100. UNITY_VERTEX_INPUT_INSTANCE_ID
  4101. UNITY_VERTEX_OUTPUT_STEREO
  4102. };
  4103. struct ExtraV2F
  4104. {
  4105. float4 extraV2F0;
  4106. float4 extraV2F1;
  4107. float4 extraV2F2;
  4108. float4 extraV2F3;
  4109. float4 extraV2F4;
  4110. float4 extraV2F5;
  4111. float4 extraV2F6;
  4112. float4 extraV2F7;
  4113. Blackboard blackboard;
  4114. float4 time;
  4115. };
  4116. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  4117. {
  4118. return mul(d.TBNMatrix, normal);
  4119. }
  4120. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  4121. {
  4122. return mul(normal, d.TBNMatrix);
  4123. }
  4124. // in this case, make standard more like SRPs, because we can't fix
  4125. // unity_WorldToObject in HDRP, since it already does macro-fu there
  4126. #if _STANDARD
  4127. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  4128. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  4129. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  4130. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  4131. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  4132. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  4133. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  4134. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  4135. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  4136. #else
  4137. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  4138. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  4139. #endif
  4140. #undef GetWorldToObjectMatrix()
  4141. #define GetWorldToObjectMatrix() unity_WorldToObject
  4142. #endif
  4143. float3 GetCameraWorldPosition()
  4144. {
  4145. #if _HDRP
  4146. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  4147. #else
  4148. return _WorldSpaceCameraPos;
  4149. #endif
  4150. }
  4151. #if _GRABPASSUSED
  4152. #if _STANDARD
  4153. TEXTURE2D(%GRABTEXTURE%);
  4154. SAMPLER(sampler_%GRABTEXTURE%);
  4155. #endif
  4156. half3 GetSceneColor(float2 uv)
  4157. {
  4158. #if _STANDARD
  4159. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  4160. #else
  4161. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  4162. #endif
  4163. }
  4164. #endif
  4165. #if _STANDARD
  4166. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  4167. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  4168. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  4169. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  4170. #else
  4171. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  4172. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  4173. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  4174. #endif
  4175. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  4176. {
  4177. float eye = GetLinearEyeDepth(uv);
  4178. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  4179. float dt = dot(worldSpaceViewDir, camView);
  4180. float3 div = worldSpaceViewDir/dt;
  4181. float3 wpos = (eye * div) + GetCameraWorldPosition();
  4182. return wpos;
  4183. }
  4184. #if _HDRP
  4185. float3 ObjectToWorldSpacePosition(float3 pos)
  4186. {
  4187. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  4188. }
  4189. #else
  4190. float3 ObjectToWorldSpacePosition(float3 pos)
  4191. {
  4192. return TransformObjectToWorld(pos);
  4193. }
  4194. #endif
  4195. #if _STANDARD
  4196. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  4197. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  4198. {
  4199. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  4200. float3 norms = DecodeViewNormalStereo(depthNorms);
  4201. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  4202. return norms;
  4203. }
  4204. #elif _HDRP && !_DECALSHADER
  4205. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  4206. {
  4207. NormalData nd;
  4208. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  4209. return nd.normalWS;
  4210. }
  4211. #elif _URP
  4212. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  4213. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  4214. #endif
  4215. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  4216. {
  4217. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  4218. return SampleSceneNormals(uv);
  4219. #else
  4220. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  4221. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  4222. #endif
  4223. }
  4224. #endif
  4225. #if _HDRP
  4226. half3 UnpackNormalmapRGorAG(half4 packednormal)
  4227. {
  4228. // This do the trick
  4229. packednormal.x *= packednormal.w;
  4230. half3 normal;
  4231. normal.xy = packednormal.xy * 2 - 1;
  4232. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  4233. return normal;
  4234. }
  4235. half3 UnpackNormal(half4 packednormal)
  4236. {
  4237. #if defined(UNITY_NO_DXT5nm)
  4238. return packednormal.xyz * 2 - 1;
  4239. #else
  4240. return UnpackNormalmapRGorAG(packednormal);
  4241. #endif
  4242. }
  4243. #endif
  4244. #if _HDRP || _URP
  4245. half3 UnpackScaleNormal(half4 packednormal, half scale)
  4246. {
  4247. #ifndef UNITY_NO_DXT5nm
  4248. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  4249. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  4250. packednormal.x *= packednormal.w;
  4251. #endif
  4252. half3 normal;
  4253. normal.xy = (packednormal.xy * 2 - 1) * scale;
  4254. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  4255. return normal;
  4256. }
  4257. #endif
  4258. void GetSun(out float3 lightDir, out float3 color)
  4259. {
  4260. lightDir = float3(0.5, 0.5, 0);
  4261. color = 1;
  4262. #if _HDRP
  4263. if (_DirectionalLightCount > 0)
  4264. {
  4265. DirectionalLightData light = _DirectionalLightDatas[0];
  4266. lightDir = -light.forward.xyz;
  4267. color = light.color;
  4268. }
  4269. #elif _STANDARD
  4270. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  4271. color = _LightColor0.rgb;
  4272. #elif _URP
  4273. Light light = GetMainLight();
  4274. lightDir = light.direction;
  4275. color = light.color;
  4276. #endif
  4277. }
  4278. CBUFFER_START(UnityPerMaterial)
  4279. float _FlowDensity;
  4280. float2 _FlowSeparationXZ;
  4281. float _FlowSimulationHeight;
  4282. float _FlowCameraHeight;
  4283. float2 _FlowCountXZ;
  4284. float4 _FlowCoordU000;
  4285. float4 _FlowCoord0V00;
  4286. float _FlowSpeed;
  4287. float4x4 _FlowMatrix;
  4288. float _Sink;
  4289. int2 _PartCountXY;
  4290. float _FlowDelta;
  4291. float _ScaleBase;
  4292. float _ScaleVolume;
  4293. float _StretchScale;
  4294. CBUFFER_END
  4295. #ifdef unity_WorldToObject
  4296. #undef unity_WorldToObject
  4297. #endif
  4298. #ifdef unity_ObjectToWorld
  4299. #undef unity_ObjectToWorld
  4300. #endif
  4301. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  4302. #define unity_WorldToObject GetWorldToObjectMatrix()
  4303. TEXTURE2D(_FlowDataA);
  4304. SAMPLER(sampler_FlowDataA);
  4305. TEXTURE2D(_FlowDataB);
  4306. SAMPLER(sampler_FlowDataB);
  4307. TEXTURE2D(_FlowDataC);
  4308. SAMPLER(sampler_FlowDataC);
  4309. TEXTURE2D(_FlowDataD);
  4310. SAMPLER(sampler_FlowDataD);
  4311. TEXTURE2D(_FlowDataE);
  4312. SAMPLER(sampler_FlowDataE);
  4313. TEXTURE2D(_FlowDataF);
  4314. SAMPLER(sampler_FlowDataF);
  4315. float4 SGT_O2W(float4 v)
  4316. {
  4317. v = mul(GetObjectToWorldMatrix(), v);
  4318. #if _HDRP
  4319. v.xyz = GetAbsolutePositionWS(v.xyz);
  4320. #endif
  4321. return v;
  4322. }
  4323. float4 SGT_W2O(float4 v)
  4324. {
  4325. #if _HDRP
  4326. v.xyz = GetCameraRelativePositionWS(v.xyz);
  4327. #endif
  4328. return mul(GetWorldToObjectMatrix(), v);
  4329. }
  4330. float4 SGT_O2V(float4 v)
  4331. {
  4332. #if _STANDARD
  4333. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  4334. #else
  4335. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  4336. #endif
  4337. }
  4338. float GetFluidHeight(float2 uv)
  4339. {
  4340. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  4341. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  4342. return groundHeight + fluidDepth;
  4343. }
  4344. float2 GetHeightAndDepth(float2 uv)
  4345. {
  4346. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  4347. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  4348. return float2(groundHeight, fluidDepth);
  4349. }
  4350. Column GetColumn(float2 uv)
  4351. {
  4352. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  4353. }
  4354. Fluid GetColumnFluid(float2 uv)
  4355. {
  4356. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  4357. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  4358. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  4359. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  4360. return DecodeFluid(c, d, e, f);
  4361. }
  4362. bool InsideFluid(float3 wpos)
  4363. {
  4364. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  4365. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  4366. float2 columnHAD = GetHeightAndDepth(columnCoord);
  4367. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  4368. }
  4369. bool UnderFluid(float3 wpos)
  4370. {
  4371. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  4372. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  4373. float2 columnHAD = GetHeightAndDepth(columnCoord);
  4374. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  4375. }
  4376. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  4377. {
  4378. float epsi = step * 0.01f;
  4379. float dist = 0.0f;
  4380. for (int i = 0; i < maxs && step > epsi; i++)
  4381. {
  4382. dist += step;
  4383. float3 pos = wpos + wdir * dist;
  4384. if (InsideFluid(pos) == false)
  4385. {
  4386. dist -= step;
  4387. step *= 0.5f;
  4388. }
  4389. if (dist > maxd)
  4390. {
  4391. return maxd;
  4392. }
  4393. }
  4394. return dist;
  4395. }
  4396. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  4397. {
  4398. float epsi = step * 0.01f;
  4399. float dist = 0.0f;
  4400. for (int i = 0; i < maxs && step > epsi; i++)
  4401. {
  4402. dist += step;
  4403. float3 pos = wpos + wdir * dist;
  4404. if (UnderFluid(pos) == false)
  4405. {
  4406. dist -= step;
  4407. step *= 0.5f;
  4408. }
  4409. if (dist > maxd)
  4410. {
  4411. return maxd;
  4412. }
  4413. }
  4414. return dist;
  4415. }
  4416. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  4417. {
  4418. float4 wpos = SGT_O2W(v.vertex);
  4419. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  4420. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  4421. Column column0 = GetColumn(columnCoord);
  4422. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  4423. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  4424. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  4425. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  4426. Fluid fluid0 = GetColumnFluid(columnCoord);
  4427. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  4428. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  4429. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  4430. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  4431. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  4432. float wL = fluidL.Depth / ww;
  4433. float wR = fluidR.Depth / ww;
  4434. float wB = fluidB.Depth / ww;
  4435. float wT = fluidT.Depth / ww;
  4436. float w0 = saturate(fluid0.Depth * 10);
  4437. float hL = columnL.GroundHeight + fluidL.Depth;
  4438. float hR = columnR.GroundHeight + fluidR.Depth;
  4439. float hB = columnB.GroundHeight + fluidB.Depth;
  4440. float hT = columnT.GroundHeight + fluidT.Depth;
  4441. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  4442. float h0 = column0.GroundHeight + fluid0.Depth;
  4443. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  4444. Fluid fluid = fluid0;
  4445. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  4446. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  4447. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  4448. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  4449. e.blackboard.groundHeight = column0.GroundHeight;
  4450. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  4451. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  4452. e.blackboard.fluid = fluid;
  4453. }
  4454. TEXTURE2D(_MainTex);
  4455. SAMPLER(sampler_MainTex);
  4456. TEXTURE2D(_BumpMap);
  4457. SAMPLER(sampler_BumpMap);
  4458. TEXTURE2D(_PartDataA);
  4459. SAMPLER(sampler_PartDataA);
  4460. TEXTURE2D(_PartDataB);
  4461. SAMPLER(sampler_PartDataB);
  4462. TEXTURE2D(_PartDataC);
  4463. SAMPLER(sampler_PartDataC);
  4464. TEXTURE2D(_PartDataD);
  4465. SAMPLER(sampler_PartDataD);
  4466. TEXTURE2D(_PartDataE);
  4467. SAMPLER(sampler_PartDataE);
  4468. TEXTURE2D(_PartDataF);
  4469. SAMPLER(sampler_PartDataF);
  4470. Particle GetParticle(float2 uv)
  4471. {
  4472. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  4473. }
  4474. Fluid GetParticleFluid(float2 uv)
  4475. {
  4476. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  4477. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  4478. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  4479. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  4480. return DecodeFluid(c, d, e, f);
  4481. }
  4482. float2 Rotate(float2 v, float a)
  4483. {
  4484. float s = sin(a);
  4485. float c = cos(a);
  4486. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  4487. }
  4488. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  4489. {
  4490. float2 particlePixel = v.texcoord1.xy;
  4491. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  4492. Particle particle = GetParticle(particleCoord);
  4493. Fluid fluid = GetParticleFluid(particleCoord);
  4494. float size = particle.Age < particle.Life;
  4495. float4 wpos = float4(particle.Position, 1.0f);
  4496. float2 rvec = v.texcoord0.xy * size;
  4497. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  4498. #if _STRETCH_ON
  4499. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  4500. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  4501. float2 posV = posB.xy - posA.xy;
  4502. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  4503. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  4504. #endif
  4505. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  4506. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  4507. v.vertex = SGT_W2O(wpos);
  4508. v.normal = GetWorldToViewMatrix()[2].xyz;
  4509. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  4510. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  4511. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  4512. v.texcoord0 += 0.5f;
  4513. v.texcoord1 = fluid.RGBA;
  4514. v.texcoord2 = fluid.ESMV;
  4515. }
  4516. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  4517. {
  4518. Fluid fluid;
  4519. fluid.RGBA = d.texcoord1;
  4520. fluid.ESMV = d.texcoord2;
  4521. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  4522. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  4523. //clip(texMain.a - 0.5f);
  4524. float DITHER_THRESHOLDS[16] =
  4525. {
  4526. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  4527. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  4528. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  4529. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  4530. };
  4531. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  4532. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  4533. clip(texMain.a - DITHER_THRESHOLDS[index]);
  4534. o.Albedo = fluid.RGBA.xyz;
  4535. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  4536. o.Smoothness = fluid.ESMV.y;
  4537. o.Metallic = fluid.ESMV.z;
  4538. o.Normal = UnpackScaleNormal(bump, 1.0f);
  4539. }
  4540. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  4541. {
  4542. // Ext_SurfaceFunction0(l, d);
  4543. Ext_SurfaceFunction1(l, d);
  4544. // Ext_SurfaceFunction2(l, d);
  4545. // Ext_SurfaceFunction3(l, d);
  4546. // Ext_SurfaceFunction4(l, d);
  4547. // Ext_SurfaceFunction5(l, d);
  4548. // Ext_SurfaceFunction6(l, d);
  4549. // Ext_SurfaceFunction7(l, d);
  4550. // Ext_SurfaceFunction8(l, d);
  4551. // Ext_SurfaceFunction9(l, d);
  4552. // Ext_SurfaceFunction10(l, d);
  4553. // Ext_SurfaceFunction11(l, d);
  4554. // Ext_SurfaceFunction12(l, d);
  4555. // Ext_SurfaceFunction13(l, d);
  4556. // Ext_SurfaceFunction14(l, d);
  4557. // Ext_SurfaceFunction15(l, d);
  4558. // Ext_SurfaceFunction16(l, d);
  4559. // Ext_SurfaceFunction17(l, d);
  4560. // Ext_SurfaceFunction18(l, d);
  4561. // Ext_SurfaceFunction19(l, d);
  4562. // Ext_SurfaceFunction20(l, d);
  4563. // Ext_SurfaceFunction21(l, d);
  4564. // Ext_SurfaceFunction22(l, d);
  4565. // Ext_SurfaceFunction23(l, d);
  4566. // Ext_SurfaceFunction24(l, d);
  4567. // Ext_SurfaceFunction25(l, d);
  4568. // Ext_SurfaceFunction26(l, d);
  4569. // Ext_SurfaceFunction27(l, d);
  4570. // Ext_SurfaceFunction28(l, d);
  4571. // Ext_SurfaceFunction29(l, d);
  4572. }
  4573. #if !_DECALSHADER
  4574. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  4575. {
  4576. ExtraV2F d;
  4577. ZERO_INITIALIZE(ExtraV2F, d);
  4578. ZERO_INITIALIZE(Blackboard, d.blackboard);
  4579. // due to motion vectors in HDRP, we need to use the last
  4580. // time in certain spots. So if you are going to use _Time to adjust vertices,
  4581. // you need to use this time or motion vectors will break.
  4582. d.time = time;
  4583. Ext_ModifyVertex0(v, d);
  4584. Ext_ModifyVertex1(v, d);
  4585. // Ext_ModifyVertex2(v, d);
  4586. // Ext_ModifyVertex3(v, d);
  4587. // Ext_ModifyVertex4(v, d);
  4588. // Ext_ModifyVertex5(v, d);
  4589. // Ext_ModifyVertex6(v, d);
  4590. // Ext_ModifyVertex7(v, d);
  4591. // Ext_ModifyVertex8(v, d);
  4592. // Ext_ModifyVertex9(v, d);
  4593. // Ext_ModifyVertex10(v, d);
  4594. // Ext_ModifyVertex11(v, d);
  4595. // Ext_ModifyVertex12(v, d);
  4596. // Ext_ModifyVertex13(v, d);
  4597. // Ext_ModifyVertex14(v, d);
  4598. // Ext_ModifyVertex15(v, d);
  4599. // Ext_ModifyVertex16(v, d);
  4600. // Ext_ModifyVertex17(v, d);
  4601. // Ext_ModifyVertex18(v, d);
  4602. // Ext_ModifyVertex19(v, d);
  4603. // Ext_ModifyVertex20(v, d);
  4604. // Ext_ModifyVertex21(v, d);
  4605. // Ext_ModifyVertex22(v, d);
  4606. // Ext_ModifyVertex23(v, d);
  4607. // Ext_ModifyVertex24(v, d);
  4608. // Ext_ModifyVertex25(v, d);
  4609. // Ext_ModifyVertex26(v, d);
  4610. // Ext_ModifyVertex27(v, d);
  4611. // Ext_ModifyVertex28(v, d);
  4612. // Ext_ModifyVertex29(v, d);
  4613. // #if %EXTRAV2F0REQUIREKEY%
  4614. // v2p.extraV2F0 = d.extraV2F0;
  4615. // #endif
  4616. // #if %EXTRAV2F1REQUIREKEY%
  4617. // v2p.extraV2F1 = d.extraV2F1;
  4618. // #endif
  4619. // #if %EXTRAV2F2REQUIREKEY%
  4620. // v2p.extraV2F2 = d.extraV2F2;
  4621. // #endif
  4622. // #if %EXTRAV2F3REQUIREKEY%
  4623. // v2p.extraV2F3 = d.extraV2F3;
  4624. // #endif
  4625. // #if %EXTRAV2F4REQUIREKEY%
  4626. // v2p.extraV2F4 = d.extraV2F4;
  4627. // #endif
  4628. // #if %EXTRAV2F5REQUIREKEY%
  4629. // v2p.extraV2F5 = d.extraV2F5;
  4630. // #endif
  4631. // #if %EXTRAV2F6REQUIREKEY%
  4632. // v2p.extraV2F6 = d.extraV2F6;
  4633. // #endif
  4634. // #if %EXTRAV2F7REQUIREKEY%
  4635. // v2p.extraV2F7 = d.extraV2F7;
  4636. // #endif
  4637. }
  4638. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  4639. {
  4640. ExtraV2F d;
  4641. ZERO_INITIALIZE(ExtraV2F, d);
  4642. ZERO_INITIALIZE(Blackboard, d.blackboard);
  4643. // #if %EXTRAV2F0REQUIREKEY%
  4644. // d.extraV2F0 = v2p.extraV2F0;
  4645. // #endif
  4646. // #if %EXTRAV2F1REQUIREKEY%
  4647. // d.extraV2F1 = v2p.extraV2F1;
  4648. // #endif
  4649. // #if %EXTRAV2F2REQUIREKEY%
  4650. // d.extraV2F2 = v2p.extraV2F2;
  4651. // #endif
  4652. // #if %EXTRAV2F3REQUIREKEY%
  4653. // d.extraV2F3 = v2p.extraV2F3;
  4654. // #endif
  4655. // #if %EXTRAV2F4REQUIREKEY%
  4656. // d.extraV2F4 = v2p.extraV2F4;
  4657. // #endif
  4658. // #if %EXTRAV2F5REQUIREKEY%
  4659. // d.extraV2F5 = v2p.extraV2F5;
  4660. // #endif
  4661. // #if %EXTRAV2F6REQUIREKEY%
  4662. // d.extraV2F6 = v2p.extraV2F6;
  4663. // #endif
  4664. // #if %EXTRAV2F7REQUIREKEY%
  4665. // d.extraV2F7 = v2p.extraV2F7;
  4666. // #endif
  4667. // Ext_ModifyTessellatedVertex0(v, d);
  4668. // Ext_ModifyTessellatedVertex1(v, d);
  4669. // Ext_ModifyTessellatedVertex2(v, d);
  4670. // Ext_ModifyTessellatedVertex3(v, d);
  4671. // Ext_ModifyTessellatedVertex4(v, d);
  4672. // Ext_ModifyTessellatedVertex5(v, d);
  4673. // Ext_ModifyTessellatedVertex6(v, d);
  4674. // Ext_ModifyTessellatedVertex7(v, d);
  4675. // Ext_ModifyTessellatedVertex8(v, d);
  4676. // Ext_ModifyTessellatedVertex9(v, d);
  4677. // Ext_ModifyTessellatedVertex10(v, d);
  4678. // Ext_ModifyTessellatedVertex11(v, d);
  4679. // Ext_ModifyTessellatedVertex12(v, d);
  4680. // Ext_ModifyTessellatedVertex13(v, d);
  4681. // Ext_ModifyTessellatedVertex14(v, d);
  4682. // Ext_ModifyTessellatedVertex15(v, d);
  4683. // Ext_ModifyTessellatedVertex16(v, d);
  4684. // Ext_ModifyTessellatedVertex17(v, d);
  4685. // Ext_ModifyTessellatedVertex18(v, d);
  4686. // Ext_ModifyTessellatedVertex19(v, d);
  4687. // Ext_ModifyTessellatedVertex20(v, d);
  4688. // Ext_ModifyTessellatedVertex21(v, d);
  4689. // Ext_ModifyTessellatedVertex22(v, d);
  4690. // Ext_ModifyTessellatedVertex23(v, d);
  4691. // Ext_ModifyTessellatedVertex24(v, d);
  4692. // Ext_ModifyTessellatedVertex25(v, d);
  4693. // Ext_ModifyTessellatedVertex26(v, d);
  4694. // Ext_ModifyTessellatedVertex27(v, d);
  4695. // Ext_ModifyTessellatedVertex28(v, d);
  4696. // Ext_ModifyTessellatedVertex29(v, d);
  4697. // #if %EXTRAV2F0REQUIREKEY%
  4698. // v2p.extraV2F0 = d.extraV2F0;
  4699. // #endif
  4700. // #if %EXTRAV2F1REQUIREKEY%
  4701. // v2p.extraV2F1 = d.extraV2F1;
  4702. // #endif
  4703. // #if %EXTRAV2F2REQUIREKEY%
  4704. // v2p.extraV2F2 = d.extraV2F2;
  4705. // #endif
  4706. // #if %EXTRAV2F3REQUIREKEY%
  4707. // v2p.extraV2F3 = d.extraV2F3;
  4708. // #endif
  4709. // #if %EXTRAV2F4REQUIREKEY%
  4710. // v2p.extraV2F4 = d.extraV2F4;
  4711. // #endif
  4712. // #if %EXTRAV2F5REQUIREKEY%
  4713. // v2p.extraV2F5 = d.extraV2F5;
  4714. // #endif
  4715. // #if %EXTRAV2F6REQUIREKEY%
  4716. // v2p.extraV2F6 = d.extraV2F6;
  4717. // #endif
  4718. // #if %EXTRAV2F7REQUIREKEY%
  4719. // v2p.extraV2F7 = d.extraV2F7;
  4720. // #endif
  4721. }
  4722. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  4723. {
  4724. // Ext_FinalColorForward0(l, d, color);
  4725. // Ext_FinalColorForward1(l, d, color);
  4726. // Ext_FinalColorForward2(l, d, color);
  4727. // Ext_FinalColorForward3(l, d, color);
  4728. // Ext_FinalColorForward4(l, d, color);
  4729. // Ext_FinalColorForward5(l, d, color);
  4730. // Ext_FinalColorForward6(l, d, color);
  4731. // Ext_FinalColorForward7(l, d, color);
  4732. // Ext_FinalColorForward8(l, d, color);
  4733. // Ext_FinalColorForward9(l, d, color);
  4734. // Ext_FinalColorForward10(l, d, color);
  4735. // Ext_FinalColorForward11(l, d, color);
  4736. // Ext_FinalColorForward12(l, d, color);
  4737. // Ext_FinalColorForward13(l, d, color);
  4738. // Ext_FinalColorForward14(l, d, color);
  4739. // Ext_FinalColorForward15(l, d, color);
  4740. // Ext_FinalColorForward16(l, d, color);
  4741. // Ext_FinalColorForward17(l, d, color);
  4742. // Ext_FinalColorForward18(l, d, color);
  4743. // Ext_FinalColorForward19(l, d, color);
  4744. // Ext_FinalColorForward20(l, d, color);
  4745. // Ext_FinalColorForward21(l, d, color);
  4746. // Ext_FinalColorForward22(l, d, color);
  4747. // Ext_FinalColorForward23(l, d, color);
  4748. // Ext_FinalColorForward24(l, d, color);
  4749. // Ext_FinalColorForward25(l, d, color);
  4750. // Ext_FinalColorForward26(l, d, color);
  4751. // Ext_FinalColorForward27(l, d, color);
  4752. // Ext_FinalColorForward28(l, d, color);
  4753. // Ext_FinalColorForward29(l, d, color);
  4754. }
  4755. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  4756. {
  4757. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4758. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4759. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4760. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4761. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4762. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4763. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4764. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4765. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4766. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4767. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4768. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4769. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4770. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4771. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4772. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4773. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4774. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4775. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4776. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4777. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4778. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4779. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4780. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4781. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4782. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4783. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4784. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4785. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4786. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  4787. }
  4788. #endif
  4789. #if _DECALSHADER
  4790. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  4791. {
  4792. ShaderData d = (ShaderData)0;
  4793. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  4794. d.worldSpaceNormal = IN.WorldSpaceNormal;
  4795. d.worldSpaceTangent = IN.WorldSpaceTangent;
  4796. d.worldSpacePosition = IN.WorldSpacePosition;
  4797. d.texcoord0 = IN.uv0.xyxy;
  4798. d.screenPos = IN.ScreenPosition;
  4799. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  4800. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  4801. // these rarely get used, so we back transform them. Usually will be stripped.
  4802. #if _HDRP
  4803. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  4804. #else
  4805. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  4806. #endif
  4807. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  4808. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  4809. // #if %SCREENPOSREQUIREKEY%
  4810. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  4811. // #endif
  4812. return d;
  4813. }
  4814. #else
  4815. ShaderData CreateShaderData(VertexToPixel i
  4816. #if NEED_FACING
  4817. , bool facing
  4818. #endif
  4819. )
  4820. {
  4821. ShaderData d = (ShaderData)0;
  4822. d.clipPos = i.pos;
  4823. d.worldSpacePosition = i.worldPos;
  4824. d.worldSpaceNormal = normalize(i.worldNormal);
  4825. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  4826. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  4827. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  4828. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  4829. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  4830. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  4831. d.texcoord0 = i.texcoord0;
  4832. d.texcoord1 = i.texcoord1;
  4833. d.texcoord2 = i.texcoord2;
  4834. // #if %TEXCOORD3REQUIREKEY%
  4835. d.texcoord3 = i.texcoord3;
  4836. // #endif
  4837. // d.isFrontFace = facing;
  4838. // #if %VERTEXCOLORREQUIREKEY%
  4839. // d.vertexColor = i.vertexColor;
  4840. // #endif
  4841. // these rarely get used, so we back transform them. Usually will be stripped.
  4842. #if _HDRP
  4843. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  4844. #else
  4845. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  4846. #endif
  4847. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  4848. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  4849. // #if %SCREENPOSREQUIREKEY%
  4850. d.screenPos = i.screenPos;
  4851. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  4852. // #endif
  4853. // #if %EXTRAV2F0REQUIREKEY%
  4854. // d.extraV2F0 = i.extraV2F0;
  4855. // #endif
  4856. // #if %EXTRAV2F1REQUIREKEY%
  4857. // d.extraV2F1 = i.extraV2F1;
  4858. // #endif
  4859. // #if %EXTRAV2F2REQUIREKEY%
  4860. // d.extraV2F2 = i.extraV2F2;
  4861. // #endif
  4862. // #if %EXTRAV2F3REQUIREKEY%
  4863. // d.extraV2F3 = i.extraV2F3;
  4864. // #endif
  4865. // #if %EXTRAV2F4REQUIREKEY%
  4866. // d.extraV2F4 = i.extraV2F4;
  4867. // #endif
  4868. // #if %EXTRAV2F5REQUIREKEY%
  4869. // d.extraV2F5 = i.extraV2F5;
  4870. // #endif
  4871. // #if %EXTRAV2F6REQUIREKEY%
  4872. // d.extraV2F6 = i.extraV2F6;
  4873. // #endif
  4874. // #if %EXTRAV2F7REQUIREKEY%
  4875. // d.extraV2F7 = i.extraV2F7;
  4876. // #endif
  4877. return d;
  4878. }
  4879. #endif
  4880. #if defined(_PASSSHADOW)
  4881. float3 _LightDirection;
  4882. float3 _LightPosition;
  4883. #endif
  4884. // vertex shader
  4885. VertexToPixel Vert (VertexData v)
  4886. {
  4887. VertexToPixel o = (VertexToPixel)0;
  4888. UNITY_SETUP_INSTANCE_ID(v);
  4889. UNITY_TRANSFER_INSTANCE_ID(v, o);
  4890. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  4891. #if !_TESSELLATION_ON
  4892. ChainModifyVertex(v, o, _Time);
  4893. #endif
  4894. o.texcoord0 = v.texcoord0;
  4895. o.texcoord1 = v.texcoord1;
  4896. o.texcoord2 = v.texcoord2;
  4897. // #if %TEXCOORD3REQUIREKEY%
  4898. o.texcoord3 = v.texcoord3;
  4899. // #endif
  4900. // #if %VERTEXCOLORREQUIREKEY%
  4901. // o.vertexColor = v.vertexColor;
  4902. // #endif
  4903. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  4904. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  4905. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  4906. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  4907. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  4908. #if _PASSSHADOW
  4909. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  4910. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  4911. #else
  4912. float3 lightDirectionWS = _LightDirection;
  4913. #endif
  4914. // Define shadow pass specific clip position for Universal
  4915. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  4916. #if UNITY_REVERSED_Z
  4917. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  4918. #else
  4919. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  4920. #endif
  4921. #elif _PASSMETA
  4922. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  4923. #else
  4924. o.pos = TransformWorldToHClip(o.worldPos);
  4925. #endif
  4926. // #if %SCREENPOSREQUIREKEY%
  4927. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  4928. // #endif
  4929. #if _PASSFORWARD || _PASSGBUFFER
  4930. float2 uv1 = v.texcoord1.xy;
  4931. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  4932. o.texcoord1.xy = uv1;
  4933. OUTPUT_SH(o.worldNormal, o.sh);
  4934. #if defined(DYNAMICLIGHTMAP_ON)
  4935. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  4936. #endif
  4937. #endif
  4938. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  4939. half fogFactor = 0;
  4940. #if defined(_FOG_FRAGMENT)
  4941. fogFactor = ComputeFogFactor(o.pos.z);
  4942. #endif
  4943. #if _BAKEDLIT
  4944. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  4945. #else
  4946. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  4947. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  4948. #endif
  4949. #endif
  4950. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  4951. o.shadowCoord = GetShadowCoord(vertexInput);
  4952. #endif
  4953. return o;
  4954. }
  4955. // fragment shader
  4956. half4 Frag (VertexToPixel IN
  4957. #ifdef _DEPTHOFFSET_ON
  4958. , out float outputDepth : SV_Depth
  4959. #endif
  4960. #if NEED_FACING
  4961. , bool facing : SV_IsFrontFace
  4962. #endif
  4963. ) : SV_Target
  4964. {
  4965. UNITY_SETUP_INSTANCE_ID(IN);
  4966. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  4967. ShaderData d = CreateShaderData(IN
  4968. #if NEED_FACING
  4969. , facing
  4970. #endif
  4971. );
  4972. Surface l = (Surface)0;
  4973. #ifdef _DEPTHOFFSET_ON
  4974. l.outputDepth = outputDepth;
  4975. #endif
  4976. l.Albedo = half3(0.5, 0.5, 0.5);
  4977. l.Normal = float3(0,0,1);
  4978. l.Occlusion = 1;
  4979. l.Alpha = 1;
  4980. ChainSurfaceFunction(l, d);
  4981. #ifdef _DEPTHOFFSET_ON
  4982. outputDepth = l.outputDepth;
  4983. #endif
  4984. return 0;
  4985. }
  4986. ENDHLSL
  4987. }
  4988. Pass
  4989. {
  4990. Name "Meta"
  4991. Tags
  4992. {
  4993. "LightMode" = "Meta"
  4994. }
  4995. Cull Off
  4996. HLSLPROGRAM
  4997. #pragma vertex Vert
  4998. #pragma fragment Frag
  4999. #pragma target 3.0
  5000. #pragma prefer_hlslcc gles
  5001. #pragma exclude_renderers d3d11_9x
  5002. #define SHADERPASS SHADERPASS_META
  5003. #define _PASSMETA 1
  5004. #include "Flow.cginc"
  5005. #pragma shader_feature_local _ _STRETCH_ON
  5006. #pragma shader_feature_local DISABLEFOG
  5007. #define _URP 1
  5008. #define _USINGTEXCOORD1 1
  5009. #define _USINGTEXCOORD2 1
  5010. // Includes
  5011. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  5012. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  5013. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  5014. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  5015. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  5016. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
  5017. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  5018. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  5019. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  5020. #undef WorldNormalVector
  5021. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  5022. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  5023. #define _WorldSpaceLightPos0 _MainLightPosition
  5024. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  5025. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  5026. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  5027. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  5028. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  5029. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  5030. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  5031. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  5032. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  5033. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  5034. #if defined(UNITY_COMPILER_HLSL)
  5035. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  5036. #else
  5037. #define UNITY_INITIALIZE_OUTPUT(type,name)
  5038. #endif
  5039. #define sampler2D_float sampler2D
  5040. #define sampler2D_half sampler2D
  5041. // data across stages, stripped like the above.
  5042. struct VertexToPixel
  5043. {
  5044. float4 pos : SV_POSITION;
  5045. float3 worldPos : TEXCOORD0;
  5046. float3 worldNormal : TEXCOORD1;
  5047. float4 worldTangent : TEXCOORD2;
  5048. float4 texcoord0 : TEXCOORD3;
  5049. float4 texcoord1 : TEXCOORD4;
  5050. float4 texcoord2 : TEXCOORD5;
  5051. // #if %TEXCOORD3REQUIREKEY%
  5052. float4 texcoord3 : TEXCOORD6;
  5053. // #endif
  5054. // #if %SCREENPOSREQUIREKEY%
  5055. float4 screenPos : TEXCOORD7;
  5056. // #endif
  5057. // #if %VERTEXCOLORREQUIREKEY%
  5058. // half4 vertexColor : COLOR;
  5059. // #endif
  5060. #if defined(LIGHTMAP_ON)
  5061. float2 lightmapUV : TEXCOORD8;
  5062. #endif
  5063. #if defined(DYNAMICLIGHTMAP_ON)
  5064. float2 dynamicLightmapUV : TEXCOORD9;
  5065. #endif
  5066. #if !defined(LIGHTMAP_ON)
  5067. float3 sh : TEXCOORD10;
  5068. #endif
  5069. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  5070. float4 fogFactorAndVertexLight : TEXCOORD11;
  5071. #endif
  5072. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  5073. float4 shadowCoord : TEXCOORD12;
  5074. #endif
  5075. // #if %EXTRAV2F0REQUIREKEY%
  5076. // float4 extraV2F0 : TEXCOORD13;
  5077. // #endif
  5078. // #if %EXTRAV2F1REQUIREKEY%
  5079. // float4 extraV2F1 : TEXCOORD14;
  5080. // #endif
  5081. // #if %EXTRAV2F2REQUIREKEY%
  5082. // float4 extraV2F2 : TEXCOORD15;
  5083. // #endif
  5084. // #if %EXTRAV2F3REQUIREKEY%
  5085. // float4 extraV2F3 : TEXCOORD16;
  5086. // #endif
  5087. // #if %EXTRAV2F4REQUIREKEY%
  5088. // float4 extraV2F4 : TEXCOORD17;
  5089. // #endif
  5090. // #if %EXTRAV2F5REQUIREKEY%
  5091. // float4 extraV2F5 : TEXCOORD18;
  5092. // #endif
  5093. // #if %EXTRAV2F6REQUIREKEY%
  5094. // float4 extraV2F6 : TEXCOORD19;
  5095. // #endif
  5096. // #if %EXTRAV2F7REQUIREKEY%
  5097. // float4 extraV2F7 : TEXCOORD20;
  5098. // #endif
  5099. #if UNITY_ANY_INSTANCING_ENABLED
  5100. uint instanceID : CUSTOM_INSTANCE_ID;
  5101. #endif
  5102. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  5103. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  5104. #endif
  5105. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  5106. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  5107. #endif
  5108. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  5109. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  5110. #endif
  5111. };
  5112. // data describing the user output of a pixel
  5113. struct Surface
  5114. {
  5115. half3 Albedo;
  5116. half Height;
  5117. half3 Normal;
  5118. half Smoothness;
  5119. half3 Emission;
  5120. half Metallic;
  5121. half3 Specular;
  5122. half Occlusion;
  5123. half SpecularPower; // for simple lighting
  5124. half Alpha;
  5125. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  5126. // HDRP Only
  5127. half SpecularOcclusion;
  5128. half SubsurfaceMask;
  5129. half Thickness;
  5130. half CoatMask;
  5131. half CoatSmoothness;
  5132. half Anisotropy;
  5133. half IridescenceMask;
  5134. half IridescenceThickness;
  5135. int DiffusionProfileHash;
  5136. float SpecularAAThreshold;
  5137. float SpecularAAScreenSpaceVariance;
  5138. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  5139. float3 DiffuseGI;
  5140. float3 BackDiffuseGI;
  5141. float3 SpecularGI;
  5142. float ior;
  5143. float3 transmittanceColor;
  5144. float atDistance;
  5145. float transmittanceMask;
  5146. // requires _OVERRIDE_SHADOWMASK to be defines
  5147. float4 ShadowMask;
  5148. // for decals
  5149. float NormalAlpha;
  5150. float MAOSAlpha;
  5151. };
  5152. // Data the user declares in blackboard blocks
  5153. struct Blackboard
  5154. {
  5155. float groundHeight;
  5156. float surfaceHeight;
  5157. float3 surfaceNormal;
  5158. Fluid fluid;
  5159. float blackboardDummyData;
  5160. };
  5161. // data the user might need, this will grow to be big. But easy to strip
  5162. struct ShaderData
  5163. {
  5164. float4 clipPos; // SV_POSITION
  5165. float3 localSpacePosition;
  5166. float3 localSpaceNormal;
  5167. float3 localSpaceTangent;
  5168. float3 worldSpacePosition;
  5169. float3 worldSpaceNormal;
  5170. float3 worldSpaceTangent;
  5171. float tangentSign;
  5172. float3 worldSpaceViewDir;
  5173. float3 tangentSpaceViewDir;
  5174. float4 texcoord0;
  5175. float4 texcoord1;
  5176. float4 texcoord2;
  5177. float4 texcoord3;
  5178. float2 screenUV;
  5179. float4 screenPos;
  5180. float4 vertexColor;
  5181. bool isFrontFace;
  5182. float4 extraV2F0;
  5183. float4 extraV2F1;
  5184. float4 extraV2F2;
  5185. float4 extraV2F3;
  5186. float4 extraV2F4;
  5187. float4 extraV2F5;
  5188. float4 extraV2F6;
  5189. float4 extraV2F7;
  5190. float3x3 TBNMatrix;
  5191. Blackboard blackboard;
  5192. };
  5193. struct VertexData
  5194. {
  5195. #if SHADER_TARGET > 30
  5196. // uint vertexID : SV_VertexID;
  5197. #endif
  5198. float4 vertex : POSITION;
  5199. float3 normal : NORMAL;
  5200. float4 tangent : TANGENT;
  5201. float4 texcoord0 : TEXCOORD0;
  5202. // optimize out mesh coords when not in use by user or lighting system
  5203. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  5204. float4 texcoord1 : TEXCOORD1;
  5205. #endif
  5206. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  5207. float4 texcoord2 : TEXCOORD2;
  5208. #endif
  5209. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  5210. float4 texcoord1 : TEXCOORD1;
  5211. #endif
  5212. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  5213. float4 texcoord2 : TEXCOORD2;
  5214. #endif
  5215. #if _HDRP
  5216. float4 texcoord1 : TEXCOORD1;
  5217. float4 texcoord2 : TEXCOORD2;
  5218. #endif
  5219. // #if %TEXCOORD3REQUIREKEY%
  5220. float4 texcoord3 : TEXCOORD3;
  5221. // #endif
  5222. // #if %VERTEXCOLORREQUIREKEY%
  5223. // float4 vertexColor : COLOR;
  5224. // #endif
  5225. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  5226. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  5227. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  5228. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  5229. #endif
  5230. #endif
  5231. UNITY_VERTEX_INPUT_INSTANCE_ID
  5232. };
  5233. struct TessVertex
  5234. {
  5235. float4 vertex : INTERNALTESSPOS;
  5236. float3 normal : NORMAL;
  5237. float4 tangent : TANGENT;
  5238. float4 texcoord0 : TEXCOORD0;
  5239. float4 texcoord1 : TEXCOORD1;
  5240. float4 texcoord2 : TEXCOORD2;
  5241. // #if %TEXCOORD3REQUIREKEY%
  5242. float4 texcoord3 : TEXCOORD3;
  5243. // #endif
  5244. // #if %VERTEXCOLORREQUIREKEY%
  5245. // float4 vertexColor : COLOR;
  5246. // #endif
  5247. // #if %EXTRAV2F0REQUIREKEY%
  5248. // float4 extraV2F0 : TEXCOORD5;
  5249. // #endif
  5250. // #if %EXTRAV2F1REQUIREKEY%
  5251. // float4 extraV2F1 : TEXCOORD6;
  5252. // #endif
  5253. // #if %EXTRAV2F2REQUIREKEY%
  5254. // float4 extraV2F2 : TEXCOORD7;
  5255. // #endif
  5256. // #if %EXTRAV2F3REQUIREKEY%
  5257. // float4 extraV2F3 : TEXCOORD8;
  5258. // #endif
  5259. // #if %EXTRAV2F4REQUIREKEY%
  5260. // float4 extraV2F4 : TEXCOORD9;
  5261. // #endif
  5262. // #if %EXTRAV2F5REQUIREKEY%
  5263. // float4 extraV2F5 : TEXCOORD10;
  5264. // #endif
  5265. // #if %EXTRAV2F6REQUIREKEY%
  5266. // float4 extraV2F6 : TEXCOORD11;
  5267. // #endif
  5268. // #if %EXTRAV2F7REQUIREKEY%
  5269. // float4 extraV2F7 : TEXCOORD12;
  5270. // #endif
  5271. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  5272. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  5273. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  5274. float3 precomputedVelocity : TEXCOORD14;
  5275. #endif
  5276. #endif
  5277. UNITY_VERTEX_INPUT_INSTANCE_ID
  5278. UNITY_VERTEX_OUTPUT_STEREO
  5279. };
  5280. struct ExtraV2F
  5281. {
  5282. float4 extraV2F0;
  5283. float4 extraV2F1;
  5284. float4 extraV2F2;
  5285. float4 extraV2F3;
  5286. float4 extraV2F4;
  5287. float4 extraV2F5;
  5288. float4 extraV2F6;
  5289. float4 extraV2F7;
  5290. Blackboard blackboard;
  5291. float4 time;
  5292. };
  5293. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  5294. {
  5295. return mul(d.TBNMatrix, normal);
  5296. }
  5297. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  5298. {
  5299. return mul(normal, d.TBNMatrix);
  5300. }
  5301. // in this case, make standard more like SRPs, because we can't fix
  5302. // unity_WorldToObject in HDRP, since it already does macro-fu there
  5303. #if _STANDARD
  5304. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  5305. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  5306. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  5307. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  5308. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  5309. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  5310. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  5311. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  5312. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  5313. #else
  5314. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  5315. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  5316. #endif
  5317. #undef GetWorldToObjectMatrix()
  5318. #define GetWorldToObjectMatrix() unity_WorldToObject
  5319. #endif
  5320. float3 GetCameraWorldPosition()
  5321. {
  5322. #if _HDRP
  5323. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  5324. #else
  5325. return _WorldSpaceCameraPos;
  5326. #endif
  5327. }
  5328. #if _GRABPASSUSED
  5329. #if _STANDARD
  5330. TEXTURE2D(%GRABTEXTURE%);
  5331. SAMPLER(sampler_%GRABTEXTURE%);
  5332. #endif
  5333. half3 GetSceneColor(float2 uv)
  5334. {
  5335. #if _STANDARD
  5336. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  5337. #else
  5338. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  5339. #endif
  5340. }
  5341. #endif
  5342. #if _STANDARD
  5343. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  5344. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  5345. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  5346. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  5347. #else
  5348. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  5349. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  5350. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  5351. #endif
  5352. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  5353. {
  5354. float eye = GetLinearEyeDepth(uv);
  5355. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  5356. float dt = dot(worldSpaceViewDir, camView);
  5357. float3 div = worldSpaceViewDir/dt;
  5358. float3 wpos = (eye * div) + GetCameraWorldPosition();
  5359. return wpos;
  5360. }
  5361. #if _HDRP
  5362. float3 ObjectToWorldSpacePosition(float3 pos)
  5363. {
  5364. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  5365. }
  5366. #else
  5367. float3 ObjectToWorldSpacePosition(float3 pos)
  5368. {
  5369. return TransformObjectToWorld(pos);
  5370. }
  5371. #endif
  5372. #if _STANDARD
  5373. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  5374. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  5375. {
  5376. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  5377. float3 norms = DecodeViewNormalStereo(depthNorms);
  5378. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  5379. return norms;
  5380. }
  5381. #elif _HDRP && !_DECALSHADER
  5382. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  5383. {
  5384. NormalData nd;
  5385. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  5386. return nd.normalWS;
  5387. }
  5388. #elif _URP
  5389. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  5390. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  5391. #endif
  5392. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  5393. {
  5394. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  5395. return SampleSceneNormals(uv);
  5396. #else
  5397. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  5398. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  5399. #endif
  5400. }
  5401. #endif
  5402. #if _HDRP
  5403. half3 UnpackNormalmapRGorAG(half4 packednormal)
  5404. {
  5405. // This do the trick
  5406. packednormal.x *= packednormal.w;
  5407. half3 normal;
  5408. normal.xy = packednormal.xy * 2 - 1;
  5409. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  5410. return normal;
  5411. }
  5412. half3 UnpackNormal(half4 packednormal)
  5413. {
  5414. #if defined(UNITY_NO_DXT5nm)
  5415. return packednormal.xyz * 2 - 1;
  5416. #else
  5417. return UnpackNormalmapRGorAG(packednormal);
  5418. #endif
  5419. }
  5420. #endif
  5421. #if _HDRP || _URP
  5422. half3 UnpackScaleNormal(half4 packednormal, half scale)
  5423. {
  5424. #ifndef UNITY_NO_DXT5nm
  5425. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  5426. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  5427. packednormal.x *= packednormal.w;
  5428. #endif
  5429. half3 normal;
  5430. normal.xy = (packednormal.xy * 2 - 1) * scale;
  5431. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  5432. return normal;
  5433. }
  5434. #endif
  5435. void GetSun(out float3 lightDir, out float3 color)
  5436. {
  5437. lightDir = float3(0.5, 0.5, 0);
  5438. color = 1;
  5439. #if _HDRP
  5440. if (_DirectionalLightCount > 0)
  5441. {
  5442. DirectionalLightData light = _DirectionalLightDatas[0];
  5443. lightDir = -light.forward.xyz;
  5444. color = light.color;
  5445. }
  5446. #elif _STANDARD
  5447. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  5448. color = _LightColor0.rgb;
  5449. #elif _URP
  5450. Light light = GetMainLight();
  5451. lightDir = light.direction;
  5452. color = light.color;
  5453. #endif
  5454. }
  5455. CBUFFER_START(UnityPerMaterial)
  5456. float _FlowDensity;
  5457. float2 _FlowSeparationXZ;
  5458. float _FlowSimulationHeight;
  5459. float _FlowCameraHeight;
  5460. float2 _FlowCountXZ;
  5461. float4 _FlowCoordU000;
  5462. float4 _FlowCoord0V00;
  5463. float _FlowSpeed;
  5464. float4x4 _FlowMatrix;
  5465. float _Sink;
  5466. int2 _PartCountXY;
  5467. float _FlowDelta;
  5468. float _ScaleBase;
  5469. float _ScaleVolume;
  5470. float _StretchScale;
  5471. CBUFFER_END
  5472. #ifdef unity_WorldToObject
  5473. #undef unity_WorldToObject
  5474. #endif
  5475. #ifdef unity_ObjectToWorld
  5476. #undef unity_ObjectToWorld
  5477. #endif
  5478. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  5479. #define unity_WorldToObject GetWorldToObjectMatrix()
  5480. TEXTURE2D(_FlowDataA);
  5481. SAMPLER(sampler_FlowDataA);
  5482. TEXTURE2D(_FlowDataB);
  5483. SAMPLER(sampler_FlowDataB);
  5484. TEXTURE2D(_FlowDataC);
  5485. SAMPLER(sampler_FlowDataC);
  5486. TEXTURE2D(_FlowDataD);
  5487. SAMPLER(sampler_FlowDataD);
  5488. TEXTURE2D(_FlowDataE);
  5489. SAMPLER(sampler_FlowDataE);
  5490. TEXTURE2D(_FlowDataF);
  5491. SAMPLER(sampler_FlowDataF);
  5492. float4 SGT_O2W(float4 v)
  5493. {
  5494. v = mul(GetObjectToWorldMatrix(), v);
  5495. #if _HDRP
  5496. v.xyz = GetAbsolutePositionWS(v.xyz);
  5497. #endif
  5498. return v;
  5499. }
  5500. float4 SGT_W2O(float4 v)
  5501. {
  5502. #if _HDRP
  5503. v.xyz = GetCameraRelativePositionWS(v.xyz);
  5504. #endif
  5505. return mul(GetWorldToObjectMatrix(), v);
  5506. }
  5507. float4 SGT_O2V(float4 v)
  5508. {
  5509. #if _STANDARD
  5510. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  5511. #else
  5512. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  5513. #endif
  5514. }
  5515. float GetFluidHeight(float2 uv)
  5516. {
  5517. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  5518. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  5519. return groundHeight + fluidDepth;
  5520. }
  5521. float2 GetHeightAndDepth(float2 uv)
  5522. {
  5523. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  5524. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  5525. return float2(groundHeight, fluidDepth);
  5526. }
  5527. Column GetColumn(float2 uv)
  5528. {
  5529. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  5530. }
  5531. Fluid GetColumnFluid(float2 uv)
  5532. {
  5533. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  5534. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  5535. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  5536. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  5537. return DecodeFluid(c, d, e, f);
  5538. }
  5539. bool InsideFluid(float3 wpos)
  5540. {
  5541. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  5542. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  5543. float2 columnHAD = GetHeightAndDepth(columnCoord);
  5544. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  5545. }
  5546. bool UnderFluid(float3 wpos)
  5547. {
  5548. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  5549. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  5550. float2 columnHAD = GetHeightAndDepth(columnCoord);
  5551. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  5552. }
  5553. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  5554. {
  5555. float epsi = step * 0.01f;
  5556. float dist = 0.0f;
  5557. for (int i = 0; i < maxs && step > epsi; i++)
  5558. {
  5559. dist += step;
  5560. float3 pos = wpos + wdir * dist;
  5561. if (InsideFluid(pos) == false)
  5562. {
  5563. dist -= step;
  5564. step *= 0.5f;
  5565. }
  5566. if (dist > maxd)
  5567. {
  5568. return maxd;
  5569. }
  5570. }
  5571. return dist;
  5572. }
  5573. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  5574. {
  5575. float epsi = step * 0.01f;
  5576. float dist = 0.0f;
  5577. for (int i = 0; i < maxs && step > epsi; i++)
  5578. {
  5579. dist += step;
  5580. float3 pos = wpos + wdir * dist;
  5581. if (UnderFluid(pos) == false)
  5582. {
  5583. dist -= step;
  5584. step *= 0.5f;
  5585. }
  5586. if (dist > maxd)
  5587. {
  5588. return maxd;
  5589. }
  5590. }
  5591. return dist;
  5592. }
  5593. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  5594. {
  5595. float4 wpos = SGT_O2W(v.vertex);
  5596. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  5597. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  5598. Column column0 = GetColumn(columnCoord);
  5599. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  5600. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  5601. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  5602. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  5603. Fluid fluid0 = GetColumnFluid(columnCoord);
  5604. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  5605. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  5606. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  5607. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  5608. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  5609. float wL = fluidL.Depth / ww;
  5610. float wR = fluidR.Depth / ww;
  5611. float wB = fluidB.Depth / ww;
  5612. float wT = fluidT.Depth / ww;
  5613. float w0 = saturate(fluid0.Depth * 10);
  5614. float hL = columnL.GroundHeight + fluidL.Depth;
  5615. float hR = columnR.GroundHeight + fluidR.Depth;
  5616. float hB = columnB.GroundHeight + fluidB.Depth;
  5617. float hT = columnT.GroundHeight + fluidT.Depth;
  5618. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  5619. float h0 = column0.GroundHeight + fluid0.Depth;
  5620. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  5621. Fluid fluid = fluid0;
  5622. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  5623. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  5624. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  5625. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  5626. e.blackboard.groundHeight = column0.GroundHeight;
  5627. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  5628. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  5629. e.blackboard.fluid = fluid;
  5630. }
  5631. TEXTURE2D(_MainTex);
  5632. SAMPLER(sampler_MainTex);
  5633. TEXTURE2D(_BumpMap);
  5634. SAMPLER(sampler_BumpMap);
  5635. TEXTURE2D(_PartDataA);
  5636. SAMPLER(sampler_PartDataA);
  5637. TEXTURE2D(_PartDataB);
  5638. SAMPLER(sampler_PartDataB);
  5639. TEXTURE2D(_PartDataC);
  5640. SAMPLER(sampler_PartDataC);
  5641. TEXTURE2D(_PartDataD);
  5642. SAMPLER(sampler_PartDataD);
  5643. TEXTURE2D(_PartDataE);
  5644. SAMPLER(sampler_PartDataE);
  5645. TEXTURE2D(_PartDataF);
  5646. SAMPLER(sampler_PartDataF);
  5647. Particle GetParticle(float2 uv)
  5648. {
  5649. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  5650. }
  5651. Fluid GetParticleFluid(float2 uv)
  5652. {
  5653. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  5654. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  5655. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  5656. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  5657. return DecodeFluid(c, d, e, f);
  5658. }
  5659. float2 Rotate(float2 v, float a)
  5660. {
  5661. float s = sin(a);
  5662. float c = cos(a);
  5663. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  5664. }
  5665. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  5666. {
  5667. float2 particlePixel = v.texcoord1.xy;
  5668. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  5669. Particle particle = GetParticle(particleCoord);
  5670. Fluid fluid = GetParticleFluid(particleCoord);
  5671. float size = particle.Age < particle.Life;
  5672. float4 wpos = float4(particle.Position, 1.0f);
  5673. float2 rvec = v.texcoord0.xy * size;
  5674. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  5675. #if _STRETCH_ON
  5676. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  5677. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  5678. float2 posV = posB.xy - posA.xy;
  5679. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  5680. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  5681. #endif
  5682. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  5683. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  5684. v.vertex = SGT_W2O(wpos);
  5685. v.normal = GetWorldToViewMatrix()[2].xyz;
  5686. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  5687. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  5688. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  5689. v.texcoord0 += 0.5f;
  5690. v.texcoord1 = fluid.RGBA;
  5691. v.texcoord2 = fluid.ESMV;
  5692. }
  5693. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  5694. {
  5695. Fluid fluid;
  5696. fluid.RGBA = d.texcoord1;
  5697. fluid.ESMV = d.texcoord2;
  5698. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  5699. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  5700. //clip(texMain.a - 0.5f);
  5701. float DITHER_THRESHOLDS[16] =
  5702. {
  5703. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  5704. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  5705. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  5706. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  5707. };
  5708. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  5709. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  5710. clip(texMain.a - DITHER_THRESHOLDS[index]);
  5711. o.Albedo = fluid.RGBA.xyz;
  5712. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  5713. o.Smoothness = fluid.ESMV.y;
  5714. o.Metallic = fluid.ESMV.z;
  5715. o.Normal = UnpackScaleNormal(bump, 1.0f);
  5716. }
  5717. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  5718. {
  5719. // Ext_SurfaceFunction0(l, d);
  5720. Ext_SurfaceFunction1(l, d);
  5721. // Ext_SurfaceFunction2(l, d);
  5722. // Ext_SurfaceFunction3(l, d);
  5723. // Ext_SurfaceFunction4(l, d);
  5724. // Ext_SurfaceFunction5(l, d);
  5725. // Ext_SurfaceFunction6(l, d);
  5726. // Ext_SurfaceFunction7(l, d);
  5727. // Ext_SurfaceFunction8(l, d);
  5728. // Ext_SurfaceFunction9(l, d);
  5729. // Ext_SurfaceFunction10(l, d);
  5730. // Ext_SurfaceFunction11(l, d);
  5731. // Ext_SurfaceFunction12(l, d);
  5732. // Ext_SurfaceFunction13(l, d);
  5733. // Ext_SurfaceFunction14(l, d);
  5734. // Ext_SurfaceFunction15(l, d);
  5735. // Ext_SurfaceFunction16(l, d);
  5736. // Ext_SurfaceFunction17(l, d);
  5737. // Ext_SurfaceFunction18(l, d);
  5738. // Ext_SurfaceFunction19(l, d);
  5739. // Ext_SurfaceFunction20(l, d);
  5740. // Ext_SurfaceFunction21(l, d);
  5741. // Ext_SurfaceFunction22(l, d);
  5742. // Ext_SurfaceFunction23(l, d);
  5743. // Ext_SurfaceFunction24(l, d);
  5744. // Ext_SurfaceFunction25(l, d);
  5745. // Ext_SurfaceFunction26(l, d);
  5746. // Ext_SurfaceFunction27(l, d);
  5747. // Ext_SurfaceFunction28(l, d);
  5748. // Ext_SurfaceFunction29(l, d);
  5749. }
  5750. #if !_DECALSHADER
  5751. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  5752. {
  5753. ExtraV2F d;
  5754. ZERO_INITIALIZE(ExtraV2F, d);
  5755. ZERO_INITIALIZE(Blackboard, d.blackboard);
  5756. // due to motion vectors in HDRP, we need to use the last
  5757. // time in certain spots. So if you are going to use _Time to adjust vertices,
  5758. // you need to use this time or motion vectors will break.
  5759. d.time = time;
  5760. Ext_ModifyVertex0(v, d);
  5761. Ext_ModifyVertex1(v, d);
  5762. // Ext_ModifyVertex2(v, d);
  5763. // Ext_ModifyVertex3(v, d);
  5764. // Ext_ModifyVertex4(v, d);
  5765. // Ext_ModifyVertex5(v, d);
  5766. // Ext_ModifyVertex6(v, d);
  5767. // Ext_ModifyVertex7(v, d);
  5768. // Ext_ModifyVertex8(v, d);
  5769. // Ext_ModifyVertex9(v, d);
  5770. // Ext_ModifyVertex10(v, d);
  5771. // Ext_ModifyVertex11(v, d);
  5772. // Ext_ModifyVertex12(v, d);
  5773. // Ext_ModifyVertex13(v, d);
  5774. // Ext_ModifyVertex14(v, d);
  5775. // Ext_ModifyVertex15(v, d);
  5776. // Ext_ModifyVertex16(v, d);
  5777. // Ext_ModifyVertex17(v, d);
  5778. // Ext_ModifyVertex18(v, d);
  5779. // Ext_ModifyVertex19(v, d);
  5780. // Ext_ModifyVertex20(v, d);
  5781. // Ext_ModifyVertex21(v, d);
  5782. // Ext_ModifyVertex22(v, d);
  5783. // Ext_ModifyVertex23(v, d);
  5784. // Ext_ModifyVertex24(v, d);
  5785. // Ext_ModifyVertex25(v, d);
  5786. // Ext_ModifyVertex26(v, d);
  5787. // Ext_ModifyVertex27(v, d);
  5788. // Ext_ModifyVertex28(v, d);
  5789. // Ext_ModifyVertex29(v, d);
  5790. // #if %EXTRAV2F0REQUIREKEY%
  5791. // v2p.extraV2F0 = d.extraV2F0;
  5792. // #endif
  5793. // #if %EXTRAV2F1REQUIREKEY%
  5794. // v2p.extraV2F1 = d.extraV2F1;
  5795. // #endif
  5796. // #if %EXTRAV2F2REQUIREKEY%
  5797. // v2p.extraV2F2 = d.extraV2F2;
  5798. // #endif
  5799. // #if %EXTRAV2F3REQUIREKEY%
  5800. // v2p.extraV2F3 = d.extraV2F3;
  5801. // #endif
  5802. // #if %EXTRAV2F4REQUIREKEY%
  5803. // v2p.extraV2F4 = d.extraV2F4;
  5804. // #endif
  5805. // #if %EXTRAV2F5REQUIREKEY%
  5806. // v2p.extraV2F5 = d.extraV2F5;
  5807. // #endif
  5808. // #if %EXTRAV2F6REQUIREKEY%
  5809. // v2p.extraV2F6 = d.extraV2F6;
  5810. // #endif
  5811. // #if %EXTRAV2F7REQUIREKEY%
  5812. // v2p.extraV2F7 = d.extraV2F7;
  5813. // #endif
  5814. }
  5815. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  5816. {
  5817. ExtraV2F d;
  5818. ZERO_INITIALIZE(ExtraV2F, d);
  5819. ZERO_INITIALIZE(Blackboard, d.blackboard);
  5820. // #if %EXTRAV2F0REQUIREKEY%
  5821. // d.extraV2F0 = v2p.extraV2F0;
  5822. // #endif
  5823. // #if %EXTRAV2F1REQUIREKEY%
  5824. // d.extraV2F1 = v2p.extraV2F1;
  5825. // #endif
  5826. // #if %EXTRAV2F2REQUIREKEY%
  5827. // d.extraV2F2 = v2p.extraV2F2;
  5828. // #endif
  5829. // #if %EXTRAV2F3REQUIREKEY%
  5830. // d.extraV2F3 = v2p.extraV2F3;
  5831. // #endif
  5832. // #if %EXTRAV2F4REQUIREKEY%
  5833. // d.extraV2F4 = v2p.extraV2F4;
  5834. // #endif
  5835. // #if %EXTRAV2F5REQUIREKEY%
  5836. // d.extraV2F5 = v2p.extraV2F5;
  5837. // #endif
  5838. // #if %EXTRAV2F6REQUIREKEY%
  5839. // d.extraV2F6 = v2p.extraV2F6;
  5840. // #endif
  5841. // #if %EXTRAV2F7REQUIREKEY%
  5842. // d.extraV2F7 = v2p.extraV2F7;
  5843. // #endif
  5844. // Ext_ModifyTessellatedVertex0(v, d);
  5845. // Ext_ModifyTessellatedVertex1(v, d);
  5846. // Ext_ModifyTessellatedVertex2(v, d);
  5847. // Ext_ModifyTessellatedVertex3(v, d);
  5848. // Ext_ModifyTessellatedVertex4(v, d);
  5849. // Ext_ModifyTessellatedVertex5(v, d);
  5850. // Ext_ModifyTessellatedVertex6(v, d);
  5851. // Ext_ModifyTessellatedVertex7(v, d);
  5852. // Ext_ModifyTessellatedVertex8(v, d);
  5853. // Ext_ModifyTessellatedVertex9(v, d);
  5854. // Ext_ModifyTessellatedVertex10(v, d);
  5855. // Ext_ModifyTessellatedVertex11(v, d);
  5856. // Ext_ModifyTessellatedVertex12(v, d);
  5857. // Ext_ModifyTessellatedVertex13(v, d);
  5858. // Ext_ModifyTessellatedVertex14(v, d);
  5859. // Ext_ModifyTessellatedVertex15(v, d);
  5860. // Ext_ModifyTessellatedVertex16(v, d);
  5861. // Ext_ModifyTessellatedVertex17(v, d);
  5862. // Ext_ModifyTessellatedVertex18(v, d);
  5863. // Ext_ModifyTessellatedVertex19(v, d);
  5864. // Ext_ModifyTessellatedVertex20(v, d);
  5865. // Ext_ModifyTessellatedVertex21(v, d);
  5866. // Ext_ModifyTessellatedVertex22(v, d);
  5867. // Ext_ModifyTessellatedVertex23(v, d);
  5868. // Ext_ModifyTessellatedVertex24(v, d);
  5869. // Ext_ModifyTessellatedVertex25(v, d);
  5870. // Ext_ModifyTessellatedVertex26(v, d);
  5871. // Ext_ModifyTessellatedVertex27(v, d);
  5872. // Ext_ModifyTessellatedVertex28(v, d);
  5873. // Ext_ModifyTessellatedVertex29(v, d);
  5874. // #if %EXTRAV2F0REQUIREKEY%
  5875. // v2p.extraV2F0 = d.extraV2F0;
  5876. // #endif
  5877. // #if %EXTRAV2F1REQUIREKEY%
  5878. // v2p.extraV2F1 = d.extraV2F1;
  5879. // #endif
  5880. // #if %EXTRAV2F2REQUIREKEY%
  5881. // v2p.extraV2F2 = d.extraV2F2;
  5882. // #endif
  5883. // #if %EXTRAV2F3REQUIREKEY%
  5884. // v2p.extraV2F3 = d.extraV2F3;
  5885. // #endif
  5886. // #if %EXTRAV2F4REQUIREKEY%
  5887. // v2p.extraV2F4 = d.extraV2F4;
  5888. // #endif
  5889. // #if %EXTRAV2F5REQUIREKEY%
  5890. // v2p.extraV2F5 = d.extraV2F5;
  5891. // #endif
  5892. // #if %EXTRAV2F6REQUIREKEY%
  5893. // v2p.extraV2F6 = d.extraV2F6;
  5894. // #endif
  5895. // #if %EXTRAV2F7REQUIREKEY%
  5896. // v2p.extraV2F7 = d.extraV2F7;
  5897. // #endif
  5898. }
  5899. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  5900. {
  5901. // Ext_FinalColorForward0(l, d, color);
  5902. // Ext_FinalColorForward1(l, d, color);
  5903. // Ext_FinalColorForward2(l, d, color);
  5904. // Ext_FinalColorForward3(l, d, color);
  5905. // Ext_FinalColorForward4(l, d, color);
  5906. // Ext_FinalColorForward5(l, d, color);
  5907. // Ext_FinalColorForward6(l, d, color);
  5908. // Ext_FinalColorForward7(l, d, color);
  5909. // Ext_FinalColorForward8(l, d, color);
  5910. // Ext_FinalColorForward9(l, d, color);
  5911. // Ext_FinalColorForward10(l, d, color);
  5912. // Ext_FinalColorForward11(l, d, color);
  5913. // Ext_FinalColorForward12(l, d, color);
  5914. // Ext_FinalColorForward13(l, d, color);
  5915. // Ext_FinalColorForward14(l, d, color);
  5916. // Ext_FinalColorForward15(l, d, color);
  5917. // Ext_FinalColorForward16(l, d, color);
  5918. // Ext_FinalColorForward17(l, d, color);
  5919. // Ext_FinalColorForward18(l, d, color);
  5920. // Ext_FinalColorForward19(l, d, color);
  5921. // Ext_FinalColorForward20(l, d, color);
  5922. // Ext_FinalColorForward21(l, d, color);
  5923. // Ext_FinalColorForward22(l, d, color);
  5924. // Ext_FinalColorForward23(l, d, color);
  5925. // Ext_FinalColorForward24(l, d, color);
  5926. // Ext_FinalColorForward25(l, d, color);
  5927. // Ext_FinalColorForward26(l, d, color);
  5928. // Ext_FinalColorForward27(l, d, color);
  5929. // Ext_FinalColorForward28(l, d, color);
  5930. // Ext_FinalColorForward29(l, d, color);
  5931. }
  5932. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  5933. {
  5934. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5935. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5936. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5937. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5938. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5939. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5940. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5941. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5942. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5943. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5944. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5945. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5946. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5947. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5948. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5949. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5950. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5951. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5952. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5953. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5954. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5955. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5956. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5957. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5958. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5959. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5960. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5961. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5962. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5963. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  5964. }
  5965. #endif
  5966. #if _DECALSHADER
  5967. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  5968. {
  5969. ShaderData d = (ShaderData)0;
  5970. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  5971. d.worldSpaceNormal = IN.WorldSpaceNormal;
  5972. d.worldSpaceTangent = IN.WorldSpaceTangent;
  5973. d.worldSpacePosition = IN.WorldSpacePosition;
  5974. d.texcoord0 = IN.uv0.xyxy;
  5975. d.screenPos = IN.ScreenPosition;
  5976. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  5977. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  5978. // these rarely get used, so we back transform them. Usually will be stripped.
  5979. #if _HDRP
  5980. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  5981. #else
  5982. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  5983. #endif
  5984. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  5985. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  5986. // #if %SCREENPOSREQUIREKEY%
  5987. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  5988. // #endif
  5989. return d;
  5990. }
  5991. #else
  5992. ShaderData CreateShaderData(VertexToPixel i
  5993. #if NEED_FACING
  5994. , bool facing
  5995. #endif
  5996. )
  5997. {
  5998. ShaderData d = (ShaderData)0;
  5999. d.clipPos = i.pos;
  6000. d.worldSpacePosition = i.worldPos;
  6001. d.worldSpaceNormal = normalize(i.worldNormal);
  6002. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  6003. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  6004. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  6005. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  6006. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  6007. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  6008. d.texcoord0 = i.texcoord0;
  6009. d.texcoord1 = i.texcoord1;
  6010. d.texcoord2 = i.texcoord2;
  6011. // #if %TEXCOORD3REQUIREKEY%
  6012. d.texcoord3 = i.texcoord3;
  6013. // #endif
  6014. // d.isFrontFace = facing;
  6015. // #if %VERTEXCOLORREQUIREKEY%
  6016. // d.vertexColor = i.vertexColor;
  6017. // #endif
  6018. // these rarely get used, so we back transform them. Usually will be stripped.
  6019. #if _HDRP
  6020. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  6021. #else
  6022. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  6023. #endif
  6024. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  6025. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  6026. // #if %SCREENPOSREQUIREKEY%
  6027. d.screenPos = i.screenPos;
  6028. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  6029. // #endif
  6030. // #if %EXTRAV2F0REQUIREKEY%
  6031. // d.extraV2F0 = i.extraV2F0;
  6032. // #endif
  6033. // #if %EXTRAV2F1REQUIREKEY%
  6034. // d.extraV2F1 = i.extraV2F1;
  6035. // #endif
  6036. // #if %EXTRAV2F2REQUIREKEY%
  6037. // d.extraV2F2 = i.extraV2F2;
  6038. // #endif
  6039. // #if %EXTRAV2F3REQUIREKEY%
  6040. // d.extraV2F3 = i.extraV2F3;
  6041. // #endif
  6042. // #if %EXTRAV2F4REQUIREKEY%
  6043. // d.extraV2F4 = i.extraV2F4;
  6044. // #endif
  6045. // #if %EXTRAV2F5REQUIREKEY%
  6046. // d.extraV2F5 = i.extraV2F5;
  6047. // #endif
  6048. // #if %EXTRAV2F6REQUIREKEY%
  6049. // d.extraV2F6 = i.extraV2F6;
  6050. // #endif
  6051. // #if %EXTRAV2F7REQUIREKEY%
  6052. // d.extraV2F7 = i.extraV2F7;
  6053. // #endif
  6054. return d;
  6055. }
  6056. #endif
  6057. #if defined(_PASSSHADOW)
  6058. float3 _LightDirection;
  6059. float3 _LightPosition;
  6060. #endif
  6061. // vertex shader
  6062. VertexToPixel Vert (VertexData v)
  6063. {
  6064. VertexToPixel o = (VertexToPixel)0;
  6065. UNITY_SETUP_INSTANCE_ID(v);
  6066. UNITY_TRANSFER_INSTANCE_ID(v, o);
  6067. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  6068. #if !_TESSELLATION_ON
  6069. ChainModifyVertex(v, o, _Time);
  6070. #endif
  6071. o.texcoord0 = v.texcoord0;
  6072. o.texcoord1 = v.texcoord1;
  6073. o.texcoord2 = v.texcoord2;
  6074. // #if %TEXCOORD3REQUIREKEY%
  6075. o.texcoord3 = v.texcoord3;
  6076. // #endif
  6077. // #if %VERTEXCOLORREQUIREKEY%
  6078. // o.vertexColor = v.vertexColor;
  6079. // #endif
  6080. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  6081. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  6082. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  6083. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  6084. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  6085. #if _PASSSHADOW
  6086. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  6087. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  6088. #else
  6089. float3 lightDirectionWS = _LightDirection;
  6090. #endif
  6091. // Define shadow pass specific clip position for Universal
  6092. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  6093. #if UNITY_REVERSED_Z
  6094. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  6095. #else
  6096. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  6097. #endif
  6098. #elif _PASSMETA
  6099. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  6100. #else
  6101. o.pos = TransformWorldToHClip(o.worldPos);
  6102. #endif
  6103. // #if %SCREENPOSREQUIREKEY%
  6104. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  6105. // #endif
  6106. #if _PASSFORWARD || _PASSGBUFFER
  6107. float2 uv1 = v.texcoord1.xy;
  6108. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  6109. o.texcoord1.xy = uv1;
  6110. OUTPUT_SH(o.worldNormal, o.sh);
  6111. #if defined(DYNAMICLIGHTMAP_ON)
  6112. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  6113. #endif
  6114. #endif
  6115. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  6116. half fogFactor = 0;
  6117. #if defined(_FOG_FRAGMENT)
  6118. fogFactor = ComputeFogFactor(o.pos.z);
  6119. #endif
  6120. #if _BAKEDLIT
  6121. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  6122. #else
  6123. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  6124. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  6125. #endif
  6126. #endif
  6127. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  6128. o.shadowCoord = GetShadowCoord(vertexInput);
  6129. #endif
  6130. return o;
  6131. }
  6132. // fragment shader
  6133. half4 Frag (VertexToPixel IN
  6134. #if NEED_FACING
  6135. , bool facing : SV_IsFrontFace
  6136. #endif
  6137. ) : SV_Target
  6138. {
  6139. UNITY_SETUP_INSTANCE_ID(IN);
  6140. ShaderData d = CreateShaderData(IN
  6141. #if NEED_FACING
  6142. , facing
  6143. #endif
  6144. );
  6145. Surface l = (Surface)0;
  6146. l.Albedo = half3(0.5, 0.5, 0.5);
  6147. l.Normal = float3(0,0,1);
  6148. l.Occlusion = 1;
  6149. l.Alpha = 1;
  6150. ChainSurfaceFunction(l, d);
  6151. MetaInput metaInput = (MetaInput)0;
  6152. metaInput.Albedo = l.Albedo;
  6153. metaInput.Emission = l.Emission;
  6154. return MetaFragment(metaInput);
  6155. }
  6156. ENDHLSL
  6157. }
  6158. Pass
  6159. {
  6160. Name "DepthNormals"
  6161. Tags
  6162. {
  6163. "LightMode" = "DepthNormals"
  6164. }
  6165. // Render State
  6166. Cull Back
  6167. ZTest LEqual
  6168. ZWrite On
  6169. HLSLPROGRAM
  6170. #pragma vertex Vert
  6171. #pragma fragment Frag
  6172. #pragma target 3.0
  6173. #pragma prefer_hlslcc gles
  6174. #pragma exclude_renderers d3d11_9x
  6175. #pragma multi_compile_fog
  6176. #pragma multi_compile_instancing
  6177. #pragma multi_compile _ DOTS_INSTANCING_ON
  6178. #define SHADERPASS SHADERPASS_DEPTHNORMALSONLY
  6179. #define _PASSDEPTH 1
  6180. #define _PASSDEPTHNORMALS 1
  6181. #include "Flow.cginc"
  6182. #pragma shader_feature_local _ _STRETCH_ON
  6183. #pragma shader_feature_local DISABLEFOG
  6184. #define _URP 1
  6185. #define _USINGTEXCOORD1 1
  6186. #define _USINGTEXCOORD2 1
  6187. // this has to be here or specular color will be ignored. Not in SG code
  6188. #if _SIMPLELIT
  6189. #define _SPECULAR_COLOR
  6190. #endif
  6191. // Includes
  6192. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  6193. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  6194. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  6195. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  6196. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  6197. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  6198. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  6199. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  6200. #undef WorldNormalVector
  6201. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  6202. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  6203. #define _WorldSpaceLightPos0 _MainLightPosition
  6204. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  6205. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  6206. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  6207. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  6208. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  6209. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  6210. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  6211. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  6212. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  6213. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  6214. #if defined(UNITY_COMPILER_HLSL)
  6215. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  6216. #else
  6217. #define UNITY_INITIALIZE_OUTPUT(type,name)
  6218. #endif
  6219. #define sampler2D_float sampler2D
  6220. #define sampler2D_half sampler2D
  6221. // data across stages, stripped like the above.
  6222. struct VertexToPixel
  6223. {
  6224. float4 pos : SV_POSITION;
  6225. float3 worldPos : TEXCOORD0;
  6226. float3 worldNormal : TEXCOORD1;
  6227. float4 worldTangent : TEXCOORD2;
  6228. float4 texcoord0 : TEXCOORD3;
  6229. float4 texcoord1 : TEXCOORD4;
  6230. float4 texcoord2 : TEXCOORD5;
  6231. // #if %TEXCOORD3REQUIREKEY%
  6232. float4 texcoord3 : TEXCOORD6;
  6233. // #endif
  6234. // #if %SCREENPOSREQUIREKEY%
  6235. float4 screenPos : TEXCOORD7;
  6236. // #endif
  6237. // #if %VERTEXCOLORREQUIREKEY%
  6238. // half4 vertexColor : COLOR;
  6239. // #endif
  6240. #if defined(LIGHTMAP_ON)
  6241. float2 lightmapUV : TEXCOORD8;
  6242. #endif
  6243. #if defined(DYNAMICLIGHTMAP_ON)
  6244. float2 dynamicLightmapUV : TEXCOORD9;
  6245. #endif
  6246. #if !defined(LIGHTMAP_ON)
  6247. float3 sh : TEXCOORD10;
  6248. #endif
  6249. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  6250. float4 fogFactorAndVertexLight : TEXCOORD11;
  6251. #endif
  6252. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  6253. float4 shadowCoord : TEXCOORD12;
  6254. #endif
  6255. // #if %EXTRAV2F0REQUIREKEY%
  6256. // float4 extraV2F0 : TEXCOORD13;
  6257. // #endif
  6258. // #if %EXTRAV2F1REQUIREKEY%
  6259. // float4 extraV2F1 : TEXCOORD14;
  6260. // #endif
  6261. // #if %EXTRAV2F2REQUIREKEY%
  6262. // float4 extraV2F2 : TEXCOORD15;
  6263. // #endif
  6264. // #if %EXTRAV2F3REQUIREKEY%
  6265. // float4 extraV2F3 : TEXCOORD16;
  6266. // #endif
  6267. // #if %EXTRAV2F4REQUIREKEY%
  6268. // float4 extraV2F4 : TEXCOORD17;
  6269. // #endif
  6270. // #if %EXTRAV2F5REQUIREKEY%
  6271. // float4 extraV2F5 : TEXCOORD18;
  6272. // #endif
  6273. // #if %EXTRAV2F6REQUIREKEY%
  6274. // float4 extraV2F6 : TEXCOORD19;
  6275. // #endif
  6276. // #if %EXTRAV2F7REQUIREKEY%
  6277. // float4 extraV2F7 : TEXCOORD20;
  6278. // #endif
  6279. #if UNITY_ANY_INSTANCING_ENABLED
  6280. uint instanceID : CUSTOM_INSTANCE_ID;
  6281. #endif
  6282. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  6283. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  6284. #endif
  6285. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  6286. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  6287. #endif
  6288. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  6289. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  6290. #endif
  6291. };
  6292. // data describing the user output of a pixel
  6293. struct Surface
  6294. {
  6295. half3 Albedo;
  6296. half Height;
  6297. half3 Normal;
  6298. half Smoothness;
  6299. half3 Emission;
  6300. half Metallic;
  6301. half3 Specular;
  6302. half Occlusion;
  6303. half SpecularPower; // for simple lighting
  6304. half Alpha;
  6305. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  6306. // HDRP Only
  6307. half SpecularOcclusion;
  6308. half SubsurfaceMask;
  6309. half Thickness;
  6310. half CoatMask;
  6311. half CoatSmoothness;
  6312. half Anisotropy;
  6313. half IridescenceMask;
  6314. half IridescenceThickness;
  6315. int DiffusionProfileHash;
  6316. float SpecularAAThreshold;
  6317. float SpecularAAScreenSpaceVariance;
  6318. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  6319. float3 DiffuseGI;
  6320. float3 BackDiffuseGI;
  6321. float3 SpecularGI;
  6322. float ior;
  6323. float3 transmittanceColor;
  6324. float atDistance;
  6325. float transmittanceMask;
  6326. // requires _OVERRIDE_SHADOWMASK to be defines
  6327. float4 ShadowMask;
  6328. // for decals
  6329. float NormalAlpha;
  6330. float MAOSAlpha;
  6331. };
  6332. // Data the user declares in blackboard blocks
  6333. struct Blackboard
  6334. {
  6335. float groundHeight;
  6336. float surfaceHeight;
  6337. float3 surfaceNormal;
  6338. Fluid fluid;
  6339. float blackboardDummyData;
  6340. };
  6341. // data the user might need, this will grow to be big. But easy to strip
  6342. struct ShaderData
  6343. {
  6344. float4 clipPos; // SV_POSITION
  6345. float3 localSpacePosition;
  6346. float3 localSpaceNormal;
  6347. float3 localSpaceTangent;
  6348. float3 worldSpacePosition;
  6349. float3 worldSpaceNormal;
  6350. float3 worldSpaceTangent;
  6351. float tangentSign;
  6352. float3 worldSpaceViewDir;
  6353. float3 tangentSpaceViewDir;
  6354. float4 texcoord0;
  6355. float4 texcoord1;
  6356. float4 texcoord2;
  6357. float4 texcoord3;
  6358. float2 screenUV;
  6359. float4 screenPos;
  6360. float4 vertexColor;
  6361. bool isFrontFace;
  6362. float4 extraV2F0;
  6363. float4 extraV2F1;
  6364. float4 extraV2F2;
  6365. float4 extraV2F3;
  6366. float4 extraV2F4;
  6367. float4 extraV2F5;
  6368. float4 extraV2F6;
  6369. float4 extraV2F7;
  6370. float3x3 TBNMatrix;
  6371. Blackboard blackboard;
  6372. };
  6373. struct VertexData
  6374. {
  6375. #if SHADER_TARGET > 30
  6376. // uint vertexID : SV_VertexID;
  6377. #endif
  6378. float4 vertex : POSITION;
  6379. float3 normal : NORMAL;
  6380. float4 tangent : TANGENT;
  6381. float4 texcoord0 : TEXCOORD0;
  6382. // optimize out mesh coords when not in use by user or lighting system
  6383. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  6384. float4 texcoord1 : TEXCOORD1;
  6385. #endif
  6386. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  6387. float4 texcoord2 : TEXCOORD2;
  6388. #endif
  6389. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  6390. float4 texcoord1 : TEXCOORD1;
  6391. #endif
  6392. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  6393. float4 texcoord2 : TEXCOORD2;
  6394. #endif
  6395. #if _HDRP
  6396. float4 texcoord1 : TEXCOORD1;
  6397. float4 texcoord2 : TEXCOORD2;
  6398. #endif
  6399. // #if %TEXCOORD3REQUIREKEY%
  6400. float4 texcoord3 : TEXCOORD3;
  6401. // #endif
  6402. // #if %VERTEXCOLORREQUIREKEY%
  6403. // float4 vertexColor : COLOR;
  6404. // #endif
  6405. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  6406. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  6407. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  6408. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  6409. #endif
  6410. #endif
  6411. UNITY_VERTEX_INPUT_INSTANCE_ID
  6412. };
  6413. struct TessVertex
  6414. {
  6415. float4 vertex : INTERNALTESSPOS;
  6416. float3 normal : NORMAL;
  6417. float4 tangent : TANGENT;
  6418. float4 texcoord0 : TEXCOORD0;
  6419. float4 texcoord1 : TEXCOORD1;
  6420. float4 texcoord2 : TEXCOORD2;
  6421. // #if %TEXCOORD3REQUIREKEY%
  6422. float4 texcoord3 : TEXCOORD3;
  6423. // #endif
  6424. // #if %VERTEXCOLORREQUIREKEY%
  6425. // float4 vertexColor : COLOR;
  6426. // #endif
  6427. // #if %EXTRAV2F0REQUIREKEY%
  6428. // float4 extraV2F0 : TEXCOORD5;
  6429. // #endif
  6430. // #if %EXTRAV2F1REQUIREKEY%
  6431. // float4 extraV2F1 : TEXCOORD6;
  6432. // #endif
  6433. // #if %EXTRAV2F2REQUIREKEY%
  6434. // float4 extraV2F2 : TEXCOORD7;
  6435. // #endif
  6436. // #if %EXTRAV2F3REQUIREKEY%
  6437. // float4 extraV2F3 : TEXCOORD8;
  6438. // #endif
  6439. // #if %EXTRAV2F4REQUIREKEY%
  6440. // float4 extraV2F4 : TEXCOORD9;
  6441. // #endif
  6442. // #if %EXTRAV2F5REQUIREKEY%
  6443. // float4 extraV2F5 : TEXCOORD10;
  6444. // #endif
  6445. // #if %EXTRAV2F6REQUIREKEY%
  6446. // float4 extraV2F6 : TEXCOORD11;
  6447. // #endif
  6448. // #if %EXTRAV2F7REQUIREKEY%
  6449. // float4 extraV2F7 : TEXCOORD12;
  6450. // #endif
  6451. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  6452. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  6453. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  6454. float3 precomputedVelocity : TEXCOORD14;
  6455. #endif
  6456. #endif
  6457. UNITY_VERTEX_INPUT_INSTANCE_ID
  6458. UNITY_VERTEX_OUTPUT_STEREO
  6459. };
  6460. struct ExtraV2F
  6461. {
  6462. float4 extraV2F0;
  6463. float4 extraV2F1;
  6464. float4 extraV2F2;
  6465. float4 extraV2F3;
  6466. float4 extraV2F4;
  6467. float4 extraV2F5;
  6468. float4 extraV2F6;
  6469. float4 extraV2F7;
  6470. Blackboard blackboard;
  6471. float4 time;
  6472. };
  6473. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  6474. {
  6475. return mul(d.TBNMatrix, normal);
  6476. }
  6477. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  6478. {
  6479. return mul(normal, d.TBNMatrix);
  6480. }
  6481. // in this case, make standard more like SRPs, because we can't fix
  6482. // unity_WorldToObject in HDRP, since it already does macro-fu there
  6483. #if _STANDARD
  6484. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  6485. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  6486. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  6487. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  6488. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  6489. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  6490. #if (defined(SHADER_API_D3D11) || defined(SHADER_API_XBOXONE) || defined(UNITY_COMPILER_HLSLCC) || defined(SHADER_API_PSSL) || (SHADER_TARGET_SURFACE_ANALYSIS && !SHADER_TARGET_SURFACE_ANALYSIS_MOJOSHADER))
  6491. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  6492. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  6493. #else
  6494. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  6495. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  6496. #endif
  6497. #undef GetWorldToObjectMatrix()
  6498. #define GetWorldToObjectMatrix() unity_WorldToObject
  6499. #endif
  6500. float3 GetCameraWorldPosition()
  6501. {
  6502. #if _HDRP
  6503. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  6504. #else
  6505. return _WorldSpaceCameraPos;
  6506. #endif
  6507. }
  6508. #if _GRABPASSUSED
  6509. #if _STANDARD
  6510. TEXTURE2D(%GRABTEXTURE%);
  6511. SAMPLER(sampler_%GRABTEXTURE%);
  6512. #endif
  6513. half3 GetSceneColor(float2 uv)
  6514. {
  6515. #if _STANDARD
  6516. return SAMPLE_TEXTURE2D(%GRABTEXTURE%, sampler_%GRABTEXTURE%, uv).rgb;
  6517. #else
  6518. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  6519. #endif
  6520. }
  6521. #endif
  6522. #if _STANDARD
  6523. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  6524. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  6525. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  6526. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  6527. #else
  6528. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  6529. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  6530. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  6531. #endif
  6532. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  6533. {
  6534. float eye = GetLinearEyeDepth(uv);
  6535. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  6536. float dt = dot(worldSpaceViewDir, camView);
  6537. float3 div = worldSpaceViewDir/dt;
  6538. float3 wpos = (eye * div) + GetCameraWorldPosition();
  6539. return wpos;
  6540. }
  6541. #if _HDRP
  6542. float3 ObjectToWorldSpacePosition(float3 pos)
  6543. {
  6544. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  6545. }
  6546. #else
  6547. float3 ObjectToWorldSpacePosition(float3 pos)
  6548. {
  6549. return TransformObjectToWorld(pos);
  6550. }
  6551. #endif
  6552. #if _STANDARD
  6553. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  6554. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  6555. {
  6556. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  6557. float3 norms = DecodeViewNormalStereo(depthNorms);
  6558. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  6559. return norms;
  6560. }
  6561. #elif _HDRP && !_DECALSHADER
  6562. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  6563. {
  6564. NormalData nd;
  6565. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  6566. return nd.normalWS;
  6567. }
  6568. #elif _URP
  6569. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  6570. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  6571. #endif
  6572. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  6573. {
  6574. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  6575. return SampleSceneNormals(uv);
  6576. #else
  6577. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  6578. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  6579. #endif
  6580. }
  6581. #endif
  6582. #if _HDRP
  6583. half3 UnpackNormalmapRGorAG(half4 packednormal)
  6584. {
  6585. // This do the trick
  6586. packednormal.x *= packednormal.w;
  6587. half3 normal;
  6588. normal.xy = packednormal.xy * 2 - 1;
  6589. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  6590. return normal;
  6591. }
  6592. half3 UnpackNormal(half4 packednormal)
  6593. {
  6594. #if defined(UNITY_NO_DXT5nm)
  6595. return packednormal.xyz * 2 - 1;
  6596. #else
  6597. return UnpackNormalmapRGorAG(packednormal);
  6598. #endif
  6599. }
  6600. #endif
  6601. #if _HDRP || _URP
  6602. half3 UnpackScaleNormal(half4 packednormal, half scale)
  6603. {
  6604. #ifndef UNITY_NO_DXT5nm
  6605. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  6606. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  6607. packednormal.x *= packednormal.w;
  6608. #endif
  6609. half3 normal;
  6610. normal.xy = (packednormal.xy * 2 - 1) * scale;
  6611. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  6612. return normal;
  6613. }
  6614. #endif
  6615. void GetSun(out float3 lightDir, out float3 color)
  6616. {
  6617. lightDir = float3(0.5, 0.5, 0);
  6618. color = 1;
  6619. #if _HDRP
  6620. if (_DirectionalLightCount > 0)
  6621. {
  6622. DirectionalLightData light = _DirectionalLightDatas[0];
  6623. lightDir = -light.forward.xyz;
  6624. color = light.color;
  6625. }
  6626. #elif _STANDARD
  6627. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  6628. color = _LightColor0.rgb;
  6629. #elif _URP
  6630. Light light = GetMainLight();
  6631. lightDir = light.direction;
  6632. color = light.color;
  6633. #endif
  6634. }
  6635. CBUFFER_START(UnityPerMaterial)
  6636. float _FlowDensity;
  6637. float2 _FlowSeparationXZ;
  6638. float _FlowSimulationHeight;
  6639. float _FlowCameraHeight;
  6640. float2 _FlowCountXZ;
  6641. float4 _FlowCoordU000;
  6642. float4 _FlowCoord0V00;
  6643. float _FlowSpeed;
  6644. float4x4 _FlowMatrix;
  6645. float _Sink;
  6646. int2 _PartCountXY;
  6647. float _FlowDelta;
  6648. float _ScaleBase;
  6649. float _ScaleVolume;
  6650. float _StretchScale;
  6651. CBUFFER_END
  6652. #ifdef unity_WorldToObject
  6653. #undef unity_WorldToObject
  6654. #endif
  6655. #ifdef unity_ObjectToWorld
  6656. #undef unity_ObjectToWorld
  6657. #endif
  6658. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  6659. #define unity_WorldToObject GetWorldToObjectMatrix()
  6660. TEXTURE2D(_FlowDataA);
  6661. SAMPLER(sampler_FlowDataA);
  6662. TEXTURE2D(_FlowDataB);
  6663. SAMPLER(sampler_FlowDataB);
  6664. TEXTURE2D(_FlowDataC);
  6665. SAMPLER(sampler_FlowDataC);
  6666. TEXTURE2D(_FlowDataD);
  6667. SAMPLER(sampler_FlowDataD);
  6668. TEXTURE2D(_FlowDataE);
  6669. SAMPLER(sampler_FlowDataE);
  6670. TEXTURE2D(_FlowDataF);
  6671. SAMPLER(sampler_FlowDataF);
  6672. float4 SGT_O2W(float4 v)
  6673. {
  6674. v = mul(GetObjectToWorldMatrix(), v);
  6675. #if _HDRP
  6676. v.xyz = GetAbsolutePositionWS(v.xyz);
  6677. #endif
  6678. return v;
  6679. }
  6680. float4 SGT_W2O(float4 v)
  6681. {
  6682. #if _HDRP
  6683. v.xyz = GetCameraRelativePositionWS(v.xyz);
  6684. #endif
  6685. return mul(GetWorldToObjectMatrix(), v);
  6686. }
  6687. float4 SGT_O2V(float4 v)
  6688. {
  6689. #if _STANDARD
  6690. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  6691. #else
  6692. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  6693. #endif
  6694. }
  6695. float GetFluidHeight(float2 uv)
  6696. {
  6697. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  6698. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  6699. return groundHeight + fluidDepth;
  6700. }
  6701. float2 GetHeightAndDepth(float2 uv)
  6702. {
  6703. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  6704. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  6705. return float2(groundHeight, fluidDepth);
  6706. }
  6707. Column GetColumn(float2 uv)
  6708. {
  6709. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  6710. }
  6711. Fluid GetColumnFluid(float2 uv)
  6712. {
  6713. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  6714. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  6715. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  6716. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  6717. return DecodeFluid(c, d, e, f);
  6718. }
  6719. bool InsideFluid(float3 wpos)
  6720. {
  6721. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  6722. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  6723. float2 columnHAD = GetHeightAndDepth(columnCoord);
  6724. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  6725. }
  6726. bool UnderFluid(float3 wpos)
  6727. {
  6728. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  6729. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  6730. float2 columnHAD = GetHeightAndDepth(columnCoord);
  6731. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  6732. }
  6733. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  6734. {
  6735. float epsi = step * 0.01f;
  6736. float dist = 0.0f;
  6737. for (int i = 0; i < maxs && step > epsi; i++)
  6738. {
  6739. dist += step;
  6740. float3 pos = wpos + wdir * dist;
  6741. if (InsideFluid(pos) == false)
  6742. {
  6743. dist -= step;
  6744. step *= 0.5f;
  6745. }
  6746. if (dist > maxd)
  6747. {
  6748. return maxd;
  6749. }
  6750. }
  6751. return dist;
  6752. }
  6753. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  6754. {
  6755. float epsi = step * 0.01f;
  6756. float dist = 0.0f;
  6757. for (int i = 0; i < maxs && step > epsi; i++)
  6758. {
  6759. dist += step;
  6760. float3 pos = wpos + wdir * dist;
  6761. if (UnderFluid(pos) == false)
  6762. {
  6763. dist -= step;
  6764. step *= 0.5f;
  6765. }
  6766. if (dist > maxd)
  6767. {
  6768. return maxd;
  6769. }
  6770. }
  6771. return dist;
  6772. }
  6773. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  6774. {
  6775. float4 wpos = SGT_O2W(v.vertex);
  6776. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  6777. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  6778. Column column0 = GetColumn(columnCoord);
  6779. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  6780. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  6781. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  6782. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  6783. Fluid fluid0 = GetColumnFluid(columnCoord);
  6784. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  6785. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  6786. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  6787. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  6788. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  6789. float wL = fluidL.Depth / ww;
  6790. float wR = fluidR.Depth / ww;
  6791. float wB = fluidB.Depth / ww;
  6792. float wT = fluidT.Depth / ww;
  6793. float w0 = saturate(fluid0.Depth * 10);
  6794. float hL = columnL.GroundHeight + fluidL.Depth;
  6795. float hR = columnR.GroundHeight + fluidR.Depth;
  6796. float hB = columnB.GroundHeight + fluidB.Depth;
  6797. float hT = columnT.GroundHeight + fluidT.Depth;
  6798. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  6799. float h0 = column0.GroundHeight + fluid0.Depth;
  6800. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  6801. Fluid fluid = fluid0;
  6802. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  6803. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  6804. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  6805. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  6806. e.blackboard.groundHeight = column0.GroundHeight;
  6807. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  6808. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  6809. e.blackboard.fluid = fluid;
  6810. }
  6811. TEXTURE2D(_MainTex);
  6812. SAMPLER(sampler_MainTex);
  6813. TEXTURE2D(_BumpMap);
  6814. SAMPLER(sampler_BumpMap);
  6815. TEXTURE2D(_PartDataA);
  6816. SAMPLER(sampler_PartDataA);
  6817. TEXTURE2D(_PartDataB);
  6818. SAMPLER(sampler_PartDataB);
  6819. TEXTURE2D(_PartDataC);
  6820. SAMPLER(sampler_PartDataC);
  6821. TEXTURE2D(_PartDataD);
  6822. SAMPLER(sampler_PartDataD);
  6823. TEXTURE2D(_PartDataE);
  6824. SAMPLER(sampler_PartDataE);
  6825. TEXTURE2D(_PartDataF);
  6826. SAMPLER(sampler_PartDataF);
  6827. Particle GetParticle(float2 uv)
  6828. {
  6829. return DecodeParticle(SAMPLE_TEXTURE2D_LOD(_PartDataA, sampler_PartDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_PartDataB, sampler_PartDataB, uv, 0));
  6830. }
  6831. Fluid GetParticleFluid(float2 uv)
  6832. {
  6833. float4 c = SAMPLE_TEXTURE2D_LOD(_PartDataC, sampler_PartDataC, uv, 0);
  6834. float4 d = SAMPLE_TEXTURE2D_LOD(_PartDataD, sampler_PartDataD, uv, 0);
  6835. float4 e = SAMPLE_TEXTURE2D_LOD(_PartDataE, sampler_PartDataE, uv, 0);
  6836. float4 f = SAMPLE_TEXTURE2D_LOD(_PartDataF, sampler_PartDataF, uv, 0);
  6837. return DecodeFluid(c, d, e, f);
  6838. }
  6839. float2 Rotate(float2 v, float a)
  6840. {
  6841. float s = sin(a);
  6842. float c = cos(a);
  6843. return float2(c * v.x - s * v.y, s * v.x + c * v.y);
  6844. }
  6845. void Ext_ModifyVertex1 (inout VertexData v, inout ExtraV2F e)
  6846. {
  6847. float2 particlePixel = v.texcoord1.xy;
  6848. float2 particleCoord = SnapCoordFromPixel(particlePixel, _PartCountXY);
  6849. Particle particle = GetParticle(particleCoord);
  6850. Fluid fluid = GetParticleFluid(particleCoord);
  6851. float size = particle.Age < particle.Life;
  6852. float4 wpos = float4(particle.Position, 1.0f);
  6853. float2 rvec = v.texcoord0.xy * size;
  6854. rvec *= _ScaleBase + _ScaleVolume * pow(abs(3.0f * fluid.Depth / 12.56637f), 1.0f / 3.0f);
  6855. #if _STRETCH_ON
  6856. float4 posA = SGT_O2V(float4(particle.Position - particle.Velocity, 1.0f));
  6857. float4 posB = SGT_O2V(float4(particle.Position + particle.Velocity, 1.0f));
  6858. float2 posV = posB.xy - posA.xy;
  6859. rvec.y *= 1.0f + length(particle.Velocity * _StretchScale * _FlowDelta);
  6860. rvec = Rotate(rvec, atan2(posV.x, posV.y));
  6861. #endif
  6862. wpos.xyz += GetWorldToViewMatrix()[0].xyz * rvec.x;
  6863. wpos.xyz += GetWorldToViewMatrix()[1].xyz * rvec.y;
  6864. v.vertex = SGT_W2O(wpos);
  6865. v.normal = GetWorldToViewMatrix()[2].xyz;
  6866. v.tangent = float4(GetWorldToViewMatrix()[0].xyz, -1.0f);
  6867. v.texcoord0.zw = Rotate(v.texcoord0.xy, v.texcoord1.z);
  6868. v.texcoord3.x = v.texcoord1.x + v.texcoord1.y * _PartCountXY.x;
  6869. v.texcoord0 += 0.5f;
  6870. v.texcoord1 = fluid.RGBA;
  6871. v.texcoord2 = fluid.ESMV;
  6872. }
  6873. void Ext_SurfaceFunction1 (inout Surface o, ShaderData d)
  6874. {
  6875. Fluid fluid;
  6876. fluid.RGBA = d.texcoord1;
  6877. fluid.ESMV = d.texcoord2;
  6878. float4 texMain = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, d.texcoord0.zw);
  6879. float4 bump = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, d.texcoord0.xy);
  6880. //clip(texMain.a - 0.5f);
  6881. float DITHER_THRESHOLDS[16] =
  6882. {
  6883. 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
  6884. 13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
  6885. 4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
  6886. 16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
  6887. };
  6888. float2 uv = d.screenUV.xy * _ScreenParams.xy + d.texcoord3.x;
  6889. uint index = (uint(uv.x) % uint(4)) * uint(4) + (uint(uv.y) % uint(4));
  6890. clip(texMain.a - DITHER_THRESHOLDS[index]);
  6891. o.Albedo = fluid.RGBA.xyz;
  6892. o.Emission = fluid.ESMV.x * fluid.RGBA.xyz;
  6893. o.Smoothness = fluid.ESMV.y;
  6894. o.Metallic = fluid.ESMV.z;
  6895. o.Normal = UnpackScaleNormal(bump, 1.0f);
  6896. }
  6897. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  6898. {
  6899. // Ext_SurfaceFunction0(l, d);
  6900. Ext_SurfaceFunction1(l, d);
  6901. // Ext_SurfaceFunction2(l, d);
  6902. // Ext_SurfaceFunction3(l, d);
  6903. // Ext_SurfaceFunction4(l, d);
  6904. // Ext_SurfaceFunction5(l, d);
  6905. // Ext_SurfaceFunction6(l, d);
  6906. // Ext_SurfaceFunction7(l, d);
  6907. // Ext_SurfaceFunction8(l, d);
  6908. // Ext_SurfaceFunction9(l, d);
  6909. // Ext_SurfaceFunction10(l, d);
  6910. // Ext_SurfaceFunction11(l, d);
  6911. // Ext_SurfaceFunction12(l, d);
  6912. // Ext_SurfaceFunction13(l, d);
  6913. // Ext_SurfaceFunction14(l, d);
  6914. // Ext_SurfaceFunction15(l, d);
  6915. // Ext_SurfaceFunction16(l, d);
  6916. // Ext_SurfaceFunction17(l, d);
  6917. // Ext_SurfaceFunction18(l, d);
  6918. // Ext_SurfaceFunction19(l, d);
  6919. // Ext_SurfaceFunction20(l, d);
  6920. // Ext_SurfaceFunction21(l, d);
  6921. // Ext_SurfaceFunction22(l, d);
  6922. // Ext_SurfaceFunction23(l, d);
  6923. // Ext_SurfaceFunction24(l, d);
  6924. // Ext_SurfaceFunction25(l, d);
  6925. // Ext_SurfaceFunction26(l, d);
  6926. // Ext_SurfaceFunction27(l, d);
  6927. // Ext_SurfaceFunction28(l, d);
  6928. // Ext_SurfaceFunction29(l, d);
  6929. }
  6930. #if !_DECALSHADER
  6931. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  6932. {
  6933. ExtraV2F d;
  6934. ZERO_INITIALIZE(ExtraV2F, d);
  6935. ZERO_INITIALIZE(Blackboard, d.blackboard);
  6936. // due to motion vectors in HDRP, we need to use the last
  6937. // time in certain spots. So if you are going to use _Time to adjust vertices,
  6938. // you need to use this time or motion vectors will break.
  6939. d.time = time;
  6940. Ext_ModifyVertex0(v, d);
  6941. Ext_ModifyVertex1(v, d);
  6942. // Ext_ModifyVertex2(v, d);
  6943. // Ext_ModifyVertex3(v, d);
  6944. // Ext_ModifyVertex4(v, d);
  6945. // Ext_ModifyVertex5(v, d);
  6946. // Ext_ModifyVertex6(v, d);
  6947. // Ext_ModifyVertex7(v, d);
  6948. // Ext_ModifyVertex8(v, d);
  6949. // Ext_ModifyVertex9(v, d);
  6950. // Ext_ModifyVertex10(v, d);
  6951. // Ext_ModifyVertex11(v, d);
  6952. // Ext_ModifyVertex12(v, d);
  6953. // Ext_ModifyVertex13(v, d);
  6954. // Ext_ModifyVertex14(v, d);
  6955. // Ext_ModifyVertex15(v, d);
  6956. // Ext_ModifyVertex16(v, d);
  6957. // Ext_ModifyVertex17(v, d);
  6958. // Ext_ModifyVertex18(v, d);
  6959. // Ext_ModifyVertex19(v, d);
  6960. // Ext_ModifyVertex20(v, d);
  6961. // Ext_ModifyVertex21(v, d);
  6962. // Ext_ModifyVertex22(v, d);
  6963. // Ext_ModifyVertex23(v, d);
  6964. // Ext_ModifyVertex24(v, d);
  6965. // Ext_ModifyVertex25(v, d);
  6966. // Ext_ModifyVertex26(v, d);
  6967. // Ext_ModifyVertex27(v, d);
  6968. // Ext_ModifyVertex28(v, d);
  6969. // Ext_ModifyVertex29(v, d);
  6970. // #if %EXTRAV2F0REQUIREKEY%
  6971. // v2p.extraV2F0 = d.extraV2F0;
  6972. // #endif
  6973. // #if %EXTRAV2F1REQUIREKEY%
  6974. // v2p.extraV2F1 = d.extraV2F1;
  6975. // #endif
  6976. // #if %EXTRAV2F2REQUIREKEY%
  6977. // v2p.extraV2F2 = d.extraV2F2;
  6978. // #endif
  6979. // #if %EXTRAV2F3REQUIREKEY%
  6980. // v2p.extraV2F3 = d.extraV2F3;
  6981. // #endif
  6982. // #if %EXTRAV2F4REQUIREKEY%
  6983. // v2p.extraV2F4 = d.extraV2F4;
  6984. // #endif
  6985. // #if %EXTRAV2F5REQUIREKEY%
  6986. // v2p.extraV2F5 = d.extraV2F5;
  6987. // #endif
  6988. // #if %EXTRAV2F6REQUIREKEY%
  6989. // v2p.extraV2F6 = d.extraV2F6;
  6990. // #endif
  6991. // #if %EXTRAV2F7REQUIREKEY%
  6992. // v2p.extraV2F7 = d.extraV2F7;
  6993. // #endif
  6994. }
  6995. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  6996. {
  6997. ExtraV2F d;
  6998. ZERO_INITIALIZE(ExtraV2F, d);
  6999. ZERO_INITIALIZE(Blackboard, d.blackboard);
  7000. // #if %EXTRAV2F0REQUIREKEY%
  7001. // d.extraV2F0 = v2p.extraV2F0;
  7002. // #endif
  7003. // #if %EXTRAV2F1REQUIREKEY%
  7004. // d.extraV2F1 = v2p.extraV2F1;
  7005. // #endif
  7006. // #if %EXTRAV2F2REQUIREKEY%
  7007. // d.extraV2F2 = v2p.extraV2F2;
  7008. // #endif
  7009. // #if %EXTRAV2F3REQUIREKEY%
  7010. // d.extraV2F3 = v2p.extraV2F3;
  7011. // #endif
  7012. // #if %EXTRAV2F4REQUIREKEY%
  7013. // d.extraV2F4 = v2p.extraV2F4;
  7014. // #endif
  7015. // #if %EXTRAV2F5REQUIREKEY%
  7016. // d.extraV2F5 = v2p.extraV2F5;
  7017. // #endif
  7018. // #if %EXTRAV2F6REQUIREKEY%
  7019. // d.extraV2F6 = v2p.extraV2F6;
  7020. // #endif
  7021. // #if %EXTRAV2F7REQUIREKEY%
  7022. // d.extraV2F7 = v2p.extraV2F7;
  7023. // #endif
  7024. // Ext_ModifyTessellatedVertex0(v, d);
  7025. // Ext_ModifyTessellatedVertex1(v, d);
  7026. // Ext_ModifyTessellatedVertex2(v, d);
  7027. // Ext_ModifyTessellatedVertex3(v, d);
  7028. // Ext_ModifyTessellatedVertex4(v, d);
  7029. // Ext_ModifyTessellatedVertex5(v, d);
  7030. // Ext_ModifyTessellatedVertex6(v, d);
  7031. // Ext_ModifyTessellatedVertex7(v, d);
  7032. // Ext_ModifyTessellatedVertex8(v, d);
  7033. // Ext_ModifyTessellatedVertex9(v, d);
  7034. // Ext_ModifyTessellatedVertex10(v, d);
  7035. // Ext_ModifyTessellatedVertex11(v, d);
  7036. // Ext_ModifyTessellatedVertex12(v, d);
  7037. // Ext_ModifyTessellatedVertex13(v, d);
  7038. // Ext_ModifyTessellatedVertex14(v, d);
  7039. // Ext_ModifyTessellatedVertex15(v, d);
  7040. // Ext_ModifyTessellatedVertex16(v, d);
  7041. // Ext_ModifyTessellatedVertex17(v, d);
  7042. // Ext_ModifyTessellatedVertex18(v, d);
  7043. // Ext_ModifyTessellatedVertex19(v, d);
  7044. // Ext_ModifyTessellatedVertex20(v, d);
  7045. // Ext_ModifyTessellatedVertex21(v, d);
  7046. // Ext_ModifyTessellatedVertex22(v, d);
  7047. // Ext_ModifyTessellatedVertex23(v, d);
  7048. // Ext_ModifyTessellatedVertex24(v, d);
  7049. // Ext_ModifyTessellatedVertex25(v, d);
  7050. // Ext_ModifyTessellatedVertex26(v, d);
  7051. // Ext_ModifyTessellatedVertex27(v, d);
  7052. // Ext_ModifyTessellatedVertex28(v, d);
  7053. // Ext_ModifyTessellatedVertex29(v, d);
  7054. // #if %EXTRAV2F0REQUIREKEY%
  7055. // v2p.extraV2F0 = d.extraV2F0;
  7056. // #endif
  7057. // #if %EXTRAV2F1REQUIREKEY%
  7058. // v2p.extraV2F1 = d.extraV2F1;
  7059. // #endif
  7060. // #if %EXTRAV2F2REQUIREKEY%
  7061. // v2p.extraV2F2 = d.extraV2F2;
  7062. // #endif
  7063. // #if %EXTRAV2F3REQUIREKEY%
  7064. // v2p.extraV2F3 = d.extraV2F3;
  7065. // #endif
  7066. // #if %EXTRAV2F4REQUIREKEY%
  7067. // v2p.extraV2F4 = d.extraV2F4;
  7068. // #endif
  7069. // #if %EXTRAV2F5REQUIREKEY%
  7070. // v2p.extraV2F5 = d.extraV2F5;
  7071. // #endif
  7072. // #if %EXTRAV2F6REQUIREKEY%
  7073. // v2p.extraV2F6 = d.extraV2F6;
  7074. // #endif
  7075. // #if %EXTRAV2F7REQUIREKEY%
  7076. // v2p.extraV2F7 = d.extraV2F7;
  7077. // #endif
  7078. }
  7079. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  7080. {
  7081. // Ext_FinalColorForward0(l, d, color);
  7082. // Ext_FinalColorForward1(l, d, color);
  7083. // Ext_FinalColorForward2(l, d, color);
  7084. // Ext_FinalColorForward3(l, d, color);
  7085. // Ext_FinalColorForward4(l, d, color);
  7086. // Ext_FinalColorForward5(l, d, color);
  7087. // Ext_FinalColorForward6(l, d, color);
  7088. // Ext_FinalColorForward7(l, d, color);
  7089. // Ext_FinalColorForward8(l, d, color);
  7090. // Ext_FinalColorForward9(l, d, color);
  7091. // Ext_FinalColorForward10(l, d, color);
  7092. // Ext_FinalColorForward11(l, d, color);
  7093. // Ext_FinalColorForward12(l, d, color);
  7094. // Ext_FinalColorForward13(l, d, color);
  7095. // Ext_FinalColorForward14(l, d, color);
  7096. // Ext_FinalColorForward15(l, d, color);
  7097. // Ext_FinalColorForward16(l, d, color);
  7098. // Ext_FinalColorForward17(l, d, color);
  7099. // Ext_FinalColorForward18(l, d, color);
  7100. // Ext_FinalColorForward19(l, d, color);
  7101. // Ext_FinalColorForward20(l, d, color);
  7102. // Ext_FinalColorForward21(l, d, color);
  7103. // Ext_FinalColorForward22(l, d, color);
  7104. // Ext_FinalColorForward23(l, d, color);
  7105. // Ext_FinalColorForward24(l, d, color);
  7106. // Ext_FinalColorForward25(l, d, color);
  7107. // Ext_FinalColorForward26(l, d, color);
  7108. // Ext_FinalColorForward27(l, d, color);
  7109. // Ext_FinalColorForward28(l, d, color);
  7110. // Ext_FinalColorForward29(l, d, color);
  7111. }
  7112. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  7113. {
  7114. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7115. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7116. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7117. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7118. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7119. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7120. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7121. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7122. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7123. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7124. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7125. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7126. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7127. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7128. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7129. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7130. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7131. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7132. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7133. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7134. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7135. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7136. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7137. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7138. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7139. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7140. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7141. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7142. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7143. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  7144. }
  7145. #endif
  7146. #if _DECALSHADER
  7147. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  7148. {
  7149. ShaderData d = (ShaderData)0;
  7150. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  7151. d.worldSpaceNormal = IN.WorldSpaceNormal;
  7152. d.worldSpaceTangent = IN.WorldSpaceTangent;
  7153. d.worldSpacePosition = IN.WorldSpacePosition;
  7154. d.texcoord0 = IN.uv0.xyxy;
  7155. d.screenPos = IN.ScreenPosition;
  7156. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  7157. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  7158. // these rarely get used, so we back transform them. Usually will be stripped.
  7159. #if _HDRP
  7160. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  7161. #else
  7162. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  7163. #endif
  7164. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  7165. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  7166. // #if %SCREENPOSREQUIREKEY%
  7167. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  7168. // #endif
  7169. return d;
  7170. }
  7171. #else
  7172. ShaderData CreateShaderData(VertexToPixel i
  7173. #if NEED_FACING
  7174. , bool facing
  7175. #endif
  7176. )
  7177. {
  7178. ShaderData d = (ShaderData)0;
  7179. d.clipPos = i.pos;
  7180. d.worldSpacePosition = i.worldPos;
  7181. d.worldSpaceNormal = normalize(i.worldNormal);
  7182. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  7183. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  7184. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  7185. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  7186. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  7187. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  7188. d.texcoord0 = i.texcoord0;
  7189. d.texcoord1 = i.texcoord1;
  7190. d.texcoord2 = i.texcoord2;
  7191. // #if %TEXCOORD3REQUIREKEY%
  7192. d.texcoord3 = i.texcoord3;
  7193. // #endif
  7194. // d.isFrontFace = facing;
  7195. // #if %VERTEXCOLORREQUIREKEY%
  7196. // d.vertexColor = i.vertexColor;
  7197. // #endif
  7198. // these rarely get used, so we back transform them. Usually will be stripped.
  7199. #if _HDRP
  7200. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  7201. #else
  7202. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  7203. #endif
  7204. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  7205. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  7206. // #if %SCREENPOSREQUIREKEY%
  7207. d.screenPos = i.screenPos;
  7208. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  7209. // #endif
  7210. // #if %EXTRAV2F0REQUIREKEY%
  7211. // d.extraV2F0 = i.extraV2F0;
  7212. // #endif
  7213. // #if %EXTRAV2F1REQUIREKEY%
  7214. // d.extraV2F1 = i.extraV2F1;
  7215. // #endif
  7216. // #if %EXTRAV2F2REQUIREKEY%
  7217. // d.extraV2F2 = i.extraV2F2;
  7218. // #endif
  7219. // #if %EXTRAV2F3REQUIREKEY%
  7220. // d.extraV2F3 = i.extraV2F3;
  7221. // #endif
  7222. // #if %EXTRAV2F4REQUIREKEY%
  7223. // d.extraV2F4 = i.extraV2F4;
  7224. // #endif
  7225. // #if %EXTRAV2F5REQUIREKEY%
  7226. // d.extraV2F5 = i.extraV2F5;
  7227. // #endif
  7228. // #if %EXTRAV2F6REQUIREKEY%
  7229. // d.extraV2F6 = i.extraV2F6;
  7230. // #endif
  7231. // #if %EXTRAV2F7REQUIREKEY%
  7232. // d.extraV2F7 = i.extraV2F7;
  7233. // #endif
  7234. return d;
  7235. }
  7236. #endif
  7237. #if defined(_PASSSHADOW)
  7238. float3 _LightDirection;
  7239. float3 _LightPosition;
  7240. #endif
  7241. // vertex shader
  7242. VertexToPixel Vert (VertexData v)
  7243. {
  7244. VertexToPixel o = (VertexToPixel)0;
  7245. UNITY_SETUP_INSTANCE_ID(v);
  7246. UNITY_TRANSFER_INSTANCE_ID(v, o);
  7247. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  7248. #if !_TESSELLATION_ON
  7249. ChainModifyVertex(v, o, _Time);
  7250. #endif
  7251. o.texcoord0 = v.texcoord0;
  7252. o.texcoord1 = v.texcoord1;
  7253. o.texcoord2 = v.texcoord2;
  7254. // #if %TEXCOORD3REQUIREKEY%
  7255. o.texcoord3 = v.texcoord3;
  7256. // #endif
  7257. // #if %VERTEXCOLORREQUIREKEY%
  7258. // o.vertexColor = v.vertexColor;
  7259. // #endif
  7260. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  7261. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  7262. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  7263. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  7264. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  7265. #if _PASSSHADOW
  7266. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  7267. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  7268. #else
  7269. float3 lightDirectionWS = _LightDirection;
  7270. #endif
  7271. // Define shadow pass specific clip position for Universal
  7272. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  7273. #if UNITY_REVERSED_Z
  7274. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  7275. #else
  7276. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  7277. #endif
  7278. #elif _PASSMETA
  7279. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  7280. #else
  7281. o.pos = TransformWorldToHClip(o.worldPos);
  7282. #endif
  7283. // #if %SCREENPOSREQUIREKEY%
  7284. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  7285. // #endif
  7286. #if _PASSFORWARD || _PASSGBUFFER
  7287. float2 uv1 = v.texcoord1.xy;
  7288. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  7289. o.texcoord1.xy = uv1;
  7290. OUTPUT_SH(o.worldNormal, o.sh);
  7291. #if defined(DYNAMICLIGHTMAP_ON)
  7292. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  7293. #endif
  7294. #endif
  7295. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  7296. half fogFactor = 0;
  7297. #if defined(_FOG_FRAGMENT)
  7298. fogFactor = ComputeFogFactor(o.pos.z);
  7299. #endif
  7300. #if _BAKEDLIT
  7301. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  7302. #else
  7303. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  7304. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  7305. #endif
  7306. #endif
  7307. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  7308. o.shadowCoord = GetShadowCoord(vertexInput);
  7309. #endif
  7310. return o;
  7311. }
  7312. // fragment shader
  7313. half4 Frag (VertexToPixel IN
  7314. #ifdef _DEPTHOFFSET_ON
  7315. , out float outputDepth : SV_Depth
  7316. #endif
  7317. #if NEED_FACING
  7318. , bool facing : SV_IsFrontFace
  7319. #endif
  7320. ) : SV_Target
  7321. {
  7322. UNITY_SETUP_INSTANCE_ID(IN);
  7323. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  7324. ShaderData d = CreateShaderData(IN
  7325. #if NEED_FACING
  7326. , facing
  7327. #endif
  7328. );
  7329. Surface l = (Surface)0;
  7330. #ifdef _DEPTHOFFSET_ON
  7331. l.outputDepth = outputDepth;
  7332. #endif
  7333. l.Albedo = half3(0.5, 0.5, 0.5);
  7334. l.Normal = float3(0,0,1);
  7335. l.Occlusion = 1;
  7336. l.Alpha = 1;
  7337. ChainSurfaceFunction(l, d);
  7338. #ifdef _DEPTHOFFSET_ON
  7339. outputDepth = l.outputDepth;
  7340. #endif
  7341. #if defined(_GBUFFER_NORMALS_OCT)
  7342. float3 normalWS = d.worldSpaceNormal;
  7343. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
  7344. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  7345. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  7346. return half4(packedNormalWS, 0.0);
  7347. #else
  7348. float3 wsn = l.Normal;
  7349. #if !_WORLDSPACENORMAL
  7350. wsn = TangentToWorldSpace(d, l.Normal);
  7351. #endif
  7352. return half4(NormalizeNormalPerPixel(wsn), 0.0);
  7353. #endif
  7354. }
  7355. ENDHLSL
  7356. }
  7357. }
  7358. }