Terrain.shader 298 KB

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