Dither.shader 292 KB

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