Debug Ground.shader 309 KB

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