Surface_Transparent.shader 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049
  1. //<HASH>1426093573</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/Surface_Transparent"
  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. _Sink("Sink", Float) = 1
  21. _Emission("Emission", Float) = 1
  22. [Header(WAVE)]
  23. [NoScaleOffset]_NormalFoamMap(" Normal (RGB) Foam (A)", 2D) = "bump" {}
  24. _WaveStrengthMin(" Strength Min", Range(0,2)) = 0.0
  25. _WaveStrengthMax(" Strength Max", Range(0,2)) = 0.5
  26. _WaveStrengthScale(" Strength Scale", Float) = 1
  27. _Tiling (" Tiling", Float) = 1
  28. _AnimationSpeed (" Animation Speed", Float) = 1
  29. [Header(STOCHASTIC)]
  30. [Toggle(_STOCHASTIC_ON)] _HasStochastic (" Enabled", Float) = 0
  31. [NoScaleOffset]_NoiseMap(" Noise (A)", 2D) = "black" {}
  32. [Header(FOAM)]
  33. [KeywordEnum(Off, Alpha, Cutout)] _Foam (" Mode", Float) = 0
  34. _FoamBrightness(" Brightness", Range(0,2)) = 1
  35. [Header(FACETED)]
  36. [Toggle(_FACETED_ON)] _HasFaceted (" Enabled", Float) = 0
  37. _FlatShadingBlend(" Flat Amount", Range(0,3)) = 0.9
  38. [Header(TRANSPARENCY)]
  39. [KeywordEnum(Off, Vertical, Depth, March Fluid, March Fluid And Depth)] _Alpha (" Mode", Float) = 0
  40. _RangeMax (" Range Max", Float) = 25
  41. _AlphaStep (" Step", Float) = 2.0
  42. _AlphaMaxSteps (" Max Steps", Int) = 100
  43. _AlphaDepthScale (" Depth Scale", Float) = 0.1
  44. [Header(UNITY FOG)]
  45. [Toggle(DISABLEFOG)] _CW_DisableFog(" Disable", Float) = 0
  46. }
  47. SubShader
  48. {
  49. Tags { "RenderPipeline"="UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" }
  50. ZWrite Off ColorMask RGB
  51. Pass
  52. {
  53. Name "Universal Forward"
  54. Tags
  55. {
  56. "LightMode" = "UniversalForward"
  57. }
  58. Cull Back
  59. Blend One Zero
  60. ZTest LEqual
  61. ZWrite On
  62. Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
  63. Cull Back
  64. ZTest LEqual
  65. ZWrite Off
  66. ZWrite On
  67. HLSLPROGRAM
  68. #pragma vertex Vert
  69. #pragma fragment Frag
  70. #pragma target 3.0
  71. #pragma prefer_hlslcc gles
  72. #pragma exclude_renderers d3d11_9x
  73. #pragma multi_compile_fog
  74. #pragma multi_compile_instancing
  75. #pragma instancing_options renderinglayer
  76. #pragma multi_compile _ DOTS_INSTANCING_ON
  77. // Keywords
  78. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  79. #pragma multi_compile _ LIGHTMAP_ON
  80. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  81. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  82. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  83. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  84. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  85. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  86. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
  87. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  88. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  89. #pragma multi_compile _ SHADOWS_SHADOWMASK
  90. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  91. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  92. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  93. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  94. #pragma multi_compile _ _CLUSTERED_RENDERING
  95. // GraphKeywords: <None>
  96. #define SHADER_PASS SHADERPASS_FORWARD
  97. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  98. #define _PASSFORWARD 1
  99. #define _FOG_FRAGMENT 1
  100. #include "Flow.cginc"
  101. #pragma shader_feature_local _ _STOCHASTIC_ON
  102. #pragma shader_feature_local _FOAM_OFF _FOAM_ALPHA _FOAM_CUTOUT
  103. #pragma shader_feature_local _ _FACETED_ON
  104. #pragma shader_feature_local _ALPHA_OFF _ALPHA_VERTICAL _ALPHA_DEPTH _ALPHA_MARCH_FLUID _ALPHA_MARCH_FLUID_AND_DEPTH
  105. #pragma shader_feature_local DISABLEFOG
  106. #define _URP 1
  107. #define _ALPHABLEND_ON 1
  108. #define _ALPHABLEND_ON 1
  109. #define _SURFACE_TYPE_TRANSPARENT 1
  110. #define _GRABPASSUSED 1
  111. #define REQUIRE_OPAQUE_TEXTURE
  112. #define REQUIRE_DEPTH_TEXTURE
  113. // this has to be here or specular color will be ignored. Not in SG code
  114. #if _SIMPLELIT
  115. #define _SPECULAR_COLOR
  116. #endif
  117. // Includes
  118. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  119. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  120. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  121. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  122. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  123. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  124. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  125. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  126. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  127. #undef WorldNormalVector
  128. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  129. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  130. #define _WorldSpaceLightPos0 _MainLightPosition
  131. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  132. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  133. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  134. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  135. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  136. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  137. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  138. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  139. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  140. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  141. #if defined(UNITY_COMPILER_HLSL)
  142. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  143. #else
  144. #define UNITY_INITIALIZE_OUTPUT(type,name)
  145. #endif
  146. #define sampler2D_float sampler2D
  147. #define sampler2D_half sampler2D
  148. // data across stages, stripped like the above.
  149. struct VertexToPixel
  150. {
  151. float4 pos : SV_POSITION;
  152. float3 worldPos : TEXCOORD0;
  153. float3 worldNormal : TEXCOORD1;
  154. float4 worldTangent : TEXCOORD2;
  155. float4 texcoord0 : TEXCOORD3;
  156. // float4 texcoord1 : TEXCOORD4;
  157. // float4 texcoord2 : TEXCOORD5;
  158. // #if %TEXCOORD3REQUIREKEY%
  159. // float4 texcoord3 : TEXCOORD6;
  160. // #endif
  161. // #if %SCREENPOSREQUIREKEY%
  162. float4 screenPos : TEXCOORD7;
  163. // #endif
  164. // #if %VERTEXCOLORREQUIREKEY%
  165. half4 vertexColor : COLOR;
  166. // #endif
  167. #if defined(LIGHTMAP_ON)
  168. float2 lightmapUV : TEXCOORD8;
  169. #endif
  170. #if defined(DYNAMICLIGHTMAP_ON)
  171. float2 dynamicLightmapUV : TEXCOORD9;
  172. #endif
  173. #if !defined(LIGHTMAP_ON)
  174. float3 sh : TEXCOORD10;
  175. #endif
  176. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  177. float4 fogFactorAndVertexLight : TEXCOORD11;
  178. #endif
  179. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  180. float4 shadowCoord : TEXCOORD12;
  181. #endif
  182. // #if %EXTRAV2F0REQUIREKEY%
  183. float4 extraV2F0 : TEXCOORD13;
  184. // #endif
  185. // #if %EXTRAV2F1REQUIREKEY%
  186. float4 extraV2F1 : TEXCOORD14;
  187. // #endif
  188. // #if %EXTRAV2F2REQUIREKEY%
  189. // float4 extraV2F2 : TEXCOORD15;
  190. // #endif
  191. // #if %EXTRAV2F3REQUIREKEY%
  192. // float4 extraV2F3 : TEXCOORD16;
  193. // #endif
  194. // #if %EXTRAV2F4REQUIREKEY%
  195. // float4 extraV2F4 : TEXCOORD17;
  196. // #endif
  197. // #if %EXTRAV2F5REQUIREKEY%
  198. // float4 extraV2F5 : TEXCOORD18;
  199. // #endif
  200. // #if %EXTRAV2F6REQUIREKEY%
  201. // float4 extraV2F6 : TEXCOORD19;
  202. // #endif
  203. // #if %EXTRAV2F7REQUIREKEY%
  204. // float4 extraV2F7 : TEXCOORD20;
  205. // #endif
  206. #if UNITY_ANY_INSTANCING_ENABLED
  207. uint instanceID : CUSTOM_INSTANCE_ID;
  208. #endif
  209. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  210. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  211. #endif
  212. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  213. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  214. #endif
  215. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  216. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  217. #endif
  218. };
  219. // data describing the user output of a pixel
  220. struct Surface
  221. {
  222. half3 Albedo;
  223. half Height;
  224. half3 Normal;
  225. half Smoothness;
  226. half3 Emission;
  227. half Metallic;
  228. half3 Specular;
  229. half Occlusion;
  230. half SpecularPower; // for simple lighting
  231. half Alpha;
  232. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  233. // HDRP Only
  234. half SpecularOcclusion;
  235. half SubsurfaceMask;
  236. half Thickness;
  237. half CoatMask;
  238. half CoatSmoothness;
  239. half Anisotropy;
  240. half IridescenceMask;
  241. half IridescenceThickness;
  242. int DiffusionProfileHash;
  243. float SpecularAAThreshold;
  244. float SpecularAAScreenSpaceVariance;
  245. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  246. float3 DiffuseGI;
  247. float3 BackDiffuseGI;
  248. float3 SpecularGI;
  249. float ior;
  250. float3 transmittanceColor;
  251. float atDistance;
  252. float transmittanceMask;
  253. // requires _OVERRIDE_SHADOWMASK to be defines
  254. float4 ShadowMask;
  255. // for decals
  256. float NormalAlpha;
  257. float MAOSAlpha;
  258. };
  259. // Data the user declares in blackboard blocks
  260. struct Blackboard
  261. {
  262. float groundHeight;
  263. float surfaceHeight;
  264. float3 surfaceNormal;
  265. Fluid fluid;
  266. float foam;
  267. float blackboardDummyData;
  268. };
  269. // data the user might need, this will grow to be big. But easy to strip
  270. struct ShaderData
  271. {
  272. float4 clipPos; // SV_POSITION
  273. float3 localSpacePosition;
  274. float3 localSpaceNormal;
  275. float3 localSpaceTangent;
  276. float3 worldSpacePosition;
  277. float3 worldSpaceNormal;
  278. float3 worldSpaceTangent;
  279. float tangentSign;
  280. float3 worldSpaceViewDir;
  281. float3 tangentSpaceViewDir;
  282. float4 texcoord0;
  283. float4 texcoord1;
  284. float4 texcoord2;
  285. float4 texcoord3;
  286. float2 screenUV;
  287. float4 screenPos;
  288. float4 vertexColor;
  289. bool isFrontFace;
  290. float4 extraV2F0;
  291. float4 extraV2F1;
  292. float4 extraV2F2;
  293. float4 extraV2F3;
  294. float4 extraV2F4;
  295. float4 extraV2F5;
  296. float4 extraV2F6;
  297. float4 extraV2F7;
  298. float3x3 TBNMatrix;
  299. Blackboard blackboard;
  300. };
  301. struct VertexData
  302. {
  303. #if SHADER_TARGET > 30
  304. // uint vertexID : SV_VertexID;
  305. #endif
  306. float4 vertex : POSITION;
  307. float3 normal : NORMAL;
  308. float4 tangent : TANGENT;
  309. float4 texcoord0 : TEXCOORD0;
  310. // optimize out mesh coords when not in use by user or lighting system
  311. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  312. float4 texcoord1 : TEXCOORD1;
  313. #endif
  314. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  315. float4 texcoord2 : TEXCOORD2;
  316. #endif
  317. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  318. float4 texcoord1 : TEXCOORD1;
  319. #endif
  320. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  321. float4 texcoord2 : TEXCOORD2;
  322. #endif
  323. #if _HDRP
  324. float4 texcoord1 : TEXCOORD1;
  325. float4 texcoord2 : TEXCOORD2;
  326. #endif
  327. // #if %TEXCOORD3REQUIREKEY%
  328. // float4 texcoord3 : TEXCOORD3;
  329. // #endif
  330. // #if %VERTEXCOLORREQUIREKEY%
  331. float4 vertexColor : COLOR;
  332. // #endif
  333. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  334. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  335. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  336. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  337. #endif
  338. #endif
  339. UNITY_VERTEX_INPUT_INSTANCE_ID
  340. };
  341. struct TessVertex
  342. {
  343. float4 vertex : INTERNALTESSPOS;
  344. float3 normal : NORMAL;
  345. float4 tangent : TANGENT;
  346. float4 texcoord0 : TEXCOORD0;
  347. float4 texcoord1 : TEXCOORD1;
  348. float4 texcoord2 : TEXCOORD2;
  349. // #if %TEXCOORD3REQUIREKEY%
  350. // float4 texcoord3 : TEXCOORD3;
  351. // #endif
  352. // #if %VERTEXCOLORREQUIREKEY%
  353. float4 vertexColor : COLOR;
  354. // #endif
  355. // #if %EXTRAV2F0REQUIREKEY%
  356. float4 extraV2F0 : TEXCOORD5;
  357. // #endif
  358. // #if %EXTRAV2F1REQUIREKEY%
  359. float4 extraV2F1 : TEXCOORD6;
  360. // #endif
  361. // #if %EXTRAV2F2REQUIREKEY%
  362. // float4 extraV2F2 : TEXCOORD7;
  363. // #endif
  364. // #if %EXTRAV2F3REQUIREKEY%
  365. // float4 extraV2F3 : TEXCOORD8;
  366. // #endif
  367. // #if %EXTRAV2F4REQUIREKEY%
  368. // float4 extraV2F4 : TEXCOORD9;
  369. // #endif
  370. // #if %EXTRAV2F5REQUIREKEY%
  371. // float4 extraV2F5 : TEXCOORD10;
  372. // #endif
  373. // #if %EXTRAV2F6REQUIREKEY%
  374. // float4 extraV2F6 : TEXCOORD11;
  375. // #endif
  376. // #if %EXTRAV2F7REQUIREKEY%
  377. // float4 extraV2F7 : TEXCOORD12;
  378. // #endif
  379. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  380. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  381. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  382. float3 precomputedVelocity : TEXCOORD14;
  383. #endif
  384. #endif
  385. UNITY_VERTEX_INPUT_INSTANCE_ID
  386. UNITY_VERTEX_OUTPUT_STEREO
  387. };
  388. struct ExtraV2F
  389. {
  390. float4 extraV2F0;
  391. float4 extraV2F1;
  392. float4 extraV2F2;
  393. float4 extraV2F3;
  394. float4 extraV2F4;
  395. float4 extraV2F5;
  396. float4 extraV2F6;
  397. float4 extraV2F7;
  398. Blackboard blackboard;
  399. float4 time;
  400. };
  401. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  402. {
  403. return mul(d.TBNMatrix, normal);
  404. }
  405. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  406. {
  407. return mul(normal, d.TBNMatrix);
  408. }
  409. // in this case, make standard more like SRPs, because we can't fix
  410. // unity_WorldToObject in HDRP, since it already does macro-fu there
  411. #if _STANDARD
  412. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  413. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  414. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  415. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  416. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  417. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  418. #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))
  419. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  420. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  421. #else
  422. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  423. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  424. #endif
  425. #undef GetWorldToObjectMatrix()
  426. #define GetWorldToObjectMatrix() unity_WorldToObject
  427. #endif
  428. float3 GetCameraWorldPosition()
  429. {
  430. #if _HDRP
  431. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  432. #else
  433. return _WorldSpaceCameraPos;
  434. #endif
  435. }
  436. #if _GRABPASSUSED
  437. #if _STANDARD
  438. TEXTURE2D(_Grab);
  439. SAMPLER(sampler__Grab);
  440. #endif
  441. half3 GetSceneColor(float2 uv)
  442. {
  443. #if _STANDARD
  444. return SAMPLE_TEXTURE2D(_Grab, sampler__Grab, uv).rgb;
  445. #else
  446. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  447. #endif
  448. }
  449. #endif
  450. #if _STANDARD
  451. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  452. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  453. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  454. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  455. #else
  456. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  457. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  458. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  459. #endif
  460. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  461. {
  462. float eye = GetLinearEyeDepth(uv);
  463. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  464. float dt = dot(worldSpaceViewDir, camView);
  465. float3 div = worldSpaceViewDir/dt;
  466. float3 wpos = (eye * div) + GetCameraWorldPosition();
  467. return wpos;
  468. }
  469. #if _HDRP
  470. float3 ObjectToWorldSpacePosition(float3 pos)
  471. {
  472. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  473. }
  474. #else
  475. float3 ObjectToWorldSpacePosition(float3 pos)
  476. {
  477. return TransformObjectToWorld(pos);
  478. }
  479. #endif
  480. #if _STANDARD
  481. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  482. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  483. {
  484. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  485. float3 norms = DecodeViewNormalStereo(depthNorms);
  486. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  487. return norms;
  488. }
  489. #elif _HDRP && !_DECALSHADER
  490. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  491. {
  492. NormalData nd;
  493. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  494. return nd.normalWS;
  495. }
  496. #elif _URP
  497. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  498. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  499. #endif
  500. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  501. {
  502. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  503. return SampleSceneNormals(uv);
  504. #else
  505. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  506. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  507. #endif
  508. }
  509. #endif
  510. #if _HDRP
  511. half3 UnpackNormalmapRGorAG(half4 packednormal)
  512. {
  513. // This do the trick
  514. packednormal.x *= packednormal.w;
  515. half3 normal;
  516. normal.xy = packednormal.xy * 2 - 1;
  517. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  518. return normal;
  519. }
  520. half3 UnpackNormal(half4 packednormal)
  521. {
  522. #if defined(UNITY_NO_DXT5nm)
  523. return packednormal.xyz * 2 - 1;
  524. #else
  525. return UnpackNormalmapRGorAG(packednormal);
  526. #endif
  527. }
  528. #endif
  529. #if _HDRP || _URP
  530. half3 UnpackScaleNormal(half4 packednormal, half scale)
  531. {
  532. #ifndef UNITY_NO_DXT5nm
  533. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  534. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  535. packednormal.x *= packednormal.w;
  536. #endif
  537. half3 normal;
  538. normal.xy = (packednormal.xy * 2 - 1) * scale;
  539. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  540. return normal;
  541. }
  542. #endif
  543. void GetSun(out float3 lightDir, out float3 color)
  544. {
  545. lightDir = float3(0.5, 0.5, 0);
  546. color = 1;
  547. #if _HDRP
  548. if (_DirectionalLightCount > 0)
  549. {
  550. DirectionalLightData light = _DirectionalLightDatas[0];
  551. lightDir = -light.forward.xyz;
  552. color = light.color;
  553. }
  554. #elif _STANDARD
  555. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  556. color = _LightColor0.rgb;
  557. #elif _URP
  558. Light light = GetMainLight();
  559. lightDir = light.direction;
  560. color = light.color;
  561. #endif
  562. }
  563. CBUFFER_START(UnityPerMaterial)
  564. float _FlowDensity;
  565. float2 _FlowSeparationXZ;
  566. float _FlowSimulationHeight;
  567. float _FlowCameraHeight;
  568. float2 _FlowCountXZ;
  569. float4 _FlowCoordU000;
  570. float4 _FlowCoord0V00;
  571. float _FlowSpeed;
  572. float4x4 _FlowMatrix;
  573. float _Sink;
  574. float _Emission;
  575. float _WaveStrengthMin;
  576. float _WaveStrengthMax;
  577. float _WaveStrengthScale;
  578. float _Tiling;
  579. float _AnimationSpeed;
  580. float _FoamBrightness;
  581. half _FlatShadingBlend;
  582. float _RangeMax;
  583. float _AlphaStep;
  584. int _AlphaMaxSteps;
  585. float _AlphaDepthScale;
  586. CBUFFER_END
  587. #ifdef unity_WorldToObject
  588. #undef unity_WorldToObject
  589. #endif
  590. #ifdef unity_ObjectToWorld
  591. #undef unity_ObjectToWorld
  592. #endif
  593. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  594. #define unity_WorldToObject GetWorldToObjectMatrix()
  595. TEXTURE2D(_FlowDataA);
  596. SAMPLER(sampler_FlowDataA);
  597. TEXTURE2D(_FlowDataB);
  598. SAMPLER(sampler_FlowDataB);
  599. TEXTURE2D(_FlowDataC);
  600. SAMPLER(sampler_FlowDataC);
  601. TEXTURE2D(_FlowDataD);
  602. SAMPLER(sampler_FlowDataD);
  603. TEXTURE2D(_FlowDataE);
  604. SAMPLER(sampler_FlowDataE);
  605. TEXTURE2D(_FlowDataF);
  606. SAMPLER(sampler_FlowDataF);
  607. float4 SGT_O2W(float4 v)
  608. {
  609. v = mul(GetObjectToWorldMatrix(), v);
  610. #if _HDRP
  611. v.xyz = GetAbsolutePositionWS(v.xyz);
  612. #endif
  613. return v;
  614. }
  615. float4 SGT_W2O(float4 v)
  616. {
  617. #if _HDRP
  618. v.xyz = GetCameraRelativePositionWS(v.xyz);
  619. #endif
  620. return mul(GetWorldToObjectMatrix(), v);
  621. }
  622. float4 SGT_O2V(float4 v)
  623. {
  624. #if _STANDARD
  625. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  626. #else
  627. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  628. #endif
  629. }
  630. float GetFluidHeight(float2 uv)
  631. {
  632. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  633. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  634. return groundHeight + fluidDepth;
  635. }
  636. float2 GetHeightAndDepth(float2 uv)
  637. {
  638. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  639. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  640. return float2(groundHeight, fluidDepth);
  641. }
  642. Column GetColumn(float2 uv)
  643. {
  644. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  645. }
  646. Fluid GetColumnFluid(float2 uv)
  647. {
  648. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  649. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  650. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  651. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  652. return DecodeFluid(c, d, e, f);
  653. }
  654. bool InsideFluid(float3 wpos)
  655. {
  656. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  657. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  658. float2 columnHAD = GetHeightAndDepth(columnCoord);
  659. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  660. }
  661. bool UnderFluid(float3 wpos)
  662. {
  663. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  664. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  665. float2 columnHAD = GetHeightAndDepth(columnCoord);
  666. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  667. }
  668. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  669. {
  670. float epsi = step * 0.01f;
  671. float dist = 0.0f;
  672. for (int i = 0; i < maxs && step > epsi; i++)
  673. {
  674. dist += step;
  675. float3 pos = wpos + wdir * dist;
  676. if (InsideFluid(pos) == false)
  677. {
  678. dist -= step;
  679. step *= 0.5f;
  680. }
  681. if (dist > maxd)
  682. {
  683. return maxd;
  684. }
  685. }
  686. return dist;
  687. }
  688. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  689. {
  690. float epsi = step * 0.01f;
  691. float dist = 0.0f;
  692. for (int i = 0; i < maxs && step > epsi; i++)
  693. {
  694. dist += step;
  695. float3 pos = wpos + wdir * dist;
  696. if (UnderFluid(pos) == false)
  697. {
  698. dist -= step;
  699. step *= 0.5f;
  700. }
  701. if (dist > maxd)
  702. {
  703. return maxd;
  704. }
  705. }
  706. return dist;
  707. }
  708. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  709. {
  710. float4 wpos = SGT_O2W(v.vertex);
  711. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  712. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  713. Column column0 = GetColumn(columnCoord);
  714. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  715. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  716. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  717. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  718. Fluid fluid0 = GetColumnFluid(columnCoord);
  719. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  720. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  721. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  722. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  723. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  724. float wL = fluidL.Depth / ww;
  725. float wR = fluidR.Depth / ww;
  726. float wB = fluidB.Depth / ww;
  727. float wT = fluidT.Depth / ww;
  728. float w0 = saturate(fluid0.Depth * 10);
  729. float hL = columnL.GroundHeight + fluidL.Depth;
  730. float hR = columnR.GroundHeight + fluidR.Depth;
  731. float hB = columnB.GroundHeight + fluidB.Depth;
  732. float hT = columnT.GroundHeight + fluidT.Depth;
  733. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  734. float h0 = column0.GroundHeight + fluid0.Depth;
  735. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  736. Fluid fluid = fluid0;
  737. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  738. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  739. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  740. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  741. e.blackboard.groundHeight = column0.GroundHeight;
  742. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  743. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  744. e.blackboard.fluid = fluid;
  745. }
  746. TEXTURE2D(_NoiseMap);
  747. SAMPLER(sampler_NoiseMap);
  748. TEXTURE2D(_NormalFoamMap);
  749. SAMPLER(sampler_NormalFoamMap);
  750. void Ext_ModifyVertex3 (inout VertexData v, inout ExtraV2F e)
  751. {
  752. v.vertex.y = lerp(e.blackboard.groundHeight, e.blackboard.surfaceHeight, v.texcoord0.w) - _FlowSimulationHeight;
  753. v.normal = lerp(e.blackboard.surfaceNormal, v.normal, v.texcoord0.z);
  754. v.vertexColor = e.blackboard.fluid.RGBA;
  755. e.extraV2F0.xyz = SGT_O2V(v.vertex).xyz;
  756. e.extraV2F0.w = e.blackboard.fluid.Depth;
  757. e.extraV2F1.xyz = e.blackboard.fluid.ESMV.xyz;
  758. e.extraV2F1.w = e.blackboard.fluid.F123.x;
  759. }
  760. float3 FlowUVW(float2 uv, float2 flowVector, float2 jump, float tiling, float time, float phaseOffset)
  761. {
  762. float progress = frac(time + phaseOffset);
  763. float3 uvw;
  764. uvw.xy = uv - flowVector * (progress - 0.5f);
  765. uvw.xy *= tiling;
  766. uvw.xy += phaseOffset;
  767. uvw.xy += (time - progress) * jump;
  768. uvw.z = 1 - abs(1 - 2 * progress);
  769. return uvw;
  770. }
  771. float3 CombineNormals(float3 n1, float3 n2)
  772. {
  773. return normalize(half3(n1.xy + n2.xy, n1.z*n2.z));
  774. }
  775. float3 UnpackNormalAndScale(float2 xy, float scale)
  776. {
  777. xy = xy * 2.0f - 1.0f; xy *= scale; return float3(xy, sqrt(1.0 - saturate(dot(xy, xy))));
  778. }
  779. float4 SampleStochastic(float2 uv, float noise)
  780. {
  781. float cur_height = uv.y + noise;
  782. float this_index = floor(cur_height);
  783. float next_index = this_index + 1.0f;
  784. float2 uvA = uv + sin(float2(1.0f, 2.0f) * this_index);
  785. float2 uvB = uv + sin(float2(1.0f, 2.0f) * next_index);
  786. float2 gradX = ddx(uv);
  787. float2 gradY = ddy(uv);
  788. float4 sampleA = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvA, gradX, gradY);
  789. float4 sampleB = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvB, gradX, gradY);
  790. return lerp(sampleA, sampleB, cur_height - this_index);
  791. }
  792. void Ext_SurfaceFunction3 (inout Surface o, inout ShaderData d)
  793. {
  794. d.blackboard.fluid.RGBA = d.vertexColor;
  795. d.blackboard.fluid.Depth = d.extraV2F0.w;
  796. d.blackboard.fluid.ESMV.xyz = d.extraV2F1.xyz;
  797. d.blackboard.fluid.F123.x = d.extraV2F1.w;
  798. if (d.blackboard.fluid.Depth < 0.01f)
  799. {
  800. discard;
  801. }
  802. float2 uv = d.worldSpacePosition.xz;
  803. float2 columnPixel = mul(_FlowMatrix, float4(d.worldSpacePosition, 1.0f)).xy;
  804. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  805. Column column = GetColumn(columnCoord);
  806. float time = _Time.y * _AnimationSpeed;
  807. float2 jump = float2(0.13f, 0.17f);
  808. float2 fvec = (column.Outflow.yw - column.Outflow.xz) * _FlowSeparationXZ * _FlowSpeed;
  809. float fmag = log10(1.0f + length(fvec)) * 0.1f;
  810. float3 flowA = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.0f);
  811. float3 flowB = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.5f);
  812. #if _STOCHASTIC_ON
  813. float noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, uv * 0.0025f).a * 4.0f;
  814. float4 nfmA = SampleStochastic(flowA, noise);
  815. float4 nfmB = SampleStochastic(flowB, noise);
  816. #else
  817. float4 nfmA = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowA.xy);
  818. float4 nfmB = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowB.xy);
  819. #endif
  820. // Water normals
  821. float normalStr = lerp(_WaveStrengthMin, _WaveStrengthMax, saturate(_WaveStrengthScale * fmag));
  822. float3 waterNormalA = UnpackNormalAndScale(nfmA.xy, flowA.z * normalStr);
  823. float3 waterNormalB = UnpackNormalAndScale(nfmB.xy, flowB.z * normalStr);
  824. float3 waterNormals = CombineNormals(waterNormalA, waterNormalB);
  825. o.Normal = lerp(waterNormals, o.Normal, d.texcoord0.z);
  826. o.Albedo = d.blackboard.fluid.RGBA.xyz;
  827. o.Emission = d.blackboard.fluid.ESMV.x * _Emission * o.Albedo;
  828. #if _FOAM_OFF
  829. d.blackboard.foam = 0.0f;
  830. #else
  831. d.blackboard.foam = d.blackboard.fluid.F123.x * (1.0f - d.texcoord0.z);
  832. #if _FOAM_ALPHA
  833. float3 foamAlbedo = (nfmA.w * flowA.z + nfmB.w * flowB.z) * _FoamBrightness;
  834. #elif _FOAM_CUTOUT
  835. float3 foamAlbedo = _FoamBrightness;
  836. float foamRamp = nfmA.w * flowA.z + nfmB.w * flowB.z;
  837. d.blackboard.foam = saturate((d.blackboard.foam - foamRamp) * 10.0f);
  838. #endif
  839. float3 foamNormal = float3(0.0f, 0.0f, 1.0f);
  840. o.Albedo = lerp(o.Albedo, foamAlbedo, d.blackboard.foam);
  841. o.Normal = lerp(o.Normal, foamNormal, d.blackboard.foam);
  842. #endif
  843. o.Smoothness = d.blackboard.fluid.ESMV.y;
  844. o.Metallic = d.blackboard.fluid.ESMV.z;
  845. }
  846. void Ext_SurfaceFunction4 (inout Surface o, inout ShaderData d)
  847. {
  848. #if _FACETED_ON
  849. // lets just affect the TBN data, so we flat shade the original polygons, not the normal map
  850. float3 dx = ddx(d.worldSpacePosition);
  851. float3 dy = ddy(d.worldSpacePosition);
  852. float3 worldNormal = normalize(cross(dy, dx));
  853. worldNormal = lerp(d.worldSpaceNormal, worldNormal, _FlatShadingBlend);
  854. d.worldSpaceNormal = worldNormal;
  855. d.TBNMatrix[2] = worldNormal;
  856. #endif
  857. }
  858. void Ext_SurfaceFunction5 (inout Surface o, ShaderData d)
  859. {
  860. #if _ALPHA_OFF
  861. #else
  862. float3 position = d.worldSpacePosition;
  863. float3 step = d.worldSpacePosition - _WorldSpaceCameraPos;
  864. float2 bentScrUV = d.screenUV + o.Normal.xy * 0.05f * log(1.0f + d.blackboard.fluid.Depth * 1.0f);
  865. float distMax = max(_RangeMax * 0.001f, _RangeMax * (1.0f - d.blackboard.fluid.RGBA.w));
  866. float distRange = distMax;
  867. float vertDist = length(d.extraV2F0.xyz);
  868. float camtDist = GetLinearEyeDepth(bentScrUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  869. if (camtDist < vertDist)
  870. {
  871. camtDist = GetLinearEyeDepth(d.screenUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  872. }
  873. float diffDist = max(0.0f, camtDist - vertDist);
  874. // The depth buffer becomes unusable at certain ranges, so fade it out
  875. diffDist += max(0.0f, camtDist * _AlphaDepthScale - _RangeMax);
  876. distRange = min(distRange, diffDist);
  877. #if _ALPHA_VERTICAL
  878. float dist = d.blackboard.fluid.Depth;
  879. #elif _ALPHA_DEPTH
  880. float dist = diffDist;
  881. #elif _ALPHA_MARCH_FLUID
  882. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distMax);
  883. #elif _ALPHA_MARCH_FLUID_AND_DEPTH
  884. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distRange);
  885. #endif
  886. // Set opacity based on distance through fluid relative to the maximum distance, and make sure high opacity fluids become solid
  887. float opacity = saturate(dist / distMax + d.blackboard.foam + pow(d.blackboard.fluid.RGBA.w, 10.0f));
  888. o.Albedo = lerp(0.0f, o.Albedo, opacity);
  889. o.Emission = lerp(GetSceneColor(bentScrUV), o.Emission, opacity);
  890. //o.Emission += o.Albedo * d.blackboard.fluid.ESMV.x * opacity;
  891. #endif
  892. }
  893. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  894. {
  895. // Ext_SurfaceFunction0(l, d);
  896. // Ext_SurfaceFunction1(l, d);
  897. // Ext_SurfaceFunction2(l, d);
  898. Ext_SurfaceFunction3(l, d);
  899. Ext_SurfaceFunction4(l, d);
  900. Ext_SurfaceFunction5(l, d);
  901. // Ext_SurfaceFunction6(l, d);
  902. // Ext_SurfaceFunction7(l, d);
  903. // Ext_SurfaceFunction8(l, d);
  904. // Ext_SurfaceFunction9(l, d);
  905. // Ext_SurfaceFunction10(l, d);
  906. // Ext_SurfaceFunction11(l, d);
  907. // Ext_SurfaceFunction12(l, d);
  908. // Ext_SurfaceFunction13(l, d);
  909. // Ext_SurfaceFunction14(l, d);
  910. // Ext_SurfaceFunction15(l, d);
  911. // Ext_SurfaceFunction16(l, d);
  912. // Ext_SurfaceFunction17(l, d);
  913. // Ext_SurfaceFunction18(l, d);
  914. // Ext_SurfaceFunction19(l, d);
  915. // Ext_SurfaceFunction20(l, d);
  916. // Ext_SurfaceFunction21(l, d);
  917. // Ext_SurfaceFunction22(l, d);
  918. // Ext_SurfaceFunction23(l, d);
  919. // Ext_SurfaceFunction24(l, d);
  920. // Ext_SurfaceFunction25(l, d);
  921. // Ext_SurfaceFunction26(l, d);
  922. // Ext_SurfaceFunction27(l, d);
  923. // Ext_SurfaceFunction28(l, d);
  924. // Ext_SurfaceFunction29(l, d);
  925. }
  926. #if !_DECALSHADER
  927. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  928. {
  929. ExtraV2F d;
  930. ZERO_INITIALIZE(ExtraV2F, d);
  931. ZERO_INITIALIZE(Blackboard, d.blackboard);
  932. // due to motion vectors in HDRP, we need to use the last
  933. // time in certain spots. So if you are going to use _Time to adjust vertices,
  934. // you need to use this time or motion vectors will break.
  935. d.time = time;
  936. Ext_ModifyVertex0(v, d);
  937. // Ext_ModifyVertex1(v, d);
  938. // Ext_ModifyVertex2(v, d);
  939. Ext_ModifyVertex3(v, d);
  940. // Ext_ModifyVertex4(v, d);
  941. // Ext_ModifyVertex5(v, d);
  942. // Ext_ModifyVertex6(v, d);
  943. // Ext_ModifyVertex7(v, d);
  944. // Ext_ModifyVertex8(v, d);
  945. // Ext_ModifyVertex9(v, d);
  946. // Ext_ModifyVertex10(v, d);
  947. // Ext_ModifyVertex11(v, d);
  948. // Ext_ModifyVertex12(v, d);
  949. // Ext_ModifyVertex13(v, d);
  950. // Ext_ModifyVertex14(v, d);
  951. // Ext_ModifyVertex15(v, d);
  952. // Ext_ModifyVertex16(v, d);
  953. // Ext_ModifyVertex17(v, d);
  954. // Ext_ModifyVertex18(v, d);
  955. // Ext_ModifyVertex19(v, d);
  956. // Ext_ModifyVertex20(v, d);
  957. // Ext_ModifyVertex21(v, d);
  958. // Ext_ModifyVertex22(v, d);
  959. // Ext_ModifyVertex23(v, d);
  960. // Ext_ModifyVertex24(v, d);
  961. // Ext_ModifyVertex25(v, d);
  962. // Ext_ModifyVertex26(v, d);
  963. // Ext_ModifyVertex27(v, d);
  964. // Ext_ModifyVertex28(v, d);
  965. // Ext_ModifyVertex29(v, d);
  966. // #if %EXTRAV2F0REQUIREKEY%
  967. v2p.extraV2F0 = d.extraV2F0;
  968. // #endif
  969. // #if %EXTRAV2F1REQUIREKEY%
  970. v2p.extraV2F1 = d.extraV2F1;
  971. // #endif
  972. // #if %EXTRAV2F2REQUIREKEY%
  973. // v2p.extraV2F2 = d.extraV2F2;
  974. // #endif
  975. // #if %EXTRAV2F3REQUIREKEY%
  976. // v2p.extraV2F3 = d.extraV2F3;
  977. // #endif
  978. // #if %EXTRAV2F4REQUIREKEY%
  979. // v2p.extraV2F4 = d.extraV2F4;
  980. // #endif
  981. // #if %EXTRAV2F5REQUIREKEY%
  982. // v2p.extraV2F5 = d.extraV2F5;
  983. // #endif
  984. // #if %EXTRAV2F6REQUIREKEY%
  985. // v2p.extraV2F6 = d.extraV2F6;
  986. // #endif
  987. // #if %EXTRAV2F7REQUIREKEY%
  988. // v2p.extraV2F7 = d.extraV2F7;
  989. // #endif
  990. }
  991. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  992. {
  993. ExtraV2F d;
  994. ZERO_INITIALIZE(ExtraV2F, d);
  995. ZERO_INITIALIZE(Blackboard, d.blackboard);
  996. // #if %EXTRAV2F0REQUIREKEY%
  997. d.extraV2F0 = v2p.extraV2F0;
  998. // #endif
  999. // #if %EXTRAV2F1REQUIREKEY%
  1000. d.extraV2F1 = v2p.extraV2F1;
  1001. // #endif
  1002. // #if %EXTRAV2F2REQUIREKEY%
  1003. // d.extraV2F2 = v2p.extraV2F2;
  1004. // #endif
  1005. // #if %EXTRAV2F3REQUIREKEY%
  1006. // d.extraV2F3 = v2p.extraV2F3;
  1007. // #endif
  1008. // #if %EXTRAV2F4REQUIREKEY%
  1009. // d.extraV2F4 = v2p.extraV2F4;
  1010. // #endif
  1011. // #if %EXTRAV2F5REQUIREKEY%
  1012. // d.extraV2F5 = v2p.extraV2F5;
  1013. // #endif
  1014. // #if %EXTRAV2F6REQUIREKEY%
  1015. // d.extraV2F6 = v2p.extraV2F6;
  1016. // #endif
  1017. // #if %EXTRAV2F7REQUIREKEY%
  1018. // d.extraV2F7 = v2p.extraV2F7;
  1019. // #endif
  1020. // Ext_ModifyTessellatedVertex0(v, d);
  1021. // Ext_ModifyTessellatedVertex1(v, d);
  1022. // Ext_ModifyTessellatedVertex2(v, d);
  1023. // Ext_ModifyTessellatedVertex3(v, d);
  1024. // Ext_ModifyTessellatedVertex4(v, d);
  1025. // Ext_ModifyTessellatedVertex5(v, d);
  1026. // Ext_ModifyTessellatedVertex6(v, d);
  1027. // Ext_ModifyTessellatedVertex7(v, d);
  1028. // Ext_ModifyTessellatedVertex8(v, d);
  1029. // Ext_ModifyTessellatedVertex9(v, d);
  1030. // Ext_ModifyTessellatedVertex10(v, d);
  1031. // Ext_ModifyTessellatedVertex11(v, d);
  1032. // Ext_ModifyTessellatedVertex12(v, d);
  1033. // Ext_ModifyTessellatedVertex13(v, d);
  1034. // Ext_ModifyTessellatedVertex14(v, d);
  1035. // Ext_ModifyTessellatedVertex15(v, d);
  1036. // Ext_ModifyTessellatedVertex16(v, d);
  1037. // Ext_ModifyTessellatedVertex17(v, d);
  1038. // Ext_ModifyTessellatedVertex18(v, d);
  1039. // Ext_ModifyTessellatedVertex19(v, d);
  1040. // Ext_ModifyTessellatedVertex20(v, d);
  1041. // Ext_ModifyTessellatedVertex21(v, d);
  1042. // Ext_ModifyTessellatedVertex22(v, d);
  1043. // Ext_ModifyTessellatedVertex23(v, d);
  1044. // Ext_ModifyTessellatedVertex24(v, d);
  1045. // Ext_ModifyTessellatedVertex25(v, d);
  1046. // Ext_ModifyTessellatedVertex26(v, d);
  1047. // Ext_ModifyTessellatedVertex27(v, d);
  1048. // Ext_ModifyTessellatedVertex28(v, d);
  1049. // Ext_ModifyTessellatedVertex29(v, d);
  1050. // #if %EXTRAV2F0REQUIREKEY%
  1051. v2p.extraV2F0 = d.extraV2F0;
  1052. // #endif
  1053. // #if %EXTRAV2F1REQUIREKEY%
  1054. v2p.extraV2F1 = d.extraV2F1;
  1055. // #endif
  1056. // #if %EXTRAV2F2REQUIREKEY%
  1057. // v2p.extraV2F2 = d.extraV2F2;
  1058. // #endif
  1059. // #if %EXTRAV2F3REQUIREKEY%
  1060. // v2p.extraV2F3 = d.extraV2F3;
  1061. // #endif
  1062. // #if %EXTRAV2F4REQUIREKEY%
  1063. // v2p.extraV2F4 = d.extraV2F4;
  1064. // #endif
  1065. // #if %EXTRAV2F5REQUIREKEY%
  1066. // v2p.extraV2F5 = d.extraV2F5;
  1067. // #endif
  1068. // #if %EXTRAV2F6REQUIREKEY%
  1069. // v2p.extraV2F6 = d.extraV2F6;
  1070. // #endif
  1071. // #if %EXTRAV2F7REQUIREKEY%
  1072. // v2p.extraV2F7 = d.extraV2F7;
  1073. // #endif
  1074. }
  1075. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  1076. {
  1077. // Ext_FinalColorForward0(l, d, color);
  1078. // Ext_FinalColorForward1(l, d, color);
  1079. // Ext_FinalColorForward2(l, d, color);
  1080. // Ext_FinalColorForward3(l, d, color);
  1081. // Ext_FinalColorForward4(l, d, color);
  1082. // Ext_FinalColorForward5(l, d, color);
  1083. // Ext_FinalColorForward6(l, d, color);
  1084. // Ext_FinalColorForward7(l, d, color);
  1085. // Ext_FinalColorForward8(l, d, color);
  1086. // Ext_FinalColorForward9(l, d, color);
  1087. // Ext_FinalColorForward10(l, d, color);
  1088. // Ext_FinalColorForward11(l, d, color);
  1089. // Ext_FinalColorForward12(l, d, color);
  1090. // Ext_FinalColorForward13(l, d, color);
  1091. // Ext_FinalColorForward14(l, d, color);
  1092. // Ext_FinalColorForward15(l, d, color);
  1093. // Ext_FinalColorForward16(l, d, color);
  1094. // Ext_FinalColorForward17(l, d, color);
  1095. // Ext_FinalColorForward18(l, d, color);
  1096. // Ext_FinalColorForward19(l, d, color);
  1097. // Ext_FinalColorForward20(l, d, color);
  1098. // Ext_FinalColorForward21(l, d, color);
  1099. // Ext_FinalColorForward22(l, d, color);
  1100. // Ext_FinalColorForward23(l, d, color);
  1101. // Ext_FinalColorForward24(l, d, color);
  1102. // Ext_FinalColorForward25(l, d, color);
  1103. // Ext_FinalColorForward26(l, d, color);
  1104. // Ext_FinalColorForward27(l, d, color);
  1105. // Ext_FinalColorForward28(l, d, color);
  1106. // Ext_FinalColorForward29(l, d, color);
  1107. }
  1108. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  1109. {
  1110. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1111. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1112. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1113. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1114. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1115. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1116. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1117. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1118. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1119. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1120. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1121. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1122. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1123. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1124. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1125. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1126. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1127. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1128. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1129. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1130. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1131. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1132. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1133. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1134. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1135. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1136. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1137. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1138. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1139. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  1140. }
  1141. #endif
  1142. #if _DECALSHADER
  1143. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  1144. {
  1145. ShaderData d = (ShaderData)0;
  1146. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  1147. d.worldSpaceNormal = IN.WorldSpaceNormal;
  1148. d.worldSpaceTangent = IN.WorldSpaceTangent;
  1149. d.worldSpacePosition = IN.WorldSpacePosition;
  1150. d.texcoord0 = IN.uv0.xyxy;
  1151. d.screenPos = IN.ScreenPosition;
  1152. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  1153. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  1154. // these rarely get used, so we back transform them. Usually will be stripped.
  1155. #if _HDRP
  1156. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  1157. #else
  1158. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  1159. #endif
  1160. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  1161. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  1162. // #if %SCREENPOSREQUIREKEY%
  1163. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  1164. // #endif
  1165. return d;
  1166. }
  1167. #else
  1168. ShaderData CreateShaderData(VertexToPixel i
  1169. #if NEED_FACING
  1170. , bool facing
  1171. #endif
  1172. )
  1173. {
  1174. ShaderData d = (ShaderData)0;
  1175. d.clipPos = i.pos;
  1176. d.worldSpacePosition = i.worldPos;
  1177. d.worldSpaceNormal = normalize(i.worldNormal);
  1178. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  1179. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  1180. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  1181. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  1182. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  1183. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  1184. d.texcoord0 = i.texcoord0;
  1185. // d.texcoord1 = i.texcoord1;
  1186. // d.texcoord2 = i.texcoord2;
  1187. // #if %TEXCOORD3REQUIREKEY%
  1188. // d.texcoord3 = i.texcoord3;
  1189. // #endif
  1190. // d.isFrontFace = facing;
  1191. // #if %VERTEXCOLORREQUIREKEY%
  1192. d.vertexColor = i.vertexColor;
  1193. // #endif
  1194. // these rarely get used, so we back transform them. Usually will be stripped.
  1195. #if _HDRP
  1196. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  1197. #else
  1198. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  1199. #endif
  1200. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  1201. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  1202. // #if %SCREENPOSREQUIREKEY%
  1203. d.screenPos = i.screenPos;
  1204. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  1205. // #endif
  1206. // #if %EXTRAV2F0REQUIREKEY%
  1207. d.extraV2F0 = i.extraV2F0;
  1208. // #endif
  1209. // #if %EXTRAV2F1REQUIREKEY%
  1210. d.extraV2F1 = i.extraV2F1;
  1211. // #endif
  1212. // #if %EXTRAV2F2REQUIREKEY%
  1213. // d.extraV2F2 = i.extraV2F2;
  1214. // #endif
  1215. // #if %EXTRAV2F3REQUIREKEY%
  1216. // d.extraV2F3 = i.extraV2F3;
  1217. // #endif
  1218. // #if %EXTRAV2F4REQUIREKEY%
  1219. // d.extraV2F4 = i.extraV2F4;
  1220. // #endif
  1221. // #if %EXTRAV2F5REQUIREKEY%
  1222. // d.extraV2F5 = i.extraV2F5;
  1223. // #endif
  1224. // #if %EXTRAV2F6REQUIREKEY%
  1225. // d.extraV2F6 = i.extraV2F6;
  1226. // #endif
  1227. // #if %EXTRAV2F7REQUIREKEY%
  1228. // d.extraV2F7 = i.extraV2F7;
  1229. // #endif
  1230. return d;
  1231. }
  1232. #endif
  1233. #if defined(_PASSSHADOW)
  1234. float3 _LightDirection;
  1235. float3 _LightPosition;
  1236. #endif
  1237. // vertex shader
  1238. VertexToPixel Vert (VertexData v)
  1239. {
  1240. VertexToPixel o = (VertexToPixel)0;
  1241. UNITY_SETUP_INSTANCE_ID(v);
  1242. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1243. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  1244. #if !_TESSELLATION_ON
  1245. ChainModifyVertex(v, o, _Time);
  1246. #endif
  1247. o.texcoord0 = v.texcoord0;
  1248. // o.texcoord1 = v.texcoord1;
  1249. // o.texcoord2 = v.texcoord2;
  1250. // #if %TEXCOORD3REQUIREKEY%
  1251. // o.texcoord3 = v.texcoord3;
  1252. // #endif
  1253. // #if %VERTEXCOLORREQUIREKEY%
  1254. o.vertexColor = v.vertexColor;
  1255. // #endif
  1256. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  1257. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  1258. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  1259. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  1260. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  1261. #if _PASSSHADOW
  1262. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  1263. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  1264. #else
  1265. float3 lightDirectionWS = _LightDirection;
  1266. #endif
  1267. // Define shadow pass specific clip position for Universal
  1268. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  1269. #if UNITY_REVERSED_Z
  1270. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  1271. #else
  1272. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  1273. #endif
  1274. #elif _PASSMETA
  1275. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  1276. #else
  1277. o.pos = TransformWorldToHClip(o.worldPos);
  1278. #endif
  1279. // #if %SCREENPOSREQUIREKEY%
  1280. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  1281. // #endif
  1282. #if _PASSFORWARD || _PASSGBUFFER
  1283. float2 uv1 = v.texcoord1.xy;
  1284. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  1285. // o.texcoord1.xy = uv1;
  1286. OUTPUT_SH(o.worldNormal, o.sh);
  1287. #if defined(DYNAMICLIGHTMAP_ON)
  1288. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  1289. #endif
  1290. #endif
  1291. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  1292. half fogFactor = 0;
  1293. #if defined(_FOG_FRAGMENT)
  1294. fogFactor = ComputeFogFactor(o.pos.z);
  1295. #endif
  1296. #if _BAKEDLIT
  1297. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  1298. #else
  1299. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  1300. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  1301. #endif
  1302. #endif
  1303. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1304. o.shadowCoord = GetShadowCoord(vertexInput);
  1305. #endif
  1306. return o;
  1307. }
  1308. #if _UNLIT
  1309. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Unlit.hlsl"
  1310. #endif
  1311. // fragment shader
  1312. half4 Frag (VertexToPixel IN
  1313. #ifdef _DEPTHOFFSET_ON
  1314. , out float outputDepth : SV_Depth
  1315. #endif
  1316. #if NEED_FACING
  1317. , bool facing : SV_IsFrontFace
  1318. #endif
  1319. ) : SV_Target
  1320. {
  1321. UNITY_SETUP_INSTANCE_ID(IN);
  1322. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  1323. ShaderData d = CreateShaderData(IN
  1324. #if NEED_FACING
  1325. , facing
  1326. #endif
  1327. );
  1328. Surface l = (Surface)0;
  1329. #ifdef _DEPTHOFFSET_ON
  1330. l.outputDepth = outputDepth;
  1331. #endif
  1332. l.Albedo = half3(0.5, 0.5, 0.5);
  1333. l.Normal = float3(0,0,1);
  1334. l.Occlusion = 1;
  1335. l.Alpha = 1;
  1336. ChainSurfaceFunction(l, d);
  1337. #ifdef _DEPTHOFFSET_ON
  1338. outputDepth = l.outputDepth;
  1339. #endif
  1340. #if _USESPECULAR || _SIMPLELIT
  1341. float3 specular = l.Specular;
  1342. float metallic = 1;
  1343. #else
  1344. float3 specular = 0;
  1345. float metallic = l.Metallic;
  1346. #endif
  1347. InputData inputData = (InputData)0;
  1348. inputData.positionWS = IN.worldPos;
  1349. #if _WORLDSPACENORMAL
  1350. inputData.normalWS = l.Normal;
  1351. #else
  1352. inputData.normalWS = normalize(TangentToWorldSpace(d, l.Normal));
  1353. #endif
  1354. inputData.viewDirectionWS = SafeNormalize(d.worldSpaceViewDir);
  1355. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1356. inputData.shadowCoord = IN.shadowCoord;
  1357. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1358. inputData.shadowCoord = TransformWorldToShadowCoord(IN.worldPos);
  1359. #else
  1360. inputData.shadowCoord = float4(0, 0, 0, 0);
  1361. #endif
  1362. #if _BAKEDLIT
  1363. inputData.fogCoord = IN.fogFactorAndVertexLight.x;
  1364. inputData.vertexLighting = 0;
  1365. #else
  1366. inputData.fogCoord = InitializeInputDataFog(float4(IN.worldPos, 1.0), IN.fogFactorAndVertexLight.x);
  1367. inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  1368. #endif
  1369. #if defined(_OVERRIDE_BAKEDGI)
  1370. inputData.bakedGI = l.DiffuseGI;
  1371. l.Emission += l.SpecularGI;
  1372. #elif _BAKEDLIT
  1373. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
  1374. #else
  1375. #if defined(DYNAMICLIGHTMAP_ON)
  1376. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.dynamicLightmapUV.xy, IN.sh, inputData.normalWS);
  1377. #else
  1378. inputData.bakedGI = SAMPLE_GI(IN.lightmapUV, IN.sh, inputData.normalWS);
  1379. #endif
  1380. #endif
  1381. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.pos);
  1382. #if !_BAKEDLIT
  1383. inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUV);
  1384. #if defined(_OVERRIDE_SHADOWMASK)
  1385. float4 mulColor = saturate(dot(l.ShadowMask, _MainLightOcclusionProbes)); //unity_OcclusionMaskSelector));
  1386. inputData.shadowMask = mulColor;
  1387. #endif
  1388. #else
  1389. inputData.shadowMask = float4(1,1,1,1);
  1390. #endif
  1391. #if defined(DEBUG_DISPLAY)
  1392. #if defined(DYNAMICLIGHTMAP_ON)
  1393. inputData.dynamicLightmapUV = IN.dynamicLightmapUV.xy;
  1394. #endif
  1395. #if defined(LIGHTMAP_ON)
  1396. inputData.staticLightmapUV = IN.lightmapUV;
  1397. #else
  1398. inputData.vertexSH = IN.sh;
  1399. #endif
  1400. #endif
  1401. #if _WORLDSPACENORMAL
  1402. float3 normalTS = WorldToTangentSpace(d, l.Normal);
  1403. #else
  1404. float3 normalTS = l.Normal;
  1405. #endif
  1406. SurfaceData surface = (SurfaceData)0;
  1407. surface.albedo = l.Albedo;
  1408. surface.metallic = saturate(metallic);
  1409. surface.specular = specular;
  1410. surface.smoothness = saturate(l.Smoothness),
  1411. surface.occlusion = l.Occlusion,
  1412. surface.emission = l.Emission,
  1413. surface.alpha = saturate(l.Alpha);
  1414. surface.clearCoatMask = 0;
  1415. surface.clearCoatSmoothness = 1;
  1416. #ifdef _CLEARCOAT
  1417. surface.clearCoatMask = saturate(l.CoatMask);
  1418. surface.clearCoatSmoothness = saturate(l.CoatSmoothness);
  1419. #endif
  1420. #if !_UNLIT
  1421. half4 color = half4(l.Albedo, l.Alpha);
  1422. #ifdef _DBUFFER
  1423. #if _BAKEDLIT
  1424. half3 bakeColor = color.rgb;
  1425. float3 bakeNormal = inputData.normalWS.xyz;
  1426. ApplyDecalToBaseColorAndNormal(IN.pos, bakeColor, bakeNormal);
  1427. color.rgb = bakeColor;
  1428. inputData.normalWS.xyz = bakeNormal;
  1429. #else
  1430. ApplyDecalToSurfaceData(IN.pos, surface, inputData);
  1431. #endif
  1432. #endif
  1433. #if _SIMPLELIT
  1434. color = UniversalFragmentBlinnPhong(
  1435. inputData,
  1436. surface);
  1437. #elif _BAKEDLIT
  1438. color = UniversalFragmentBakedLit(inputData, color.rgb, color.a, normalTS);
  1439. #else
  1440. color = UniversalFragmentPBR(inputData, surface);
  1441. #endif
  1442. #if !DISABLEFOG
  1443. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  1444. #endif
  1445. #else // unlit
  1446. #ifdef _DBUFFER
  1447. ApplyDecalToSurfaceData(IN.pos, surface, inputData);
  1448. #endif
  1449. half4 color = UniversalFragmentUnlit(inputData, l.Albedo, l.Alpha);
  1450. #if !DISABLEFOG
  1451. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  1452. #endif
  1453. #endif
  1454. ChainFinalColorForward(l, d, color);
  1455. return color;
  1456. }
  1457. ENDHLSL
  1458. }
  1459. Pass
  1460. {
  1461. Name "Meta"
  1462. Tags
  1463. {
  1464. "LightMode" = "Meta"
  1465. }
  1466. Cull Off
  1467. ZWrite On
  1468. HLSLPROGRAM
  1469. #pragma vertex Vert
  1470. #pragma fragment Frag
  1471. #pragma target 3.0
  1472. #pragma prefer_hlslcc gles
  1473. #pragma exclude_renderers d3d11_9x
  1474. #define SHADERPASS SHADERPASS_META
  1475. #define _PASSMETA 1
  1476. #include "Flow.cginc"
  1477. #pragma shader_feature_local _ _STOCHASTIC_ON
  1478. #pragma shader_feature_local _FOAM_OFF _FOAM_ALPHA _FOAM_CUTOUT
  1479. #pragma shader_feature_local _ _FACETED_ON
  1480. #pragma shader_feature_local _ALPHA_OFF _ALPHA_VERTICAL _ALPHA_DEPTH _ALPHA_MARCH_FLUID _ALPHA_MARCH_FLUID_AND_DEPTH
  1481. #pragma shader_feature_local DISABLEFOG
  1482. #define _URP 1
  1483. #define _ALPHABLEND_ON 1
  1484. #define _ALPHABLEND_ON 1
  1485. #define _SURFACE_TYPE_TRANSPARENT 1
  1486. #define _GRABPASSUSED 1
  1487. #define REQUIRE_OPAQUE_TEXTURE
  1488. #define REQUIRE_DEPTH_TEXTURE
  1489. // Includes
  1490. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  1491. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1492. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1493. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1494. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1495. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
  1496. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  1497. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  1498. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  1499. #undef WorldNormalVector
  1500. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  1501. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  1502. #define _WorldSpaceLightPos0 _MainLightPosition
  1503. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  1504. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  1505. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  1506. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  1507. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  1508. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  1509. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  1510. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  1511. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  1512. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  1513. #if defined(UNITY_COMPILER_HLSL)
  1514. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  1515. #else
  1516. #define UNITY_INITIALIZE_OUTPUT(type,name)
  1517. #endif
  1518. #define sampler2D_float sampler2D
  1519. #define sampler2D_half sampler2D
  1520. // data across stages, stripped like the above.
  1521. struct VertexToPixel
  1522. {
  1523. float4 pos : SV_POSITION;
  1524. float3 worldPos : TEXCOORD0;
  1525. float3 worldNormal : TEXCOORD1;
  1526. float4 worldTangent : TEXCOORD2;
  1527. float4 texcoord0 : TEXCOORD3;
  1528. // float4 texcoord1 : TEXCOORD4;
  1529. // float4 texcoord2 : TEXCOORD5;
  1530. // #if %TEXCOORD3REQUIREKEY%
  1531. // float4 texcoord3 : TEXCOORD6;
  1532. // #endif
  1533. // #if %SCREENPOSREQUIREKEY%
  1534. float4 screenPos : TEXCOORD7;
  1535. // #endif
  1536. // #if %VERTEXCOLORREQUIREKEY%
  1537. half4 vertexColor : COLOR;
  1538. // #endif
  1539. #if defined(LIGHTMAP_ON)
  1540. float2 lightmapUV : TEXCOORD8;
  1541. #endif
  1542. #if defined(DYNAMICLIGHTMAP_ON)
  1543. float2 dynamicLightmapUV : TEXCOORD9;
  1544. #endif
  1545. #if !defined(LIGHTMAP_ON)
  1546. float3 sh : TEXCOORD10;
  1547. #endif
  1548. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  1549. float4 fogFactorAndVertexLight : TEXCOORD11;
  1550. #endif
  1551. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1552. float4 shadowCoord : TEXCOORD12;
  1553. #endif
  1554. // #if %EXTRAV2F0REQUIREKEY%
  1555. float4 extraV2F0 : TEXCOORD13;
  1556. // #endif
  1557. // #if %EXTRAV2F1REQUIREKEY%
  1558. float4 extraV2F1 : TEXCOORD14;
  1559. // #endif
  1560. // #if %EXTRAV2F2REQUIREKEY%
  1561. // float4 extraV2F2 : TEXCOORD15;
  1562. // #endif
  1563. // #if %EXTRAV2F3REQUIREKEY%
  1564. // float4 extraV2F3 : TEXCOORD16;
  1565. // #endif
  1566. // #if %EXTRAV2F4REQUIREKEY%
  1567. // float4 extraV2F4 : TEXCOORD17;
  1568. // #endif
  1569. // #if %EXTRAV2F5REQUIREKEY%
  1570. // float4 extraV2F5 : TEXCOORD18;
  1571. // #endif
  1572. // #if %EXTRAV2F6REQUIREKEY%
  1573. // float4 extraV2F6 : TEXCOORD19;
  1574. // #endif
  1575. // #if %EXTRAV2F7REQUIREKEY%
  1576. // float4 extraV2F7 : TEXCOORD20;
  1577. // #endif
  1578. #if UNITY_ANY_INSTANCING_ENABLED
  1579. uint instanceID : CUSTOM_INSTANCE_ID;
  1580. #endif
  1581. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  1582. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  1583. #endif
  1584. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  1585. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  1586. #endif
  1587. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  1588. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  1589. #endif
  1590. };
  1591. // data describing the user output of a pixel
  1592. struct Surface
  1593. {
  1594. half3 Albedo;
  1595. half Height;
  1596. half3 Normal;
  1597. half Smoothness;
  1598. half3 Emission;
  1599. half Metallic;
  1600. half3 Specular;
  1601. half Occlusion;
  1602. half SpecularPower; // for simple lighting
  1603. half Alpha;
  1604. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  1605. // HDRP Only
  1606. half SpecularOcclusion;
  1607. half SubsurfaceMask;
  1608. half Thickness;
  1609. half CoatMask;
  1610. half CoatSmoothness;
  1611. half Anisotropy;
  1612. half IridescenceMask;
  1613. half IridescenceThickness;
  1614. int DiffusionProfileHash;
  1615. float SpecularAAThreshold;
  1616. float SpecularAAScreenSpaceVariance;
  1617. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  1618. float3 DiffuseGI;
  1619. float3 BackDiffuseGI;
  1620. float3 SpecularGI;
  1621. float ior;
  1622. float3 transmittanceColor;
  1623. float atDistance;
  1624. float transmittanceMask;
  1625. // requires _OVERRIDE_SHADOWMASK to be defines
  1626. float4 ShadowMask;
  1627. // for decals
  1628. float NormalAlpha;
  1629. float MAOSAlpha;
  1630. };
  1631. // Data the user declares in blackboard blocks
  1632. struct Blackboard
  1633. {
  1634. float groundHeight;
  1635. float surfaceHeight;
  1636. float3 surfaceNormal;
  1637. Fluid fluid;
  1638. float foam;
  1639. float blackboardDummyData;
  1640. };
  1641. // data the user might need, this will grow to be big. But easy to strip
  1642. struct ShaderData
  1643. {
  1644. float4 clipPos; // SV_POSITION
  1645. float3 localSpacePosition;
  1646. float3 localSpaceNormal;
  1647. float3 localSpaceTangent;
  1648. float3 worldSpacePosition;
  1649. float3 worldSpaceNormal;
  1650. float3 worldSpaceTangent;
  1651. float tangentSign;
  1652. float3 worldSpaceViewDir;
  1653. float3 tangentSpaceViewDir;
  1654. float4 texcoord0;
  1655. float4 texcoord1;
  1656. float4 texcoord2;
  1657. float4 texcoord3;
  1658. float2 screenUV;
  1659. float4 screenPos;
  1660. float4 vertexColor;
  1661. bool isFrontFace;
  1662. float4 extraV2F0;
  1663. float4 extraV2F1;
  1664. float4 extraV2F2;
  1665. float4 extraV2F3;
  1666. float4 extraV2F4;
  1667. float4 extraV2F5;
  1668. float4 extraV2F6;
  1669. float4 extraV2F7;
  1670. float3x3 TBNMatrix;
  1671. Blackboard blackboard;
  1672. };
  1673. struct VertexData
  1674. {
  1675. #if SHADER_TARGET > 30
  1676. // uint vertexID : SV_VertexID;
  1677. #endif
  1678. float4 vertex : POSITION;
  1679. float3 normal : NORMAL;
  1680. float4 tangent : TANGENT;
  1681. float4 texcoord0 : TEXCOORD0;
  1682. // optimize out mesh coords when not in use by user or lighting system
  1683. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  1684. float4 texcoord1 : TEXCOORD1;
  1685. #endif
  1686. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  1687. float4 texcoord2 : TEXCOORD2;
  1688. #endif
  1689. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  1690. float4 texcoord1 : TEXCOORD1;
  1691. #endif
  1692. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  1693. float4 texcoord2 : TEXCOORD2;
  1694. #endif
  1695. #if _HDRP
  1696. float4 texcoord1 : TEXCOORD1;
  1697. float4 texcoord2 : TEXCOORD2;
  1698. #endif
  1699. // #if %TEXCOORD3REQUIREKEY%
  1700. // float4 texcoord3 : TEXCOORD3;
  1701. // #endif
  1702. // #if %VERTEXCOLORREQUIREKEY%
  1703. float4 vertexColor : COLOR;
  1704. // #endif
  1705. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  1706. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  1707. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  1708. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  1709. #endif
  1710. #endif
  1711. UNITY_VERTEX_INPUT_INSTANCE_ID
  1712. };
  1713. struct TessVertex
  1714. {
  1715. float4 vertex : INTERNALTESSPOS;
  1716. float3 normal : NORMAL;
  1717. float4 tangent : TANGENT;
  1718. float4 texcoord0 : TEXCOORD0;
  1719. float4 texcoord1 : TEXCOORD1;
  1720. float4 texcoord2 : TEXCOORD2;
  1721. // #if %TEXCOORD3REQUIREKEY%
  1722. // float4 texcoord3 : TEXCOORD3;
  1723. // #endif
  1724. // #if %VERTEXCOLORREQUIREKEY%
  1725. float4 vertexColor : COLOR;
  1726. // #endif
  1727. // #if %EXTRAV2F0REQUIREKEY%
  1728. float4 extraV2F0 : TEXCOORD5;
  1729. // #endif
  1730. // #if %EXTRAV2F1REQUIREKEY%
  1731. float4 extraV2F1 : TEXCOORD6;
  1732. // #endif
  1733. // #if %EXTRAV2F2REQUIREKEY%
  1734. // float4 extraV2F2 : TEXCOORD7;
  1735. // #endif
  1736. // #if %EXTRAV2F3REQUIREKEY%
  1737. // float4 extraV2F3 : TEXCOORD8;
  1738. // #endif
  1739. // #if %EXTRAV2F4REQUIREKEY%
  1740. // float4 extraV2F4 : TEXCOORD9;
  1741. // #endif
  1742. // #if %EXTRAV2F5REQUIREKEY%
  1743. // float4 extraV2F5 : TEXCOORD10;
  1744. // #endif
  1745. // #if %EXTRAV2F6REQUIREKEY%
  1746. // float4 extraV2F6 : TEXCOORD11;
  1747. // #endif
  1748. // #if %EXTRAV2F7REQUIREKEY%
  1749. // float4 extraV2F7 : TEXCOORD12;
  1750. // #endif
  1751. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  1752. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  1753. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  1754. float3 precomputedVelocity : TEXCOORD14;
  1755. #endif
  1756. #endif
  1757. UNITY_VERTEX_INPUT_INSTANCE_ID
  1758. UNITY_VERTEX_OUTPUT_STEREO
  1759. };
  1760. struct ExtraV2F
  1761. {
  1762. float4 extraV2F0;
  1763. float4 extraV2F1;
  1764. float4 extraV2F2;
  1765. float4 extraV2F3;
  1766. float4 extraV2F4;
  1767. float4 extraV2F5;
  1768. float4 extraV2F6;
  1769. float4 extraV2F7;
  1770. Blackboard blackboard;
  1771. float4 time;
  1772. };
  1773. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  1774. {
  1775. return mul(d.TBNMatrix, normal);
  1776. }
  1777. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  1778. {
  1779. return mul(normal, d.TBNMatrix);
  1780. }
  1781. // in this case, make standard more like SRPs, because we can't fix
  1782. // unity_WorldToObject in HDRP, since it already does macro-fu there
  1783. #if _STANDARD
  1784. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  1785. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  1786. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  1787. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  1788. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  1789. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  1790. #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))
  1791. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  1792. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  1793. #else
  1794. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  1795. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  1796. #endif
  1797. #undef GetWorldToObjectMatrix()
  1798. #define GetWorldToObjectMatrix() unity_WorldToObject
  1799. #endif
  1800. float3 GetCameraWorldPosition()
  1801. {
  1802. #if _HDRP
  1803. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  1804. #else
  1805. return _WorldSpaceCameraPos;
  1806. #endif
  1807. }
  1808. #if _GRABPASSUSED
  1809. #if _STANDARD
  1810. TEXTURE2D(_Grab);
  1811. SAMPLER(sampler__Grab);
  1812. #endif
  1813. half3 GetSceneColor(float2 uv)
  1814. {
  1815. #if _STANDARD
  1816. return SAMPLE_TEXTURE2D(_Grab, sampler__Grab, uv).rgb;
  1817. #else
  1818. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  1819. #endif
  1820. }
  1821. #endif
  1822. #if _STANDARD
  1823. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  1824. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  1825. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  1826. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  1827. #else
  1828. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  1829. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  1830. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  1831. #endif
  1832. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  1833. {
  1834. float eye = GetLinearEyeDepth(uv);
  1835. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  1836. float dt = dot(worldSpaceViewDir, camView);
  1837. float3 div = worldSpaceViewDir/dt;
  1838. float3 wpos = (eye * div) + GetCameraWorldPosition();
  1839. return wpos;
  1840. }
  1841. #if _HDRP
  1842. float3 ObjectToWorldSpacePosition(float3 pos)
  1843. {
  1844. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  1845. }
  1846. #else
  1847. float3 ObjectToWorldSpacePosition(float3 pos)
  1848. {
  1849. return TransformObjectToWorld(pos);
  1850. }
  1851. #endif
  1852. #if _STANDARD
  1853. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  1854. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1855. {
  1856. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  1857. float3 norms = DecodeViewNormalStereo(depthNorms);
  1858. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  1859. return norms;
  1860. }
  1861. #elif _HDRP && !_DECALSHADER
  1862. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1863. {
  1864. NormalData nd;
  1865. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  1866. return nd.normalWS;
  1867. }
  1868. #elif _URP
  1869. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  1870. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  1871. #endif
  1872. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  1873. {
  1874. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  1875. return SampleSceneNormals(uv);
  1876. #else
  1877. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  1878. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  1879. #endif
  1880. }
  1881. #endif
  1882. #if _HDRP
  1883. half3 UnpackNormalmapRGorAG(half4 packednormal)
  1884. {
  1885. // This do the trick
  1886. packednormal.x *= packednormal.w;
  1887. half3 normal;
  1888. normal.xy = packednormal.xy * 2 - 1;
  1889. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  1890. return normal;
  1891. }
  1892. half3 UnpackNormal(half4 packednormal)
  1893. {
  1894. #if defined(UNITY_NO_DXT5nm)
  1895. return packednormal.xyz * 2 - 1;
  1896. #else
  1897. return UnpackNormalmapRGorAG(packednormal);
  1898. #endif
  1899. }
  1900. #endif
  1901. #if _HDRP || _URP
  1902. half3 UnpackScaleNormal(half4 packednormal, half scale)
  1903. {
  1904. #ifndef UNITY_NO_DXT5nm
  1905. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  1906. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  1907. packednormal.x *= packednormal.w;
  1908. #endif
  1909. half3 normal;
  1910. normal.xy = (packednormal.xy * 2 - 1) * scale;
  1911. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  1912. return normal;
  1913. }
  1914. #endif
  1915. void GetSun(out float3 lightDir, out float3 color)
  1916. {
  1917. lightDir = float3(0.5, 0.5, 0);
  1918. color = 1;
  1919. #if _HDRP
  1920. if (_DirectionalLightCount > 0)
  1921. {
  1922. DirectionalLightData light = _DirectionalLightDatas[0];
  1923. lightDir = -light.forward.xyz;
  1924. color = light.color;
  1925. }
  1926. #elif _STANDARD
  1927. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  1928. color = _LightColor0.rgb;
  1929. #elif _URP
  1930. Light light = GetMainLight();
  1931. lightDir = light.direction;
  1932. color = light.color;
  1933. #endif
  1934. }
  1935. CBUFFER_START(UnityPerMaterial)
  1936. float _FlowDensity;
  1937. float2 _FlowSeparationXZ;
  1938. float _FlowSimulationHeight;
  1939. float _FlowCameraHeight;
  1940. float2 _FlowCountXZ;
  1941. float4 _FlowCoordU000;
  1942. float4 _FlowCoord0V00;
  1943. float _FlowSpeed;
  1944. float4x4 _FlowMatrix;
  1945. float _Sink;
  1946. float _Emission;
  1947. float _WaveStrengthMin;
  1948. float _WaveStrengthMax;
  1949. float _WaveStrengthScale;
  1950. float _Tiling;
  1951. float _AnimationSpeed;
  1952. float _FoamBrightness;
  1953. half _FlatShadingBlend;
  1954. float _RangeMax;
  1955. float _AlphaStep;
  1956. int _AlphaMaxSteps;
  1957. float _AlphaDepthScale;
  1958. CBUFFER_END
  1959. #ifdef unity_WorldToObject
  1960. #undef unity_WorldToObject
  1961. #endif
  1962. #ifdef unity_ObjectToWorld
  1963. #undef unity_ObjectToWorld
  1964. #endif
  1965. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  1966. #define unity_WorldToObject GetWorldToObjectMatrix()
  1967. TEXTURE2D(_FlowDataA);
  1968. SAMPLER(sampler_FlowDataA);
  1969. TEXTURE2D(_FlowDataB);
  1970. SAMPLER(sampler_FlowDataB);
  1971. TEXTURE2D(_FlowDataC);
  1972. SAMPLER(sampler_FlowDataC);
  1973. TEXTURE2D(_FlowDataD);
  1974. SAMPLER(sampler_FlowDataD);
  1975. TEXTURE2D(_FlowDataE);
  1976. SAMPLER(sampler_FlowDataE);
  1977. TEXTURE2D(_FlowDataF);
  1978. SAMPLER(sampler_FlowDataF);
  1979. float4 SGT_O2W(float4 v)
  1980. {
  1981. v = mul(GetObjectToWorldMatrix(), v);
  1982. #if _HDRP
  1983. v.xyz = GetAbsolutePositionWS(v.xyz);
  1984. #endif
  1985. return v;
  1986. }
  1987. float4 SGT_W2O(float4 v)
  1988. {
  1989. #if _HDRP
  1990. v.xyz = GetCameraRelativePositionWS(v.xyz);
  1991. #endif
  1992. return mul(GetWorldToObjectMatrix(), v);
  1993. }
  1994. float4 SGT_O2V(float4 v)
  1995. {
  1996. #if _STANDARD
  1997. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  1998. #else
  1999. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  2000. #endif
  2001. }
  2002. float GetFluidHeight(float2 uv)
  2003. {
  2004. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  2005. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  2006. return groundHeight + fluidDepth;
  2007. }
  2008. float2 GetHeightAndDepth(float2 uv)
  2009. {
  2010. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  2011. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  2012. return float2(groundHeight, fluidDepth);
  2013. }
  2014. Column GetColumn(float2 uv)
  2015. {
  2016. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  2017. }
  2018. Fluid GetColumnFluid(float2 uv)
  2019. {
  2020. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  2021. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  2022. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  2023. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  2024. return DecodeFluid(c, d, e, f);
  2025. }
  2026. bool InsideFluid(float3 wpos)
  2027. {
  2028. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  2029. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  2030. float2 columnHAD = GetHeightAndDepth(columnCoord);
  2031. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  2032. }
  2033. bool UnderFluid(float3 wpos)
  2034. {
  2035. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  2036. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  2037. float2 columnHAD = GetHeightAndDepth(columnCoord);
  2038. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  2039. }
  2040. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  2041. {
  2042. float epsi = step * 0.01f;
  2043. float dist = 0.0f;
  2044. for (int i = 0; i < maxs && step > epsi; i++)
  2045. {
  2046. dist += step;
  2047. float3 pos = wpos + wdir * dist;
  2048. if (InsideFluid(pos) == false)
  2049. {
  2050. dist -= step;
  2051. step *= 0.5f;
  2052. }
  2053. if (dist > maxd)
  2054. {
  2055. return maxd;
  2056. }
  2057. }
  2058. return dist;
  2059. }
  2060. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  2061. {
  2062. float epsi = step * 0.01f;
  2063. float dist = 0.0f;
  2064. for (int i = 0; i < maxs && step > epsi; i++)
  2065. {
  2066. dist += step;
  2067. float3 pos = wpos + wdir * dist;
  2068. if (UnderFluid(pos) == false)
  2069. {
  2070. dist -= step;
  2071. step *= 0.5f;
  2072. }
  2073. if (dist > maxd)
  2074. {
  2075. return maxd;
  2076. }
  2077. }
  2078. return dist;
  2079. }
  2080. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  2081. {
  2082. float4 wpos = SGT_O2W(v.vertex);
  2083. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  2084. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  2085. Column column0 = GetColumn(columnCoord);
  2086. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  2087. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  2088. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  2089. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  2090. Fluid fluid0 = GetColumnFluid(columnCoord);
  2091. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  2092. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  2093. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  2094. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  2095. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  2096. float wL = fluidL.Depth / ww;
  2097. float wR = fluidR.Depth / ww;
  2098. float wB = fluidB.Depth / ww;
  2099. float wT = fluidT.Depth / ww;
  2100. float w0 = saturate(fluid0.Depth * 10);
  2101. float hL = columnL.GroundHeight + fluidL.Depth;
  2102. float hR = columnR.GroundHeight + fluidR.Depth;
  2103. float hB = columnB.GroundHeight + fluidB.Depth;
  2104. float hT = columnT.GroundHeight + fluidT.Depth;
  2105. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  2106. float h0 = column0.GroundHeight + fluid0.Depth;
  2107. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  2108. Fluid fluid = fluid0;
  2109. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  2110. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  2111. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  2112. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  2113. e.blackboard.groundHeight = column0.GroundHeight;
  2114. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  2115. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  2116. e.blackboard.fluid = fluid;
  2117. }
  2118. TEXTURE2D(_NoiseMap);
  2119. SAMPLER(sampler_NoiseMap);
  2120. TEXTURE2D(_NormalFoamMap);
  2121. SAMPLER(sampler_NormalFoamMap);
  2122. void Ext_ModifyVertex3 (inout VertexData v, inout ExtraV2F e)
  2123. {
  2124. v.vertex.y = lerp(e.blackboard.groundHeight, e.blackboard.surfaceHeight, v.texcoord0.w) - _FlowSimulationHeight;
  2125. v.normal = lerp(e.blackboard.surfaceNormal, v.normal, v.texcoord0.z);
  2126. v.vertexColor = e.blackboard.fluid.RGBA;
  2127. e.extraV2F0.xyz = SGT_O2V(v.vertex).xyz;
  2128. e.extraV2F0.w = e.blackboard.fluid.Depth;
  2129. e.extraV2F1.xyz = e.blackboard.fluid.ESMV.xyz;
  2130. e.extraV2F1.w = e.blackboard.fluid.F123.x;
  2131. }
  2132. float3 FlowUVW(float2 uv, float2 flowVector, float2 jump, float tiling, float time, float phaseOffset)
  2133. {
  2134. float progress = frac(time + phaseOffset);
  2135. float3 uvw;
  2136. uvw.xy = uv - flowVector * (progress - 0.5f);
  2137. uvw.xy *= tiling;
  2138. uvw.xy += phaseOffset;
  2139. uvw.xy += (time - progress) * jump;
  2140. uvw.z = 1 - abs(1 - 2 * progress);
  2141. return uvw;
  2142. }
  2143. float3 CombineNormals(float3 n1, float3 n2)
  2144. {
  2145. return normalize(half3(n1.xy + n2.xy, n1.z*n2.z));
  2146. }
  2147. float3 UnpackNormalAndScale(float2 xy, float scale)
  2148. {
  2149. xy = xy * 2.0f - 1.0f; xy *= scale; return float3(xy, sqrt(1.0 - saturate(dot(xy, xy))));
  2150. }
  2151. float4 SampleStochastic(float2 uv, float noise)
  2152. {
  2153. float cur_height = uv.y + noise;
  2154. float this_index = floor(cur_height);
  2155. float next_index = this_index + 1.0f;
  2156. float2 uvA = uv + sin(float2(1.0f, 2.0f) * this_index);
  2157. float2 uvB = uv + sin(float2(1.0f, 2.0f) * next_index);
  2158. float2 gradX = ddx(uv);
  2159. float2 gradY = ddy(uv);
  2160. float4 sampleA = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvA, gradX, gradY);
  2161. float4 sampleB = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvB, gradX, gradY);
  2162. return lerp(sampleA, sampleB, cur_height - this_index);
  2163. }
  2164. void Ext_SurfaceFunction3 (inout Surface o, inout ShaderData d)
  2165. {
  2166. d.blackboard.fluid.RGBA = d.vertexColor;
  2167. d.blackboard.fluid.Depth = d.extraV2F0.w;
  2168. d.blackboard.fluid.ESMV.xyz = d.extraV2F1.xyz;
  2169. d.blackboard.fluid.F123.x = d.extraV2F1.w;
  2170. if (d.blackboard.fluid.Depth < 0.01f)
  2171. {
  2172. discard;
  2173. }
  2174. float2 uv = d.worldSpacePosition.xz;
  2175. float2 columnPixel = mul(_FlowMatrix, float4(d.worldSpacePosition, 1.0f)).xy;
  2176. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  2177. Column column = GetColumn(columnCoord);
  2178. float time = _Time.y * _AnimationSpeed;
  2179. float2 jump = float2(0.13f, 0.17f);
  2180. float2 fvec = (column.Outflow.yw - column.Outflow.xz) * _FlowSeparationXZ * _FlowSpeed;
  2181. float fmag = log10(1.0f + length(fvec)) * 0.1f;
  2182. float3 flowA = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.0f);
  2183. float3 flowB = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.5f);
  2184. #if _STOCHASTIC_ON
  2185. float noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, uv * 0.0025f).a * 4.0f;
  2186. float4 nfmA = SampleStochastic(flowA, noise);
  2187. float4 nfmB = SampleStochastic(flowB, noise);
  2188. #else
  2189. float4 nfmA = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowA.xy);
  2190. float4 nfmB = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowB.xy);
  2191. #endif
  2192. // Water normals
  2193. float normalStr = lerp(_WaveStrengthMin, _WaveStrengthMax, saturate(_WaveStrengthScale * fmag));
  2194. float3 waterNormalA = UnpackNormalAndScale(nfmA.xy, flowA.z * normalStr);
  2195. float3 waterNormalB = UnpackNormalAndScale(nfmB.xy, flowB.z * normalStr);
  2196. float3 waterNormals = CombineNormals(waterNormalA, waterNormalB);
  2197. o.Normal = lerp(waterNormals, o.Normal, d.texcoord0.z);
  2198. o.Albedo = d.blackboard.fluid.RGBA.xyz;
  2199. o.Emission = d.blackboard.fluid.ESMV.x * _Emission * o.Albedo;
  2200. #if _FOAM_OFF
  2201. d.blackboard.foam = 0.0f;
  2202. #else
  2203. d.blackboard.foam = d.blackboard.fluid.F123.x * (1.0f - d.texcoord0.z);
  2204. #if _FOAM_ALPHA
  2205. float3 foamAlbedo = (nfmA.w * flowA.z + nfmB.w * flowB.z) * _FoamBrightness;
  2206. #elif _FOAM_CUTOUT
  2207. float3 foamAlbedo = _FoamBrightness;
  2208. float foamRamp = nfmA.w * flowA.z + nfmB.w * flowB.z;
  2209. d.blackboard.foam = saturate((d.blackboard.foam - foamRamp) * 10.0f);
  2210. #endif
  2211. float3 foamNormal = float3(0.0f, 0.0f, 1.0f);
  2212. o.Albedo = lerp(o.Albedo, foamAlbedo, d.blackboard.foam);
  2213. o.Normal = lerp(o.Normal, foamNormal, d.blackboard.foam);
  2214. #endif
  2215. o.Smoothness = d.blackboard.fluid.ESMV.y;
  2216. o.Metallic = d.blackboard.fluid.ESMV.z;
  2217. }
  2218. void Ext_SurfaceFunction4 (inout Surface o, inout ShaderData d)
  2219. {
  2220. #if _FACETED_ON
  2221. // lets just affect the TBN data, so we flat shade the original polygons, not the normal map
  2222. float3 dx = ddx(d.worldSpacePosition);
  2223. float3 dy = ddy(d.worldSpacePosition);
  2224. float3 worldNormal = normalize(cross(dy, dx));
  2225. worldNormal = lerp(d.worldSpaceNormal, worldNormal, _FlatShadingBlend);
  2226. d.worldSpaceNormal = worldNormal;
  2227. d.TBNMatrix[2] = worldNormal;
  2228. #endif
  2229. }
  2230. void Ext_SurfaceFunction5 (inout Surface o, ShaderData d)
  2231. {
  2232. #if _ALPHA_OFF
  2233. #else
  2234. float3 position = d.worldSpacePosition;
  2235. float3 step = d.worldSpacePosition - _WorldSpaceCameraPos;
  2236. float2 bentScrUV = d.screenUV + o.Normal.xy * 0.05f * log(1.0f + d.blackboard.fluid.Depth * 1.0f);
  2237. float distMax = max(_RangeMax * 0.001f, _RangeMax * (1.0f - d.blackboard.fluid.RGBA.w));
  2238. float distRange = distMax;
  2239. float vertDist = length(d.extraV2F0.xyz);
  2240. float camtDist = GetLinearEyeDepth(bentScrUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  2241. if (camtDist < vertDist)
  2242. {
  2243. camtDist = GetLinearEyeDepth(d.screenUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  2244. }
  2245. float diffDist = max(0.0f, camtDist - vertDist);
  2246. // The depth buffer becomes unusable at certain ranges, so fade it out
  2247. diffDist += max(0.0f, camtDist * _AlphaDepthScale - _RangeMax);
  2248. distRange = min(distRange, diffDist);
  2249. #if _ALPHA_VERTICAL
  2250. float dist = d.blackboard.fluid.Depth;
  2251. #elif _ALPHA_DEPTH
  2252. float dist = diffDist;
  2253. #elif _ALPHA_MARCH_FLUID
  2254. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distMax);
  2255. #elif _ALPHA_MARCH_FLUID_AND_DEPTH
  2256. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distRange);
  2257. #endif
  2258. // Set opacity based on distance through fluid relative to the maximum distance, and make sure high opacity fluids become solid
  2259. float opacity = saturate(dist / distMax + d.blackboard.foam + pow(d.blackboard.fluid.RGBA.w, 10.0f));
  2260. o.Albedo = lerp(0.0f, o.Albedo, opacity);
  2261. o.Emission = lerp(GetSceneColor(bentScrUV), o.Emission, opacity);
  2262. //o.Emission += o.Albedo * d.blackboard.fluid.ESMV.x * opacity;
  2263. #endif
  2264. }
  2265. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  2266. {
  2267. // Ext_SurfaceFunction0(l, d);
  2268. // Ext_SurfaceFunction1(l, d);
  2269. // Ext_SurfaceFunction2(l, d);
  2270. Ext_SurfaceFunction3(l, d);
  2271. Ext_SurfaceFunction4(l, d);
  2272. Ext_SurfaceFunction5(l, d);
  2273. // Ext_SurfaceFunction6(l, d);
  2274. // Ext_SurfaceFunction7(l, d);
  2275. // Ext_SurfaceFunction8(l, d);
  2276. // Ext_SurfaceFunction9(l, d);
  2277. // Ext_SurfaceFunction10(l, d);
  2278. // Ext_SurfaceFunction11(l, d);
  2279. // Ext_SurfaceFunction12(l, d);
  2280. // Ext_SurfaceFunction13(l, d);
  2281. // Ext_SurfaceFunction14(l, d);
  2282. // Ext_SurfaceFunction15(l, d);
  2283. // Ext_SurfaceFunction16(l, d);
  2284. // Ext_SurfaceFunction17(l, d);
  2285. // Ext_SurfaceFunction18(l, d);
  2286. // Ext_SurfaceFunction19(l, d);
  2287. // Ext_SurfaceFunction20(l, d);
  2288. // Ext_SurfaceFunction21(l, d);
  2289. // Ext_SurfaceFunction22(l, d);
  2290. // Ext_SurfaceFunction23(l, d);
  2291. // Ext_SurfaceFunction24(l, d);
  2292. // Ext_SurfaceFunction25(l, d);
  2293. // Ext_SurfaceFunction26(l, d);
  2294. // Ext_SurfaceFunction27(l, d);
  2295. // Ext_SurfaceFunction28(l, d);
  2296. // Ext_SurfaceFunction29(l, d);
  2297. }
  2298. #if !_DECALSHADER
  2299. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  2300. {
  2301. ExtraV2F d;
  2302. ZERO_INITIALIZE(ExtraV2F, d);
  2303. ZERO_INITIALIZE(Blackboard, d.blackboard);
  2304. // due to motion vectors in HDRP, we need to use the last
  2305. // time in certain spots. So if you are going to use _Time to adjust vertices,
  2306. // you need to use this time or motion vectors will break.
  2307. d.time = time;
  2308. Ext_ModifyVertex0(v, d);
  2309. // Ext_ModifyVertex1(v, d);
  2310. // Ext_ModifyVertex2(v, d);
  2311. Ext_ModifyVertex3(v, d);
  2312. // Ext_ModifyVertex4(v, d);
  2313. // Ext_ModifyVertex5(v, d);
  2314. // Ext_ModifyVertex6(v, d);
  2315. // Ext_ModifyVertex7(v, d);
  2316. // Ext_ModifyVertex8(v, d);
  2317. // Ext_ModifyVertex9(v, d);
  2318. // Ext_ModifyVertex10(v, d);
  2319. // Ext_ModifyVertex11(v, d);
  2320. // Ext_ModifyVertex12(v, d);
  2321. // Ext_ModifyVertex13(v, d);
  2322. // Ext_ModifyVertex14(v, d);
  2323. // Ext_ModifyVertex15(v, d);
  2324. // Ext_ModifyVertex16(v, d);
  2325. // Ext_ModifyVertex17(v, d);
  2326. // Ext_ModifyVertex18(v, d);
  2327. // Ext_ModifyVertex19(v, d);
  2328. // Ext_ModifyVertex20(v, d);
  2329. // Ext_ModifyVertex21(v, d);
  2330. // Ext_ModifyVertex22(v, d);
  2331. // Ext_ModifyVertex23(v, d);
  2332. // Ext_ModifyVertex24(v, d);
  2333. // Ext_ModifyVertex25(v, d);
  2334. // Ext_ModifyVertex26(v, d);
  2335. // Ext_ModifyVertex27(v, d);
  2336. // Ext_ModifyVertex28(v, d);
  2337. // Ext_ModifyVertex29(v, d);
  2338. // #if %EXTRAV2F0REQUIREKEY%
  2339. v2p.extraV2F0 = d.extraV2F0;
  2340. // #endif
  2341. // #if %EXTRAV2F1REQUIREKEY%
  2342. v2p.extraV2F1 = d.extraV2F1;
  2343. // #endif
  2344. // #if %EXTRAV2F2REQUIREKEY%
  2345. // v2p.extraV2F2 = d.extraV2F2;
  2346. // #endif
  2347. // #if %EXTRAV2F3REQUIREKEY%
  2348. // v2p.extraV2F3 = d.extraV2F3;
  2349. // #endif
  2350. // #if %EXTRAV2F4REQUIREKEY%
  2351. // v2p.extraV2F4 = d.extraV2F4;
  2352. // #endif
  2353. // #if %EXTRAV2F5REQUIREKEY%
  2354. // v2p.extraV2F5 = d.extraV2F5;
  2355. // #endif
  2356. // #if %EXTRAV2F6REQUIREKEY%
  2357. // v2p.extraV2F6 = d.extraV2F6;
  2358. // #endif
  2359. // #if %EXTRAV2F7REQUIREKEY%
  2360. // v2p.extraV2F7 = d.extraV2F7;
  2361. // #endif
  2362. }
  2363. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  2364. {
  2365. ExtraV2F d;
  2366. ZERO_INITIALIZE(ExtraV2F, d);
  2367. ZERO_INITIALIZE(Blackboard, d.blackboard);
  2368. // #if %EXTRAV2F0REQUIREKEY%
  2369. d.extraV2F0 = v2p.extraV2F0;
  2370. // #endif
  2371. // #if %EXTRAV2F1REQUIREKEY%
  2372. d.extraV2F1 = v2p.extraV2F1;
  2373. // #endif
  2374. // #if %EXTRAV2F2REQUIREKEY%
  2375. // d.extraV2F2 = v2p.extraV2F2;
  2376. // #endif
  2377. // #if %EXTRAV2F3REQUIREKEY%
  2378. // d.extraV2F3 = v2p.extraV2F3;
  2379. // #endif
  2380. // #if %EXTRAV2F4REQUIREKEY%
  2381. // d.extraV2F4 = v2p.extraV2F4;
  2382. // #endif
  2383. // #if %EXTRAV2F5REQUIREKEY%
  2384. // d.extraV2F5 = v2p.extraV2F5;
  2385. // #endif
  2386. // #if %EXTRAV2F6REQUIREKEY%
  2387. // d.extraV2F6 = v2p.extraV2F6;
  2388. // #endif
  2389. // #if %EXTRAV2F7REQUIREKEY%
  2390. // d.extraV2F7 = v2p.extraV2F7;
  2391. // #endif
  2392. // Ext_ModifyTessellatedVertex0(v, d);
  2393. // Ext_ModifyTessellatedVertex1(v, d);
  2394. // Ext_ModifyTessellatedVertex2(v, d);
  2395. // Ext_ModifyTessellatedVertex3(v, d);
  2396. // Ext_ModifyTessellatedVertex4(v, d);
  2397. // Ext_ModifyTessellatedVertex5(v, d);
  2398. // Ext_ModifyTessellatedVertex6(v, d);
  2399. // Ext_ModifyTessellatedVertex7(v, d);
  2400. // Ext_ModifyTessellatedVertex8(v, d);
  2401. // Ext_ModifyTessellatedVertex9(v, d);
  2402. // Ext_ModifyTessellatedVertex10(v, d);
  2403. // Ext_ModifyTessellatedVertex11(v, d);
  2404. // Ext_ModifyTessellatedVertex12(v, d);
  2405. // Ext_ModifyTessellatedVertex13(v, d);
  2406. // Ext_ModifyTessellatedVertex14(v, d);
  2407. // Ext_ModifyTessellatedVertex15(v, d);
  2408. // Ext_ModifyTessellatedVertex16(v, d);
  2409. // Ext_ModifyTessellatedVertex17(v, d);
  2410. // Ext_ModifyTessellatedVertex18(v, d);
  2411. // Ext_ModifyTessellatedVertex19(v, d);
  2412. // Ext_ModifyTessellatedVertex20(v, d);
  2413. // Ext_ModifyTessellatedVertex21(v, d);
  2414. // Ext_ModifyTessellatedVertex22(v, d);
  2415. // Ext_ModifyTessellatedVertex23(v, d);
  2416. // Ext_ModifyTessellatedVertex24(v, d);
  2417. // Ext_ModifyTessellatedVertex25(v, d);
  2418. // Ext_ModifyTessellatedVertex26(v, d);
  2419. // Ext_ModifyTessellatedVertex27(v, d);
  2420. // Ext_ModifyTessellatedVertex28(v, d);
  2421. // Ext_ModifyTessellatedVertex29(v, d);
  2422. // #if %EXTRAV2F0REQUIREKEY%
  2423. v2p.extraV2F0 = d.extraV2F0;
  2424. // #endif
  2425. // #if %EXTRAV2F1REQUIREKEY%
  2426. v2p.extraV2F1 = d.extraV2F1;
  2427. // #endif
  2428. // #if %EXTRAV2F2REQUIREKEY%
  2429. // v2p.extraV2F2 = d.extraV2F2;
  2430. // #endif
  2431. // #if %EXTRAV2F3REQUIREKEY%
  2432. // v2p.extraV2F3 = d.extraV2F3;
  2433. // #endif
  2434. // #if %EXTRAV2F4REQUIREKEY%
  2435. // v2p.extraV2F4 = d.extraV2F4;
  2436. // #endif
  2437. // #if %EXTRAV2F5REQUIREKEY%
  2438. // v2p.extraV2F5 = d.extraV2F5;
  2439. // #endif
  2440. // #if %EXTRAV2F6REQUIREKEY%
  2441. // v2p.extraV2F6 = d.extraV2F6;
  2442. // #endif
  2443. // #if %EXTRAV2F7REQUIREKEY%
  2444. // v2p.extraV2F7 = d.extraV2F7;
  2445. // #endif
  2446. }
  2447. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  2448. {
  2449. // Ext_FinalColorForward0(l, d, color);
  2450. // Ext_FinalColorForward1(l, d, color);
  2451. // Ext_FinalColorForward2(l, d, color);
  2452. // Ext_FinalColorForward3(l, d, color);
  2453. // Ext_FinalColorForward4(l, d, color);
  2454. // Ext_FinalColorForward5(l, d, color);
  2455. // Ext_FinalColorForward6(l, d, color);
  2456. // Ext_FinalColorForward7(l, d, color);
  2457. // Ext_FinalColorForward8(l, d, color);
  2458. // Ext_FinalColorForward9(l, d, color);
  2459. // Ext_FinalColorForward10(l, d, color);
  2460. // Ext_FinalColorForward11(l, d, color);
  2461. // Ext_FinalColorForward12(l, d, color);
  2462. // Ext_FinalColorForward13(l, d, color);
  2463. // Ext_FinalColorForward14(l, d, color);
  2464. // Ext_FinalColorForward15(l, d, color);
  2465. // Ext_FinalColorForward16(l, d, color);
  2466. // Ext_FinalColorForward17(l, d, color);
  2467. // Ext_FinalColorForward18(l, d, color);
  2468. // Ext_FinalColorForward19(l, d, color);
  2469. // Ext_FinalColorForward20(l, d, color);
  2470. // Ext_FinalColorForward21(l, d, color);
  2471. // Ext_FinalColorForward22(l, d, color);
  2472. // Ext_FinalColorForward23(l, d, color);
  2473. // Ext_FinalColorForward24(l, d, color);
  2474. // Ext_FinalColorForward25(l, d, color);
  2475. // Ext_FinalColorForward26(l, d, color);
  2476. // Ext_FinalColorForward27(l, d, color);
  2477. // Ext_FinalColorForward28(l, d, color);
  2478. // Ext_FinalColorForward29(l, d, color);
  2479. }
  2480. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  2481. {
  2482. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2483. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2484. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2485. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2486. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2487. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2488. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2489. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2490. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2491. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2492. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2493. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2494. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2495. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2496. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2497. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2498. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2499. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2500. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2501. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2502. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2503. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2504. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2505. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2506. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2507. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2508. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2509. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2510. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2511. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  2512. }
  2513. #endif
  2514. #if _DECALSHADER
  2515. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  2516. {
  2517. ShaderData d = (ShaderData)0;
  2518. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  2519. d.worldSpaceNormal = IN.WorldSpaceNormal;
  2520. d.worldSpaceTangent = IN.WorldSpaceTangent;
  2521. d.worldSpacePosition = IN.WorldSpacePosition;
  2522. d.texcoord0 = IN.uv0.xyxy;
  2523. d.screenPos = IN.ScreenPosition;
  2524. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  2525. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  2526. // these rarely get used, so we back transform them. Usually will be stripped.
  2527. #if _HDRP
  2528. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  2529. #else
  2530. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  2531. #endif
  2532. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  2533. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  2534. // #if %SCREENPOSREQUIREKEY%
  2535. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  2536. // #endif
  2537. return d;
  2538. }
  2539. #else
  2540. ShaderData CreateShaderData(VertexToPixel i
  2541. #if NEED_FACING
  2542. , bool facing
  2543. #endif
  2544. )
  2545. {
  2546. ShaderData d = (ShaderData)0;
  2547. d.clipPos = i.pos;
  2548. d.worldSpacePosition = i.worldPos;
  2549. d.worldSpaceNormal = normalize(i.worldNormal);
  2550. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  2551. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  2552. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  2553. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  2554. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  2555. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  2556. d.texcoord0 = i.texcoord0;
  2557. // d.texcoord1 = i.texcoord1;
  2558. // d.texcoord2 = i.texcoord2;
  2559. // #if %TEXCOORD3REQUIREKEY%
  2560. // d.texcoord3 = i.texcoord3;
  2561. // #endif
  2562. // d.isFrontFace = facing;
  2563. // #if %VERTEXCOLORREQUIREKEY%
  2564. d.vertexColor = i.vertexColor;
  2565. // #endif
  2566. // these rarely get used, so we back transform them. Usually will be stripped.
  2567. #if _HDRP
  2568. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  2569. #else
  2570. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  2571. #endif
  2572. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  2573. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  2574. // #if %SCREENPOSREQUIREKEY%
  2575. d.screenPos = i.screenPos;
  2576. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  2577. // #endif
  2578. // #if %EXTRAV2F0REQUIREKEY%
  2579. d.extraV2F0 = i.extraV2F0;
  2580. // #endif
  2581. // #if %EXTRAV2F1REQUIREKEY%
  2582. d.extraV2F1 = i.extraV2F1;
  2583. // #endif
  2584. // #if %EXTRAV2F2REQUIREKEY%
  2585. // d.extraV2F2 = i.extraV2F2;
  2586. // #endif
  2587. // #if %EXTRAV2F3REQUIREKEY%
  2588. // d.extraV2F3 = i.extraV2F3;
  2589. // #endif
  2590. // #if %EXTRAV2F4REQUIREKEY%
  2591. // d.extraV2F4 = i.extraV2F4;
  2592. // #endif
  2593. // #if %EXTRAV2F5REQUIREKEY%
  2594. // d.extraV2F5 = i.extraV2F5;
  2595. // #endif
  2596. // #if %EXTRAV2F6REQUIREKEY%
  2597. // d.extraV2F6 = i.extraV2F6;
  2598. // #endif
  2599. // #if %EXTRAV2F7REQUIREKEY%
  2600. // d.extraV2F7 = i.extraV2F7;
  2601. // #endif
  2602. return d;
  2603. }
  2604. #endif
  2605. #if defined(_PASSSHADOW)
  2606. float3 _LightDirection;
  2607. float3 _LightPosition;
  2608. #endif
  2609. // vertex shader
  2610. VertexToPixel Vert (VertexData v)
  2611. {
  2612. VertexToPixel o = (VertexToPixel)0;
  2613. UNITY_SETUP_INSTANCE_ID(v);
  2614. UNITY_TRANSFER_INSTANCE_ID(v, o);
  2615. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  2616. #if !_TESSELLATION_ON
  2617. ChainModifyVertex(v, o, _Time);
  2618. #endif
  2619. o.texcoord0 = v.texcoord0;
  2620. // o.texcoord1 = v.texcoord1;
  2621. // o.texcoord2 = v.texcoord2;
  2622. // #if %TEXCOORD3REQUIREKEY%
  2623. // o.texcoord3 = v.texcoord3;
  2624. // #endif
  2625. // #if %VERTEXCOLORREQUIREKEY%
  2626. o.vertexColor = v.vertexColor;
  2627. // #endif
  2628. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  2629. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  2630. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  2631. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  2632. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  2633. #if _PASSSHADOW
  2634. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  2635. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  2636. #else
  2637. float3 lightDirectionWS = _LightDirection;
  2638. #endif
  2639. // Define shadow pass specific clip position for Universal
  2640. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  2641. #if UNITY_REVERSED_Z
  2642. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  2643. #else
  2644. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  2645. #endif
  2646. #elif _PASSMETA
  2647. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  2648. #else
  2649. o.pos = TransformWorldToHClip(o.worldPos);
  2650. #endif
  2651. // #if %SCREENPOSREQUIREKEY%
  2652. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  2653. // #endif
  2654. #if _PASSFORWARD || _PASSGBUFFER
  2655. float2 uv1 = v.texcoord1.xy;
  2656. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  2657. // o.texcoord1.xy = uv1;
  2658. OUTPUT_SH(o.worldNormal, o.sh);
  2659. #if defined(DYNAMICLIGHTMAP_ON)
  2660. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  2661. #endif
  2662. #endif
  2663. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2664. half fogFactor = 0;
  2665. #if defined(_FOG_FRAGMENT)
  2666. fogFactor = ComputeFogFactor(o.pos.z);
  2667. #endif
  2668. #if _BAKEDLIT
  2669. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  2670. #else
  2671. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  2672. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  2673. #endif
  2674. #endif
  2675. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  2676. o.shadowCoord = GetShadowCoord(vertexInput);
  2677. #endif
  2678. return o;
  2679. }
  2680. // fragment shader
  2681. half4 Frag (VertexToPixel IN
  2682. #if NEED_FACING
  2683. , bool facing : SV_IsFrontFace
  2684. #endif
  2685. ) : SV_Target
  2686. {
  2687. UNITY_SETUP_INSTANCE_ID(IN);
  2688. ShaderData d = CreateShaderData(IN
  2689. #if NEED_FACING
  2690. , facing
  2691. #endif
  2692. );
  2693. Surface l = (Surface)0;
  2694. l.Albedo = half3(0.5, 0.5, 0.5);
  2695. l.Normal = float3(0,0,1);
  2696. l.Occlusion = 1;
  2697. l.Alpha = 1;
  2698. ChainSurfaceFunction(l, d);
  2699. MetaInput metaInput = (MetaInput)0;
  2700. metaInput.Albedo = l.Albedo;
  2701. metaInput.Emission = l.Emission;
  2702. return MetaFragment(metaInput);
  2703. }
  2704. ENDHLSL
  2705. }
  2706. Pass
  2707. {
  2708. Name "DepthNormals"
  2709. Tags
  2710. {
  2711. "LightMode" = "DepthNormals"
  2712. }
  2713. // Render State
  2714. Cull Back
  2715. ZTest LEqual
  2716. ZWrite On
  2717. ZWrite On
  2718. HLSLPROGRAM
  2719. #pragma vertex Vert
  2720. #pragma fragment Frag
  2721. #pragma target 3.0
  2722. #pragma prefer_hlslcc gles
  2723. #pragma exclude_renderers d3d11_9x
  2724. #pragma multi_compile_fog
  2725. #pragma multi_compile_instancing
  2726. #pragma multi_compile _ DOTS_INSTANCING_ON
  2727. #define SHADERPASS SHADERPASS_DEPTHNORMALSONLY
  2728. #define _PASSDEPTH 1
  2729. #define _PASSDEPTHNORMALS 1
  2730. #include "Flow.cginc"
  2731. #pragma shader_feature_local _ _STOCHASTIC_ON
  2732. #pragma shader_feature_local _FOAM_OFF _FOAM_ALPHA _FOAM_CUTOUT
  2733. #pragma shader_feature_local _ _FACETED_ON
  2734. #pragma shader_feature_local _ALPHA_OFF _ALPHA_VERTICAL _ALPHA_DEPTH _ALPHA_MARCH_FLUID _ALPHA_MARCH_FLUID_AND_DEPTH
  2735. #pragma shader_feature_local DISABLEFOG
  2736. #define _URP 1
  2737. #define _ALPHABLEND_ON 1
  2738. #define _ALPHABLEND_ON 1
  2739. #define _SURFACE_TYPE_TRANSPARENT 1
  2740. #define _GRABPASSUSED 1
  2741. #define REQUIRE_OPAQUE_TEXTURE
  2742. #define REQUIRE_DEPTH_TEXTURE
  2743. // this has to be here or specular color will be ignored. Not in SG code
  2744. #if _SIMPLELIT
  2745. #define _SPECULAR_COLOR
  2746. #endif
  2747. // Includes
  2748. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Version.hlsl"
  2749. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  2750. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2751. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  2752. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  2753. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  2754. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  2755. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl"
  2756. #undef WorldNormalVector
  2757. #define WorldNormalVector(data, normal) mul(normal, data.TBNMatrix)
  2758. #define UnityObjectToWorldNormal(normal) mul(GetObjectToWorldMatrix(), normal)
  2759. #define _WorldSpaceLightPos0 _MainLightPosition
  2760. #define UNITY_DECLARE_TEX2D(name) TEXTURE2D(name); SAMPLER(sampler##name);
  2761. #define UNITY_DECLARE_TEX2D_NOSAMPLER(name) TEXTURE2D(name);
  2762. #define UNITY_DECLARE_TEX2DARRAY(name) TEXTURE2D_ARRAY(name); SAMPLER(sampler##name);
  2763. #define UNITY_DECLARE_TEX2DARRAY_NOSAMPLER(name) TEXTURE2D_ARRAY(name);
  2764. #define UNITY_SAMPLE_TEX2DARRAY(tex,coord) SAMPLE_TEXTURE2D_ARRAY(tex, sampler##tex, coord.xy, coord.z)
  2765. #define UNITY_SAMPLE_TEX2DARRAY_LOD(tex,coord,lod) SAMPLE_TEXTURE2D_ARRAY_LOD(tex, sampler##tex, coord.xy, coord.z, lod)
  2766. #define UNITY_SAMPLE_TEX2D(tex, coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
  2767. #define UNITY_SAMPLE_TEX2D_SAMPLER(tex, samp, coord) SAMPLE_TEXTURE2D(tex, sampler##samp, coord)
  2768. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) SAMPLE_TEXTURE2D_LOD(tex, sampler_##tex, coord, lod)
  2769. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) SAMPLE_TEXTURE2D_LOD (tex, sampler##samplertex,coord, lod)
  2770. #if defined(UNITY_COMPILER_HLSL)
  2771. #define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
  2772. #else
  2773. #define UNITY_INITIALIZE_OUTPUT(type,name)
  2774. #endif
  2775. #define sampler2D_float sampler2D
  2776. #define sampler2D_half sampler2D
  2777. // data across stages, stripped like the above.
  2778. struct VertexToPixel
  2779. {
  2780. float4 pos : SV_POSITION;
  2781. float3 worldPos : TEXCOORD0;
  2782. float3 worldNormal : TEXCOORD1;
  2783. float4 worldTangent : TEXCOORD2;
  2784. float4 texcoord0 : TEXCOORD3;
  2785. // float4 texcoord1 : TEXCOORD4;
  2786. // float4 texcoord2 : TEXCOORD5;
  2787. // #if %TEXCOORD3REQUIREKEY%
  2788. // float4 texcoord3 : TEXCOORD6;
  2789. // #endif
  2790. // #if %SCREENPOSREQUIREKEY%
  2791. float4 screenPos : TEXCOORD7;
  2792. // #endif
  2793. // #if %VERTEXCOLORREQUIREKEY%
  2794. half4 vertexColor : COLOR;
  2795. // #endif
  2796. #if defined(LIGHTMAP_ON)
  2797. float2 lightmapUV : TEXCOORD8;
  2798. #endif
  2799. #if defined(DYNAMICLIGHTMAP_ON)
  2800. float2 dynamicLightmapUV : TEXCOORD9;
  2801. #endif
  2802. #if !defined(LIGHTMAP_ON)
  2803. float3 sh : TEXCOORD10;
  2804. #endif
  2805. #if defined(VARYINGS_NEED_FOG_AND_VERTEX_LIGHT)
  2806. float4 fogFactorAndVertexLight : TEXCOORD11;
  2807. #endif
  2808. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  2809. float4 shadowCoord : TEXCOORD12;
  2810. #endif
  2811. // #if %EXTRAV2F0REQUIREKEY%
  2812. float4 extraV2F0 : TEXCOORD13;
  2813. // #endif
  2814. // #if %EXTRAV2F1REQUIREKEY%
  2815. float4 extraV2F1 : TEXCOORD14;
  2816. // #endif
  2817. // #if %EXTRAV2F2REQUIREKEY%
  2818. // float4 extraV2F2 : TEXCOORD15;
  2819. // #endif
  2820. // #if %EXTRAV2F3REQUIREKEY%
  2821. // float4 extraV2F3 : TEXCOORD16;
  2822. // #endif
  2823. // #if %EXTRAV2F4REQUIREKEY%
  2824. // float4 extraV2F4 : TEXCOORD17;
  2825. // #endif
  2826. // #if %EXTRAV2F5REQUIREKEY%
  2827. // float4 extraV2F5 : TEXCOORD18;
  2828. // #endif
  2829. // #if %EXTRAV2F6REQUIREKEY%
  2830. // float4 extraV2F6 : TEXCOORD19;
  2831. // #endif
  2832. // #if %EXTRAV2F7REQUIREKEY%
  2833. // float4 extraV2F7 : TEXCOORD20;
  2834. // #endif
  2835. #if UNITY_ANY_INSTANCING_ENABLED
  2836. uint instanceID : CUSTOM_INSTANCE_ID;
  2837. #endif
  2838. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  2839. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  2840. #endif
  2841. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  2842. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  2843. #endif
  2844. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  2845. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  2846. #endif
  2847. };
  2848. // data describing the user output of a pixel
  2849. struct Surface
  2850. {
  2851. half3 Albedo;
  2852. half Height;
  2853. half3 Normal;
  2854. half Smoothness;
  2855. half3 Emission;
  2856. half Metallic;
  2857. half3 Specular;
  2858. half Occlusion;
  2859. half SpecularPower; // for simple lighting
  2860. half Alpha;
  2861. float outputDepth; // if written, SV_Depth semantic is used. ShaderData.clipPos.z is unused value
  2862. // HDRP Only
  2863. half SpecularOcclusion;
  2864. half SubsurfaceMask;
  2865. half Thickness;
  2866. half CoatMask;
  2867. half CoatSmoothness;
  2868. half Anisotropy;
  2869. half IridescenceMask;
  2870. half IridescenceThickness;
  2871. int DiffusionProfileHash;
  2872. float SpecularAAThreshold;
  2873. float SpecularAAScreenSpaceVariance;
  2874. // requires _OVERRIDE_BAKEDGI to be defined, but is mapped in all pipelines
  2875. float3 DiffuseGI;
  2876. float3 BackDiffuseGI;
  2877. float3 SpecularGI;
  2878. float ior;
  2879. float3 transmittanceColor;
  2880. float atDistance;
  2881. float transmittanceMask;
  2882. // requires _OVERRIDE_SHADOWMASK to be defines
  2883. float4 ShadowMask;
  2884. // for decals
  2885. float NormalAlpha;
  2886. float MAOSAlpha;
  2887. };
  2888. // Data the user declares in blackboard blocks
  2889. struct Blackboard
  2890. {
  2891. float groundHeight;
  2892. float surfaceHeight;
  2893. float3 surfaceNormal;
  2894. Fluid fluid;
  2895. float foam;
  2896. float blackboardDummyData;
  2897. };
  2898. // data the user might need, this will grow to be big. But easy to strip
  2899. struct ShaderData
  2900. {
  2901. float4 clipPos; // SV_POSITION
  2902. float3 localSpacePosition;
  2903. float3 localSpaceNormal;
  2904. float3 localSpaceTangent;
  2905. float3 worldSpacePosition;
  2906. float3 worldSpaceNormal;
  2907. float3 worldSpaceTangent;
  2908. float tangentSign;
  2909. float3 worldSpaceViewDir;
  2910. float3 tangentSpaceViewDir;
  2911. float4 texcoord0;
  2912. float4 texcoord1;
  2913. float4 texcoord2;
  2914. float4 texcoord3;
  2915. float2 screenUV;
  2916. float4 screenPos;
  2917. float4 vertexColor;
  2918. bool isFrontFace;
  2919. float4 extraV2F0;
  2920. float4 extraV2F1;
  2921. float4 extraV2F2;
  2922. float4 extraV2F3;
  2923. float4 extraV2F4;
  2924. float4 extraV2F5;
  2925. float4 extraV2F6;
  2926. float4 extraV2F7;
  2927. float3x3 TBNMatrix;
  2928. Blackboard blackboard;
  2929. };
  2930. struct VertexData
  2931. {
  2932. #if SHADER_TARGET > 30
  2933. // uint vertexID : SV_VertexID;
  2934. #endif
  2935. float4 vertex : POSITION;
  2936. float3 normal : NORMAL;
  2937. float4 tangent : TANGENT;
  2938. float4 texcoord0 : TEXCOORD0;
  2939. // optimize out mesh coords when not in use by user or lighting system
  2940. #if _URP && (_USINGTEXCOORD1 || _PASSMETA || _PASSFORWARD || _PASSGBUFFER)
  2941. float4 texcoord1 : TEXCOORD1;
  2942. #endif
  2943. #if _URP && (_USINGTEXCOORD2 || _PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && defined(DYNAMICLIGHTMAP_ON)))
  2944. float4 texcoord2 : TEXCOORD2;
  2945. #endif
  2946. #if _STANDARD && (_USINGTEXCOORD1 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER || _PASSFORWARDADD) && LIGHTMAP_ON)))
  2947. float4 texcoord1 : TEXCOORD1;
  2948. #endif
  2949. #if _STANDARD && (_USINGTEXCOORD2 || (_PASSMETA || ((_PASSFORWARD || _PASSGBUFFER) && DYNAMICLIGHTMAP_ON)))
  2950. float4 texcoord2 : TEXCOORD2;
  2951. #endif
  2952. #if _HDRP
  2953. float4 texcoord1 : TEXCOORD1;
  2954. float4 texcoord2 : TEXCOORD2;
  2955. #endif
  2956. // #if %TEXCOORD3REQUIREKEY%
  2957. // float4 texcoord3 : TEXCOORD3;
  2958. // #endif
  2959. // #if %VERTEXCOLORREQUIREKEY%
  2960. float4 vertexColor : COLOR;
  2961. // #endif
  2962. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  2963. float3 previousPositionOS : TEXCOORD4; // Contain previous transform position (in case of skinning for example)
  2964. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  2965. float3 precomputedVelocity : TEXCOORD5; // Add Precomputed Velocity (Alembic computes velocities on runtime side).
  2966. #endif
  2967. #endif
  2968. UNITY_VERTEX_INPUT_INSTANCE_ID
  2969. };
  2970. struct TessVertex
  2971. {
  2972. float4 vertex : INTERNALTESSPOS;
  2973. float3 normal : NORMAL;
  2974. float4 tangent : TANGENT;
  2975. float4 texcoord0 : TEXCOORD0;
  2976. float4 texcoord1 : TEXCOORD1;
  2977. float4 texcoord2 : TEXCOORD2;
  2978. // #if %TEXCOORD3REQUIREKEY%
  2979. // float4 texcoord3 : TEXCOORD3;
  2980. // #endif
  2981. // #if %VERTEXCOLORREQUIREKEY%
  2982. float4 vertexColor : COLOR;
  2983. // #endif
  2984. // #if %EXTRAV2F0REQUIREKEY%
  2985. float4 extraV2F0 : TEXCOORD5;
  2986. // #endif
  2987. // #if %EXTRAV2F1REQUIREKEY%
  2988. float4 extraV2F1 : TEXCOORD6;
  2989. // #endif
  2990. // #if %EXTRAV2F2REQUIREKEY%
  2991. // float4 extraV2F2 : TEXCOORD7;
  2992. // #endif
  2993. // #if %EXTRAV2F3REQUIREKEY%
  2994. // float4 extraV2F3 : TEXCOORD8;
  2995. // #endif
  2996. // #if %EXTRAV2F4REQUIREKEY%
  2997. // float4 extraV2F4 : TEXCOORD9;
  2998. // #endif
  2999. // #if %EXTRAV2F5REQUIREKEY%
  3000. // float4 extraV2F5 : TEXCOORD10;
  3001. // #endif
  3002. // #if %EXTRAV2F6REQUIREKEY%
  3003. // float4 extraV2F6 : TEXCOORD11;
  3004. // #endif
  3005. // #if %EXTRAV2F7REQUIREKEY%
  3006. // float4 extraV2F7 : TEXCOORD12;
  3007. // #endif
  3008. #if _HDRP && (_PASSMOTIONVECTOR || ((_PASSFORWARD || _PASSUNLIT) && defined(_WRITE_TRANSPARENT_MOTION_VECTOR)))
  3009. float3 previousPositionOS : TEXCOORD13; // Contain previous transform position (in case of skinning for example)
  3010. #if defined (_ADD_PRECOMPUTED_VELOCITY)
  3011. float3 precomputedVelocity : TEXCOORD14;
  3012. #endif
  3013. #endif
  3014. UNITY_VERTEX_INPUT_INSTANCE_ID
  3015. UNITY_VERTEX_OUTPUT_STEREO
  3016. };
  3017. struct ExtraV2F
  3018. {
  3019. float4 extraV2F0;
  3020. float4 extraV2F1;
  3021. float4 extraV2F2;
  3022. float4 extraV2F3;
  3023. float4 extraV2F4;
  3024. float4 extraV2F5;
  3025. float4 extraV2F6;
  3026. float4 extraV2F7;
  3027. Blackboard blackboard;
  3028. float4 time;
  3029. };
  3030. float3 WorldToTangentSpace(ShaderData d, float3 normal)
  3031. {
  3032. return mul(d.TBNMatrix, normal);
  3033. }
  3034. float3 TangentToWorldSpace(ShaderData d, float3 normal)
  3035. {
  3036. return mul(normal, d.TBNMatrix);
  3037. }
  3038. // in this case, make standard more like SRPs, because we can't fix
  3039. // unity_WorldToObject in HDRP, since it already does macro-fu there
  3040. #if _STANDARD
  3041. float3 TransformWorldToObject(float3 p) { return mul(unity_WorldToObject, float4(p, 1)); };
  3042. float3 TransformObjectToWorld(float3 p) { return mul(unity_ObjectToWorld, float4(p, 1)); };
  3043. float4 TransformWorldToObject(float4 p) { return mul(unity_WorldToObject, p); };
  3044. float4 TransformObjectToWorld(float4 p) { return mul(unity_ObjectToWorld, p); };
  3045. float4x4 GetWorldToObjectMatrix() { return unity_WorldToObject; }
  3046. float4x4 GetObjectToWorldMatrix() { return unity_ObjectToWorld; }
  3047. #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))
  3048. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord, lod) tex.SampleLevel (sampler##tex,coord, lod)
  3049. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord, lod) tex.SampleLevel (sampler##samplertex,coord, lod)
  3050. #else
  3051. #define UNITY_SAMPLE_TEX2D_LOD(tex,coord,lod) tex2D (tex,coord,0,lod)
  3052. #define UNITY_SAMPLE_TEX2D_SAMPLER_LOD(tex,samplertex,coord,lod) tex2D (tex,coord,0,lod)
  3053. #endif
  3054. #undef GetWorldToObjectMatrix()
  3055. #define GetWorldToObjectMatrix() unity_WorldToObject
  3056. #endif
  3057. float3 GetCameraWorldPosition()
  3058. {
  3059. #if _HDRP
  3060. return GetCameraRelativePositionWS(_WorldSpaceCameraPos);
  3061. #else
  3062. return _WorldSpaceCameraPos;
  3063. #endif
  3064. }
  3065. #if _GRABPASSUSED
  3066. #if _STANDARD
  3067. TEXTURE2D(_Grab);
  3068. SAMPLER(sampler__Grab);
  3069. #endif
  3070. half3 GetSceneColor(float2 uv)
  3071. {
  3072. #if _STANDARD
  3073. return SAMPLE_TEXTURE2D(_Grab, sampler__Grab, uv).rgb;
  3074. #else
  3075. return SHADERGRAPH_SAMPLE_SCENE_COLOR(uv);
  3076. #endif
  3077. }
  3078. #endif
  3079. #if _STANDARD
  3080. UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
  3081. float GetSceneDepth(float2 uv) { return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); }
  3082. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv)); }
  3083. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv)); }
  3084. #else
  3085. float GetSceneDepth(float2 uv) { return SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv); }
  3086. float GetLinear01Depth(float2 uv) { return Linear01Depth(GetSceneDepth(uv), _ZBufferParams); }
  3087. float GetLinearEyeDepth(float2 uv) { return LinearEyeDepth(GetSceneDepth(uv), _ZBufferParams); }
  3088. #endif
  3089. float3 GetWorldPositionFromDepthBuffer(float2 uv, float3 worldSpaceViewDir)
  3090. {
  3091. float eye = GetLinearEyeDepth(uv);
  3092. float3 camView = mul((float3x3)GetObjectToWorldMatrix(), transpose(mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V)) [2].xyz);
  3093. float dt = dot(worldSpaceViewDir, camView);
  3094. float3 div = worldSpaceViewDir/dt;
  3095. float3 wpos = (eye * div) + GetCameraWorldPosition();
  3096. return wpos;
  3097. }
  3098. #if _HDRP
  3099. float3 ObjectToWorldSpacePosition(float3 pos)
  3100. {
  3101. return GetAbsolutePositionWS(TransformObjectToWorld(pos));
  3102. }
  3103. #else
  3104. float3 ObjectToWorldSpacePosition(float3 pos)
  3105. {
  3106. return TransformObjectToWorld(pos);
  3107. }
  3108. #endif
  3109. #if _STANDARD
  3110. UNITY_DECLARE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture);
  3111. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3112. {
  3113. float4 depthNorms = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_CameraDepthNormalsTexture, uv);
  3114. float3 norms = DecodeViewNormalStereo(depthNorms);
  3115. norms = mul((float3x3)GetWorldToViewMatrix(), norms) * 0.5 + 0.5;
  3116. return norms;
  3117. }
  3118. #elif _HDRP && !_DECALSHADER
  3119. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3120. {
  3121. NormalData nd;
  3122. DecodeFromNormalBuffer(_ScreenSize.xy * uv, nd);
  3123. return nd.normalWS;
  3124. }
  3125. #elif _URP
  3126. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  3127. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  3128. #endif
  3129. float3 GetSceneNormal(float2 uv, float3 worldSpaceViewDir)
  3130. {
  3131. #if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
  3132. return SampleSceneNormals(uv);
  3133. #else
  3134. float3 wpos = GetWorldPositionFromDepthBuffer(uv, worldSpaceViewDir);
  3135. return normalize(-cross(ddx(wpos), ddy(wpos))) * 0.5 + 0.5;
  3136. #endif
  3137. }
  3138. #endif
  3139. #if _HDRP
  3140. half3 UnpackNormalmapRGorAG(half4 packednormal)
  3141. {
  3142. // This do the trick
  3143. packednormal.x *= packednormal.w;
  3144. half3 normal;
  3145. normal.xy = packednormal.xy * 2 - 1;
  3146. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  3147. return normal;
  3148. }
  3149. half3 UnpackNormal(half4 packednormal)
  3150. {
  3151. #if defined(UNITY_NO_DXT5nm)
  3152. return packednormal.xyz * 2 - 1;
  3153. #else
  3154. return UnpackNormalmapRGorAG(packednormal);
  3155. #endif
  3156. }
  3157. #endif
  3158. #if _HDRP || _URP
  3159. half3 UnpackScaleNormal(half4 packednormal, half scale)
  3160. {
  3161. #ifndef UNITY_NO_DXT5nm
  3162. // Unpack normal as DXT5nm (1, y, 1, x) or BC5 (x, y, 0, 1)
  3163. // Note neutral texture like "bump" is (0, 0, 1, 1) to work with both plain RGB normal and DXT5nm/BC5
  3164. packednormal.x *= packednormal.w;
  3165. #endif
  3166. half3 normal;
  3167. normal.xy = (packednormal.xy * 2 - 1) * scale;
  3168. normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
  3169. return normal;
  3170. }
  3171. #endif
  3172. void GetSun(out float3 lightDir, out float3 color)
  3173. {
  3174. lightDir = float3(0.5, 0.5, 0);
  3175. color = 1;
  3176. #if _HDRP
  3177. if (_DirectionalLightCount > 0)
  3178. {
  3179. DirectionalLightData light = _DirectionalLightDatas[0];
  3180. lightDir = -light.forward.xyz;
  3181. color = light.color;
  3182. }
  3183. #elif _STANDARD
  3184. lightDir = normalize(_WorldSpaceLightPos0.xyz);
  3185. color = _LightColor0.rgb;
  3186. #elif _URP
  3187. Light light = GetMainLight();
  3188. lightDir = light.direction;
  3189. color = light.color;
  3190. #endif
  3191. }
  3192. CBUFFER_START(UnityPerMaterial)
  3193. float _FlowDensity;
  3194. float2 _FlowSeparationXZ;
  3195. float _FlowSimulationHeight;
  3196. float _FlowCameraHeight;
  3197. float2 _FlowCountXZ;
  3198. float4 _FlowCoordU000;
  3199. float4 _FlowCoord0V00;
  3200. float _FlowSpeed;
  3201. float4x4 _FlowMatrix;
  3202. float _Sink;
  3203. float _Emission;
  3204. float _WaveStrengthMin;
  3205. float _WaveStrengthMax;
  3206. float _WaveStrengthScale;
  3207. float _Tiling;
  3208. float _AnimationSpeed;
  3209. float _FoamBrightness;
  3210. half _FlatShadingBlend;
  3211. float _RangeMax;
  3212. float _AlphaStep;
  3213. int _AlphaMaxSteps;
  3214. float _AlphaDepthScale;
  3215. CBUFFER_END
  3216. #ifdef unity_WorldToObject
  3217. #undef unity_WorldToObject
  3218. #endif
  3219. #ifdef unity_ObjectToWorld
  3220. #undef unity_ObjectToWorld
  3221. #endif
  3222. #define unity_ObjectToWorld GetObjectToWorldMatrix()
  3223. #define unity_WorldToObject GetWorldToObjectMatrix()
  3224. TEXTURE2D(_FlowDataA);
  3225. SAMPLER(sampler_FlowDataA);
  3226. TEXTURE2D(_FlowDataB);
  3227. SAMPLER(sampler_FlowDataB);
  3228. TEXTURE2D(_FlowDataC);
  3229. SAMPLER(sampler_FlowDataC);
  3230. TEXTURE2D(_FlowDataD);
  3231. SAMPLER(sampler_FlowDataD);
  3232. TEXTURE2D(_FlowDataE);
  3233. SAMPLER(sampler_FlowDataE);
  3234. TEXTURE2D(_FlowDataF);
  3235. SAMPLER(sampler_FlowDataF);
  3236. float4 SGT_O2W(float4 v)
  3237. {
  3238. v = mul(GetObjectToWorldMatrix(), v);
  3239. #if _HDRP
  3240. v.xyz = GetAbsolutePositionWS(v.xyz);
  3241. #endif
  3242. return v;
  3243. }
  3244. float4 SGT_W2O(float4 v)
  3245. {
  3246. #if _HDRP
  3247. v.xyz = GetCameraRelativePositionWS(v.xyz);
  3248. #endif
  3249. return mul(GetWorldToObjectMatrix(), v);
  3250. }
  3251. float4 SGT_O2V(float4 v)
  3252. {
  3253. #if _STANDARD
  3254. return float4(UnityObjectToViewPos(v.xyz), 1.0f);
  3255. #else
  3256. return float4(TransformWorldToView(TransformObjectToWorld(v.xyz)), 1.0f);
  3257. #endif
  3258. }
  3259. float GetFluidHeight(float2 uv)
  3260. {
  3261. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  3262. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  3263. return groundHeight + fluidDepth;
  3264. }
  3265. float2 GetHeightAndDepth(float2 uv)
  3266. {
  3267. float groundHeight = SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0).r;
  3268. float fluidDepth = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0).r;
  3269. return float2(groundHeight, fluidDepth);
  3270. }
  3271. Column GetColumn(float2 uv)
  3272. {
  3273. return DecodeColumn(SAMPLE_TEXTURE2D_LOD(_FlowDataA, sampler_FlowDataA, uv, 0), SAMPLE_TEXTURE2D_LOD(_FlowDataB, sampler_FlowDataB, uv, 0));
  3274. }
  3275. Fluid GetColumnFluid(float2 uv)
  3276. {
  3277. float4 c = SAMPLE_TEXTURE2D_LOD(_FlowDataC, sampler_FlowDataC, uv, 0);
  3278. float4 d = SAMPLE_TEXTURE2D_LOD(_FlowDataD, sampler_FlowDataD, uv, 0);
  3279. float4 e = SAMPLE_TEXTURE2D_LOD(_FlowDataE, sampler_FlowDataE, uv, 0);
  3280. float4 f = SAMPLE_TEXTURE2D_LOD(_FlowDataF, sampler_FlowDataF, uv, 0);
  3281. return DecodeFluid(c, d, e, f);
  3282. }
  3283. bool InsideFluid(float3 wpos)
  3284. {
  3285. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  3286. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  3287. float2 columnHAD = GetHeightAndDepth(columnCoord);
  3288. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y > columnHAD.x && wpos.y < (columnHAD.x + columnHAD.y);
  3289. }
  3290. bool UnderFluid(float3 wpos)
  3291. {
  3292. float2 columnPixel = mul(_FlowMatrix, float4(wpos, 1.0f)).xy;
  3293. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  3294. float2 columnHAD = GetHeightAndDepth(columnCoord);
  3295. return min(columnCoord.x, columnCoord.y) >= 0.0 && max(columnCoord.x, columnCoord.y) <= 1.0f && wpos.y < (columnHAD.x + columnHAD.y);
  3296. }
  3297. float RayMarchInside(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  3298. {
  3299. float epsi = step * 0.01f;
  3300. float dist = 0.0f;
  3301. for (int i = 0; i < maxs && step > epsi; i++)
  3302. {
  3303. dist += step;
  3304. float3 pos = wpos + wdir * dist;
  3305. if (InsideFluid(pos) == false)
  3306. {
  3307. dist -= step;
  3308. step *= 0.5f;
  3309. }
  3310. if (dist > maxd)
  3311. {
  3312. return maxd;
  3313. }
  3314. }
  3315. return dist;
  3316. }
  3317. float RayMarchUnder(float3 wpos, float3 wdir, float step, int maxs, float maxd)
  3318. {
  3319. float epsi = step * 0.01f;
  3320. float dist = 0.0f;
  3321. for (int i = 0; i < maxs && step > epsi; i++)
  3322. {
  3323. dist += step;
  3324. float3 pos = wpos + wdir * dist;
  3325. if (UnderFluid(pos) == false)
  3326. {
  3327. dist -= step;
  3328. step *= 0.5f;
  3329. }
  3330. if (dist > maxd)
  3331. {
  3332. return maxd;
  3333. }
  3334. }
  3335. return dist;
  3336. }
  3337. void Ext_ModifyVertex0 (inout VertexData v, inout ExtraV2F e)
  3338. {
  3339. float4 wpos = SGT_O2W(v.vertex);
  3340. float2 columnPixel = mul(_FlowMatrix, float4(wpos.xyz, 1.0f)).xy;
  3341. float2 columnCoord = SnapCoordFromPixel(round(columnPixel), _FlowCountXZ);
  3342. Column column0 = GetColumn(columnCoord);
  3343. Column columnL = GetColumn(columnCoord - _FlowCoordU000.xy);
  3344. Column columnR = GetColumn(columnCoord + _FlowCoordU000.xy);
  3345. Column columnB = GetColumn(columnCoord - _FlowCoord0V00.xy);
  3346. Column columnT = GetColumn(columnCoord + _FlowCoord0V00.xy);
  3347. Fluid fluid0 = GetColumnFluid(columnCoord);
  3348. Fluid fluidL = GetColumnFluid(columnCoord - _FlowCoordU000.xy);
  3349. Fluid fluidR = GetColumnFluid(columnCoord + _FlowCoordU000.xy);
  3350. Fluid fluidB = GetColumnFluid(columnCoord - _FlowCoord0V00.xy);
  3351. Fluid fluidT = GetColumnFluid(columnCoord + _FlowCoord0V00.xy);
  3352. float ww = fluidL.Depth + fluidR.Depth + fluidB.Depth + fluidT.Depth + 0.001f;
  3353. float wL = fluidL.Depth / ww;
  3354. float wR = fluidR.Depth / ww;
  3355. float wB = fluidB.Depth / ww;
  3356. float wT = fluidT.Depth / ww;
  3357. float w0 = saturate(fluid0.Depth * 10);
  3358. float hL = columnL.GroundHeight + fluidL.Depth;
  3359. float hR = columnR.GroundHeight + fluidR.Depth;
  3360. float hB = columnB.GroundHeight + fluidB.Depth;
  3361. float hT = columnT.GroundHeight + fluidT.Depth;
  3362. float hh = hL * wL + hR * wR + hB * wB + hT * wT;
  3363. float h0 = column0.GroundHeight + fluid0.Depth;
  3364. hh = lerp(hh, h0 - _Sink, saturate(0.01f / ww)); // Prevent skirts going down too far
  3365. Fluid fluid = fluid0;
  3366. fluid.Depth = lerp(fluidL.Depth * wL + fluidR.Depth * wR + fluidB.Depth * wB + fluidT.Depth * wT, fluid.Depth, w0);
  3367. fluid.RGBA = lerp(fluidL.RGBA * wL + fluidR.RGBA * wR + fluidB.RGBA * wB + fluidT.RGBA * wT, fluid.RGBA , w0);
  3368. fluid.ESMV = lerp(fluidL.ESMV * wL + fluidR.ESMV * wR + fluidB.ESMV * wB + fluidT.ESMV * wT, fluid.ESMV , w0);
  3369. fluid.F123 = lerp(fluidL.F123 * wL + fluidR.F123 * wR + fluidB.F123 * wB + fluidT.F123 * wT, fluid.F123 , w0);
  3370. e.blackboard.groundHeight = column0.GroundHeight;
  3371. e.blackboard.surfaceHeight = lerp(hh, h0, w0);
  3372. e.blackboard.surfaceNormal = normalize(float3((hL - hR) / _FlowSeparationXZ.x, 2.0f, (hB - hT) / _FlowSeparationXZ.y));
  3373. e.blackboard.fluid = fluid;
  3374. }
  3375. TEXTURE2D(_NoiseMap);
  3376. SAMPLER(sampler_NoiseMap);
  3377. TEXTURE2D(_NormalFoamMap);
  3378. SAMPLER(sampler_NormalFoamMap);
  3379. void Ext_ModifyVertex3 (inout VertexData v, inout ExtraV2F e)
  3380. {
  3381. v.vertex.y = lerp(e.blackboard.groundHeight, e.blackboard.surfaceHeight, v.texcoord0.w) - _FlowSimulationHeight;
  3382. v.normal = lerp(e.blackboard.surfaceNormal, v.normal, v.texcoord0.z);
  3383. v.vertexColor = e.blackboard.fluid.RGBA;
  3384. e.extraV2F0.xyz = SGT_O2V(v.vertex).xyz;
  3385. e.extraV2F0.w = e.blackboard.fluid.Depth;
  3386. e.extraV2F1.xyz = e.blackboard.fluid.ESMV.xyz;
  3387. e.extraV2F1.w = e.blackboard.fluid.F123.x;
  3388. }
  3389. float3 FlowUVW(float2 uv, float2 flowVector, float2 jump, float tiling, float time, float phaseOffset)
  3390. {
  3391. float progress = frac(time + phaseOffset);
  3392. float3 uvw;
  3393. uvw.xy = uv - flowVector * (progress - 0.5f);
  3394. uvw.xy *= tiling;
  3395. uvw.xy += phaseOffset;
  3396. uvw.xy += (time - progress) * jump;
  3397. uvw.z = 1 - abs(1 - 2 * progress);
  3398. return uvw;
  3399. }
  3400. float3 CombineNormals(float3 n1, float3 n2)
  3401. {
  3402. return normalize(half3(n1.xy + n2.xy, n1.z*n2.z));
  3403. }
  3404. float3 UnpackNormalAndScale(float2 xy, float scale)
  3405. {
  3406. xy = xy * 2.0f - 1.0f; xy *= scale; return float3(xy, sqrt(1.0 - saturate(dot(xy, xy))));
  3407. }
  3408. float4 SampleStochastic(float2 uv, float noise)
  3409. {
  3410. float cur_height = uv.y + noise;
  3411. float this_index = floor(cur_height);
  3412. float next_index = this_index + 1.0f;
  3413. float2 uvA = uv + sin(float2(1.0f, 2.0f) * this_index);
  3414. float2 uvB = uv + sin(float2(1.0f, 2.0f) * next_index);
  3415. float2 gradX = ddx(uv);
  3416. float2 gradY = ddy(uv);
  3417. float4 sampleA = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvA, gradX, gradY);
  3418. float4 sampleB = SAMPLE_TEXTURE2D_GRAD(_NormalFoamMap, sampler_NormalFoamMap, uvB, gradX, gradY);
  3419. return lerp(sampleA, sampleB, cur_height - this_index);
  3420. }
  3421. void Ext_SurfaceFunction3 (inout Surface o, inout ShaderData d)
  3422. {
  3423. d.blackboard.fluid.RGBA = d.vertexColor;
  3424. d.blackboard.fluid.Depth = d.extraV2F0.w;
  3425. d.blackboard.fluid.ESMV.xyz = d.extraV2F1.xyz;
  3426. d.blackboard.fluid.F123.x = d.extraV2F1.w;
  3427. if (d.blackboard.fluid.Depth < 0.01f)
  3428. {
  3429. discard;
  3430. }
  3431. float2 uv = d.worldSpacePosition.xz;
  3432. float2 columnPixel = mul(_FlowMatrix, float4(d.worldSpacePosition, 1.0f)).xy;
  3433. float2 columnCoord = CoordFromPixel(columnPixel, _FlowCountXZ);
  3434. Column column = GetColumn(columnCoord);
  3435. float time = _Time.y * _AnimationSpeed;
  3436. float2 jump = float2(0.13f, 0.17f);
  3437. float2 fvec = (column.Outflow.yw - column.Outflow.xz) * _FlowSeparationXZ * _FlowSpeed;
  3438. float fmag = log10(1.0f + length(fvec)) * 0.1f;
  3439. float3 flowA = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.0f);
  3440. float3 flowB = FlowUVW(uv, fvec / _AnimationSpeed, jump, _Tiling, time, 0.5f);
  3441. #if _STOCHASTIC_ON
  3442. float noise = SAMPLE_TEXTURE2D(_NoiseMap, sampler_NoiseMap, uv * 0.0025f).a * 4.0f;
  3443. float4 nfmA = SampleStochastic(flowA, noise);
  3444. float4 nfmB = SampleStochastic(flowB, noise);
  3445. #else
  3446. float4 nfmA = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowA.xy);
  3447. float4 nfmB = SAMPLE_TEXTURE2D(_NormalFoamMap, sampler_NormalFoamMap, flowB.xy);
  3448. #endif
  3449. // Water normals
  3450. float normalStr = lerp(_WaveStrengthMin, _WaveStrengthMax, saturate(_WaveStrengthScale * fmag));
  3451. float3 waterNormalA = UnpackNormalAndScale(nfmA.xy, flowA.z * normalStr);
  3452. float3 waterNormalB = UnpackNormalAndScale(nfmB.xy, flowB.z * normalStr);
  3453. float3 waterNormals = CombineNormals(waterNormalA, waterNormalB);
  3454. o.Normal = lerp(waterNormals, o.Normal, d.texcoord0.z);
  3455. o.Albedo = d.blackboard.fluid.RGBA.xyz;
  3456. o.Emission = d.blackboard.fluid.ESMV.x * _Emission * o.Albedo;
  3457. #if _FOAM_OFF
  3458. d.blackboard.foam = 0.0f;
  3459. #else
  3460. d.blackboard.foam = d.blackboard.fluid.F123.x * (1.0f - d.texcoord0.z);
  3461. #if _FOAM_ALPHA
  3462. float3 foamAlbedo = (nfmA.w * flowA.z + nfmB.w * flowB.z) * _FoamBrightness;
  3463. #elif _FOAM_CUTOUT
  3464. float3 foamAlbedo = _FoamBrightness;
  3465. float foamRamp = nfmA.w * flowA.z + nfmB.w * flowB.z;
  3466. d.blackboard.foam = saturate((d.blackboard.foam - foamRamp) * 10.0f);
  3467. #endif
  3468. float3 foamNormal = float3(0.0f, 0.0f, 1.0f);
  3469. o.Albedo = lerp(o.Albedo, foamAlbedo, d.blackboard.foam);
  3470. o.Normal = lerp(o.Normal, foamNormal, d.blackboard.foam);
  3471. #endif
  3472. o.Smoothness = d.blackboard.fluid.ESMV.y;
  3473. o.Metallic = d.blackboard.fluid.ESMV.z;
  3474. }
  3475. void Ext_SurfaceFunction4 (inout Surface o, inout ShaderData d)
  3476. {
  3477. #if _FACETED_ON
  3478. // lets just affect the TBN data, so we flat shade the original polygons, not the normal map
  3479. float3 dx = ddx(d.worldSpacePosition);
  3480. float3 dy = ddy(d.worldSpacePosition);
  3481. float3 worldNormal = normalize(cross(dy, dx));
  3482. worldNormal = lerp(d.worldSpaceNormal, worldNormal, _FlatShadingBlend);
  3483. d.worldSpaceNormal = worldNormal;
  3484. d.TBNMatrix[2] = worldNormal;
  3485. #endif
  3486. }
  3487. void Ext_SurfaceFunction5 (inout Surface o, ShaderData d)
  3488. {
  3489. #if _ALPHA_OFF
  3490. #else
  3491. float3 position = d.worldSpacePosition;
  3492. float3 step = d.worldSpacePosition - _WorldSpaceCameraPos;
  3493. float2 bentScrUV = d.screenUV + o.Normal.xy * 0.05f * log(1.0f + d.blackboard.fluid.Depth * 1.0f);
  3494. float distMax = max(_RangeMax * 0.001f, _RangeMax * (1.0f - d.blackboard.fluid.RGBA.w));
  3495. float distRange = distMax;
  3496. float vertDist = length(d.extraV2F0.xyz);
  3497. float camtDist = GetLinearEyeDepth(bentScrUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  3498. if (camtDist < vertDist)
  3499. {
  3500. camtDist = GetLinearEyeDepth(d.screenUV) * length(d.extraV2F0.xyz / d.extraV2F0.z);
  3501. }
  3502. float diffDist = max(0.0f, camtDist - vertDist);
  3503. // The depth buffer becomes unusable at certain ranges, so fade it out
  3504. diffDist += max(0.0f, camtDist * _AlphaDepthScale - _RangeMax);
  3505. distRange = min(distRange, diffDist);
  3506. #if _ALPHA_VERTICAL
  3507. float dist = d.blackboard.fluid.Depth;
  3508. #elif _ALPHA_DEPTH
  3509. float dist = diffDist;
  3510. #elif _ALPHA_MARCH_FLUID
  3511. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distMax);
  3512. #elif _ALPHA_MARCH_FLUID_AND_DEPTH
  3513. float dist = RayMarchInside(position, normalize(step), _AlphaStep, _AlphaMaxSteps, distRange);
  3514. #endif
  3515. // Set opacity based on distance through fluid relative to the maximum distance, and make sure high opacity fluids become solid
  3516. float opacity = saturate(dist / distMax + d.blackboard.foam + pow(d.blackboard.fluid.RGBA.w, 10.0f));
  3517. o.Albedo = lerp(0.0f, o.Albedo, opacity);
  3518. o.Emission = lerp(GetSceneColor(bentScrUV), o.Emission, opacity);
  3519. //o.Emission += o.Albedo * d.blackboard.fluid.ESMV.x * opacity;
  3520. #endif
  3521. }
  3522. void ChainSurfaceFunction(inout Surface l, inout ShaderData d)
  3523. {
  3524. // Ext_SurfaceFunction0(l, d);
  3525. // Ext_SurfaceFunction1(l, d);
  3526. // Ext_SurfaceFunction2(l, d);
  3527. Ext_SurfaceFunction3(l, d);
  3528. Ext_SurfaceFunction4(l, d);
  3529. Ext_SurfaceFunction5(l, d);
  3530. // Ext_SurfaceFunction6(l, d);
  3531. // Ext_SurfaceFunction7(l, d);
  3532. // Ext_SurfaceFunction8(l, d);
  3533. // Ext_SurfaceFunction9(l, d);
  3534. // Ext_SurfaceFunction10(l, d);
  3535. // Ext_SurfaceFunction11(l, d);
  3536. // Ext_SurfaceFunction12(l, d);
  3537. // Ext_SurfaceFunction13(l, d);
  3538. // Ext_SurfaceFunction14(l, d);
  3539. // Ext_SurfaceFunction15(l, d);
  3540. // Ext_SurfaceFunction16(l, d);
  3541. // Ext_SurfaceFunction17(l, d);
  3542. // Ext_SurfaceFunction18(l, d);
  3543. // Ext_SurfaceFunction19(l, d);
  3544. // Ext_SurfaceFunction20(l, d);
  3545. // Ext_SurfaceFunction21(l, d);
  3546. // Ext_SurfaceFunction22(l, d);
  3547. // Ext_SurfaceFunction23(l, d);
  3548. // Ext_SurfaceFunction24(l, d);
  3549. // Ext_SurfaceFunction25(l, d);
  3550. // Ext_SurfaceFunction26(l, d);
  3551. // Ext_SurfaceFunction27(l, d);
  3552. // Ext_SurfaceFunction28(l, d);
  3553. // Ext_SurfaceFunction29(l, d);
  3554. }
  3555. #if !_DECALSHADER
  3556. void ChainModifyVertex(inout VertexData v, inout VertexToPixel v2p, float4 time)
  3557. {
  3558. ExtraV2F d;
  3559. ZERO_INITIALIZE(ExtraV2F, d);
  3560. ZERO_INITIALIZE(Blackboard, d.blackboard);
  3561. // due to motion vectors in HDRP, we need to use the last
  3562. // time in certain spots. So if you are going to use _Time to adjust vertices,
  3563. // you need to use this time or motion vectors will break.
  3564. d.time = time;
  3565. Ext_ModifyVertex0(v, d);
  3566. // Ext_ModifyVertex1(v, d);
  3567. // Ext_ModifyVertex2(v, d);
  3568. Ext_ModifyVertex3(v, d);
  3569. // Ext_ModifyVertex4(v, d);
  3570. // Ext_ModifyVertex5(v, d);
  3571. // Ext_ModifyVertex6(v, d);
  3572. // Ext_ModifyVertex7(v, d);
  3573. // Ext_ModifyVertex8(v, d);
  3574. // Ext_ModifyVertex9(v, d);
  3575. // Ext_ModifyVertex10(v, d);
  3576. // Ext_ModifyVertex11(v, d);
  3577. // Ext_ModifyVertex12(v, d);
  3578. // Ext_ModifyVertex13(v, d);
  3579. // Ext_ModifyVertex14(v, d);
  3580. // Ext_ModifyVertex15(v, d);
  3581. // Ext_ModifyVertex16(v, d);
  3582. // Ext_ModifyVertex17(v, d);
  3583. // Ext_ModifyVertex18(v, d);
  3584. // Ext_ModifyVertex19(v, d);
  3585. // Ext_ModifyVertex20(v, d);
  3586. // Ext_ModifyVertex21(v, d);
  3587. // Ext_ModifyVertex22(v, d);
  3588. // Ext_ModifyVertex23(v, d);
  3589. // Ext_ModifyVertex24(v, d);
  3590. // Ext_ModifyVertex25(v, d);
  3591. // Ext_ModifyVertex26(v, d);
  3592. // Ext_ModifyVertex27(v, d);
  3593. // Ext_ModifyVertex28(v, d);
  3594. // Ext_ModifyVertex29(v, d);
  3595. // #if %EXTRAV2F0REQUIREKEY%
  3596. v2p.extraV2F0 = d.extraV2F0;
  3597. // #endif
  3598. // #if %EXTRAV2F1REQUIREKEY%
  3599. v2p.extraV2F1 = d.extraV2F1;
  3600. // #endif
  3601. // #if %EXTRAV2F2REQUIREKEY%
  3602. // v2p.extraV2F2 = d.extraV2F2;
  3603. // #endif
  3604. // #if %EXTRAV2F3REQUIREKEY%
  3605. // v2p.extraV2F3 = d.extraV2F3;
  3606. // #endif
  3607. // #if %EXTRAV2F4REQUIREKEY%
  3608. // v2p.extraV2F4 = d.extraV2F4;
  3609. // #endif
  3610. // #if %EXTRAV2F5REQUIREKEY%
  3611. // v2p.extraV2F5 = d.extraV2F5;
  3612. // #endif
  3613. // #if %EXTRAV2F6REQUIREKEY%
  3614. // v2p.extraV2F6 = d.extraV2F6;
  3615. // #endif
  3616. // #if %EXTRAV2F7REQUIREKEY%
  3617. // v2p.extraV2F7 = d.extraV2F7;
  3618. // #endif
  3619. }
  3620. void ChainModifyTessellatedVertex(inout VertexData v, inout VertexToPixel v2p)
  3621. {
  3622. ExtraV2F d;
  3623. ZERO_INITIALIZE(ExtraV2F, d);
  3624. ZERO_INITIALIZE(Blackboard, d.blackboard);
  3625. // #if %EXTRAV2F0REQUIREKEY%
  3626. d.extraV2F0 = v2p.extraV2F0;
  3627. // #endif
  3628. // #if %EXTRAV2F1REQUIREKEY%
  3629. d.extraV2F1 = v2p.extraV2F1;
  3630. // #endif
  3631. // #if %EXTRAV2F2REQUIREKEY%
  3632. // d.extraV2F2 = v2p.extraV2F2;
  3633. // #endif
  3634. // #if %EXTRAV2F3REQUIREKEY%
  3635. // d.extraV2F3 = v2p.extraV2F3;
  3636. // #endif
  3637. // #if %EXTRAV2F4REQUIREKEY%
  3638. // d.extraV2F4 = v2p.extraV2F4;
  3639. // #endif
  3640. // #if %EXTRAV2F5REQUIREKEY%
  3641. // d.extraV2F5 = v2p.extraV2F5;
  3642. // #endif
  3643. // #if %EXTRAV2F6REQUIREKEY%
  3644. // d.extraV2F6 = v2p.extraV2F6;
  3645. // #endif
  3646. // #if %EXTRAV2F7REQUIREKEY%
  3647. // d.extraV2F7 = v2p.extraV2F7;
  3648. // #endif
  3649. // Ext_ModifyTessellatedVertex0(v, d);
  3650. // Ext_ModifyTessellatedVertex1(v, d);
  3651. // Ext_ModifyTessellatedVertex2(v, d);
  3652. // Ext_ModifyTessellatedVertex3(v, d);
  3653. // Ext_ModifyTessellatedVertex4(v, d);
  3654. // Ext_ModifyTessellatedVertex5(v, d);
  3655. // Ext_ModifyTessellatedVertex6(v, d);
  3656. // Ext_ModifyTessellatedVertex7(v, d);
  3657. // Ext_ModifyTessellatedVertex8(v, d);
  3658. // Ext_ModifyTessellatedVertex9(v, d);
  3659. // Ext_ModifyTessellatedVertex10(v, d);
  3660. // Ext_ModifyTessellatedVertex11(v, d);
  3661. // Ext_ModifyTessellatedVertex12(v, d);
  3662. // Ext_ModifyTessellatedVertex13(v, d);
  3663. // Ext_ModifyTessellatedVertex14(v, d);
  3664. // Ext_ModifyTessellatedVertex15(v, d);
  3665. // Ext_ModifyTessellatedVertex16(v, d);
  3666. // Ext_ModifyTessellatedVertex17(v, d);
  3667. // Ext_ModifyTessellatedVertex18(v, d);
  3668. // Ext_ModifyTessellatedVertex19(v, d);
  3669. // Ext_ModifyTessellatedVertex20(v, d);
  3670. // Ext_ModifyTessellatedVertex21(v, d);
  3671. // Ext_ModifyTessellatedVertex22(v, d);
  3672. // Ext_ModifyTessellatedVertex23(v, d);
  3673. // Ext_ModifyTessellatedVertex24(v, d);
  3674. // Ext_ModifyTessellatedVertex25(v, d);
  3675. // Ext_ModifyTessellatedVertex26(v, d);
  3676. // Ext_ModifyTessellatedVertex27(v, d);
  3677. // Ext_ModifyTessellatedVertex28(v, d);
  3678. // Ext_ModifyTessellatedVertex29(v, d);
  3679. // #if %EXTRAV2F0REQUIREKEY%
  3680. v2p.extraV2F0 = d.extraV2F0;
  3681. // #endif
  3682. // #if %EXTRAV2F1REQUIREKEY%
  3683. v2p.extraV2F1 = d.extraV2F1;
  3684. // #endif
  3685. // #if %EXTRAV2F2REQUIREKEY%
  3686. // v2p.extraV2F2 = d.extraV2F2;
  3687. // #endif
  3688. // #if %EXTRAV2F3REQUIREKEY%
  3689. // v2p.extraV2F3 = d.extraV2F3;
  3690. // #endif
  3691. // #if %EXTRAV2F4REQUIREKEY%
  3692. // v2p.extraV2F4 = d.extraV2F4;
  3693. // #endif
  3694. // #if %EXTRAV2F5REQUIREKEY%
  3695. // v2p.extraV2F5 = d.extraV2F5;
  3696. // #endif
  3697. // #if %EXTRAV2F6REQUIREKEY%
  3698. // v2p.extraV2F6 = d.extraV2F6;
  3699. // #endif
  3700. // #if %EXTRAV2F7REQUIREKEY%
  3701. // v2p.extraV2F7 = d.extraV2F7;
  3702. // #endif
  3703. }
  3704. void ChainFinalColorForward(inout Surface l, inout ShaderData d, inout half4 color)
  3705. {
  3706. // Ext_FinalColorForward0(l, d, color);
  3707. // Ext_FinalColorForward1(l, d, color);
  3708. // Ext_FinalColorForward2(l, d, color);
  3709. // Ext_FinalColorForward3(l, d, color);
  3710. // Ext_FinalColorForward4(l, d, color);
  3711. // Ext_FinalColorForward5(l, d, color);
  3712. // Ext_FinalColorForward6(l, d, color);
  3713. // Ext_FinalColorForward7(l, d, color);
  3714. // Ext_FinalColorForward8(l, d, color);
  3715. // Ext_FinalColorForward9(l, d, color);
  3716. // Ext_FinalColorForward10(l, d, color);
  3717. // Ext_FinalColorForward11(l, d, color);
  3718. // Ext_FinalColorForward12(l, d, color);
  3719. // Ext_FinalColorForward13(l, d, color);
  3720. // Ext_FinalColorForward14(l, d, color);
  3721. // Ext_FinalColorForward15(l, d, color);
  3722. // Ext_FinalColorForward16(l, d, color);
  3723. // Ext_FinalColorForward17(l, d, color);
  3724. // Ext_FinalColorForward18(l, d, color);
  3725. // Ext_FinalColorForward19(l, d, color);
  3726. // Ext_FinalColorForward20(l, d, color);
  3727. // Ext_FinalColorForward21(l, d, color);
  3728. // Ext_FinalColorForward22(l, d, color);
  3729. // Ext_FinalColorForward23(l, d, color);
  3730. // Ext_FinalColorForward24(l, d, color);
  3731. // Ext_FinalColorForward25(l, d, color);
  3732. // Ext_FinalColorForward26(l, d, color);
  3733. // Ext_FinalColorForward27(l, d, color);
  3734. // Ext_FinalColorForward28(l, d, color);
  3735. // Ext_FinalColorForward29(l, d, color);
  3736. }
  3737. void ChainFinalGBufferStandard(inout Surface s, inout ShaderData d, inout half4 GBuffer0, inout half4 GBuffer1, inout half4 GBuffer2, inout half4 outEmission, inout half4 outShadowMask)
  3738. {
  3739. // Ext_FinalGBufferStandard0(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3740. // Ext_FinalGBufferStandard1(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3741. // Ext_FinalGBufferStandard2(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3742. // Ext_FinalGBufferStandard3(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3743. // Ext_FinalGBufferStandard4(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3744. // Ext_FinalGBufferStandard5(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3745. // Ext_FinalGBufferStandard6(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3746. // Ext_FinalGBufferStandard7(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3747. // Ext_FinalGBufferStandard8(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3748. // Ext_FinalGBufferStandard9(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3749. // Ext_FinalGBufferStandard10(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3750. // Ext_FinalGBufferStandard11(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3751. // Ext_FinalGBufferStandard12(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3752. // Ext_FinalGBufferStandard13(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3753. // Ext_FinalGBufferStandard14(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3754. // Ext_FinalGBufferStandard15(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3755. // Ext_FinalGBufferStandard16(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3756. // Ext_FinalGBufferStandard17(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3757. // Ext_FinalGBufferStandard18(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3758. // Ext_FinalGBufferStandard19(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3759. // Ext_FinalGBufferStandard20(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3760. // Ext_FinalGBufferStandard21(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3761. // Ext_FinalGBufferStandard22(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3762. // Ext_FinalGBufferStandard23(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3763. // Ext_FinalGBufferStandard24(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3764. // Ext_FinalGBufferStandard25(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3765. // Ext_FinalGBufferStandard26(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3766. // Ext_FinalGBufferStandard27(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3767. // Ext_FinalGBufferStandard28(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3768. // Ext_FinalGBufferStandard29(s, d, GBuffer0, GBuffer1, GBuffer2, outEmission, outShadowMask);
  3769. }
  3770. #endif
  3771. #if _DECALSHADER
  3772. ShaderData CreateShaderData(SurfaceDescriptionInputs IN)
  3773. {
  3774. ShaderData d = (ShaderData)0;
  3775. d.TBNMatrix = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);
  3776. d.worldSpaceNormal = IN.WorldSpaceNormal;
  3777. d.worldSpaceTangent = IN.WorldSpaceTangent;
  3778. d.worldSpacePosition = IN.WorldSpacePosition;
  3779. d.texcoord0 = IN.uv0.xyxy;
  3780. d.screenPos = IN.ScreenPosition;
  3781. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - d.worldSpacePosition);
  3782. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  3783. // these rarely get used, so we back transform them. Usually will be stripped.
  3784. #if _HDRP
  3785. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(d.worldSpacePosition), 1)).xyz;
  3786. #else
  3787. // d.localSpacePosition = mul(unity_WorldToObject, float4(d.worldSpacePosition, 1)).xyz;
  3788. #endif
  3789. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceNormal));
  3790. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, d.worldSpaceTangent.xyz));
  3791. // #if %SCREENPOSREQUIREKEY%
  3792. d.screenUV = (IN.ScreenPosition.xy / max(0.01, IN.ScreenPosition.w));
  3793. // #endif
  3794. return d;
  3795. }
  3796. #else
  3797. ShaderData CreateShaderData(VertexToPixel i
  3798. #if NEED_FACING
  3799. , bool facing
  3800. #endif
  3801. )
  3802. {
  3803. ShaderData d = (ShaderData)0;
  3804. d.clipPos = i.pos;
  3805. d.worldSpacePosition = i.worldPos;
  3806. d.worldSpaceNormal = normalize(i.worldNormal);
  3807. d.worldSpaceTangent.xyz = normalize(i.worldTangent.xyz);
  3808. d.tangentSign = i.worldTangent.w * unity_WorldTransformParams.w;
  3809. float3 bitangent = cross(d.worldSpaceTangent.xyz, d.worldSpaceNormal) * d.tangentSign;
  3810. d.TBNMatrix = float3x3(d.worldSpaceTangent, -bitangent, d.worldSpaceNormal);
  3811. d.worldSpaceViewDir = normalize(_WorldSpaceCameraPos - i.worldPos);
  3812. d.tangentSpaceViewDir = mul(d.TBNMatrix, d.worldSpaceViewDir);
  3813. d.texcoord0 = i.texcoord0;
  3814. // d.texcoord1 = i.texcoord1;
  3815. // d.texcoord2 = i.texcoord2;
  3816. // #if %TEXCOORD3REQUIREKEY%
  3817. // d.texcoord3 = i.texcoord3;
  3818. // #endif
  3819. // d.isFrontFace = facing;
  3820. // #if %VERTEXCOLORREQUIREKEY%
  3821. d.vertexColor = i.vertexColor;
  3822. // #endif
  3823. // these rarely get used, so we back transform them. Usually will be stripped.
  3824. #if _HDRP
  3825. // d.localSpacePosition = mul(unity_WorldToObject, float4(GetCameraRelativePositionWS(i.worldPos), 1)).xyz;
  3826. #else
  3827. // d.localSpacePosition = mul(unity_WorldToObject, float4(i.worldPos, 1)).xyz;
  3828. #endif
  3829. // d.localSpaceNormal = normalize(mul((float3x3)unity_WorldToObject, i.worldNormal));
  3830. // d.localSpaceTangent = normalize(mul((float3x3)unity_WorldToObject, i.worldTangent.xyz));
  3831. // #if %SCREENPOSREQUIREKEY%
  3832. d.screenPos = i.screenPos;
  3833. d.screenUV = (i.screenPos.xy / i.screenPos.w);
  3834. // #endif
  3835. // #if %EXTRAV2F0REQUIREKEY%
  3836. d.extraV2F0 = i.extraV2F0;
  3837. // #endif
  3838. // #if %EXTRAV2F1REQUIREKEY%
  3839. d.extraV2F1 = i.extraV2F1;
  3840. // #endif
  3841. // #if %EXTRAV2F2REQUIREKEY%
  3842. // d.extraV2F2 = i.extraV2F2;
  3843. // #endif
  3844. // #if %EXTRAV2F3REQUIREKEY%
  3845. // d.extraV2F3 = i.extraV2F3;
  3846. // #endif
  3847. // #if %EXTRAV2F4REQUIREKEY%
  3848. // d.extraV2F4 = i.extraV2F4;
  3849. // #endif
  3850. // #if %EXTRAV2F5REQUIREKEY%
  3851. // d.extraV2F5 = i.extraV2F5;
  3852. // #endif
  3853. // #if %EXTRAV2F6REQUIREKEY%
  3854. // d.extraV2F6 = i.extraV2F6;
  3855. // #endif
  3856. // #if %EXTRAV2F7REQUIREKEY%
  3857. // d.extraV2F7 = i.extraV2F7;
  3858. // #endif
  3859. return d;
  3860. }
  3861. #endif
  3862. #if defined(_PASSSHADOW)
  3863. float3 _LightDirection;
  3864. float3 _LightPosition;
  3865. #endif
  3866. // vertex shader
  3867. VertexToPixel Vert (VertexData v)
  3868. {
  3869. VertexToPixel o = (VertexToPixel)0;
  3870. UNITY_SETUP_INSTANCE_ID(v);
  3871. UNITY_TRANSFER_INSTANCE_ID(v, o);
  3872. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  3873. #if !_TESSELLATION_ON
  3874. ChainModifyVertex(v, o, _Time);
  3875. #endif
  3876. o.texcoord0 = v.texcoord0;
  3877. // o.texcoord1 = v.texcoord1;
  3878. // o.texcoord2 = v.texcoord2;
  3879. // #if %TEXCOORD3REQUIREKEY%
  3880. // o.texcoord3 = v.texcoord3;
  3881. // #endif
  3882. // #if %VERTEXCOLORREQUIREKEY%
  3883. o.vertexColor = v.vertexColor;
  3884. // #endif
  3885. VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);
  3886. o.worldPos = TransformObjectToWorld(v.vertex.xyz);
  3887. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  3888. o.worldTangent = float4(TransformObjectToWorldDir(v.tangent.xyz), v.tangent.w);
  3889. // For some very odd reason, in 2021.2, we can't use Unity's defines, but have to use our own..
  3890. #if _PASSSHADOW
  3891. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  3892. float3 lightDirectionWS = normalize(_LightPosition - o.worldPos);
  3893. #else
  3894. float3 lightDirectionWS = _LightDirection;
  3895. #endif
  3896. // Define shadow pass specific clip position for Universal
  3897. o.pos = TransformWorldToHClip(ApplyShadowBias(o.worldPos, o.worldNormal, lightDirectionWS));
  3898. #if UNITY_REVERSED_Z
  3899. o.pos.z = min(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  3900. #else
  3901. o.pos.z = max(o.pos.z, UNITY_NEAR_CLIP_VALUE);
  3902. #endif
  3903. #elif _PASSMETA
  3904. o.pos = MetaVertexPosition(float4(v.vertex.xyz, 0), v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST);
  3905. #else
  3906. o.pos = TransformWorldToHClip(o.worldPos);
  3907. #endif
  3908. // #if %SCREENPOSREQUIREKEY%
  3909. o.screenPos = ComputeScreenPos(o.pos, _ProjectionParams.x);
  3910. // #endif
  3911. #if _PASSFORWARD || _PASSGBUFFER
  3912. float2 uv1 = v.texcoord1.xy;
  3913. OUTPUT_LIGHTMAP_UV(uv1, unity_LightmapST, o.lightmapUV);
  3914. // o.texcoord1.xy = uv1;
  3915. OUTPUT_SH(o.worldNormal, o.sh);
  3916. #if defined(DYNAMICLIGHTMAP_ON)
  3917. o.dynamicLightmapUV.xy = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  3918. #endif
  3919. #endif
  3920. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  3921. half fogFactor = 0;
  3922. #if defined(_FOG_FRAGMENT)
  3923. fogFactor = ComputeFogFactor(o.pos.z);
  3924. #endif
  3925. #if _BAKEDLIT
  3926. o.fogFactorAndVertexLight = half4(fogFactor, 0, 0, 0);
  3927. #else
  3928. half3 vertexLight = VertexLighting(o.worldPos, o.worldNormal);
  3929. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  3930. #endif
  3931. #endif
  3932. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  3933. o.shadowCoord = GetShadowCoord(vertexInput);
  3934. #endif
  3935. return o;
  3936. }
  3937. // fragment shader
  3938. half4 Frag (VertexToPixel IN
  3939. #ifdef _DEPTHOFFSET_ON
  3940. , out float outputDepth : SV_Depth
  3941. #endif
  3942. #if NEED_FACING
  3943. , bool facing : SV_IsFrontFace
  3944. #endif
  3945. ) : SV_Target
  3946. {
  3947. UNITY_SETUP_INSTANCE_ID(IN);
  3948. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  3949. ShaderData d = CreateShaderData(IN
  3950. #if NEED_FACING
  3951. , facing
  3952. #endif
  3953. );
  3954. Surface l = (Surface)0;
  3955. #ifdef _DEPTHOFFSET_ON
  3956. l.outputDepth = outputDepth;
  3957. #endif
  3958. l.Albedo = half3(0.5, 0.5, 0.5);
  3959. l.Normal = float3(0,0,1);
  3960. l.Occlusion = 1;
  3961. l.Alpha = 1;
  3962. ChainSurfaceFunction(l, d);
  3963. #ifdef _DEPTHOFFSET_ON
  3964. outputDepth = l.outputDepth;
  3965. #endif
  3966. #if defined(_GBUFFER_NORMALS_OCT)
  3967. float3 normalWS = d.worldSpaceNormal;
  3968. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
  3969. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  3970. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  3971. return half4(packedNormalWS, 0.0);
  3972. #else
  3973. float3 wsn = l.Normal;
  3974. #if !_WORLDSPACENORMAL
  3975. wsn = TangentToWorldSpace(d, l.Normal);
  3976. #endif
  3977. return half4(NormalizeNormalPerPixel(wsn), 0.0);
  3978. #endif
  3979. }
  3980. ENDHLSL
  3981. }
  3982. }
  3983. }