Decal.shader 153 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965
  1. Shader /*ase_name*/"Hidden/Universal/Decal"/*end*/
  2. {
  3. Properties
  4. {
  5. /*ase_props*/
  6. [HideInInspector] _DrawOrder("Draw Order", Range(-50, 50)) = 0
  7. [HideInInspector][Enum(Depth Bias, 0, View Bias, 1)] _DecalMeshBiasType("DecalMesh BiasType", Float) = 0
  8. [HideInInspector] _DecalMeshDepthBias("DecalMesh DepthBias", Float) = 0
  9. [HideInInspector] _DecalMeshViewBias("DecalMesh ViewBias", Float) = 0
  10. [HideInInspector][NoScaleOffset] unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
  11. [HideInInspector][NoScaleOffset] unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
  12. [HideInInspector][NoScaleOffset] unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
  13. //_DecalAngleFadeSupported("Decal Angle Fade Supported", Float) = 1
  14. }
  15. SubShader
  16. {
  17. /*ase_subshader_options:Name=Additional Options
  18. Option:Affect BaseColor:false,true:true
  19. true:SetDefine:_MATERIAL_AFFECTS_ALBEDO 1
  20. false:RemoveDefine:_MATERIAL_AFFECTS_ALBEDO 1
  21. Option:Affect Normal:false,true:true
  22. true:SetDefine:_MATERIAL_AFFECTS_NORMAL 1
  23. true:SetPropertyOnPass:DBufferProjector:ColorMask1,true,true,true,true
  24. true:SetPropertyOnPass:DecalGBufferProjector:ColorMask2,true,true,true,false
  25. true:SetPropertyOnPass:DBufferMesh:ColorMask1,true,true,true,true
  26. true:SetPropertyOnPass:DecalGBufferMesh:ColorMask2,true,true,true,false
  27. false:RemoveDefine:_MATERIAL_AFFECTS_NORMAL 1
  28. false:SetPropertyOnPass:DBufferProjector:ColorMask1,false,false,false,false
  29. false:SetPropertyOnPass:DecalGBufferProjector:ColorMask2,false,false,false,false
  30. false:SetPropertyOnPass:DBufferMesh:ColorMask1,false,false,false,false
  31. false:SetPropertyOnPass:DecalGBufferMesh:ColorMask2,false,false,false,false
  32. Option:Blend:false,true:true
  33. true:SetDefine:_MATERIAL_AFFECTS_NORMAL_BLEND 1
  34. false:RemoveDefine:_MATERIAL_AFFECTS_NORMAL_BLEND 1
  35. Option:Affect MAOS:false,true:false
  36. true:SetDefine: _MATERIAL_AFFECTS_MAOS 1
  37. true:ShowPort:DecalScreenSpaceProjector:Metallic
  38. true:ShowPort:DecalScreenSpaceProjector:Occlusion
  39. true:ShowPort:DecalScreenSpaceProjector:Smoothness
  40. true:ShowPort:DecalScreenSpaceProjector:MAOS Alpha
  41. false:RemoveDefine: _MATERIAL_AFFECTS_MAOS 1
  42. false:HidePort:DecalScreenSpaceProjector:Metallic
  43. false:HidePort:DecalScreenSpaceProjector:Occlusion
  44. false:HidePort:DecalScreenSpaceProjector:Smoothness
  45. false:HidePort:DecalScreenSpaceProjector:MAOS Alpha
  46. Option:Affect Emission:false,true:false
  47. true:SetDefine:_MATERIAL_AFFECTS_EMISSION 1
  48. true:IncludePass:DecalProjectorForwardEmissive
  49. true:IncludePass:DecalMeshForwardEmissive
  50. true:ShowPort:DecalScreenSpaceProjector:Emission
  51. false:RemoveDefine:_MATERIAL_AFFECTS_EMISSION 1
  52. false:ExcludePass:DecalProjectorForwardEmissive
  53. false:ExcludePass:DecalMeshForwardEmissive
  54. false:HidePort:DecalScreenSpaceProjector:Emission
  55. Option:Support LOD CrossFade:false,true:false
  56. true:SetDefine:DBufferMesh:USE_UNITY_CROSSFADE 1
  57. true:SetDefine:DecalScreenSpaceMesh:USE_UNITY_CROSSFADE 1
  58. true:SetDefine:DecalProjectorForwardEmissive:USE_UNITY_CROSSFADE 1
  59. true:SetDefine:DecalGBufferMesh:USE_UNITY_CROSSFADE 1
  60. true:SetDefine:DBufferMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  61. true:SetDefine:DecalScreenSpaceMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  62. true:SetDefine:DecalProjectorForwardEmissive:pragma multi_compile _ LOD_FADE_CROSSFADE
  63. true:SetDefine:DecalGBufferMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  64. false:RemoveDefine:DBufferMesh:USE_UNITY_CROSSFADE 1
  65. false:RemoveDefine:DecalScreenSpaceMesh:USE_UNITY_CROSSFADE 1
  66. false:RemoveDefine:DecalProjectorForwardEmissive:USE_UNITY_CROSSFADE 1
  67. false:RemoveDefine:DecalGBufferMesh:USE_UNITY_CROSSFADE 1
  68. false:RemoveDefine:DBufferMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  69. false:RemoveDefine:DecalScreenSpaceMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  70. false:RemoveDefine:DecalProjectorForwardEmissive:pragma multi_compile _ LOD_FADE_CROSSFADE
  71. false:RemoveDefine:DecalGBufferMesh:pragma multi_compile _ LOD_FADE_CROSSFADE
  72. Option:Angle Fade:false,true:true
  73. true:SetDefine:DBufferProjector:DECAL_ANGLE_FADE 1
  74. true:SetDefine:DecalScreenSpaceProjector:DECAL_ANGLE_FADE 1
  75. true:SetDefine:DecalProjectorForwardEmissive:DECAL_ANGLE_FADE 1
  76. true:SetDefine:DecalGBufferProjector:DECAL_ANGLE_FADE 1
  77. true:SetDefine:DBufferProjector:DECAL_ANGLE_FADE 1
  78. false:RemoveDefine:DBufferProjector:DECAL_ANGLE_FADE 1
  79. false:RemoveDefine:DecalScreenSpaceProjector:DECAL_ANGLE_FADE 1
  80. false:RemoveDefine:DecalProjectorForwardEmissive:DECAL_ANGLE_FADE 1
  81. false:RemoveDefine:DecalGBufferProjector:DECAL_ANGLE_FADE 1
  82. false:RemoveDefine:DBufferProjector:DECAL_ANGLE_FADE 1
  83. true:SetShaderProperty:_DecalAngleFadeSupported,[HideInInspector] _DecalAngleFadeSupported("Decal Angle Fade Supported", Float) = 1
  84. false:SetShaderProperty:_DecalAngleFadeSupported,//[HideInInspector] _DecalAngleFadeSupported("Decal Angle Fade Supported", Float) = 1
  85. */
  86. Tags
  87. {
  88. "RenderPipeline"="UniversalPipeline"
  89. "PreviewType"="Plane"
  90. "DisableBatching" = "LODFading"
  91. "ShaderGraphShader"="true"
  92. "ShaderGraphTargetId" = "UniversalDecalSubTarget"
  93. }
  94. HLSLINCLUDE
  95. #pragma target 3.5
  96. #pragma prefer_hlslcc gles
  97. #pragma exclude_renderers d3d9 // ensure rendering platforms toggle list is visible
  98. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  99. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
  100. ENDHLSL
  101. /*ase_pass*/
  102. Pass
  103. {
  104. /*ase_hide_pass*/
  105. Name "DBufferProjector"
  106. Tags
  107. {
  108. "LightMode" = "DBufferProjector"
  109. }
  110. Cull Front
  111. Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  112. Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  113. Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  114. ZTest Greater
  115. ZWrite Off
  116. ColorMask RGBA
  117. ColorMask RGBA 1
  118. ColorMask RGBA 2
  119. HLSLPROGRAM
  120. #pragma vertex Vert
  121. #pragma fragment Frag
  122. #pragma exclude_renderers gles gles3 glcore
  123. #pragma multi_compile_instancing
  124. #pragma editor_sync_compilation
  125. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  126. #pragma multi_compile _ _DECAL_LAYERS
  127. /*ase_srp_cond_begin:<140010*/
  128. #pragma multi_compile_fragment _ _FOVEATED_RENDERING_NON_UNIFORM_RASTER
  129. /*ase_srp_cond_end*/
  130. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  131. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  132. #define HAVE_MESH_MODIFICATION
  133. #define SHADERPASS SHADERPASS_DBUFFER_PROJECTOR
  134. #if _RENDER_PASS_ENABLED
  135. #define GBUFFER3 0
  136. #define GBUFFER4 1
  137. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  138. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  139. #endif
  140. /*ase_srp_cond_begin:<140007*/
  141. #pragma multi_compile _ DOTS_INSTANCING_ON
  142. /*ase_srp_cond_end*/
  143. /*ase_srp_cond_begin:>=140007*/
  144. #if ASE_SRP_VERSION >=140007
  145. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  146. #endif
  147. /*ase_srp_cond_end*/
  148. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  149. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  150. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  151. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  152. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  153. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  154. /*ase_unity_cond_begin:>=20220316*/
  155. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  156. /*ase_unity_cond_end*/
  157. /*ase_unity_cond_begin:>=20220316*/
  158. #if ASE_SRP_VERSION >=140009
  159. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  160. #endif
  161. /*ase_unity_cond_end*/
  162. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  163. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  164. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  165. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  166. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  167. #if defined(LOD_FADE_CROSSFADE)
  168. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  169. #endif
  170. /*ase_pragma*/
  171. struct SurfaceDescription
  172. {
  173. float3 BaseColor;
  174. float Alpha;
  175. float3 NormalTS;
  176. float NormalAlpha;
  177. float Metallic;
  178. float Occlusion;
  179. float Smoothness;
  180. float MAOSAlpha;
  181. };
  182. struct Attributes
  183. {
  184. float3 positionOS : POSITION;
  185. float3 normalOS : NORMAL;
  186. float4 tangentOS : TANGENT;
  187. /*ase_vdata:p=p;n=n;t=t*/
  188. UNITY_VERTEX_INPUT_INSTANCE_ID
  189. };
  190. struct PackedVaryings
  191. {
  192. float4 positionCS : SV_POSITION;
  193. /*ase_interp(0,):sp=sp*/
  194. UNITY_VERTEX_INPUT_INSTANCE_ID
  195. UNITY_VERTEX_OUTPUT_STEREO
  196. };
  197. CBUFFER_START(UnityPerMaterial)
  198. float _DrawOrder;
  199. float _DecalMeshBiasType;
  200. float _DecalMeshDepthBias;
  201. float _DecalMeshViewBias;
  202. #if defined(DECAL_ANGLE_FADE)
  203. float _DecalAngleFadeSupported;
  204. #endif
  205. CBUFFER_END
  206. #ifdef SCENEPICKINGPASS
  207. float4 _SelectionID;
  208. #endif
  209. #ifdef SCENESELECTIONPASS
  210. int _ObjectId;
  211. int _PassValue;
  212. #endif
  213. /*ase_globals*/
  214. /*ase_funcs*/
  215. void GetSurfaceData(SurfaceDescription surfaceDescription, float angleFadeFactor, out DecalSurfaceData surfaceData)
  216. {
  217. half4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  218. half fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f) * angleFadeFactor;
  219. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  220. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  221. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  222. surfaceData.occlusion = half(1.0);
  223. surfaceData.smoothness = half(0);
  224. #ifdef _MATERIAL_AFFECTS_NORMAL
  225. surfaceData.normalWS.w = half(1.0);
  226. #else
  227. surfaceData.normalWS.w = half(0.0);
  228. #endif
  229. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  230. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  231. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  232. #if defined(_MATERIAL_AFFECTS_NORMAL)
  233. /*ase_unity_cond_begin:<20220310*/
  234. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  235. /*ase_unity_cond_end*/
  236. /*ase_unity_cond_begin:>=20220310*/
  237. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  238. /*ase_unity_cond_end*/
  239. #else
  240. /*ase_unity_cond_begin:<20220310*/
  241. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  242. /*ase_unity_cond_end*/
  243. /*ase_unity_cond_begin:>=20220310*/
  244. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  245. /*ase_unity_cond_end*/
  246. #endif
  247. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  248. #if defined(_MATERIAL_AFFECTS_NORMAL)
  249. float sgn = input.tangentWS.w;
  250. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  251. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  252. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  253. #else
  254. /*ase_unity_cond_begin:<20220310*/
  255. surfaceData.normalWS.xyz = half3(input.normalWS);
  256. /*ase_unity_cond_end*/
  257. /*ase_unity_cond_begin:>=20220310*/
  258. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  259. /*ase_unity_cond_end*/
  260. #endif
  261. #endif
  262. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  263. #if defined( _MATERIAL_AFFECTS_MAOS )
  264. surfaceData.metallic = half(surfaceDescription.Metallic);
  265. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  266. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  267. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  268. #endif
  269. }
  270. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  271. #define DECAL_PROJECTOR
  272. #endif
  273. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  274. #define DECAL_MESH
  275. #endif
  276. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  277. #define DECAL_DBUFFER
  278. #endif
  279. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  280. #define DECAL_SCREEN_SPACE
  281. #endif
  282. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  283. #define DECAL_GBUFFER
  284. #endif
  285. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  286. #define DECAL_FORWARD_EMISSIVE
  287. #endif
  288. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  289. #define DECAL_RECONSTRUCT_NORMAL
  290. #elif defined(DECAL_ANGLE_FADE)
  291. #define DECAL_LOAD_NORMAL
  292. #endif
  293. #ifdef _DECAL_LAYERS
  294. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  295. #endif
  296. #if defined(DECAL_LOAD_NORMAL)
  297. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  298. #endif
  299. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  300. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  301. #endif
  302. #ifdef DECAL_MESH
  303. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  304. #endif
  305. #ifdef DECAL_RECONSTRUCT_NORMAL
  306. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  307. #endif
  308. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  309. {
  310. PackedVaryings packedOutput;
  311. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  312. UNITY_SETUP_INSTANCE_ID(inputMesh);
  313. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  314. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  315. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  316. inputMesh.normalOS = float3( 0, 1, 0 );
  317. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  318. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  319. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  320. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  321. return packedOutput;
  322. }
  323. void Frag(PackedVaryings packedInput,
  324. OUTPUT_DBUFFER(outDBuffer)
  325. /*ase_frag_input*/
  326. )
  327. {
  328. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  329. UNITY_SETUP_INSTANCE_ID(packedInput);
  330. half angleFadeFactor = 1.0;
  331. #ifdef _DECAL_LAYERS
  332. #ifdef _RENDER_PASS_ENABLED
  333. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  334. #else
  335. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  336. #endif
  337. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  338. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  339. #endif
  340. #if defined(DECAL_PROJECTOR)
  341. #if UNITY_REVERSED_Z
  342. #if _RENDER_PASS_ENABLED
  343. float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy).x;
  344. #else
  345. float depth = LoadSceneDepth(packedInput.positionCS.xy);
  346. #endif
  347. #else
  348. #if _RENDER_PASS_ENABLED
  349. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy));
  350. #else
  351. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(packedInput.positionCS.xy));
  352. #endif
  353. #endif
  354. #endif
  355. #if defined(DECAL_RECONSTRUCT_NORMAL)
  356. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  357. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  358. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  359. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  360. #else
  361. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  362. #endif
  363. #elif defined(DECAL_LOAD_NORMAL)
  364. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  365. #endif
  366. /*ase_unity_cond_begin:<20220352*/
  367. #if ASE_SRP_VERSION <=140011
  368. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  369. #endif
  370. /*ase_unity_cond_end*/
  371. /*ase_unity_cond_begin:>=20220352*/
  372. #if ASE_SRP_VERSION >=140011
  373. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  374. #endif
  375. /*ase_unity_cond_end*/
  376. /*ase_local_var:sp*/float4 positionCS = ComputeClipSpacePosition( positionSS, depth );
  377. float4 hpositionVS = mul( UNITY_MATRIX_I_P, positionCS );
  378. /*ase_local_var:rwp*/float3 positionRWS = mul( ( float3x3 )UNITY_MATRIX_I_V, hpositionVS.xyz / hpositionVS.w );
  379. /*ase_local_var:wp*/float3 positionWS = positionRWS + _WorldSpaceCameraPos;
  380. /*ase_local_var:op*/float3 positionOS = TransformWorldToObject( positionWS );
  381. /*ase_local_var:vp*/float3 positionVS = TransformWorldToView( positionWS );
  382. float3 positionDS = TransformWorldToObject(positionWS);
  383. positionDS = positionDS * float3(1.0, -1.0, 1.0);
  384. float clipValue = 0.5 - Max3(abs(positionDS).x, abs(positionDS).y, abs(positionDS).z);
  385. clip(clipValue);
  386. float2 texCoord = positionDS.xz + float2(0.5, 0.5);
  387. float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  388. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  389. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  390. texCoord.xy = texCoord.xy * scale + offset;
  391. /*ase_local_var:uv0*/float2 texCoord0 = texCoord;
  392. /*ase_local_var:uv1*/float2 texCoord1 = texCoord;
  393. /*ase_local_var:uv2*/float2 texCoord2 = texCoord;
  394. /*ase_local_var:uv3*/float2 texCoord3 = texCoord;
  395. /*ase_local_var:wt*/float3 worldTangent = TransformObjectToWorldDir(float3(1, 0, 0));
  396. /*ase_local_var:wn*/float3 worldNormal = TransformObjectToWorldDir(float3(0, 1, 0));
  397. /*ase_local_var:wbt*/float3 worldBitangent = TransformObjectToWorldDir(float3(0, 0, 1));
  398. #ifdef DECAL_ANGLE_FADE
  399. half2 angleFade = half2(normalToWorld[1][3], normalToWorld[2][3]);
  400. if (angleFade.y < 0.0f)
  401. {
  402. half3 decalNormal = half3(normalToWorld[0].z, normalToWorld[1].z, normalToWorld[2].z);
  403. half dotAngle = dot(normalWS, decalNormal);
  404. angleFadeFactor = saturate(angleFade.x + angleFade.y * (dotAngle * (dotAngle - 2.0)));
  405. }
  406. #endif
  407. half3 viewDirectionWS = half3(1.0, 1.0, 1.0);
  408. DecalSurfaceData surfaceData;
  409. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  410. /*ase_frag_code:packedInput=PackedVaryings*/
  411. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  412. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  413. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  414. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  415. #if defined( _MATERIAL_AFFECTS_MAOS )
  416. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  417. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  418. surfaceDescription.Smoothness =/*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/ 0.5/*end*/;
  419. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  420. #endif
  421. GetSurfaceData(surfaceDescription, angleFadeFactor, surfaceData);
  422. ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
  423. /*ase_unity_cond_begin:<20220352*/
  424. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  425. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  426. {
  427. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  428. }
  429. #endif
  430. /*ase_unity_cond_end*/
  431. }
  432. ENDHLSL
  433. }
  434. /*ase_pass*/
  435. Pass
  436. {
  437. /*ase_hide_pass*/
  438. Name "DecalProjectorForwardEmissive"
  439. Tags
  440. {
  441. "LightMode" = "DecalProjectorForwardEmissive"
  442. }
  443. Cull Front
  444. Blend 0 SrcAlpha One
  445. ZTest Greater
  446. ZWrite Off
  447. HLSLPROGRAM
  448. #pragma vertex Vert
  449. #pragma fragment Frag
  450. #pragma multi_compile_instancing
  451. #pragma editor_sync_compilation
  452. #pragma multi_compile _ _DECAL_LAYERS
  453. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  454. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  455. #define HAVE_MESH_MODIFICATION
  456. #define SHADERPASS SHADERPASS_FORWARD_EMISSIVE_PROJECTOR
  457. #if _RENDER_PASS_ENABLED
  458. #define GBUFFER3 0
  459. #define GBUFFER4 1
  460. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  461. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  462. #endif
  463. /*ase_srp_cond_begin:<140007*/
  464. #pragma multi_compile _ DOTS_INSTANCING_ON
  465. /*ase_srp_cond_end*/
  466. /*ase_srp_cond_begin:>=140007*/
  467. #if ASE_SRP_VERSION >=140007
  468. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  469. #endif
  470. /*ase_srp_cond_end*/
  471. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  472. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  473. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  474. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  475. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  476. /*ase_unity_cond_begin:>=20220316*/
  477. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  478. /*ase_unity_cond_end*/
  479. /*ase_unity_cond_begin:>=20220316*/
  480. #if ASE_SRP_VERSION >=140009
  481. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  482. #endif
  483. /*ase_unity_cond_end*/
  484. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  485. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  486. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  487. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  488. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  489. #if defined(LOD_FADE_CROSSFADE)
  490. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  491. #endif
  492. /*ase_pragma*/
  493. struct SurfaceDescription
  494. {
  495. float Alpha;
  496. float3 Emission;
  497. };
  498. struct Attributes
  499. {
  500. float3 positionOS : POSITION;
  501. float3 normalOS : NORMAL;
  502. float4 tangentOS : TANGENT;
  503. /*ase_vdata:p=p;n=n;t=t*/
  504. UNITY_VERTEX_INPUT_INSTANCE_ID
  505. };
  506. struct PackedVaryings
  507. {
  508. float4 positionCS : SV_POSITION;
  509. /*ase_interp(0,):sp=sp*/
  510. UNITY_VERTEX_INPUT_INSTANCE_ID
  511. UNITY_VERTEX_OUTPUT_STEREO
  512. };
  513. CBUFFER_START(UnityPerMaterial)
  514. float _DrawOrder;
  515. float _DecalMeshBiasType;
  516. float _DecalMeshDepthBias;
  517. float _DecalMeshViewBias;
  518. #if defined(DECAL_ANGLE_FADE)
  519. float _DecalAngleFadeSupported;
  520. #endif
  521. CBUFFER_END
  522. #ifdef SCENEPICKINGPASS
  523. float4 _SelectionID;
  524. #endif
  525. #ifdef SCENESELECTIONPASS
  526. int _ObjectId;
  527. int _PassValue;
  528. #endif
  529. /*ase_globals*/
  530. /*ase_funcs*/
  531. void GetSurfaceData(SurfaceDescription surfaceDescription, float angleFadeFactor, out DecalSurfaceData surfaceData)
  532. {
  533. half4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  534. half fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f) * angleFadeFactor;
  535. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  536. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  537. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  538. surfaceData.occlusion = half(1.0);
  539. surfaceData.smoothness = half(0);
  540. #ifdef _MATERIAL_AFFECTS_NORMAL
  541. surfaceData.normalWS.w = half(1.0);
  542. #else
  543. surfaceData.normalWS.w = half(0.0);
  544. #endif
  545. #if defined( _MATERIAL_AFFECTS_EMISSION )
  546. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  547. #endif
  548. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  549. }
  550. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  551. #define DECAL_PROJECTOR
  552. #endif
  553. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  554. #define DECAL_MESH
  555. #endif
  556. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  557. #define DECAL_DBUFFER
  558. #endif
  559. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  560. #define DECAL_SCREEN_SPACE
  561. #endif
  562. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  563. #define DECAL_GBUFFER
  564. #endif
  565. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  566. #define DECAL_FORWARD_EMISSIVE
  567. #endif
  568. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  569. #define DECAL_RECONSTRUCT_NORMAL
  570. #elif defined(DECAL_ANGLE_FADE)
  571. #define DECAL_LOAD_NORMAL
  572. #endif
  573. #ifdef _DECAL_LAYERS
  574. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  575. #endif
  576. #if defined(DECAL_LOAD_NORMAL)
  577. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  578. #endif
  579. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  580. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  581. #endif
  582. #ifdef DECAL_MESH
  583. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  584. #endif
  585. #ifdef DECAL_RECONSTRUCT_NORMAL
  586. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  587. #endif
  588. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  589. {
  590. PackedVaryings packedOutput;
  591. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  592. UNITY_SETUP_INSTANCE_ID(inputMesh);
  593. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  594. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  595. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  596. inputMesh.normalOS = float3( 0, 1, 0 );
  597. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  598. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  599. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  600. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  601. return packedOutput;
  602. }
  603. void Frag(PackedVaryings packedInput,
  604. out half4 outEmissive : SV_Target0
  605. /*ase_frag_input*/
  606. )
  607. {
  608. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  609. UNITY_SETUP_INSTANCE_ID(packedInput);
  610. half angleFadeFactor = 1.0;
  611. #ifdef _DECAL_LAYERS
  612. #ifdef _RENDER_PASS_ENABLED
  613. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  614. #else
  615. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  616. #endif
  617. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  618. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  619. #endif
  620. #if defined(DECAL_PROJECTOR)
  621. #if UNITY_REVERSED_Z
  622. #if _RENDER_PASS_ENABLED
  623. float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy).x;
  624. #else
  625. float depth = LoadSceneDepth(packedInput.positionCS.xy);
  626. #endif
  627. #else
  628. #if _RENDER_PASS_ENABLED
  629. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy));
  630. #else
  631. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(packedInput.positionCS.xy));
  632. #endif
  633. #endif
  634. #endif
  635. #if defined(DECAL_RECONSTRUCT_NORMAL)
  636. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  637. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  638. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  639. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  640. #else
  641. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  642. #endif
  643. #elif defined(DECAL_LOAD_NORMAL)
  644. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  645. #endif
  646. /*ase_unity_cond_begin:<20220352*/
  647. #if ASE_SRP_VERSION <=140011
  648. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  649. #endif
  650. /*ase_unity_cond_end*/
  651. /*ase_unity_cond_begin:>=20220352*/
  652. #if ASE_SRP_VERSION >=140011
  653. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  654. #endif
  655. /*ase_unity_cond_end*/
  656. /*ase_local_var:sp*/float4 positionCS = ComputeClipSpacePosition( positionSS, depth );
  657. float4 hpositionVS = mul( UNITY_MATRIX_I_P, positionCS );
  658. /*ase_local_var:rwp*/float3 positionRWS = mul( ( float3x3 )UNITY_MATRIX_I_V, hpositionVS.xyz / hpositionVS.w );
  659. /*ase_local_var:wp*/float3 positionWS = positionRWS + _WorldSpaceCameraPos;
  660. /*ase_local_var:op*/float3 positionOS = TransformWorldToObject( positionWS );
  661. /*ase_local_var:vp*/float3 positionVS = TransformWorldToView( positionWS );
  662. float3 positionDS = TransformWorldToObject(positionWS);
  663. positionDS = positionDS * float3(1.0, -1.0, 1.0);
  664. float clipValue = 0.5 - Max3(abs(positionDS).x, abs(positionDS).y, abs(positionDS).z);
  665. clip(clipValue);
  666. float2 texCoord = positionDS.xz + float2(0.5, 0.5);
  667. float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  668. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  669. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  670. texCoord.xy = texCoord.xy * scale + offset;
  671. #ifdef DECAL_ANGLE_FADE
  672. half2 angleFade = half2(normalToWorld[1][3], normalToWorld[2][3]);
  673. if (angleFade.y < 0.0f)
  674. {
  675. half3 decalNormal = half3(normalToWorld[0].z, normalToWorld[1].z, normalToWorld[2].z);
  676. half dotAngle = dot(normalWS, decalNormal);
  677. angleFadeFactor = saturate(angleFade.x + angleFade.y * (dotAngle * (dotAngle - 2.0)));
  678. }
  679. #endif
  680. half3 viewDirectionWS = half3(1.0, 1.0, 1.0);
  681. DecalSurfaceData surfaceData;
  682. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  683. /*ase_local_var:uv0*/float2 texCoord0 = texCoord;
  684. /*ase_local_var:uv1*/float2 texCoord1 = texCoord;
  685. /*ase_local_var:uv2*/float2 texCoord2 = texCoord;
  686. /*ase_local_var:uv3*/float2 texCoord3 = texCoord;
  687. /*ase_local_var:wt*/float3 worldTangent = TransformObjectToWorldDir(float3(1, 0, 0));
  688. /*ase_local_var:wn*/float3 worldNormal = TransformObjectToWorldDir(float3(0, 1, 0));
  689. /*ase_local_var:wbt*/float3 worldBitangent = TransformObjectToWorldDir(float3(0, 0, 1));
  690. /*ase_frag_code:packedInput=PackedVaryings*/
  691. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;0;-1;_Alpha*/1/*end*/;
  692. #if defined( _MATERIAL_AFFECTS_EMISSION )
  693. surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;1;-1;_Emission*/float3(0, 0, 0)/*end*/;
  694. #endif
  695. GetSurfaceData( surfaceDescription, angleFadeFactor, surfaceData);
  696. outEmissive.rgb = surfaceData.emissive;
  697. outEmissive.a = surfaceData.baseColor.a;
  698. /*ase_unity_cond_begin:<20220352*/
  699. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  700. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  701. {
  702. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  703. }
  704. #endif
  705. /*ase_unity_cond_end*/
  706. }
  707. ENDHLSL
  708. }
  709. /*ase_pass*/
  710. Pass
  711. {
  712. /*ase_main_pass*/
  713. Name "DecalScreenSpaceProjector"
  714. Tags
  715. {
  716. "LightMode" = "DecalScreenSpaceProjector"
  717. }
  718. Cull Front
  719. Blend SrcAlpha OneMinusSrcAlpha
  720. ZTest Greater
  721. ZWrite Off
  722. HLSLPROGRAM
  723. #pragma vertex Vert
  724. #pragma fragment Frag
  725. #pragma multi_compile_instancing
  726. #pragma multi_compile_fog
  727. #pragma editor_sync_compilation
  728. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  729. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  730. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  731. /*ase_srp_cond_begin:<140009*/
  732. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  733. /*ase_srp_cond_end*/
  734. /*ase_srp_cond_begin:>=140009*/
  735. #pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
  736. /*ase_srp_cond_end*/
  737. #pragma multi_compile _ _FORWARD_PLUS
  738. /*ase_unity_cond_begin:>=20220325*/
  739. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  740. /*ase_unity_cond_end*/
  741. /*ase_srp_cond_begin:<140010*/
  742. #pragma multi_compile_fragment _ _FOVEATED_RENDERING_NON_UNIFORM_RASTER
  743. /*ase_srp_cond_end*/
  744. #pragma multi_compile _DECAL_NORMAL_BLEND_LOW _DECAL_NORMAL_BLEND_MEDIUM _DECAL_NORMAL_BLEND_HIGH
  745. #pragma multi_compile _ _DECAL_LAYERS
  746. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  747. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  748. #define ATTRIBUTES_NEED_NORMAL
  749. #define ATTRIBUTES_NEED_TEXCOORD0
  750. #define VARYINGS_NEED_NORMAL_WS
  751. #define VARYINGS_NEED_TEXCOORD0
  752. #define VARYINGS_NEED_VIEWDIRECTION_WS
  753. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  754. #define VARYINGS_NEED_SH
  755. #define VARYINGS_NEED_STATIC_LIGHTMAP_UV
  756. #define VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV
  757. #define HAVE_MESH_MODIFICATION
  758. #define SHADERPASS SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR
  759. #if _RENDER_PASS_ENABLED
  760. #define GBUFFER3 0
  761. #define GBUFFER4 1
  762. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  763. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  764. #endif
  765. /*ase_srp_cond_begin:<140007*/
  766. #pragma multi_compile _ DOTS_INSTANCING_ON
  767. /*ase_srp_cond_end*/
  768. /*ase_srp_cond_begin:>=140007*/
  769. #if ASE_SRP_VERSION >=140007
  770. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  771. #endif
  772. /*ase_srp_cond_end*/
  773. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  774. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  775. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  776. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  777. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  778. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  779. /*ase_unity_cond_begin:>=20220316*/
  780. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  781. /*ase_unity_cond_end*/
  782. /*ase_unity_cond_begin:>=20220316*/
  783. #if ASE_SRP_VERSION >=140009
  784. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  785. #endif
  786. /*ase_unity_cond_end*/
  787. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  788. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  789. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  790. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  791. #if defined(LOD_FADE_CROSSFADE)
  792. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  793. #endif
  794. /*ase_pragma*/
  795. struct SurfaceDescription
  796. {
  797. float3 BaseColor;
  798. float Alpha;
  799. float3 NormalTS;
  800. float NormalAlpha;
  801. float Metallic;
  802. float Occlusion;
  803. float Smoothness;
  804. float MAOSAlpha;
  805. float3 Emission;
  806. };
  807. struct Attributes
  808. {
  809. float3 positionOS : POSITION;
  810. float3 normalOS : NORMAL;
  811. float4 tangentOS : TANGENT;
  812. /*ase_vdata:p=p;n=n;t=t*/
  813. UNITY_VERTEX_INPUT_INSTANCE_ID
  814. };
  815. struct PackedVaryings
  816. {
  817. float4 positionCS : SV_POSITION;
  818. float3 normalWS : TEXCOORD0;
  819. float3 viewDirectionWS : TEXCOORD1;
  820. float2 staticLightmapUV : TEXCOORD2;
  821. float2 dynamicLightmapUV : TEXCOORD3;
  822. float3 sh : TEXCOORD4;
  823. float4 fogFactorAndVertexLight : TEXCOORD5;
  824. /*ase_interp(6,):sp=sp;wn=tc0;wvd=tc1*/
  825. UNITY_VERTEX_INPUT_INSTANCE_ID
  826. UNITY_VERTEX_OUTPUT_STEREO
  827. };
  828. CBUFFER_START(UnityPerMaterial)
  829. float _DrawOrder;
  830. float _DecalMeshBiasType;
  831. float _DecalMeshDepthBias;
  832. float _DecalMeshViewBias;
  833. #if defined(DECAL_ANGLE_FADE)
  834. float _DecalAngleFadeSupported;
  835. #endif
  836. CBUFFER_END
  837. #ifdef SCENEPICKINGPASS
  838. float4 _SelectionID;
  839. #endif
  840. #ifdef SCENESELECTIONPASS
  841. int _ObjectId;
  842. int _PassValue;
  843. #endif
  844. /*ase_globals*/
  845. /*ase_funcs*/
  846. void GetSurfaceData(SurfaceDescription surfaceDescription, float angleFadeFactor, out DecalSurfaceData surfaceData)
  847. {
  848. half4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  849. half fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f) * angleFadeFactor;
  850. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  851. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  852. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  853. surfaceData.occlusion = half(1.0);
  854. surfaceData.smoothness = half(0);
  855. #ifdef _MATERIAL_AFFECTS_NORMAL
  856. surfaceData.normalWS.w = half(1.0);
  857. #else
  858. surfaceData.normalWS.w = half(0.0);
  859. #endif
  860. #if defined( _MATERIAL_AFFECTS_EMISSION )
  861. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  862. #endif
  863. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  864. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  865. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  866. #if defined(_MATERIAL_AFFECTS_NORMAL)
  867. /*ase_unity_cond_begin:<20220310*/
  868. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  869. /*ase_unity_cond_end*/
  870. /*ase_unity_cond_begin:>=20220310*/
  871. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  872. /*ase_unity_cond_end*/
  873. #else
  874. /*ase_unity_cond_begin:<20220310*/
  875. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  876. /*ase_unity_cond_end*/
  877. /*ase_unity_cond_begin:>=20220310*/
  878. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  879. /*ase_unity_cond_end*/
  880. #endif
  881. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  882. #if defined(_MATERIAL_AFFECTS_NORMAL)
  883. float sgn = input.tangentWS.w;
  884. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  885. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  886. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  887. #else
  888. /*ase_unity_cond_begin:<20220310*/
  889. surfaceData.normalWS.xyz = half3(input.normalWS);
  890. /*ase_unity_cond_end*/
  891. /*ase_unity_cond_begin:>=20220310*/
  892. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  893. /*ase_unity_cond_end*/
  894. #endif
  895. #endif
  896. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  897. #if defined( _MATERIAL_AFFECTS_MAOS )
  898. surfaceData.metallic = half(surfaceDescription.Metallic);
  899. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  900. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  901. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  902. #endif
  903. }
  904. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  905. #define DECAL_PROJECTOR
  906. #endif
  907. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  908. #define DECAL_MESH
  909. #endif
  910. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  911. #define DECAL_DBUFFER
  912. #endif
  913. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  914. #define DECAL_SCREEN_SPACE
  915. #endif
  916. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  917. #define DECAL_GBUFFER
  918. #endif
  919. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  920. #define DECAL_FORWARD_EMISSIVE
  921. #endif
  922. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  923. #define DECAL_RECONSTRUCT_NORMAL
  924. #elif defined(DECAL_ANGLE_FADE)
  925. #define DECAL_LOAD_NORMAL
  926. #endif
  927. #ifdef _DECAL_LAYERS
  928. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  929. #endif
  930. #if defined(DECAL_LOAD_NORMAL)
  931. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  932. #endif
  933. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  934. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  935. #endif
  936. #ifdef DECAL_MESH
  937. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  938. #endif
  939. #ifdef DECAL_RECONSTRUCT_NORMAL
  940. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  941. #endif
  942. void InitializeInputData(PackedVaryings input, float3 positionWS, half3 normalWS, half3 viewDirectionWS, out InputData inputData)
  943. {
  944. inputData = (InputData)0;
  945. inputData.positionWS = positionWS;
  946. inputData.normalWS = normalWS;
  947. inputData.viewDirectionWS = viewDirectionWS;
  948. inputData.shadowCoord = float4(0, 0, 0, 0);
  949. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  950. inputData.fogCoord = InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
  951. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  952. #endif
  953. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  954. inputData.bakedGI = SAMPLE_GI(input.lightmapUVs.xy, input.lightmapUVs.zw, input.sh, normalWS);
  955. #elif defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  956. inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, half3(input.sh), normalWS);
  957. #endif
  958. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  959. inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
  960. #endif
  961. #if defined(DEBUG_DISPLAY)
  962. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  963. inputData.dynamicLightmapUV = input.lightmapUVs.zw;
  964. #endif
  965. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV) && defined(LIGHTMAP_ON)
  966. inputData.staticLightmapUV = input.lightmapUVs.xy;
  967. #elif defined(VARYINGS_NEED_SH)
  968. inputData.vertexSH = input.sh;
  969. #endif
  970. #endif
  971. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  972. }
  973. void GetSurface(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
  974. {
  975. surfaceData.albedo = decalSurfaceData.baseColor.rgb;
  976. surfaceData.metallic = saturate(decalSurfaceData.metallic);
  977. surfaceData.specular = 0;
  978. surfaceData.smoothness = saturate(decalSurfaceData.smoothness);
  979. surfaceData.occlusion = decalSurfaceData.occlusion;
  980. surfaceData.emission = decalSurfaceData.emissive;
  981. surfaceData.alpha = saturate(decalSurfaceData.baseColor.w);
  982. surfaceData.clearCoatMask = 0;
  983. surfaceData.clearCoatSmoothness = 1;
  984. }
  985. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  986. {
  987. PackedVaryings packedOutput;
  988. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  989. UNITY_SETUP_INSTANCE_ID(inputMesh);
  990. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  991. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  992. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  993. inputMesh.normalOS = float3( 0, 1, 0 );
  994. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  995. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  996. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  997. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  998. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  999. half fogFactor = 0;
  1000. #if !defined(_FOG_FRAGMENT)
  1001. fogFactor = ComputeFogFactor(packedOutput.positionCS.z);
  1002. #endif
  1003. half3 vertexLight = VertexLighting(positionWS, normalWS);
  1004. packedOutput.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  1005. packedOutput.normalWS.xyz = normalWS;
  1006. packedOutput.viewDirectionWS.xyz = GetWorldSpaceViewDir(positionWS);
  1007. #if defined(LIGHTMAP_ON)
  1008. OUTPUT_LIGHTMAP_UV(inputMesh.uv1, unity_LightmapST, packedOutput.staticLightmapUV);
  1009. #endif
  1010. #if defined(DYNAMICLIGHTMAP_ON)
  1011. packedOutput.dynamicLightmapUV.xy = inputMesh.uv2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  1012. #endif
  1013. #if !defined(LIGHTMAP_ON)
  1014. packedOutput.sh.xyz = float3(SampleSHVertex(half3(normalWS)));
  1015. #endif
  1016. return packedOutput;
  1017. }
  1018. void Frag(PackedVaryings packedInput,
  1019. out half4 outColor : SV_Target0
  1020. /*ase_frag_input*/
  1021. )
  1022. {
  1023. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  1024. UNITY_SETUP_INSTANCE_ID(packedInput);
  1025. half angleFadeFactor = 1.0;
  1026. #ifdef _DECAL_LAYERS
  1027. #ifdef _RENDER_PASS_ENABLED
  1028. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  1029. #else
  1030. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  1031. #endif
  1032. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  1033. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  1034. #endif
  1035. #if defined(DECAL_PROJECTOR)
  1036. #if UNITY_REVERSED_Z
  1037. #if _RENDER_PASS_ENABLED
  1038. float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy).x;
  1039. #else
  1040. float depth = LoadSceneDepth(packedInput.positionCS.xy);
  1041. #endif
  1042. #else
  1043. #if _RENDER_PASS_ENABLED
  1044. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy));
  1045. #else
  1046. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(packedInput.positionCS.xy));
  1047. #endif
  1048. #endif
  1049. #endif
  1050. #if defined(DECAL_RECONSTRUCT_NORMAL)
  1051. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  1052. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  1053. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  1054. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  1055. #else
  1056. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  1057. #endif
  1058. #elif defined(DECAL_LOAD_NORMAL)
  1059. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  1060. #endif
  1061. /*ase_unity_cond_begin:<20220352*/
  1062. #if ASE_SRP_VERSION <=140011
  1063. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  1064. #endif
  1065. /*ase_unity_cond_end*/
  1066. /*ase_unity_cond_begin:>=20220352*/
  1067. #if ASE_SRP_VERSION >=140011
  1068. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  1069. #endif
  1070. /*ase_unity_cond_end*/
  1071. /*ase_local_var:sp*/float4 positionCS = ComputeClipSpacePosition( positionSS, depth );
  1072. float4 hpositionVS = mul( UNITY_MATRIX_I_P, positionCS );
  1073. /*ase_local_var:rwp*/float3 positionRWS = mul( ( float3x3 )UNITY_MATRIX_I_V, hpositionVS.xyz / hpositionVS.w );
  1074. /*ase_local_var:wp*/float3 positionWS = positionRWS + _WorldSpaceCameraPos;
  1075. /*ase_local_var:op*/float3 positionOS = TransformWorldToObject( positionWS );
  1076. /*ase_local_var:vp*/float3 positionVS = TransformWorldToView( positionWS );
  1077. float3 positionDS = TransformWorldToObject(positionWS);
  1078. positionDS = positionDS * float3(1.0, -1.0, 1.0);
  1079. float clipValue = 0.5 - Max3(abs(positionDS).x, abs(positionDS).y, abs(positionDS).z);
  1080. clip(clipValue);
  1081. float2 texCoord = positionDS.xz + float2(0.5, 0.5);
  1082. float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  1083. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  1084. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  1085. texCoord.xy = texCoord.xy * scale + offset;
  1086. /*ase_local_var:uv0*/float2 texCoord0 = texCoord;
  1087. /*ase_local_var:uv1*/float2 texCoord1 = texCoord;
  1088. /*ase_local_var:uv2*/float2 texCoord2 = texCoord;
  1089. /*ase_local_var:uv3*/float2 texCoord3 = texCoord;
  1090. /*ase_local_var:wt*/float3 worldTangent = TransformObjectToWorldDir(float3(1, 0, 0));
  1091. /*ase_local_var:wn*/float3 worldNormal = TransformObjectToWorldDir(float3(0, 1, 0));
  1092. /*ase_local_var:wbt*/float3 worldBitangent = TransformObjectToWorldDir(float3(0, 0, 1));
  1093. #ifdef DECAL_ANGLE_FADE
  1094. half2 angleFade = half2(normalToWorld[1][3], normalToWorld[2][3]);
  1095. if (angleFade.y < 0.0f)
  1096. {
  1097. half3 decalNormal = half3(normalToWorld[0].z, normalToWorld[1].z, normalToWorld[2].z);
  1098. half dotAngle = dot(normalWS, decalNormal);
  1099. angleFadeFactor = saturate(angleFade.x + angleFade.y * (dotAngle * (dotAngle - 2.0)));
  1100. }
  1101. #endif
  1102. half3 viewDirectionWS = half3(packedInput.viewDirectionWS);
  1103. DecalSurfaceData surfaceData;
  1104. /*ase_frag_code:packedInput=PackedVaryings*/
  1105. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  1106. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  1107. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  1108. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  1109. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  1110. #if defined( _MATERIAL_AFFECTS_MAOS )
  1111. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  1112. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  1113. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  1114. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  1115. #endif
  1116. #if defined( _MATERIAL_AFFECTS_EMISSION )
  1117. surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;8;-1;_Emission*/float3(0, 0, 0)/*end*/;
  1118. #endif
  1119. GetSurfaceData( surfaceDescription, angleFadeFactor, surfaceData);
  1120. half3 normalToPack = surfaceData.normalWS.xyz;
  1121. #ifdef DECAL_RECONSTRUCT_NORMAL
  1122. surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
  1123. #endif
  1124. InputData inputData;
  1125. InitializeInputData( packedInput, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);
  1126. SurfaceData surface = (SurfaceData)0;
  1127. GetSurface(surfaceData, surface);
  1128. half4 color = UniversalFragmentPBR(inputData, surface);
  1129. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  1130. outColor = color;
  1131. /*ase_unity_cond_begin:<20220352*/
  1132. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1133. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1134. {
  1135. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  1136. }
  1137. #endif
  1138. /*ase_unity_cond_end*/
  1139. }
  1140. ENDHLSL
  1141. }
  1142. /*ase_pass*/
  1143. Pass
  1144. {
  1145. /*ase_hide_pass*/
  1146. Name "DecalGBufferProjector"
  1147. Tags
  1148. {
  1149. "LightMode" = "DecalGBufferProjector"
  1150. }
  1151. Cull Front
  1152. Blend 0 SrcAlpha OneMinusSrcAlpha
  1153. Blend 1 SrcAlpha OneMinusSrcAlpha
  1154. Blend 2 SrcAlpha OneMinusSrcAlpha
  1155. Blend 3 SrcAlpha OneMinusSrcAlpha
  1156. ZTest Greater
  1157. ZWrite Off
  1158. ColorMask RGB
  1159. ColorMask 0 1
  1160. ColorMask RGB 2
  1161. ColorMask RGB 3
  1162. HLSLPROGRAM
  1163. #pragma vertex Vert
  1164. #pragma fragment Frag
  1165. #pragma multi_compile_instancing
  1166. #pragma multi_compile_fog
  1167. #pragma editor_sync_compilation
  1168. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  1169. /*ase_srp_cond_begin:<140009*/
  1170. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  1171. /*ase_srp_cond_end*/
  1172. /*ase_srp_cond_begin:>=140009*/
  1173. #pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
  1174. /*ase_srp_cond_end*/
  1175. #pragma multi_compile _DECAL_NORMAL_BLEND_LOW _DECAL_NORMAL_BLEND_MEDIUM _DECAL_NORMAL_BLEND_HIGH
  1176. #pragma multi_compile _ _DECAL_LAYERS
  1177. #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
  1178. #pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
  1179. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  1180. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1181. #define ATTRIBUTES_NEED_NORMAL
  1182. #define ATTRIBUTES_NEED_TEXCOORD0
  1183. #define VARYINGS_NEED_NORMAL_WS
  1184. #define VARYINGS_NEED_TEXCOORD0
  1185. #define VARYINGS_NEED_VIEWDIRECTION_WS
  1186. #define VARYINGS_NEED_SH
  1187. #define VARYINGS_NEED_STATIC_LIGHTMAP_UV
  1188. #define VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV
  1189. #define HAVE_MESH_MODIFICATION
  1190. #define SHADERPASS SHADERPASS_DECAL_GBUFFER_PROJECTOR
  1191. #if _RENDER_PASS_ENABLED
  1192. #define GBUFFER3 0
  1193. #define GBUFFER4 1
  1194. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  1195. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  1196. #endif
  1197. /*ase_srp_cond_begin:<140007*/
  1198. #pragma multi_compile _ DOTS_INSTANCING_ON
  1199. /*ase_srp_cond_end*/
  1200. /*ase_srp_cond_begin:>=140007*/
  1201. #if ASE_SRP_VERSION >=140007
  1202. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  1203. #endif
  1204. /*ase_srp_cond_end*/
  1205. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1206. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1207. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1208. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1209. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  1210. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  1211. /*ase_unity_cond_begin:>=20220316*/
  1212. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  1213. /*ase_unity_cond_end*/
  1214. /*ase_unity_cond_begin:>=20220316*/
  1215. #if ASE_SRP_VERSION >=140009
  1216. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  1217. #endif
  1218. /*ase_unity_cond_end*/
  1219. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1220. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
  1221. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  1222. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  1223. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  1224. #if defined(LOD_FADE_CROSSFADE)
  1225. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  1226. #endif
  1227. /*ase_pragma*/
  1228. struct SurfaceDescription
  1229. {
  1230. float3 BaseColor;
  1231. float Alpha;
  1232. float3 NormalTS;
  1233. float NormalAlpha;
  1234. float Metallic;
  1235. float Occlusion;
  1236. float Smoothness;
  1237. float MAOSAlpha;
  1238. float3 Emission;
  1239. };
  1240. struct Attributes
  1241. {
  1242. float3 positionOS : POSITION;
  1243. float3 normalOS : NORMAL;
  1244. float4 tangentOS : TANGENT;
  1245. /*ase_vdata:p=p;n=n;t=t*/
  1246. UNITY_VERTEX_INPUT_INSTANCE_ID
  1247. };
  1248. struct PackedVaryings
  1249. {
  1250. float4 positionCS : SV_POSITION;
  1251. float3 normalWS : TEXCOORD0;
  1252. float3 viewDirectionWS : TEXCOORD1;
  1253. float2 staticLightmapUV : TEXCOORD2;
  1254. float2 dynamicLightmapUV : TEXCOORD3;
  1255. float3 sh : TEXCOORD4;
  1256. /*ase_interp(5,):sp=sp;wn=tc0;wvd=tc1*/
  1257. UNITY_VERTEX_INPUT_INSTANCE_ID
  1258. UNITY_VERTEX_OUTPUT_STEREO
  1259. };
  1260. CBUFFER_START(UnityPerMaterial)
  1261. float _DrawOrder;
  1262. float _DecalMeshBiasType;
  1263. float _DecalMeshDepthBias;
  1264. float _DecalMeshViewBias;
  1265. #if defined(DECAL_ANGLE_FADE)
  1266. float _DecalAngleFadeSupported;
  1267. #endif
  1268. CBUFFER_END
  1269. #ifdef SCENEPICKINGPASS
  1270. float4 _SelectionID;
  1271. #endif
  1272. #ifdef SCENESELECTIONPASS
  1273. int _ObjectId;
  1274. int _PassValue;
  1275. #endif
  1276. /*ase_globals*/
  1277. /*ase_funcs*/
  1278. void GetSurfaceData(SurfaceDescription surfaceDescription, float angleFadeFactor, out DecalSurfaceData surfaceData)
  1279. {
  1280. half4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  1281. half fadeFactor = clamp(normalToWorld[0][3], 0.0f, 1.0f) * angleFadeFactor;
  1282. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  1283. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  1284. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  1285. surfaceData.occlusion = half(1.0);
  1286. surfaceData.smoothness = half(0);
  1287. #ifdef _MATERIAL_AFFECTS_NORMAL
  1288. surfaceData.normalWS.w = half(1.0);
  1289. #else
  1290. surfaceData.normalWS.w = half(0.0);
  1291. #endif
  1292. #if defined( _MATERIAL_AFFECTS_EMISSION )
  1293. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  1294. #endif
  1295. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  1296. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  1297. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  1298. #if defined(_MATERIAL_AFFECTS_NORMAL)
  1299. /*ase_unity_cond_begin:<20220310*/
  1300. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  1301. /*ase_unity_cond_end*/
  1302. /*ase_unity_cond_begin:>=20220310*/
  1303. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  1304. /*ase_unity_cond_end*/
  1305. #else
  1306. /*ase_unity_cond_begin:<20220310*/
  1307. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  1308. /*ase_unity_cond_end*/
  1309. /*ase_unity_cond_begin:>=20220310*/
  1310. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  1311. /*ase_unity_cond_end*/
  1312. #endif
  1313. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1314. #if defined(_MATERIAL_AFFECTS_NORMAL)
  1315. float sgn = input.tangentWS.w;
  1316. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  1317. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  1318. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  1319. #else
  1320. /*ase_unity_cond_begin:<20220310*/
  1321. surfaceData.normalWS.xyz = half3(input.normalWS);
  1322. /*ase_unity_cond_end*/
  1323. /*ase_unity_cond_begin:>=20220310*/
  1324. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  1325. /*ase_unity_cond_end*/
  1326. #endif
  1327. #endif
  1328. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  1329. #if defined( _MATERIAL_AFFECTS_MAOS )
  1330. surfaceData.metallic = half(surfaceDescription.Metallic);
  1331. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  1332. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  1333. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  1334. #endif
  1335. }
  1336. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  1337. #define DECAL_PROJECTOR
  1338. #endif
  1339. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1340. #define DECAL_MESH
  1341. #endif
  1342. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  1343. #define DECAL_DBUFFER
  1344. #endif
  1345. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  1346. #define DECAL_SCREEN_SPACE
  1347. #endif
  1348. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1349. #define DECAL_GBUFFER
  1350. #endif
  1351. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  1352. #define DECAL_FORWARD_EMISSIVE
  1353. #endif
  1354. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  1355. #define DECAL_RECONSTRUCT_NORMAL
  1356. #elif defined(DECAL_ANGLE_FADE)
  1357. #define DECAL_LOAD_NORMAL
  1358. #endif
  1359. #ifdef _DECAL_LAYERS
  1360. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  1361. #endif
  1362. #if defined(DECAL_LOAD_NORMAL)
  1363. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  1364. #endif
  1365. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  1366. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  1367. #endif
  1368. #ifdef DECAL_MESH
  1369. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  1370. #endif
  1371. #ifdef DECAL_RECONSTRUCT_NORMAL
  1372. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  1373. #endif
  1374. void InitializeInputData(PackedVaryings input, float3 positionWS, half3 normalWS, half3 viewDirectionWS, out InputData inputData)
  1375. {
  1376. inputData = (InputData)0;
  1377. inputData.positionWS = positionWS;
  1378. inputData.normalWS = normalWS;
  1379. inputData.viewDirectionWS = viewDirectionWS;
  1380. inputData.shadowCoord = float4(0, 0, 0, 0);
  1381. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  1382. inputData.fogCoord = InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
  1383. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  1384. #endif
  1385. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  1386. inputData.bakedGI = SAMPLE_GI(input.lightmapUVs.xy, input.lightmapUVs.zw, input.sh, normalWS);
  1387. #elif defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  1388. inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, half3(input.sh), normalWS);
  1389. #endif
  1390. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  1391. inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
  1392. #endif
  1393. #if defined(DEBUG_DISPLAY)
  1394. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  1395. inputData.dynamicLightmapUV = input.lightmapUVs.zw;
  1396. #endif
  1397. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV) && defined(LIGHTMAP_ON)
  1398. inputData.staticLightmapUV = input.lightmapUVs.xy;
  1399. #elif defined(VARYINGS_NEED_SH)
  1400. inputData.vertexSH = input.sh;
  1401. #endif
  1402. #endif
  1403. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  1404. }
  1405. void GetSurface(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
  1406. {
  1407. surfaceData.albedo = decalSurfaceData.baseColor.rgb;
  1408. surfaceData.metallic = saturate(decalSurfaceData.metallic);
  1409. surfaceData.specular = 0;
  1410. surfaceData.smoothness = saturate(decalSurfaceData.smoothness);
  1411. surfaceData.occlusion = decalSurfaceData.occlusion;
  1412. surfaceData.emission = decalSurfaceData.emissive;
  1413. surfaceData.alpha = saturate(decalSurfaceData.baseColor.w);
  1414. surfaceData.clearCoatMask = 0;
  1415. surfaceData.clearCoatSmoothness = 1;
  1416. }
  1417. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  1418. {
  1419. PackedVaryings packedOutput;
  1420. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  1421. UNITY_SETUP_INSTANCE_ID(inputMesh);
  1422. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  1423. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  1424. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  1425. inputMesh.normalOS = float3( 0, 1, 0 );
  1426. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  1427. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  1428. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  1429. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  1430. packedOutput.normalWS.xyz = normalWS;
  1431. packedOutput.viewDirectionWS.xyz = GetWorldSpaceViewDir(positionWS);
  1432. #if defined(LIGHTMAP_ON)
  1433. OUTPUT_LIGHTMAP_UV(inputMesh.uv1, unity_LightmapST, packedOutput.staticLightmapUV);
  1434. #endif
  1435. #if defined(DYNAMICLIGHTMAP_ON)
  1436. packedOutput.dynamicLightmapUV.xy = inputMesh.uv2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  1437. #endif
  1438. #if !defined(LIGHTMAP_ON)
  1439. packedOutput.sh = float3(SampleSHVertex(half3(normalWS)));
  1440. #endif
  1441. return packedOutput;
  1442. }
  1443. void Frag(PackedVaryings packedInput,
  1444. out FragmentOutput fragmentOutput
  1445. /*ase_frag_input*/
  1446. )
  1447. {
  1448. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  1449. UNITY_SETUP_INSTANCE_ID(packedInput);
  1450. half angleFadeFactor = 1.0;
  1451. #ifdef _DECAL_LAYERS
  1452. #ifdef _RENDER_PASS_ENABLED
  1453. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  1454. #else
  1455. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  1456. #endif
  1457. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  1458. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  1459. #endif
  1460. #if defined(DECAL_PROJECTOR)
  1461. #if UNITY_REVERSED_Z
  1462. #if _RENDER_PASS_ENABLED
  1463. float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy).x;
  1464. #else
  1465. float depth = LoadSceneDepth(packedInput.positionCS.xy);
  1466. #endif
  1467. #else
  1468. #if _RENDER_PASS_ENABLED
  1469. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LOAD_FRAMEBUFFER_INPUT(GBUFFER3, packedInput.positionCS.xy));
  1470. #else
  1471. float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, LoadSceneDepth(packedInput.positionCS.xy));
  1472. #endif
  1473. #endif
  1474. #endif
  1475. #if defined(DECAL_RECONSTRUCT_NORMAL)
  1476. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  1477. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  1478. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  1479. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  1480. #else
  1481. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  1482. #endif
  1483. #elif defined(DECAL_LOAD_NORMAL)
  1484. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  1485. #endif
  1486. /*ase_unity_cond_begin:<20220352*/
  1487. #if ASE_SRP_VERSION <=140011
  1488. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  1489. #endif
  1490. /*ase_unity_cond_end*/
  1491. /*ase_unity_cond_begin:>=20220352*/
  1492. #if ASE_SRP_VERSION >=140011
  1493. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  1494. #endif
  1495. /*ase_unity_cond_end*/
  1496. /*ase_local_var:sp*/float4 positionCS = ComputeClipSpacePosition( positionSS, depth );
  1497. float4 hpositionVS = mul( UNITY_MATRIX_I_P, positionCS );
  1498. /*ase_local_var:rwp*/float3 positionRWS = mul( ( float3x3 )UNITY_MATRIX_I_V, hpositionVS.xyz / hpositionVS.w );
  1499. /*ase_local_var:wp*/float3 positionWS = positionRWS + _WorldSpaceCameraPos;
  1500. /*ase_local_var:op*/float3 positionOS = TransformWorldToObject( positionWS );
  1501. /*ase_local_var:vp*/float3 positionVS = TransformWorldToView( positionWS );
  1502. float3 positionDS = TransformWorldToObject(positionWS);
  1503. positionDS = positionDS * float3(1.0, -1.0, 1.0);
  1504. float clipValue = 0.5 - Max3(abs(positionDS).x, abs(positionDS).y, abs(positionDS).z);
  1505. clip(clipValue);
  1506. float2 texCoord = positionDS.xz + float2(0.5, 0.5);
  1507. float4x4 normalToWorld = UNITY_ACCESS_INSTANCED_PROP(Decal, _NormalToWorld);
  1508. float2 scale = float2(normalToWorld[3][0], normalToWorld[3][1]);
  1509. float2 offset = float2(normalToWorld[3][2], normalToWorld[3][3]);
  1510. texCoord.xy = texCoord.xy * scale + offset;
  1511. /*ase_local_var:uv0*/float2 texCoord0 = texCoord;
  1512. /*ase_local_var:uv1*/float2 texCoord1 = texCoord;
  1513. /*ase_local_var:uv2*/float2 texCoord2 = texCoord;
  1514. /*ase_local_var:uv3*/float2 texCoord3 = texCoord;
  1515. /*ase_local_var:wt*/float3 worldTangent = TransformObjectToWorldDir(float3(1, 0, 0));
  1516. /*ase_local_var:wn*/float3 worldNormal = TransformObjectToWorldDir(float3(0, 1, 0));
  1517. /*ase_local_var:wbt*/float3 worldBitangent = TransformObjectToWorldDir(float3(0, 0, 1));
  1518. #ifdef DECAL_ANGLE_FADE
  1519. half2 angleFade = half2(normalToWorld[1][3], normalToWorld[2][3]);
  1520. if (angleFade.y < 0.0f)
  1521. {
  1522. half3 decalNormal = half3(normalToWorld[0].z, normalToWorld[1].z, normalToWorld[2].z);
  1523. half dotAngle = dot(normalWS, decalNormal);
  1524. angleFadeFactor = saturate(angleFade.x + angleFade.y * (dotAngle * (dotAngle - 2.0)));
  1525. }
  1526. #endif
  1527. half3 viewDirectionWS = half3(packedInput.viewDirectionWS);
  1528. DecalSurfaceData surfaceData;
  1529. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  1530. /*ase_frag_code:packedInput=PackedVaryings*/
  1531. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  1532. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  1533. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  1534. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  1535. #if defined( _MATERIAL_AFFECTS_MAOS )
  1536. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  1537. surfaceDescription.Occlusion =/*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  1538. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  1539. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  1540. #endif
  1541. #if defined( _MATERIAL_AFFECTS_EMISSION )
  1542. surfaceDescription.Emission = /*ase_frag_out:Emission;Float;8;-1;_Emission*/float3(0, 0, 0)/*end*/;
  1543. #endif
  1544. GetSurfaceData(surfaceDescription, angleFadeFactor, surfaceData);
  1545. half3 normalToPack = surfaceData.normalWS.xyz;
  1546. #ifdef DECAL_RECONSTRUCT_NORMAL
  1547. surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
  1548. #endif
  1549. InputData inputData;
  1550. InitializeInputData(packedInput, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);
  1551. SurfaceData surface = (SurfaceData)0;
  1552. GetSurface(surfaceData, surface);
  1553. BRDFData brdfData;
  1554. InitializeBRDFData(surface.albedo, surface.metallic, 0, surface.smoothness, surface.alpha, brdfData);
  1555. #ifdef _MATERIAL_AFFECTS_ALBEDO
  1556. Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
  1557. MixRealtimeAndBakedGI(mainLight, surfaceData.normalWS.xyz, inputData.bakedGI, inputData.shadowMask);
  1558. half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, surfaceData.normalWS.xyz, inputData.viewDirectionWS);
  1559. #else
  1560. half3 color = 0;
  1561. #endif
  1562. #pragma warning (disable : 3578) // The output value isn't completely initialized.
  1563. half3 packedNormalWS = PackNormal(normalToPack);
  1564. fragmentOutput.GBuffer0 = half4(surfaceData.baseColor.rgb, surfaceData.baseColor.a);
  1565. fragmentOutput.GBuffer1 = 0;
  1566. fragmentOutput.GBuffer2 = half4(packedNormalWS, surfaceData.normalWS.a);
  1567. fragmentOutput.GBuffer3 = half4(surfaceData.emissive + color, surfaceData.baseColor.a);
  1568. #if OUTPUT_SHADOWMASK
  1569. fragmentOutput.GBuffer4 = inputData.shadowMask;
  1570. #endif
  1571. #pragma warning (default : 3578) // Restore output value isn't completely initialized.
  1572. /*ase_unity_cond_begin:<20220352*/
  1573. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1574. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1575. {
  1576. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  1577. }
  1578. #endif
  1579. /*ase_unity_cond_end*/
  1580. }
  1581. ENDHLSL
  1582. }
  1583. /*ase_pass*/
  1584. Pass
  1585. {
  1586. /*ase_hide_pass*/
  1587. Name "DBufferMesh"
  1588. Tags
  1589. {
  1590. "LightMode" = "DBufferMesh"
  1591. }
  1592. Blend 0 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  1593. Blend 1 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  1594. Blend 2 SrcAlpha OneMinusSrcAlpha, Zero OneMinusSrcAlpha
  1595. ZTest LEqual
  1596. ZWrite Off
  1597. ColorMask RGBA
  1598. ColorMask RGBA 1
  1599. ColorMask RGBA 2
  1600. HLSLPROGRAM
  1601. #pragma vertex Vert
  1602. #pragma fragment Frag
  1603. #pragma multi_compile_instancing
  1604. #pragma editor_sync_compilation
  1605. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  1606. #pragma multi_compile _ _DECAL_LAYERS
  1607. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  1608. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1609. #define ATTRIBUTES_NEED_NORMAL
  1610. #define ATTRIBUTES_NEED_TANGENT
  1611. #define ATTRIBUTES_NEED_TEXCOORD0
  1612. #define ATTRIBUTES_NEED_TEXCOORD1
  1613. #define ATTRIBUTES_NEED_TEXCOORD2
  1614. #define VARYINGS_NEED_POSITION_WS
  1615. #define VARYINGS_NEED_NORMAL_WS
  1616. #define VARYINGS_NEED_TANGENT_WS
  1617. #define VARYINGS_NEED_TEXCOORD0
  1618. #define HAVE_MESH_MODIFICATION
  1619. #define SHADERPASS SHADERPASS_DBUFFER_MESH
  1620. #if _RENDER_PASS_ENABLED
  1621. #define GBUFFER3 0
  1622. #define GBUFFER4 1
  1623. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  1624. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  1625. #endif
  1626. /*ase_srp_cond_begin:<140007*/
  1627. #pragma multi_compile _ DOTS_INSTANCING_ON
  1628. /*ase_srp_cond_end*/
  1629. /*ase_srp_cond_begin:>=140007*/
  1630. #if ASE_SRP_VERSION >=140007
  1631. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  1632. #endif
  1633. /*ase_srp_cond_end*/
  1634. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1635. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1636. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1637. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1638. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  1639. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  1640. /*ase_unity_cond_begin:>=20220316*/
  1641. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  1642. /*ase_unity_cond_end*/
  1643. /*ase_unity_cond_begin:>=20220316*/
  1644. #if ASE_SRP_VERSION >=140009
  1645. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  1646. #endif
  1647. /*ase_unity_cond_end*/
  1648. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1649. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  1650. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  1651. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  1652. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  1653. #if defined(LOD_FADE_CROSSFADE)
  1654. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  1655. #endif
  1656. /*ase_pragma*/
  1657. struct SurfaceDescription
  1658. {
  1659. float3 BaseColor;
  1660. float Alpha;
  1661. float3 NormalTS;
  1662. float NormalAlpha;
  1663. float Metallic;
  1664. float Occlusion;
  1665. float Smoothness;
  1666. float MAOSAlpha;
  1667. };
  1668. struct Attributes
  1669. {
  1670. float3 positionOS : POSITION;
  1671. float3 normalOS : NORMAL;
  1672. float4 tangentOS : TANGENT;
  1673. float4 uv0 : TEXCOORD0;
  1674. float4 uv1 : TEXCOORD1;
  1675. float4 uv2 : TEXCOORD2;
  1676. /*ase_vdata:p=p;n=n;t=t;uv0=tc0;uv1=tc1;uv2=tc2*/
  1677. UNITY_VERTEX_INPUT_INSTANCE_ID
  1678. };
  1679. struct PackedVaryings
  1680. {
  1681. float4 positionCS : SV_POSITION;
  1682. float3 positionWS : TEXCOORD0;
  1683. float3 normalWS : TEXCOORD1;
  1684. float4 tangentWS : TEXCOORD2;
  1685. float4 texCoord0 : TEXCOORD3;
  1686. /*ase_interp(4,):sp=sp;wp=tc0;wn=tc1;wt=tc2;uv0=tc3*/
  1687. UNITY_VERTEX_INPUT_INSTANCE_ID
  1688. UNITY_VERTEX_OUTPUT_STEREO
  1689. };
  1690. CBUFFER_START(UnityPerMaterial)
  1691. float _DrawOrder;
  1692. float _DecalMeshBiasType;
  1693. float _DecalMeshDepthBias;
  1694. float _DecalMeshViewBias;
  1695. #if defined(DECAL_ANGLE_FADE)
  1696. float _DecalAngleFadeSupported;
  1697. #endif
  1698. CBUFFER_END
  1699. #ifdef SCENEPICKINGPASS
  1700. float4 _SelectionID;
  1701. #endif
  1702. #ifdef SCENESELECTIONPASS
  1703. int _ObjectId;
  1704. int _PassValue;
  1705. #endif
  1706. /*ase_globals*/
  1707. /*ase_funcs*/
  1708. void GetSurfaceData(PackedVaryings input, SurfaceDescription surfaceDescription, out DecalSurfaceData surfaceData)
  1709. {
  1710. #if defined(LOD_FADE_CROSSFADE)
  1711. LODFadeCrossFade( input.positionCS );
  1712. #endif
  1713. half fadeFactor = half(1.0);
  1714. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  1715. surfaceData.occlusion = half(1.0);
  1716. surfaceData.smoothness = half(0);
  1717. #ifdef _MATERIAL_AFFECTS_NORMAL
  1718. surfaceData.normalWS.w = half(1.0);
  1719. #else
  1720. surfaceData.normalWS.w = half(0.0);
  1721. #endif
  1722. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  1723. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  1724. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  1725. #if defined(_MATERIAL_AFFECTS_NORMAL)
  1726. /*ase_unity_cond_begin:<20220310*/
  1727. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  1728. /*ase_unity_cond_end*/
  1729. /*ase_unity_cond_begin:>=20220310*/
  1730. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  1731. /*ase_unity_cond_end*/
  1732. #else
  1733. /*ase_unity_cond_begin:<20220310*/
  1734. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  1735. /*ase_unity_cond_end*/
  1736. /*ase_unity_cond_begin:>=20220310*/
  1737. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  1738. /*ase_unity_cond_end*/
  1739. #endif
  1740. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1741. #if defined(_MATERIAL_AFFECTS_NORMAL)
  1742. float sgn = input.tangentWS.w;
  1743. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  1744. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  1745. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  1746. #else
  1747. /*ase_unity_cond_begin:<20220310*/
  1748. surfaceData.normalWS.xyz = half3(input.normalWS);
  1749. /*ase_unity_cond_end*/
  1750. /*ase_unity_cond_begin:>=20220310*/
  1751. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  1752. /*ase_unity_cond_end*/
  1753. #endif
  1754. #endif
  1755. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  1756. #if defined( _MATERIAL_AFFECTS_MAOS )
  1757. surfaceData.metallic = half(surfaceDescription.Metallic);
  1758. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  1759. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  1760. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  1761. #endif
  1762. }
  1763. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  1764. #define DECAL_PROJECTOR
  1765. #endif
  1766. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1767. #define DECAL_MESH
  1768. #endif
  1769. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  1770. #define DECAL_DBUFFER
  1771. #endif
  1772. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  1773. #define DECAL_SCREEN_SPACE
  1774. #endif
  1775. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  1776. #define DECAL_GBUFFER
  1777. #endif
  1778. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  1779. #define DECAL_FORWARD_EMISSIVE
  1780. #endif
  1781. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  1782. #define DECAL_RECONSTRUCT_NORMAL
  1783. #elif defined(DECAL_ANGLE_FADE)
  1784. #define DECAL_LOAD_NORMAL
  1785. #endif
  1786. #ifdef _DECAL_LAYERS
  1787. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  1788. #endif
  1789. #if defined(DECAL_LOAD_NORMAL)
  1790. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  1791. #endif
  1792. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  1793. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  1794. #endif
  1795. #ifdef DECAL_MESH
  1796. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  1797. #endif
  1798. #ifdef DECAL_RECONSTRUCT_NORMAL
  1799. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  1800. #endif
  1801. void MeshDecalsPositionZBias(inout PackedVaryings input)
  1802. {
  1803. #if UNITY_REVERSED_Z
  1804. input.positionCS.z -= _DecalMeshDepthBias;
  1805. #else
  1806. input.positionCS.z += _DecalMeshDepthBias;
  1807. #endif
  1808. }
  1809. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  1810. {
  1811. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_VIEW_BIAS)
  1812. {
  1813. float3 viewDirectionOS = GetObjectSpaceNormalizeViewDir(inputMesh.positionOS);
  1814. inputMesh.positionOS += viewDirectionOS * (_DecalMeshViewBias);
  1815. }
  1816. PackedVaryings packedOutput;
  1817. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  1818. UNITY_SETUP_INSTANCE_ID(inputMesh);
  1819. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  1820. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  1821. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  1822. inputMesh.normalOS = float3( 0, 1, 0 );
  1823. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  1824. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  1825. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  1826. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  1827. float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
  1828. packedOutput.positionWS.xyz = positionWS;
  1829. packedOutput.normalWS.xyz = normalWS;
  1830. packedOutput.tangentWS.xyzw = tangentWS;
  1831. packedOutput.texCoord0.xyzw = inputMesh.uv0;
  1832. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  1833. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_DEPTH_BIAS)
  1834. {
  1835. MeshDecalsPositionZBias(packedOutput);
  1836. }
  1837. return packedOutput;
  1838. }
  1839. void Frag(PackedVaryings packedInput,
  1840. OUTPUT_DBUFFER(outDBuffer)
  1841. /*ase_frag_input*/
  1842. )
  1843. {
  1844. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  1845. UNITY_SETUP_INSTANCE_ID(packedInput);
  1846. half angleFadeFactor = 1.0;
  1847. #ifdef _DECAL_LAYERS
  1848. #ifdef _RENDER_PASS_ENABLED
  1849. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  1850. #else
  1851. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  1852. #endif
  1853. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  1854. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  1855. #endif
  1856. #if defined(DECAL_RECONSTRUCT_NORMAL)
  1857. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  1858. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  1859. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  1860. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  1861. #else
  1862. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  1863. #endif
  1864. #elif defined(DECAL_LOAD_NORMAL)
  1865. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  1866. #endif
  1867. /*ase_unity_cond_begin:<20220352*/
  1868. #if ASE_SRP_VERSION <=140011
  1869. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  1870. #endif
  1871. /*ase_unity_cond_end*/
  1872. /*ase_unity_cond_begin:>=20220352*/
  1873. #if ASE_SRP_VERSION >=140011
  1874. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  1875. #endif
  1876. /*ase_unity_cond_end*/
  1877. float3 positionWS = packedInput.positionWS.xyz;
  1878. half3 viewDirectionWS = half3(1.0, 1.0, 1.0);
  1879. DecalSurfaceData surfaceData;
  1880. SurfaceDescription surfaceDescription;
  1881. /*ase_frag_code:packedInput=PackedVaryings*/
  1882. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  1883. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  1884. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  1885. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  1886. #if defined( _MATERIAL_AFFECTS_MAOS )
  1887. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  1888. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  1889. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  1890. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  1891. #endif
  1892. GetSurfaceData(packedInput, surfaceDescription, surfaceData);
  1893. ENCODE_INTO_DBUFFER(surfaceData, outDBuffer);
  1894. /*ase_unity_cond_begin:<20220352*/
  1895. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1896. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  1897. {
  1898. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  1899. }
  1900. #endif
  1901. /*ase_unity_cond_end*/
  1902. }
  1903. ENDHLSL
  1904. }
  1905. /*ase_pass*/
  1906. Pass
  1907. {
  1908. /*ase_hide_pass*/
  1909. Name "DecalMeshForwardEmissive"
  1910. Tags
  1911. {
  1912. "LightMode" = "DecalMeshForwardEmissive"
  1913. }
  1914. Blend 0 SrcAlpha One
  1915. ZTest LEqual
  1916. ZWrite Off
  1917. HLSLPROGRAM
  1918. #pragma vertex Vert
  1919. #pragma fragment Frag
  1920. #pragma multi_compile_instancing
  1921. #pragma editor_sync_compilation
  1922. #pragma multi_compile _ _DECAL_LAYERS
  1923. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  1924. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1925. #define ATTRIBUTES_NEED_NORMAL
  1926. #define ATTRIBUTES_NEED_TANGENT
  1927. #define ATTRIBUTES_NEED_TEXCOORD0
  1928. #define ATTRIBUTES_NEED_TEXCOORD1
  1929. #define ATTRIBUTES_NEED_TEXCOORD2
  1930. #define VARYINGS_NEED_POSITION_WS
  1931. #define VARYINGS_NEED_NORMAL_WS
  1932. #define VARYINGS_NEED_TANGENT_WS
  1933. #define VARYINGS_NEED_TEXCOORD0
  1934. #define HAVE_MESH_MODIFICATION
  1935. #define SHADERPASS SHADERPASS_FORWARD_EMISSIVE_MESH
  1936. #if _RENDER_PASS_ENABLED
  1937. #define GBUFFER3 0
  1938. #define GBUFFER4 1
  1939. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  1940. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  1941. #endif
  1942. /*ase_srp_cond_begin:<140007*/
  1943. #pragma multi_compile _ DOTS_INSTANCING_ON
  1944. /*ase_srp_cond_end*/
  1945. /*ase_srp_cond_begin:>=140007*/
  1946. #if ASE_SRP_VERSION >=140007
  1947. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  1948. #endif
  1949. /*ase_srp_cond_end*/
  1950. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1951. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  1952. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1953. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1954. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  1955. /*ase_unity_cond_begin:>=20220316*/
  1956. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  1957. /*ase_unity_cond_end*/
  1958. /*ase_unity_cond_begin:>=20220316*/
  1959. #if ASE_SRP_VERSION >=140009
  1960. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  1961. #endif
  1962. /*ase_unity_cond_end*/
  1963. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1964. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  1965. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  1966. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  1967. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  1968. #if defined(LOD_FADE_CROSSFADE)
  1969. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  1970. #endif
  1971. /*ase_pragma*/
  1972. struct SurfaceDescription
  1973. {
  1974. float3 BaseColor;
  1975. float Alpha;
  1976. float3 NormalTS;
  1977. float NormalAlpha;
  1978. float Metallic;
  1979. float Occlusion;
  1980. float Smoothness;
  1981. float MAOSAlpha;
  1982. float3 Emission;
  1983. };
  1984. struct Attributes
  1985. {
  1986. float3 positionOS : POSITION;
  1987. float3 normalOS : NORMAL;
  1988. float4 tangentOS : TANGENT;
  1989. float4 uv0 : TEXCOORD0;
  1990. float4 uv1 : TEXCOORD1;
  1991. float4 uv2 : TEXCOORD2;
  1992. /*ase_vdata:p=p;n=n;t=t;uv0=tc0;uv1=tc1;uv2=tc2*/
  1993. UNITY_VERTEX_INPUT_INSTANCE_ID
  1994. };
  1995. struct PackedVaryings
  1996. {
  1997. float4 positionCS : SV_POSITION;
  1998. float3 positionWS : TEXCOORD0;
  1999. float3 normalWS : TEXCOORD1;
  2000. float4 tangentWS : TEXCOORD2;
  2001. float4 texCoord0 : TEXCOORD3;
  2002. /*ase_interp(4,):sp=sp;wp=tc0;wn=tc1;wt=tc2;uv0=tc3*/
  2003. UNITY_VERTEX_INPUT_INSTANCE_ID
  2004. UNITY_VERTEX_OUTPUT_STEREO
  2005. };
  2006. CBUFFER_START(UnityPerMaterial)
  2007. float _DrawOrder;
  2008. float _DecalMeshBiasType;
  2009. float _DecalMeshDepthBias;
  2010. float _DecalMeshViewBias;
  2011. #if defined(DECAL_ANGLE_FADE)
  2012. float _DecalAngleFadeSupported;
  2013. #endif
  2014. CBUFFER_END
  2015. #ifdef SCENEPICKINGPASS
  2016. float4 _SelectionID;
  2017. #endif
  2018. #ifdef SCENESELECTIONPASS
  2019. int _ObjectId;
  2020. int _PassValue;
  2021. #endif
  2022. /*ase_globals*/
  2023. /*ase_funcs*/
  2024. void GetSurfaceData(SurfaceDescription surfaceDescription, float4 positionCS, out DecalSurfaceData surfaceData)
  2025. {
  2026. #if defined(LOD_FADE_CROSSFADE)
  2027. LODFadeCrossFade( input.positionCS );
  2028. #endif
  2029. half fadeFactor = half(1.0);
  2030. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  2031. surfaceData.occlusion = half(1.0);
  2032. surfaceData.smoothness = half(0);
  2033. #ifdef _MATERIAL_AFFECTS_NORMAL
  2034. surfaceData.normalWS.w = half(1.0);
  2035. #else
  2036. surfaceData.normalWS.w = half(0.0);
  2037. #endif
  2038. #if defined( _MATERIAL_AFFECTS_EMISSION )
  2039. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  2040. #endif
  2041. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  2042. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  2043. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  2044. #if defined( _MATERIAL_AFFECTS_MAOS )
  2045. surfaceData.metallic = half(surfaceDescription.Metallic);
  2046. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  2047. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  2048. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  2049. #endif
  2050. }
  2051. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  2052. #define DECAL_PROJECTOR
  2053. #endif
  2054. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2055. #define DECAL_MESH
  2056. #endif
  2057. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  2058. #define DECAL_DBUFFER
  2059. #endif
  2060. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  2061. #define DECAL_SCREEN_SPACE
  2062. #endif
  2063. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2064. #define DECAL_GBUFFER
  2065. #endif
  2066. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  2067. #define DECAL_FORWARD_EMISSIVE
  2068. #endif
  2069. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  2070. #define DECAL_RECONSTRUCT_NORMAL
  2071. #elif defined(DECAL_ANGLE_FADE)
  2072. #define DECAL_LOAD_NORMAL
  2073. #endif
  2074. #ifdef _DECAL_LAYERS
  2075. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  2076. #endif
  2077. #if defined(DECAL_LOAD_NORMAL)
  2078. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  2079. #endif
  2080. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  2081. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  2082. #endif
  2083. #ifdef DECAL_MESH
  2084. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  2085. #endif
  2086. #ifdef DECAL_RECONSTRUCT_NORMAL
  2087. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  2088. #endif
  2089. void MeshDecalsPositionZBias(inout PackedVaryings input)
  2090. {
  2091. #if UNITY_REVERSED_Z
  2092. input.positionCS.z -= _DecalMeshDepthBias;
  2093. #else
  2094. input.positionCS.z += _DecalMeshDepthBias;
  2095. #endif
  2096. }
  2097. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  2098. {
  2099. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_VIEW_BIAS)
  2100. {
  2101. float3 viewDirectionOS = GetObjectSpaceNormalizeViewDir(inputMesh.positionOS);
  2102. inputMesh.positionOS += viewDirectionOS * (_DecalMeshViewBias);
  2103. }
  2104. PackedVaryings packedOutput;
  2105. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  2106. UNITY_SETUP_INSTANCE_ID(inputMesh);
  2107. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  2108. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  2109. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  2110. inputMesh.normalOS = float3( 0, 1, 0 );
  2111. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  2112. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  2113. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  2114. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  2115. float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
  2116. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  2117. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_DEPTH_BIAS)
  2118. {
  2119. MeshDecalsPositionZBias(packedOutput);
  2120. }
  2121. packedOutput.positionWS.xyz = positionWS;
  2122. packedOutput.normalWS.xyz = normalWS;
  2123. packedOutput.tangentWS.xyzw = tangentWS;
  2124. packedOutput.texCoord0.xyzw = inputMesh.uv0;
  2125. return packedOutput;
  2126. }
  2127. void Frag(PackedVaryings packedInput,
  2128. out half4 outEmissive : SV_Target0
  2129. /*ase_frag_input*/
  2130. )
  2131. {
  2132. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  2133. UNITY_SETUP_INSTANCE_ID(packedInput);
  2134. half angleFadeFactor = 1.0;
  2135. #ifdef _DECAL_LAYERS
  2136. #ifdef _RENDER_PASS_ENABLED
  2137. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  2138. #else
  2139. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  2140. #endif
  2141. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  2142. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  2143. #endif
  2144. #if defined(DECAL_RECONSTRUCT_NORMAL)
  2145. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  2146. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  2147. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  2148. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  2149. #else
  2150. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  2151. #endif
  2152. #elif defined(DECAL_LOAD_NORMAL)
  2153. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  2154. #endif
  2155. /*ase_unity_cond_begin:<20220352*/
  2156. #if ASE_SRP_VERSION <=140011
  2157. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  2158. #endif
  2159. /*ase_unity_cond_end*/
  2160. /*ase_unity_cond_begin:>=20220352*/
  2161. #if ASE_SRP_VERSION >=140011
  2162. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  2163. #endif
  2164. /*ase_unity_cond_end*/
  2165. float3 positionWS = packedInput.positionWS.xyz;
  2166. half3 viewDirectionWS = half3(1.0, 1.0, 1.0);
  2167. DecalSurfaceData surfaceData;
  2168. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  2169. /*ase_frag_code:packedInput=PackedVaryings*/
  2170. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  2171. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  2172. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  2173. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  2174. #if defined( _MATERIAL_AFFECTS_MAOS )
  2175. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  2176. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  2177. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  2178. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  2179. #endif
  2180. #if defined( _MATERIAL_AFFECTS_EMISSION )
  2181. surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;8;-1;_Emission*/float3(0, 0, 0)/*end*/;
  2182. #endif
  2183. GetSurfaceData(surfaceDescription, packedInput.positionCS, surfaceData);
  2184. outEmissive.rgb = surfaceData.emissive;
  2185. outEmissive.a = surfaceData.baseColor.a;
  2186. /*ase_unity_cond_begin:<20220352*/
  2187. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  2188. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  2189. {
  2190. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  2191. }
  2192. #endif
  2193. /*ase_unity_cond_end*/
  2194. }
  2195. ENDHLSL
  2196. }
  2197. /*ase_pass*/
  2198. Pass
  2199. {
  2200. /*ase_hide_pass*/
  2201. Name "DecalScreenSpaceMesh"
  2202. Tags
  2203. {
  2204. "LightMode" = "DecalScreenSpaceMesh"
  2205. }
  2206. Blend SrcAlpha OneMinusSrcAlpha
  2207. ZTest LEqual
  2208. ZWrite Off
  2209. HLSLPROGRAM
  2210. #pragma vertex Vert
  2211. #pragma fragment Frag
  2212. #pragma multi_compile_instancing
  2213. #pragma multi_compile_fog
  2214. #pragma editor_sync_compilation
  2215. #pragma multi_compile _ LIGHTMAP_ON
  2216. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  2217. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  2218. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  2219. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  2220. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  2221. /*ase_srp_cond_begin:<140009*/
  2222. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  2223. /*ase_srp_cond_end*/
  2224. /*ase_srp_cond_begin:>=140009*/
  2225. #pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
  2226. /*ase_srp_cond_end*/
  2227. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  2228. #pragma multi_compile _ SHADOWS_SHADOWMASK
  2229. #pragma multi_compile _ _FORWARD_PLUS
  2230. #pragma multi_compile _DECAL_NORMAL_BLEND_LOW _DECAL_NORMAL_BLEND_MEDIUM _DECAL_NORMAL_BLEND_HIGH
  2231. #pragma multi_compile _ _DECAL_LAYERS
  2232. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  2233. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  2234. #define ATTRIBUTES_NEED_NORMAL
  2235. #define ATTRIBUTES_NEED_TANGENT
  2236. #define ATTRIBUTES_NEED_TEXCOORD0
  2237. #define ATTRIBUTES_NEED_TEXCOORD1
  2238. #define ATTRIBUTES_NEED_TEXCOORD2
  2239. #define VARYINGS_NEED_POSITION_WS
  2240. #define VARYINGS_NEED_NORMAL_WS
  2241. #define VARYINGS_NEED_VIEWDIRECTION_WS
  2242. #define VARYINGS_NEED_TANGENT_WS
  2243. #define VARYINGS_NEED_TEXCOORD0
  2244. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2245. #define VARYINGS_NEED_SH
  2246. #define VARYINGS_NEED_STATIC_LIGHTMAP_UV
  2247. #define VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV
  2248. #define HAVE_MESH_MODIFICATION
  2249. #define SHADERPASS SHADERPASS_DECAL_SCREEN_SPACE_MESH
  2250. #if _RENDER_PASS_ENABLED
  2251. #define GBUFFER3 0
  2252. #define GBUFFER4 1
  2253. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  2254. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  2255. #endif
  2256. /*ase_srp_cond_begin:<140007*/
  2257. #pragma multi_compile _ DOTS_INSTANCING_ON
  2258. /*ase_srp_cond_end*/
  2259. /*ase_srp_cond_begin:>=140007*/
  2260. #if ASE_SRP_VERSION >=140007
  2261. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  2262. #endif
  2263. /*ase_srp_cond_end*/
  2264. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  2265. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  2266. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2267. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  2268. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  2269. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  2270. /*ase_unity_cond_begin:>=20220316*/
  2271. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  2272. /*ase_unity_cond_end*/
  2273. /*ase_unity_cond_begin:>=20220316*/
  2274. #if ASE_SRP_VERSION >=140009
  2275. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  2276. #endif
  2277. /*ase_unity_cond_end*/
  2278. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  2279. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  2280. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  2281. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  2282. #if defined(LOD_FADE_CROSSFADE)
  2283. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  2284. #endif
  2285. /*ase_pragma*/
  2286. struct SurfaceDescription
  2287. {
  2288. float3 BaseColor;
  2289. float Alpha;
  2290. float3 NormalTS;
  2291. float NormalAlpha;
  2292. float Metallic;
  2293. float Occlusion;
  2294. float Smoothness;
  2295. float MAOSAlpha;
  2296. float3 Emission;
  2297. };
  2298. struct Attributes
  2299. {
  2300. float3 positionOS : POSITION;
  2301. float3 normalOS : NORMAL;
  2302. float4 tangentOS : TANGENT;
  2303. float4 uv0 : TEXCOORD0;
  2304. float4 uv1 : TEXCOORD1;
  2305. float4 uv2 : TEXCOORD2;
  2306. /*ase_vdata:p=p;n=n;t=t;uv0=tc0;uv1=tc1;uv2=tc2*/
  2307. UNITY_VERTEX_INPUT_INSTANCE_ID
  2308. };
  2309. struct PackedVaryings
  2310. {
  2311. float4 positionCS : SV_POSITION;
  2312. float3 positionWS : TEXCOORD0;
  2313. float3 normalWS : TEXCOORD1;
  2314. float4 tangentWS : TEXCOORD2;
  2315. float4 texCoord0 : TEXCOORD3;
  2316. float3 viewDirectionWS : TEXCOORD4;
  2317. float2 staticLightmapUV : TEXCOORD5;
  2318. float2 dynamicLightmapUV : TEXCOORD6;
  2319. float3 sh : TEXCOORD7;
  2320. float4 fogFactorAndVertexLight : TEXCOORD8;
  2321. /*ase_interp(9,):sp=sp;wp=tc0;wn=tc1;wt=tc2;uv0=tc3;wvd=tc4*/
  2322. UNITY_VERTEX_INPUT_INSTANCE_ID
  2323. UNITY_VERTEX_OUTPUT_STEREO
  2324. };
  2325. CBUFFER_START(UnityPerMaterial)
  2326. float _DrawOrder;
  2327. float _DecalMeshBiasType;
  2328. float _DecalMeshDepthBias;
  2329. float _DecalMeshViewBias;
  2330. #if defined(DECAL_ANGLE_FADE)
  2331. float _DecalAngleFadeSupported;
  2332. #endif
  2333. CBUFFER_END
  2334. #ifdef SCENEPICKINGPASS
  2335. float4 _SelectionID;
  2336. #endif
  2337. #ifdef SCENESELECTIONPASS
  2338. int _ObjectId;
  2339. int _PassValue;
  2340. #endif
  2341. /*ase_globals*/
  2342. /*ase_funcs*/
  2343. void GetSurfaceData(PackedVaryings input, SurfaceDescription surfaceDescription, out DecalSurfaceData surfaceData)
  2344. {
  2345. #if defined(LOD_FADE_CROSSFADE)
  2346. LODFadeCrossFade( input.positionCS );
  2347. #endif
  2348. half fadeFactor = half(1.0);
  2349. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  2350. surfaceData.occlusion = half(1.0);
  2351. surfaceData.smoothness = half(0);
  2352. #ifdef _MATERIAL_AFFECTS_NORMAL
  2353. surfaceData.normalWS.w = half(1.0);
  2354. #else
  2355. surfaceData.normalWS.w = half(0.0);
  2356. #endif
  2357. #if defined( _MATERIAL_AFFECTS_EMISSION )
  2358. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  2359. #endif
  2360. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  2361. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  2362. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  2363. #if defined(_MATERIAL_AFFECTS_NORMAL)
  2364. /*ase_unity_cond_begin:<20220310*/
  2365. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  2366. /*ase_unity_cond_end*/
  2367. /*ase_unity_cond_begin:>=20220310*/
  2368. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  2369. /*ase_unity_cond_end*/
  2370. #else
  2371. /*ase_unity_cond_begin:<20220310*/
  2372. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  2373. /*ase_unity_cond_end*/
  2374. /*ase_unity_cond_begin:>=20220310*/
  2375. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  2376. /*ase_unity_cond_end*/
  2377. #endif
  2378. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2379. #if defined(_MATERIAL_AFFECTS_NORMAL)
  2380. float sgn = input.tangentWS.w;
  2381. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  2382. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  2383. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  2384. #else
  2385. /*ase_unity_cond_begin:<20220310*/
  2386. surfaceData.normalWS.xyz = half3(input.normalWS);
  2387. /*ase_unity_cond_end*/
  2388. /*ase_unity_cond_begin:>=20220310*/
  2389. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  2390. /*ase_unity_cond_end*/
  2391. #endif
  2392. #endif
  2393. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  2394. #if defined( _MATERIAL_AFFECTS_MAOS )
  2395. surfaceData.metallic = half(surfaceDescription.Metallic);
  2396. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  2397. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  2398. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  2399. #endif
  2400. }
  2401. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  2402. #define DECAL_PROJECTOR
  2403. #endif
  2404. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2405. #define DECAL_MESH
  2406. #endif
  2407. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  2408. #define DECAL_DBUFFER
  2409. #endif
  2410. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  2411. #define DECAL_SCREEN_SPACE
  2412. #endif
  2413. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2414. #define DECAL_GBUFFER
  2415. #endif
  2416. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  2417. #define DECAL_FORWARD_EMISSIVE
  2418. #endif
  2419. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  2420. #define DECAL_RECONSTRUCT_NORMAL
  2421. #elif defined(DECAL_ANGLE_FADE)
  2422. #define DECAL_LOAD_NORMAL
  2423. #endif
  2424. #ifdef _DECAL_LAYERS
  2425. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  2426. #endif
  2427. #if defined(DECAL_LOAD_NORMAL)
  2428. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  2429. #endif
  2430. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  2431. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  2432. #endif
  2433. #ifdef DECAL_MESH
  2434. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  2435. #endif
  2436. #ifdef DECAL_RECONSTRUCT_NORMAL
  2437. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  2438. #endif
  2439. void MeshDecalsPositionZBias(inout PackedVaryings input)
  2440. {
  2441. #if UNITY_REVERSED_Z
  2442. input.positionCS.z -= _DecalMeshDepthBias;
  2443. #else
  2444. input.positionCS.z += _DecalMeshDepthBias;
  2445. #endif
  2446. }
  2447. void InitializeInputData(PackedVaryings input, float3 positionWS, half3 normalWS, half3 viewDirectionWS, out InputData inputData)
  2448. {
  2449. inputData = (InputData)0;
  2450. inputData.positionWS = positionWS;
  2451. inputData.normalWS = normalWS;
  2452. inputData.viewDirectionWS = viewDirectionWS;
  2453. inputData.shadowCoord = float4(0, 0, 0, 0);
  2454. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2455. inputData.fogCoord = InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
  2456. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  2457. #endif
  2458. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  2459. inputData.bakedGI = SAMPLE_GI(input.lightmapUVs.xy, input.lightmapUVs.zw, input.sh, normalWS);
  2460. #elif defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  2461. inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, half3(input.sh), normalWS);
  2462. #endif
  2463. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  2464. inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
  2465. #endif
  2466. #if defined(DEBUG_DISPLAY)
  2467. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  2468. inputData.dynamicLightmapUV = input.lightmapUVs.zw;
  2469. #endif
  2470. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV) && defined(LIGHTMAP_ON)
  2471. inputData.staticLightmapUV = input.lightmapUVs.xy;
  2472. #elif defined(VARYINGS_NEED_SH)
  2473. inputData.vertexSH = input.sh;
  2474. #endif
  2475. #endif
  2476. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  2477. }
  2478. void GetSurface(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
  2479. {
  2480. surfaceData.albedo = decalSurfaceData.baseColor.rgb;
  2481. surfaceData.metallic = saturate(decalSurfaceData.metallic);
  2482. surfaceData.specular = 0;
  2483. surfaceData.smoothness = saturate(decalSurfaceData.smoothness);
  2484. surfaceData.occlusion = decalSurfaceData.occlusion;
  2485. surfaceData.emission = decalSurfaceData.emissive;
  2486. surfaceData.alpha = saturate(decalSurfaceData.baseColor.w);
  2487. surfaceData.clearCoatMask = 0;
  2488. surfaceData.clearCoatSmoothness = 1;
  2489. }
  2490. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  2491. {
  2492. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_VIEW_BIAS)
  2493. {
  2494. float3 viewDirectionOS = GetObjectSpaceNormalizeViewDir(inputMesh.positionOS);
  2495. inputMesh.positionOS += viewDirectionOS * (_DecalMeshViewBias);
  2496. }
  2497. PackedVaryings packedOutput;
  2498. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  2499. UNITY_SETUP_INSTANCE_ID(inputMesh);
  2500. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  2501. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  2502. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  2503. inputMesh.normalOS = float3( 0, 1, 0 );
  2504. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  2505. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  2506. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  2507. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  2508. float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
  2509. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  2510. half fogFactor = 0;
  2511. #if !defined(_FOG_FRAGMENT)
  2512. fogFactor = ComputeFogFactor(packedOutput.positionCS.z);
  2513. #endif
  2514. half3 vertexLight = VertexLighting(positionWS, normalWS);
  2515. packedOutput.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  2516. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_DEPTH_BIAS)
  2517. {
  2518. MeshDecalsPositionZBias(packedOutput);
  2519. }
  2520. packedOutput.positionWS.xyz = positionWS;
  2521. packedOutput.normalWS.xyz = normalWS;
  2522. packedOutput.tangentWS.xyzw = tangentWS;
  2523. packedOutput.texCoord0.xyzw = inputMesh.uv0;
  2524. packedOutput.viewDirectionWS.xyz = GetWorldSpaceViewDir(positionWS);
  2525. #if defined(LIGHTMAP_ON)
  2526. OUTPUT_LIGHTMAP_UV(inputMesh.uv1, unity_LightmapST, packedOutput.staticLightmapUV);
  2527. #endif
  2528. #if defined(DYNAMICLIGHTMAP_ON)
  2529. packedOutput.dynamicLightmapUV.xy = inputMesh.uv2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  2530. #endif
  2531. #if !defined(LIGHTMAP_ON)
  2532. packedOutput.sh = float3(SampleSHVertex(half3(normalWS)));
  2533. #endif
  2534. return packedOutput;
  2535. }
  2536. void Frag(PackedVaryings packedInput,
  2537. out half4 outColor : SV_Target0
  2538. /*ase_frag_input*/
  2539. )
  2540. {
  2541. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  2542. UNITY_SETUP_INSTANCE_ID(packedInput);
  2543. half angleFadeFactor = 1.0;
  2544. #ifdef _DECAL_LAYERS
  2545. #ifdef _RENDER_PASS_ENABLED
  2546. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  2547. #else
  2548. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  2549. #endif
  2550. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  2551. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  2552. #endif
  2553. #if defined(DECAL_RECONSTRUCT_NORMAL)
  2554. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  2555. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  2556. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  2557. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  2558. #else
  2559. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  2560. #endif
  2561. #elif defined(DECAL_LOAD_NORMAL)
  2562. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  2563. #endif
  2564. /*ase_unity_cond_begin:<20220352*/
  2565. #if ASE_SRP_VERSION <=140011
  2566. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  2567. #endif
  2568. /*ase_unity_cond_end*/
  2569. /*ase_unity_cond_begin:>=20220352*/
  2570. #if ASE_SRP_VERSION >=140011
  2571. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  2572. #endif
  2573. /*ase_unity_cond_end*/
  2574. float3 positionWS = packedInput.positionWS.xyz;
  2575. half3 viewDirectionWS = half3(packedInput.viewDirectionWS);
  2576. DecalSurfaceData surfaceData;
  2577. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  2578. /*ase_frag_code:packedInput=PackedVaryings*/
  2579. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  2580. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  2581. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  2582. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  2583. #if defined( _MATERIAL_AFFECTS_MAOS )
  2584. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  2585. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  2586. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  2587. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_MAOSAlpha*/1/*end*/;
  2588. #endif
  2589. #if defined( _MATERIAL_AFFECTS_EMISSION )
  2590. surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;8;-1;_Emission*/float3(0, 0, 0)/*end*/;
  2591. #endif
  2592. GetSurfaceData(packedInput, surfaceDescription, surfaceData);
  2593. half3 normalToPack = surfaceData.normalWS.xyz;
  2594. #ifdef DECAL_RECONSTRUCT_NORMAL
  2595. surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
  2596. #endif
  2597. InputData inputData;
  2598. InitializeInputData(packedInput, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);
  2599. SurfaceData surface = (SurfaceData)0;
  2600. GetSurface(surfaceData, surface);
  2601. half4 color = UniversalFragmentPBR(inputData, surface);
  2602. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  2603. outColor = color;
  2604. /*ase_unity_cond_begin:<20220352*/
  2605. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  2606. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  2607. {
  2608. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  2609. }
  2610. #endif
  2611. /*ase_unity_cond_end*/
  2612. }
  2613. ENDHLSL
  2614. }
  2615. /*ase_pass*/
  2616. Pass
  2617. {
  2618. /*ase_hide_pass*/
  2619. Name "DecalGBufferMesh"
  2620. Tags
  2621. {
  2622. "LightMode" = "DecalGBufferMesh"
  2623. }
  2624. Blend 0 SrcAlpha OneMinusSrcAlpha
  2625. Blend 1 SrcAlpha OneMinusSrcAlpha
  2626. Blend 2 SrcAlpha OneMinusSrcAlpha
  2627. Blend 3 SrcAlpha OneMinusSrcAlpha
  2628. ZWrite Off
  2629. ColorMask RGB
  2630. ColorMask 0 1
  2631. ColorMask RGB 2
  2632. ColorMask RGB 3
  2633. HLSLPROGRAM
  2634. #pragma vertex Vert
  2635. #pragma fragment Frag
  2636. #pragma multi_compile_instancing
  2637. #pragma multi_compile_fog
  2638. #pragma editor_sync_compilation
  2639. #pragma multi_compile _ LIGHTMAP_ON
  2640. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  2641. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  2642. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  2643. /*ase_srp_cond_begin:<140009*/
  2644. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  2645. /*ase_srp_cond_end*/
  2646. /*ase_srp_cond_begin:>=140009*/
  2647. #pragma multi_compile_fragment _ _SHADOWS_SOFT _SHADOWS_SOFT_LOW _SHADOWS_SOFT_MEDIUM _SHADOWS_SOFT_HIGH
  2648. /*ase_srp_cond_end*/
  2649. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  2650. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  2651. #pragma multi_compile _DECAL_NORMAL_BLEND_LOW _DECAL_NORMAL_BLEND_MEDIUM _DECAL_NORMAL_BLEND_HIGH
  2652. #pragma multi_compile _ _DECAL_LAYERS
  2653. #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
  2654. #pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
  2655. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  2656. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  2657. #define ATTRIBUTES_NEED_NORMAL
  2658. #define ATTRIBUTES_NEED_TANGENT
  2659. #define ATTRIBUTES_NEED_TEXCOORD0
  2660. #define ATTRIBUTES_NEED_TEXCOORD1
  2661. #define ATTRIBUTES_NEED_TEXCOORD2
  2662. #define VARYINGS_NEED_POSITION_WS
  2663. #define VARYINGS_NEED_NORMAL_WS
  2664. #define VARYINGS_NEED_VIEWDIRECTION_WS
  2665. #define VARYINGS_NEED_TANGENT_WS
  2666. #define VARYINGS_NEED_TEXCOORD0
  2667. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2668. #define VARYINGS_NEED_SH
  2669. #define VARYINGS_NEED_STATIC_LIGHTMAP_UV
  2670. #define VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV
  2671. #define HAVE_MESH_MODIFICATION
  2672. #define SHADERPASS SHADERPASS_DECAL_GBUFFER_MESH
  2673. #if _RENDER_PASS_ENABLED
  2674. #define GBUFFER3 0
  2675. #define GBUFFER4 1
  2676. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  2677. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  2678. #endif
  2679. /*ase_srp_cond_begin:<140007*/
  2680. #pragma multi_compile _ DOTS_INSTANCING_ON
  2681. /*ase_srp_cond_end*/
  2682. /*ase_srp_cond_begin:>=140007*/
  2683. #if ASE_SRP_VERSION >=140007
  2684. #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
  2685. #endif
  2686. /*ase_srp_cond_end*/
  2687. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  2688. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  2689. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  2690. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  2691. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  2692. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  2693. /*ase_unity_cond_begin:>=20220316*/
  2694. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  2695. /*ase_unity_cond_end*/
  2696. /*ase_unity_cond_begin:>=20220316*/
  2697. #if ASE_SRP_VERSION >=140009
  2698. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  2699. #endif
  2700. /*ase_unity_cond_end*/
  2701. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  2702. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
  2703. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  2704. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  2705. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  2706. #if defined(LOD_FADE_CROSSFADE)
  2707. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  2708. #endif
  2709. /*ase_pragma*/
  2710. struct SurfaceDescription
  2711. {
  2712. float3 BaseColor;
  2713. float Alpha;
  2714. float3 NormalTS;
  2715. float NormalAlpha;
  2716. float Metallic;
  2717. float Occlusion;
  2718. float Smoothness;
  2719. float MAOSAlpha;
  2720. float3 Emission;
  2721. };
  2722. struct Attributes
  2723. {
  2724. float3 positionOS : POSITION;
  2725. float3 normalOS : NORMAL;
  2726. float4 tangentOS : TANGENT;
  2727. float4 uv0 : TEXCOORD0;
  2728. float4 uv1 : TEXCOORD1;
  2729. float4 uv2 : TEXCOORD2;
  2730. /*ase_vdata:p=p;n=n;t=t;uv0=tc0;uv1=tc1;uv2=tc2*/
  2731. UNITY_VERTEX_INPUT_INSTANCE_ID
  2732. };
  2733. struct PackedVaryings
  2734. {
  2735. float4 positionCS : SV_POSITION;
  2736. float3 positionWS : TEXCOORD0;
  2737. float3 normalWS : TEXCOORD1;
  2738. float4 tangentWS : TEXCOORD2;
  2739. float4 texCoord0 : TEXCOORD3;
  2740. float3 viewDirectionWS : TEXCOORD4;
  2741. float2 staticLightmapUV : TEXCOORD5;
  2742. float2 dynamicLightmapUV : TEXCOORD6;
  2743. float3 sh : TEXCOORD7;
  2744. float4 fogFactorAndVertexLight : TEXCOORD8;
  2745. /*ase_interp(9,):sp=sp;wp=tc0;wn=tc1;wt=tc2;uv0=tc3;wvd=tc4*/
  2746. UNITY_VERTEX_INPUT_INSTANCE_ID
  2747. UNITY_VERTEX_OUTPUT_STEREO
  2748. };
  2749. CBUFFER_START(UnityPerMaterial)
  2750. float _DrawOrder;
  2751. float _DecalMeshBiasType;
  2752. float _DecalMeshDepthBias;
  2753. float _DecalMeshViewBias;
  2754. #if defined(DECAL_ANGLE_FADE)
  2755. float _DecalAngleFadeSupported;
  2756. #endif
  2757. CBUFFER_END
  2758. #ifdef SCENEPICKINGPASS
  2759. float4 _SelectionID;
  2760. #endif
  2761. #ifdef SCENESELECTIONPASS
  2762. int _ObjectId;
  2763. int _PassValue;
  2764. #endif
  2765. /*ase_globals*/
  2766. /*ase_funcs*/
  2767. void GetSurfaceData(PackedVaryings input, SurfaceDescription surfaceDescription, out DecalSurfaceData surfaceData)
  2768. {
  2769. #if defined(LOD_FADE_CROSSFADE)
  2770. LODFadeCrossFade( input.positionCS );
  2771. #endif
  2772. half fadeFactor = half(1.0);
  2773. ZERO_INITIALIZE(DecalSurfaceData, surfaceData);
  2774. surfaceData.occlusion = half(1.0);
  2775. surfaceData.smoothness = half(0);
  2776. #ifdef _MATERIAL_AFFECTS_NORMAL
  2777. surfaceData.normalWS.w = half(1.0);
  2778. #else
  2779. surfaceData.normalWS.w = half(0.0);
  2780. #endif
  2781. #if defined( _MATERIAL_AFFECTS_EMISSION )
  2782. surfaceData.emissive.rgb = half3(surfaceDescription.Emission.rgb * fadeFactor);
  2783. #endif
  2784. surfaceData.baseColor.xyz = half3(surfaceDescription.BaseColor);
  2785. surfaceData.baseColor.w = half(surfaceDescription.Alpha * fadeFactor);
  2786. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  2787. #if defined(_MATERIAL_AFFECTS_NORMAL)
  2788. /*ase_unity_cond_begin:<20220310*/
  2789. surfaceData.normalWS.xyz = mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz);
  2790. /*ase_unity_cond_end*/
  2791. /*ase_unity_cond_begin:>=20220310*/
  2792. surfaceData.normalWS.xyz = normalize(mul((half3x3)normalToWorld, surfaceDescription.NormalTS.xyz));
  2793. /*ase_unity_cond_end*/
  2794. #else
  2795. /*ase_unity_cond_begin:<20220310*/
  2796. surfaceData.normalWS.xyz = normalToWorld[2].xyz;
  2797. /*ase_unity_cond_end*/
  2798. /*ase_unity_cond_begin:>=20220310*/
  2799. surfaceData.normalWS.xyz = normalize(normalToWorld[2].xyz);
  2800. /*ase_unity_cond_end*/
  2801. #endif
  2802. #elif (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2803. #if defined(_MATERIAL_AFFECTS_NORMAL)
  2804. float sgn = input.tangentWS.w;
  2805. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  2806. half3x3 tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
  2807. surfaceData.normalWS.xyz = normalize(TransformTangentToWorld(surfaceDescription.NormalTS, tangentToWorld));
  2808. #else
  2809. /*ase_unity_cond_begin:<20220310*/
  2810. surfaceData.normalWS.xyz = half3(input.normalWS);
  2811. /*ase_unity_cond_end*/
  2812. /*ase_unity_cond_begin:>=20220310*/
  2813. surfaceData.normalWS.xyz = normalize(half3(input.normalWS));
  2814. /*ase_unity_cond_end*/
  2815. #endif
  2816. #endif
  2817. surfaceData.normalWS.w = surfaceDescription.NormalAlpha * fadeFactor;
  2818. #if defined( _MATERIAL_AFFECTS_MAOS )
  2819. surfaceData.metallic = half(surfaceDescription.Metallic);
  2820. surfaceData.occlusion = half(surfaceDescription.Occlusion);
  2821. surfaceData.smoothness = half(surfaceDescription.Smoothness);
  2822. surfaceData.MAOSAlpha = half(surfaceDescription.MAOSAlpha * fadeFactor);
  2823. #endif
  2824. }
  2825. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  2826. #define DECAL_PROJECTOR
  2827. #endif
  2828. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2829. #define DECAL_MESH
  2830. #endif
  2831. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  2832. #define DECAL_DBUFFER
  2833. #endif
  2834. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  2835. #define DECAL_SCREEN_SPACE
  2836. #endif
  2837. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  2838. #define DECAL_GBUFFER
  2839. #endif
  2840. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  2841. #define DECAL_FORWARD_EMISSIVE
  2842. #endif
  2843. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  2844. #define DECAL_RECONSTRUCT_NORMAL
  2845. #elif defined(DECAL_ANGLE_FADE)
  2846. #define DECAL_LOAD_NORMAL
  2847. #endif
  2848. #ifdef _DECAL_LAYERS
  2849. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  2850. #endif
  2851. #if defined(DECAL_LOAD_NORMAL)
  2852. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  2853. #endif
  2854. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  2855. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  2856. #endif
  2857. #ifdef DECAL_MESH
  2858. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  2859. #endif
  2860. #ifdef DECAL_RECONSTRUCT_NORMAL
  2861. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  2862. #endif
  2863. void MeshDecalsPositionZBias(inout PackedVaryings input)
  2864. {
  2865. #if UNITY_REVERSED_Z
  2866. input.positionCS.z -= _DecalMeshDepthBias;
  2867. #else
  2868. input.positionCS.z += _DecalMeshDepthBias;
  2869. #endif
  2870. }
  2871. void InitializeInputData(PackedVaryings input, float3 positionWS, half3 normalWS, half3 viewDirectionWS, out InputData inputData)
  2872. {
  2873. inputData = (InputData)0;
  2874. inputData.positionWS = positionWS;
  2875. inputData.normalWS = normalWS;
  2876. inputData.viewDirectionWS = viewDirectionWS;
  2877. inputData.shadowCoord = float4(0, 0, 0, 0);
  2878. #ifdef VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  2879. inputData.fogCoord = InitializeInputDataFog(float4(positionWS, 1.0), input.fogFactorAndVertexLight.x);
  2880. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  2881. #endif
  2882. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  2883. inputData.bakedGI = SAMPLE_GI(input.lightmapUVs.xy, input.lightmapUVs.zw, input.sh, normalWS);
  2884. #elif defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  2885. inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, half3(input.sh), normalWS);
  2886. #endif
  2887. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV)
  2888. inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
  2889. #endif
  2890. #if defined(DEBUG_DISPLAY)
  2891. #if defined(VARYINGS_NEED_DYNAMIC_LIGHTMAP_UV) && defined(DYNAMICLIGHTMAP_ON)
  2892. inputData.dynamicLightmapUV = input.lightmapUVs.zw;
  2893. #endif
  2894. #if defined(VARYINGS_NEED_STATIC_LIGHTMAP_UV) && defined(LIGHTMAP_ON)
  2895. inputData.staticLightmapUV = input.lightmapUVs.xy;
  2896. #elif defined(VARYINGS_NEED_SH)
  2897. inputData.vertexSH = input.sh;
  2898. #endif
  2899. #endif
  2900. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  2901. }
  2902. void GetSurface(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
  2903. {
  2904. surfaceData.albedo = decalSurfaceData.baseColor.rgb;
  2905. surfaceData.metallic = saturate(decalSurfaceData.metallic);
  2906. surfaceData.specular = 0;
  2907. surfaceData.smoothness = saturate(decalSurfaceData.smoothness);
  2908. surfaceData.occlusion = decalSurfaceData.occlusion;
  2909. surfaceData.emission = decalSurfaceData.emissive;
  2910. surfaceData.alpha = saturate(decalSurfaceData.baseColor.w);
  2911. surfaceData.clearCoatMask = 0;
  2912. surfaceData.clearCoatSmoothness = 1;
  2913. }
  2914. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  2915. {
  2916. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_VIEW_BIAS)
  2917. {
  2918. float3 viewDirectionOS = GetObjectSpaceNormalizeViewDir(inputMesh.positionOS);
  2919. inputMesh.positionOS += viewDirectionOS * (_DecalMeshViewBias);
  2920. }
  2921. PackedVaryings packedOutput;
  2922. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  2923. UNITY_SETUP_INSTANCE_ID(inputMesh);
  2924. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  2925. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  2926. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  2927. inputMesh.normalOS = float3( 0, 1, 0 );
  2928. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  2929. VertexPositionInputs vertexInput = GetVertexPositionInputs(inputMesh.positionOS.xyz);
  2930. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  2931. float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
  2932. float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
  2933. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  2934. if (_DecalMeshBiasType == DECALMESHDEPTHBIASTYPE_DEPTH_BIAS)
  2935. {
  2936. MeshDecalsPositionZBias(packedOutput);
  2937. }
  2938. packedOutput.positionWS.xyz = positionWS;
  2939. packedOutput.normalWS.xyz = normalWS;
  2940. packedOutput.tangentWS.xyzw = tangentWS;
  2941. packedOutput.texCoord0.xyzw = inputMesh.uv0;
  2942. packedOutput.viewDirectionWS.xyz = GetWorldSpaceViewDir(positionWS);
  2943. #if defined(LIGHTMAP_ON)
  2944. OUTPUT_LIGHTMAP_UV(inputMesh.uv1, unity_LightmapST, packedOutput.staticLightmapUV);
  2945. #endif
  2946. #if defined(DYNAMICLIGHTMAP_ON)
  2947. packedOutput.dynamicLightmapUV.xy = inputMesh.uv2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  2948. #endif
  2949. #if !defined(LIGHTMAP_ON)
  2950. packedOutput.sh.xyz = float3(SampleSHVertex(half3(normalWS)));
  2951. #endif
  2952. half fogFactor = 0;
  2953. #if !defined(_FOG_FRAGMENT)
  2954. fogFactor = ComputeFogFactor(packedOutput.positionCS.z);
  2955. #endif
  2956. half3 vertexLight = VertexLighting(positionWS, normalWS);
  2957. packedOutput.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  2958. return packedOutput;
  2959. }
  2960. void Frag(PackedVaryings packedInput,
  2961. out FragmentOutput fragmentOutput
  2962. /*ase_frag_input*/
  2963. )
  2964. {
  2965. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
  2966. UNITY_SETUP_INSTANCE_ID(packedInput);
  2967. half angleFadeFactor = 1.0;
  2968. #ifdef _DECAL_LAYERS
  2969. #ifdef _RENDER_PASS_ENABLED
  2970. uint surfaceRenderingLayer = DecodeMeshRenderingLayer(LOAD_FRAMEBUFFER_INPUT(GBUFFER4, packedInput.positionCS.xy).r);
  2971. #else
  2972. uint surfaceRenderingLayer = LoadSceneRenderingLayer(packedInput.positionCS.xy);
  2973. #endif
  2974. uint projectorRenderingLayer = uint(UNITY_ACCESS_INSTANCED_PROP(Decal, _DecalLayerMaskFromDecal));
  2975. clip((surfaceRenderingLayer & projectorRenderingLayer) - 0.1);
  2976. #endif
  2977. #if defined(DECAL_RECONSTRUCT_NORMAL)
  2978. #if defined(_DECAL_NORMAL_BLEND_HIGH)
  2979. half3 normalWS = half3(ReconstructNormalTap9(packedInput.positionCS.xy));
  2980. #elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
  2981. half3 normalWS = half3(ReconstructNormalTap5(packedInput.positionCS.xy));
  2982. #else
  2983. half3 normalWS = half3(ReconstructNormalDerivative(packedInput.positionCS.xy));
  2984. #endif
  2985. #elif defined(DECAL_LOAD_NORMAL)
  2986. half3 normalWS = half3(LoadSceneNormals(packedInput.positionCS.xy));
  2987. #endif
  2988. /*ase_unity_cond_begin:<20220352*/
  2989. #if ASE_SRP_VERSION <=140011
  2990. float2 positionSS = packedInput.positionCS.xy * _ScreenSize.zw;
  2991. #endif
  2992. /*ase_unity_cond_end*/
  2993. /*ase_unity_cond_begin:>=20220352*/
  2994. #if ASE_SRP_VERSION >=140011
  2995. float2 positionSS = FoveatedRemapNonUniformToLinearCS(packedInput.positionCS.xy) * _ScreenSize.zw;
  2996. #endif
  2997. /*ase_unity_cond_end*/
  2998. float3 positionWS = packedInput.positionWS.xyz;
  2999. half3 viewDirectionWS = half3(packedInput.viewDirectionWS);
  3000. DecalSurfaceData surfaceData;
  3001. SurfaceDescription surfaceDescription = (SurfaceDescription)0;
  3002. /*ase_frag_code:packedInput=PackedVaryings*/
  3003. surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  3004. surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;1;-1;_Alpha*/1/*end*/;
  3005. surfaceDescription.NormalTS = /*ase_frag_out:Normal;Float3;2;-1;_NormalTS*/float3(0.0f, 0.0f, 1.0f)/*end*/;
  3006. surfaceDescription.NormalAlpha = /*ase_frag_out:Normal Alpha;Float;3;-1;_NormalAlpha*/1/*end*/;
  3007. #if defined( _MATERIAL_AFFECTS_MAOS )
  3008. surfaceDescription.Metallic = /*ase_frag_out:Metallic;Float;4;-1;_Metallic*/0/*end*/;
  3009. surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;5;-1;_Occlusion*/1/*end*/;
  3010. surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;6;-1;_Smoothness*/0.5/*end*/;
  3011. surfaceDescription.MAOSAlpha = /*ase_frag_out:MAOS Alpha;Float;7;-1;_ColorP*/1/*end*/;
  3012. #endif
  3013. #if defined( _MATERIAL_AFFECTS_EMISSION )
  3014. surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;8;-1;_Emission*/float3(0, 0, 0)/*end*/;
  3015. #endif
  3016. GetSurfaceData(packedInput, surfaceDescription, surfaceData);
  3017. half3 normalToPack = surfaceData.normalWS.xyz;
  3018. #ifdef DECAL_RECONSTRUCT_NORMAL
  3019. surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
  3020. #endif
  3021. InputData inputData;
  3022. InitializeInputData(packedInput, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);
  3023. SurfaceData surface = (SurfaceData)0;
  3024. GetSurface(surfaceData, surface);
  3025. BRDFData brdfData;
  3026. InitializeBRDFData(surface.albedo, surface.metallic, 0, surface.smoothness, surface.alpha, brdfData);
  3027. #ifdef _MATERIAL_AFFECTS_ALBEDO
  3028. Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
  3029. MixRealtimeAndBakedGI(mainLight, surfaceData.normalWS.xyz, inputData.bakedGI, inputData.shadowMask);
  3030. half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, surfaceData.normalWS.xyz, inputData.viewDirectionWS);
  3031. #else
  3032. half3 color = 0;
  3033. #endif
  3034. #pragma warning (disable : 3578) // The output value isn't completely initialized.
  3035. half3 packedNormalWS = PackNormal(normalToPack);
  3036. fragmentOutput.GBuffer0 = half4(surfaceData.baseColor.rgb, surfaceData.baseColor.a);
  3037. fragmentOutput.GBuffer1 = 0;
  3038. fragmentOutput.GBuffer2 = half4(packedNormalWS, surfaceData.normalWS.a);
  3039. fragmentOutput.GBuffer3 = half4(surfaceData.emissive + color, surfaceData.baseColor.a);
  3040. #if OUTPUT_SHADOWMASK
  3041. fragmentOutput.GBuffer4 = inputData.shadowMask;
  3042. #endif
  3043. #pragma warning (default : 3578) // Restore output value isn't completely initialized.
  3044. /*ase_unity_cond_begin:<20220352*/
  3045. #if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  3046. UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
  3047. {
  3048. positionSS = RemapFoveatedRenderingNonUniformToLinearCS(input.positionCS.xy, true) * _ScreenSize.zw;
  3049. }
  3050. #endif
  3051. /*ase_unity_cond_end*/
  3052. }
  3053. ENDHLSL
  3054. }
  3055. /*ase_pass*/
  3056. Pass
  3057. {
  3058. /*ase_hide_pass*/
  3059. Name "ScenePickingPass"
  3060. Tags
  3061. {
  3062. "LightMode" = "Picking"
  3063. }
  3064. Cull Back
  3065. HLSLPROGRAM
  3066. #pragma multi_compile_instancing
  3067. #pragma editor_sync_compilation
  3068. #pragma vertex Vert
  3069. #pragma fragment Frag
  3070. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
  3071. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  3072. #define HAVE_MESH_MODIFICATION
  3073. #define SHADERPASS SHADERPASS_DEPTHONLY
  3074. #define SCENEPICKINGPASS 1
  3075. #if _RENDER_PASS_ENABLED
  3076. #define GBUFFER3 0
  3077. #define GBUFFER4 1
  3078. FRAMEBUFFER_INPUT_HALF(GBUFFER3);
  3079. FRAMEBUFFER_INPUT_HALF(GBUFFER4);
  3080. #endif
  3081. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  3082. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  3083. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  3084. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  3085. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
  3086. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  3087. /*ase_unity_cond_begin:>=20220316*/
  3088. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"
  3089. /*ase_unity_cond_end*/
  3090. /*ase_unity_cond_begin:>=20220316*/
  3091. #if ASE_SRP_VERSION >=140009
  3092. #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"
  3093. #endif
  3094. /*ase_unity_cond_end*/
  3095. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  3096. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  3097. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DecalInput.hlsl"
  3098. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderVariablesDecal.hlsl"
  3099. /*ase_pragma*/
  3100. struct Attributes
  3101. {
  3102. float3 positionOS : POSITION;
  3103. float3 normalOS : NORMAL;
  3104. float4 tangentOS : TANGENT;
  3105. /*ase_vdata:p=p;n=n;t=t*/
  3106. UNITY_VERTEX_INPUT_INSTANCE_ID
  3107. };
  3108. struct PackedVaryings
  3109. {
  3110. float4 positionCS : SV_POSITION;
  3111. /*ase_interp(0,):sp=sp*/
  3112. UNITY_VERTEX_INPUT_INSTANCE_ID
  3113. UNITY_VERTEX_OUTPUT_STEREO
  3114. };
  3115. CBUFFER_START(UnityPerMaterial)
  3116. float _DrawOrder;
  3117. float _DecalMeshBiasType;
  3118. float _DecalMeshDepthBias;
  3119. float _DecalMeshViewBias;
  3120. #if defined(DECAL_ANGLE_FADE)
  3121. float _DecalAngleFadeSupported;
  3122. #endif
  3123. CBUFFER_END
  3124. #ifdef SCENEPICKINGPASS
  3125. float4 _SelectionID;
  3126. #endif
  3127. #ifdef SCENESELECTIONPASS
  3128. int _ObjectId;
  3129. int _PassValue;
  3130. #endif
  3131. /*ase_globals*/
  3132. /*ase_funcs*/
  3133. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR)
  3134. #define DECAL_PROJECTOR
  3135. #endif
  3136. #if (SHADERPASS == SHADERPASS_DBUFFER_MESH) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  3137. #define DECAL_MESH
  3138. #endif
  3139. #if (SHADERPASS == SHADERPASS_DBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DBUFFER_MESH)
  3140. #define DECAL_DBUFFER
  3141. #endif
  3142. #if (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_SCREEN_SPACE_MESH)
  3143. #define DECAL_SCREEN_SPACE
  3144. #endif
  3145. #if (SHADERPASS == SHADERPASS_DECAL_GBUFFER_PROJECTOR) || (SHADERPASS == SHADERPASS_DECAL_GBUFFER_MESH)
  3146. #define DECAL_GBUFFER
  3147. #endif
  3148. #if (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_PROJECTOR) || (SHADERPASS == SHADERPASS_FORWARD_EMISSIVE_MESH)
  3149. #define DECAL_FORWARD_EMISSIVE
  3150. #endif
  3151. #if ((!defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_ALBEDO)) || (defined(_MATERIAL_AFFECTS_NORMAL) && defined(_MATERIAL_AFFECTS_NORMAL_BLEND))) && (defined(DECAL_SCREEN_SPACE) || defined(DECAL_GBUFFER))
  3152. #define DECAL_RECONSTRUCT_NORMAL
  3153. #elif defined(DECAL_ANGLE_FADE)
  3154. #define DECAL_LOAD_NORMAL
  3155. #endif
  3156. #ifdef _DECAL_LAYERS
  3157. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareRenderingLayerTexture.hlsl"
  3158. #endif
  3159. #if defined(DECAL_LOAD_NORMAL)
  3160. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  3161. #endif
  3162. #if defined(DECAL_PROJECTOR) || defined(DECAL_RECONSTRUCT_NORMAL)
  3163. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  3164. #endif
  3165. #ifdef DECAL_MESH
  3166. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/DecalMeshBiasTypeEnum.cs.hlsl"
  3167. #endif
  3168. #ifdef DECAL_RECONSTRUCT_NORMAL
  3169. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl"
  3170. #endif
  3171. PackedVaryings Vert(Attributes inputMesh /*ase_vert_input*/ )
  3172. {
  3173. PackedVaryings packedOutput;
  3174. ZERO_INITIALIZE(PackedVaryings, packedOutput);
  3175. UNITY_SETUP_INSTANCE_ID(inputMesh);
  3176. UNITY_TRANSFER_INSTANCE_ID(inputMesh, packedOutput);
  3177. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(packedOutput);
  3178. inputMesh.tangentOS = float4( 1, 0, 0, -1 );
  3179. inputMesh.normalOS = float3( 0, 1, 0 );
  3180. /*ase_vert_code:inputMesh=Attributes;packedOutput=PackedVaryings*/
  3181. float3 positionWS = TransformObjectToWorld(inputMesh.positionOS);
  3182. packedOutput.positionCS = TransformWorldToHClip(positionWS);
  3183. return packedOutput;
  3184. }
  3185. void Frag(PackedVaryings packedInput,
  3186. out float4 outColor : SV_Target0
  3187. /*ase_frag_input*/
  3188. )
  3189. {
  3190. /*ase_frag_code:packedInput=PackedVaryings*/
  3191. float3 BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5))/*end*/;
  3192. outColor = _SelectionID;
  3193. }
  3194. ENDHLSL
  3195. }
  3196. }
  3197. CustomEditor "UnityEditor.Rendering.Universal.DecalShaderGraphGUI"
  3198. FallBack "Hidden/Shader Graph/FallbackError"
  3199. }