Solid.shader 289 KB

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