Grass.shader 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  1. // Made with Amplify Shader Editor
  2. // Available at the Unity Asset Store - http://u3d.as/y3X
  3. Shader "MTE/URP/Grass/Billboard"
  4. {
  5. Properties
  6. {
  7. [HideInInspector] _AlphaCutoff("Alpha Cutoff ", Range(0, 1)) = 0.5
  8. [HideInInspector] _EmissionColor("Emission Color", Color) = (1,1,1,1)
  9. [ASEBegin]_MainTex("MainTex", 2D) = "white" {}
  10. [ASEEnd][Toggle(_BILLBOARD_ON)] _Billboard("Billboard", Float) = 1
  11. [HideInInspector] _texcoord( "", 2D ) = "white" {}
  12. //_TransmissionShadow( "Transmission Shadow", Range( 0, 1 ) ) = 0.5
  13. //_TransStrength( "Trans Strength", Range( 0, 50 ) ) = 1
  14. //_TransNormal( "Trans Normal Distortion", Range( 0, 1 ) ) = 0.5
  15. //_TransScattering( "Trans Scattering", Range( 1, 50 ) ) = 2
  16. //_TransDirect( "Trans Direct", Range( 0, 1 ) ) = 0.9
  17. //_TransAmbient( "Trans Ambient", Range( 0, 1 ) ) = 0.1
  18. //_TransShadow( "Trans Shadow", Range( 0, 1 ) ) = 0.5
  19. //_TessPhongStrength( "Tess Phong Strength", Range( 0, 1 ) ) = 0.5
  20. //_TessValue( "Tess Max Tessellation", Range( 1, 32 ) ) = 16
  21. //_TessMin( "Tess Min Distance", Float ) = 10
  22. //_TessMax( "Tess Max Distance", Float ) = 25
  23. //_TessEdgeLength ( "Tess Edge length", Range( 2, 50 ) ) = 16
  24. //_TessMaxDisp( "Tess Max Displacement", Float ) = 25
  25. }
  26. SubShader
  27. {
  28. LOD 0
  29. Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Transparent" "Queue"="Transparent" }
  30. Cull Back
  31. AlphaToMask Off
  32. HLSLINCLUDE
  33. #pragma target 2.0
  34. #pragma prefer_hlslcc gles
  35. #pragma exclude_renderers d3d11_9x
  36. #ifndef ASE_TESS_FUNCS
  37. #define ASE_TESS_FUNCS
  38. float4 FixedTess( float tessValue )
  39. {
  40. return tessValue;
  41. }
  42. float CalcDistanceTessFactor (float4 vertex, float minDist, float maxDist, float tess, float4x4 o2w, float3 cameraPos )
  43. {
  44. float3 wpos = mul(o2w,vertex).xyz;
  45. float dist = distance (wpos, cameraPos);
  46. float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess;
  47. return f;
  48. }
  49. float4 CalcTriEdgeTessFactors (float3 triVertexFactors)
  50. {
  51. float4 tess;
  52. tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z);
  53. tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z);
  54. tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y);
  55. tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f;
  56. return tess;
  57. }
  58. float CalcEdgeTessFactor (float3 wpos0, float3 wpos1, float edgeLen, float3 cameraPos, float4 scParams )
  59. {
  60. float dist = distance (0.5 * (wpos0+wpos1), cameraPos);
  61. float len = distance(wpos0, wpos1);
  62. float f = max(len * scParams.y / (edgeLen * dist), 1.0);
  63. return f;
  64. }
  65. float DistanceFromPlane (float3 pos, float4 plane)
  66. {
  67. float d = dot (float4(pos,1.0f), plane);
  68. return d;
  69. }
  70. bool WorldViewFrustumCull (float3 wpos0, float3 wpos1, float3 wpos2, float cullEps, float4 planes[6] )
  71. {
  72. float4 planeTest;
  73. planeTest.x = (( DistanceFromPlane(wpos0, planes[0]) > -cullEps) ? 1.0f : 0.0f ) +
  74. (( DistanceFromPlane(wpos1, planes[0]) > -cullEps) ? 1.0f : 0.0f ) +
  75. (( DistanceFromPlane(wpos2, planes[0]) > -cullEps) ? 1.0f : 0.0f );
  76. planeTest.y = (( DistanceFromPlane(wpos0, planes[1]) > -cullEps) ? 1.0f : 0.0f ) +
  77. (( DistanceFromPlane(wpos1, planes[1]) > -cullEps) ? 1.0f : 0.0f ) +
  78. (( DistanceFromPlane(wpos2, planes[1]) > -cullEps) ? 1.0f : 0.0f );
  79. planeTest.z = (( DistanceFromPlane(wpos0, planes[2]) > -cullEps) ? 1.0f : 0.0f ) +
  80. (( DistanceFromPlane(wpos1, planes[2]) > -cullEps) ? 1.0f : 0.0f ) +
  81. (( DistanceFromPlane(wpos2, planes[2]) > -cullEps) ? 1.0f : 0.0f );
  82. planeTest.w = (( DistanceFromPlane(wpos0, planes[3]) > -cullEps) ? 1.0f : 0.0f ) +
  83. (( DistanceFromPlane(wpos1, planes[3]) > -cullEps) ? 1.0f : 0.0f ) +
  84. (( DistanceFromPlane(wpos2, planes[3]) > -cullEps) ? 1.0f : 0.0f );
  85. return !all (planeTest);
  86. }
  87. float4 DistanceBasedTess( float4 v0, float4 v1, float4 v2, float tess, float minDist, float maxDist, float4x4 o2w, float3 cameraPos )
  88. {
  89. float3 f;
  90. f.x = CalcDistanceTessFactor (v0,minDist,maxDist,tess,o2w,cameraPos);
  91. f.y = CalcDistanceTessFactor (v1,minDist,maxDist,tess,o2w,cameraPos);
  92. f.z = CalcDistanceTessFactor (v2,minDist,maxDist,tess,o2w,cameraPos);
  93. return CalcTriEdgeTessFactors (f);
  94. }
  95. float4 EdgeLengthBasedTess( float4 v0, float4 v1, float4 v2, float edgeLength, float4x4 o2w, float3 cameraPos, float4 scParams )
  96. {
  97. float3 pos0 = mul(o2w,v0).xyz;
  98. float3 pos1 = mul(o2w,v1).xyz;
  99. float3 pos2 = mul(o2w,v2).xyz;
  100. float4 tess;
  101. tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams);
  102. tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams);
  103. tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams);
  104. tess.w = (tess.x + tess.y + tess.z) / 3.0f;
  105. return tess;
  106. }
  107. float4 EdgeLengthBasedTessCull( float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement, float4x4 o2w, float3 cameraPos, float4 scParams, float4 planes[6] )
  108. {
  109. float3 pos0 = mul(o2w,v0).xyz;
  110. float3 pos1 = mul(o2w,v1).xyz;
  111. float3 pos2 = mul(o2w,v2).xyz;
  112. float4 tess;
  113. if (WorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement, planes))
  114. {
  115. tess = 0.0f;
  116. }
  117. else
  118. {
  119. tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams);
  120. tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams);
  121. tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams);
  122. tess.w = (tess.x + tess.y + tess.z) / 3.0f;
  123. }
  124. return tess;
  125. }
  126. #endif //ASE_TESS_FUNCS
  127. ENDHLSL
  128. Pass
  129. {
  130. Name "Forward"
  131. Tags { "LightMode"="UniversalForward" }
  132. Blend One Zero, One Zero
  133. ZWrite Off
  134. ZTest LEqual
  135. Offset 0 , 0
  136. ColorMask RGBA
  137. HLSLPROGRAM
  138. #define _SPECULAR_SETUP 1
  139. #define _NORMAL_DROPOFF_TS 1
  140. #pragma multi_compile_instancing
  141. #pragma multi_compile _ LOD_FADE_CROSSFADE
  142. #pragma multi_compile_fog
  143. #define ASE_FOG 1
  144. #define _NORMALMAP 1
  145. #define ASE_SRP_VERSION 100500
  146. #pragma multi_compile _ _SCREEN_SPACE_OCCLUSION
  147. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  148. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  149. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS _ADDITIONAL_OFF
  150. #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  151. #pragma multi_compile _ _SHADOWS_SOFT
  152. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  153. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  154. #pragma multi_compile _ SHADOWS_SHADOWMASK
  155. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  156. #pragma multi_compile _ LIGHTMAP_ON
  157. #pragma vertex vert
  158. #pragma fragment frag
  159. #define SHADERPASS_FORWARD
  160. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  161. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  162. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  163. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  164. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  165. #if ASE_SRP_VERSION <= 70108
  166. #define REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
  167. #endif
  168. #if defined(UNITY_INSTANCING_ENABLED) && defined(_TERRAIN_INSTANCED_PERPIXEL_NORMAL)
  169. #define ENABLE_TERRAIN_PERPIXEL_NORMAL
  170. #endif
  171. #define ASE_NEEDS_VERT_POSITION
  172. #define ASE_NEEDS_VERT_NORMAL
  173. #define ASE_NEEDS_VERT_TANGENT
  174. #pragma shader_feature_local _BILLBOARD_ON
  175. struct VertexInput
  176. {
  177. float4 vertex : POSITION;
  178. float3 ase_normal : NORMAL;
  179. float4 ase_tangent : TANGENT;
  180. float4 texcoord1 : TEXCOORD1;
  181. float4 texcoord : TEXCOORD0;
  182. UNITY_VERTEX_INPUT_INSTANCE_ID
  183. };
  184. struct VertexOutput
  185. {
  186. float4 clipPos : SV_POSITION;
  187. float4 lightmapUVOrVertexSH : TEXCOORD0;
  188. half4 fogFactorAndVertexLight : TEXCOORD1;
  189. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  190. float4 shadowCoord : TEXCOORD2;
  191. #endif
  192. float4 tSpace0 : TEXCOORD3;
  193. float4 tSpace1 : TEXCOORD4;
  194. float4 tSpace2 : TEXCOORD5;
  195. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  196. float4 screenPos : TEXCOORD6;
  197. #endif
  198. float4 ase_texcoord7 : TEXCOORD7;
  199. float3 ase_normal : NORMAL;
  200. UNITY_VERTEX_INPUT_INSTANCE_ID
  201. UNITY_VERTEX_OUTPUT_STEREO
  202. };
  203. CBUFFER_START(UnityPerMaterial)
  204. float4 _MainTex_ST;
  205. #ifdef _TRANSMISSION_ASE
  206. float _TransmissionShadow;
  207. #endif
  208. #ifdef _TRANSLUCENCY_ASE
  209. float _TransStrength;
  210. float _TransNormal;
  211. float _TransScattering;
  212. float _TransDirect;
  213. float _TransAmbient;
  214. float _TransShadow;
  215. #endif
  216. #ifdef TESSELLATION_ON
  217. float _TessPhongStrength;
  218. float _TessValue;
  219. float _TessMin;
  220. float _TessMax;
  221. float _TessEdgeLength;
  222. float _TessMaxDisp;
  223. #endif
  224. CBUFFER_END
  225. sampler2D _MainTex;
  226. VertexOutput VertexFunction( VertexInput v )
  227. {
  228. VertexOutput o = (VertexOutput)0;
  229. UNITY_SETUP_INSTANCE_ID(v);
  230. UNITY_TRANSFER_INSTANCE_ID(v, o);
  231. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  232. //Calculate new billboard vertex position and normal;
  233. float3 upCamVec = float3( 0, 1, 0 );
  234. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  235. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  236. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  237. //This unfortunately must be made to take non-uniform scaling into account;
  238. //Transform to world coords, apply rotation and transform back to local;
  239. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  240. v.vertex = mul( v.vertex , rotationCamMatrix );
  241. v.vertex = mul( v.vertex , unity_WorldToObject );
  242. float3 temp_cast_0 = 0;
  243. #ifdef _BILLBOARD_ON
  244. float3 staticSwitch14 = 0;
  245. #else
  246. float3 staticSwitch14 = temp_cast_0;
  247. #endif
  248. o.ase_texcoord7.xy = v.texcoord.xy;
  249. o.ase_normal = v.ase_normal;
  250. //setting value to unused interpolator channels and avoid initialization warnings
  251. o.ase_texcoord7.zw = 0;
  252. #ifdef ASE_ABSOLUTE_VERTEX_POS
  253. float3 defaultVertexValue = v.vertex.xyz;
  254. #else
  255. float3 defaultVertexValue = float3(0, 0, 0);
  256. #endif
  257. float3 vertexValue = staticSwitch14;
  258. #ifdef ASE_ABSOLUTE_VERTEX_POS
  259. v.vertex.xyz = vertexValue;
  260. #else
  261. v.vertex.xyz += vertexValue;
  262. #endif
  263. v.ase_normal = v.ase_normal;
  264. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  265. float3 positionVS = TransformWorldToView( positionWS );
  266. float4 positionCS = TransformWorldToHClip( positionWS );
  267. VertexNormalInputs normalInput = GetVertexNormalInputs( v.ase_normal, v.ase_tangent );
  268. o.tSpace0 = float4( normalInput.normalWS, positionWS.x);
  269. o.tSpace1 = float4( normalInput.tangentWS, positionWS.y);
  270. o.tSpace2 = float4( normalInput.bitangentWS, positionWS.z);
  271. OUTPUT_LIGHTMAP_UV( v.texcoord1, unity_LightmapST, o.lightmapUVOrVertexSH.xy );
  272. OUTPUT_SH( normalInput.normalWS.xyz, o.lightmapUVOrVertexSH.xyz );
  273. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  274. o.lightmapUVOrVertexSH.zw = v.texcoord;
  275. o.lightmapUVOrVertexSH.xy = v.texcoord * unity_LightmapST.xy + unity_LightmapST.zw;
  276. #endif
  277. half3 vertexLight = VertexLighting( positionWS, normalInput.normalWS );
  278. #ifdef ASE_FOG
  279. half fogFactor = ComputeFogFactor( positionCS.z );
  280. #else
  281. half fogFactor = 0;
  282. #endif
  283. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  284. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  285. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  286. vertexInput.positionWS = positionWS;
  287. vertexInput.positionCS = positionCS;
  288. o.shadowCoord = GetShadowCoord( vertexInput );
  289. #endif
  290. o.clipPos = positionCS;
  291. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  292. o.screenPos = ComputeScreenPos(positionCS);
  293. #endif
  294. return o;
  295. }
  296. #if defined(TESSELLATION_ON)
  297. struct VertexControl
  298. {
  299. float4 vertex : INTERNALTESSPOS;
  300. float3 ase_normal : NORMAL;
  301. float4 ase_tangent : TANGENT;
  302. float4 texcoord : TEXCOORD0;
  303. float4 texcoord1 : TEXCOORD1;
  304. UNITY_VERTEX_INPUT_INSTANCE_ID
  305. };
  306. struct TessellationFactors
  307. {
  308. float edge[3] : SV_TessFactor;
  309. float inside : SV_InsideTessFactor;
  310. };
  311. VertexControl vert ( VertexInput v )
  312. {
  313. VertexControl o;
  314. UNITY_SETUP_INSTANCE_ID(v);
  315. UNITY_TRANSFER_INSTANCE_ID(v, o);
  316. o.vertex = v.vertex;
  317. o.ase_normal = v.ase_normal;
  318. o.ase_tangent = v.ase_tangent;
  319. o.texcoord = v.texcoord;
  320. o.texcoord1 = v.texcoord1;
  321. return o;
  322. }
  323. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  324. {
  325. TessellationFactors o;
  326. float4 tf = 1;
  327. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  328. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  329. #if defined(ASE_FIXED_TESSELLATION)
  330. tf = FixedTess( tessValue );
  331. #elif defined(ASE_DISTANCE_TESSELLATION)
  332. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  333. #elif defined(ASE_LENGTH_TESSELLATION)
  334. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  335. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  336. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  337. #endif
  338. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  339. return o;
  340. }
  341. [domain("tri")]
  342. [partitioning("fractional_odd")]
  343. [outputtopology("triangle_cw")]
  344. [patchconstantfunc("TessellationFunction")]
  345. [outputcontrolpoints(3)]
  346. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  347. {
  348. return patch[id];
  349. }
  350. [domain("tri")]
  351. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  352. {
  353. VertexInput o = (VertexInput) 0;
  354. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  355. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  356. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  357. o.texcoord = patch[0].texcoord * bary.x + patch[1].texcoord * bary.y + patch[2].texcoord * bary.z;
  358. o.texcoord1 = patch[0].texcoord1 * bary.x + patch[1].texcoord1 * bary.y + patch[2].texcoord1 * bary.z;
  359. #if defined(ASE_PHONG_TESSELLATION)
  360. float3 pp[3];
  361. for (int i = 0; i < 3; ++i)
  362. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  363. float phongStrength = _TessPhongStrength;
  364. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  365. #endif
  366. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  367. return VertexFunction(o);
  368. }
  369. #else
  370. VertexOutput vert ( VertexInput v )
  371. {
  372. return VertexFunction( v );
  373. }
  374. #endif
  375. #if defined(ASE_EARLY_Z_DEPTH_OPTIMIZE)
  376. #define ASE_SV_DEPTH SV_DepthLessEqual
  377. #else
  378. #define ASE_SV_DEPTH SV_Depth
  379. #endif
  380. half4 frag ( VertexOutput IN
  381. #ifdef ASE_DEPTH_WRITE_ON
  382. ,out float outputDepth : ASE_SV_DEPTH
  383. #endif
  384. ) : SV_Target
  385. {
  386. UNITY_SETUP_INSTANCE_ID(IN);
  387. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  388. #ifdef LOD_FADE_CROSSFADE
  389. LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
  390. #endif
  391. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  392. float2 sampleCoords = (IN.lightmapUVOrVertexSH.zw / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
  393. float3 WorldNormal = TransformObjectToWorldNormal(normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, sampler_TerrainNormalmapTexture, sampleCoords).rgb * 2 - 1));
  394. float3 WorldTangent = -cross(GetObjectToWorldMatrix()._13_23_33, WorldNormal);
  395. float3 WorldBiTangent = cross(WorldNormal, -WorldTangent);
  396. #else
  397. float3 WorldNormal = normalize( IN.tSpace0.xyz );
  398. float3 WorldTangent = IN.tSpace1.xyz;
  399. float3 WorldBiTangent = IN.tSpace2.xyz;
  400. #endif
  401. float3 WorldPosition = float3(IN.tSpace0.w,IN.tSpace1.w,IN.tSpace2.w);
  402. float3 WorldViewDirection = _WorldSpaceCameraPos.xyz - WorldPosition;
  403. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  404. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  405. float4 ScreenPos = IN.screenPos;
  406. #endif
  407. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  408. ShadowCoords = IN.shadowCoord;
  409. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  410. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  411. #endif
  412. WorldViewDirection = SafeNormalize( WorldViewDirection );
  413. float2 uv_MainTex = IN.ase_texcoord7.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  414. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  415. float3 Albedo = tex2DNode11.rgb;
  416. float3 Normal = IN.ase_normal;
  417. float3 Emission = 0;
  418. float3 Specular = 0.5;
  419. float Metallic = 0;
  420. float Smoothness = 0.5;
  421. float Occlusion = 1;
  422. float Alpha = tex2DNode11.a;
  423. float AlphaClipThreshold = 0.5;
  424. float AlphaClipThresholdShadow = 0.5;
  425. float3 BakedGI = 0;
  426. float3 RefractionColor = 1;
  427. float RefractionIndex = 1;
  428. float3 Transmission = 1;
  429. float3 Translucency = 1;
  430. #ifdef ASE_DEPTH_WRITE_ON
  431. float DepthValue = 0;
  432. #endif
  433. #ifdef _ALPHATEST_ON
  434. clip(Alpha - AlphaClipThreshold);
  435. #endif
  436. InputData inputData;
  437. inputData.positionWS = WorldPosition;
  438. inputData.viewDirectionWS = WorldViewDirection;
  439. inputData.shadowCoord = ShadowCoords;
  440. #ifdef _NORMALMAP
  441. #if _NORMAL_DROPOFF_TS
  442. inputData.normalWS = TransformTangentToWorld(Normal, half3x3( WorldTangent, WorldBiTangent, WorldNormal ));
  443. #elif _NORMAL_DROPOFF_OS
  444. inputData.normalWS = TransformObjectToWorldNormal(Normal);
  445. #elif _NORMAL_DROPOFF_WS
  446. inputData.normalWS = Normal;
  447. #endif
  448. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  449. #else
  450. inputData.normalWS = WorldNormal;
  451. #endif
  452. #ifdef ASE_FOG
  453. inputData.fogCoord = IN.fogFactorAndVertexLight.x;
  454. #endif
  455. inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  456. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  457. float3 SH = SampleSH(inputData.normalWS.xyz);
  458. #else
  459. float3 SH = IN.lightmapUVOrVertexSH.xyz;
  460. #endif
  461. inputData.bakedGI = SAMPLE_GI( IN.lightmapUVOrVertexSH.xy, SH, inputData.normalWS );
  462. #ifdef _ASE_BAKEDGI
  463. inputData.bakedGI = BakedGI;
  464. #endif
  465. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(IN.clipPos);
  466. inputData.shadowMask = SAMPLE_SHADOWMASK(IN.lightmapUVOrVertexSH.xy);
  467. half4 color = UniversalFragmentPBR(
  468. inputData,
  469. Albedo,
  470. Metallic,
  471. Specular,
  472. Smoothness,
  473. Occlusion,
  474. Emission,
  475. Alpha);
  476. #ifdef _TRANSMISSION_ASE
  477. {
  478. float shadow = _TransmissionShadow;
  479. Light mainLight = GetMainLight( inputData.shadowCoord );
  480. float3 mainAtten = mainLight.color * mainLight.distanceAttenuation;
  481. mainAtten = lerp( mainAtten, mainAtten * mainLight.shadowAttenuation, shadow );
  482. half3 mainTransmission = max(0 , -dot(inputData.normalWS, mainLight.direction)) * mainAtten * Transmission;
  483. color.rgb += Albedo * mainTransmission;
  484. #ifdef _ADDITIONAL_LIGHTS
  485. int transPixelLightCount = GetAdditionalLightsCount();
  486. for (int i = 0; i < transPixelLightCount; ++i)
  487. {
  488. Light light = GetAdditionalLight(i, inputData.positionWS);
  489. float3 atten = light.color * light.distanceAttenuation;
  490. atten = lerp( atten, atten * light.shadowAttenuation, shadow );
  491. half3 transmission = max(0 , -dot(inputData.normalWS, light.direction)) * atten * Transmission;
  492. color.rgb += Albedo * transmission;
  493. }
  494. #endif
  495. }
  496. #endif
  497. #ifdef _TRANSLUCENCY_ASE
  498. {
  499. float shadow = _TransShadow;
  500. float normal = _TransNormal;
  501. float scattering = _TransScattering;
  502. float direct = _TransDirect;
  503. float ambient = _TransAmbient;
  504. float strength = _TransStrength;
  505. Light mainLight = GetMainLight( inputData.shadowCoord );
  506. float3 mainAtten = mainLight.color * mainLight.distanceAttenuation;
  507. mainAtten = lerp( mainAtten, mainAtten * mainLight.shadowAttenuation, shadow );
  508. half3 mainLightDir = mainLight.direction + inputData.normalWS * normal;
  509. half mainVdotL = pow( saturate( dot( inputData.viewDirectionWS, -mainLightDir ) ), scattering );
  510. half3 mainTranslucency = mainAtten * ( mainVdotL * direct + inputData.bakedGI * ambient ) * Translucency;
  511. color.rgb += Albedo * mainTranslucency * strength;
  512. #ifdef _ADDITIONAL_LIGHTS
  513. int transPixelLightCount = GetAdditionalLightsCount();
  514. for (int i = 0; i < transPixelLightCount; ++i)
  515. {
  516. Light light = GetAdditionalLight(i, inputData.positionWS);
  517. float3 atten = light.color * light.distanceAttenuation;
  518. atten = lerp( atten, atten * light.shadowAttenuation, shadow );
  519. half3 lightDir = light.direction + inputData.normalWS * normal;
  520. half VdotL = pow( saturate( dot( inputData.viewDirectionWS, -lightDir ) ), scattering );
  521. half3 translucency = atten * ( VdotL * direct + inputData.bakedGI * ambient ) * Translucency;
  522. color.rgb += Albedo * translucency * strength;
  523. }
  524. #endif
  525. }
  526. #endif
  527. #ifdef _REFRACTION_ASE
  528. float4 projScreenPos = ScreenPos / ScreenPos.w;
  529. float3 refractionOffset = ( RefractionIndex - 1.0 ) * mul( UNITY_MATRIX_V, float4( WorldNormal,0 ) ).xyz * ( 1.0 - dot( WorldNormal, WorldViewDirection ) );
  530. projScreenPos.xy += refractionOffset.xy;
  531. float3 refraction = SHADERGRAPH_SAMPLE_SCENE_COLOR( projScreenPos.xy ) * RefractionColor;
  532. color.rgb = lerp( refraction, color.rgb, color.a );
  533. color.a = 1;
  534. #endif
  535. #ifdef ASE_FINAL_COLOR_ALPHA_MULTIPLY
  536. color.rgb *= color.a;
  537. #endif
  538. #ifdef ASE_FOG
  539. #ifdef TERRAIN_SPLAT_ADDPASS
  540. color.rgb = MixFogColor(color.rgb, half3( 0, 0, 0 ), IN.fogFactorAndVertexLight.x );
  541. #else
  542. color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x);
  543. #endif
  544. #endif
  545. #ifdef ASE_DEPTH_WRITE_ON
  546. outputDepth = DepthValue;
  547. #endif
  548. return color;
  549. }
  550. ENDHLSL
  551. }
  552. Pass
  553. {
  554. Name "ShadowCaster"
  555. Tags { "LightMode"="ShadowCaster" }
  556. ZWrite On
  557. ZTest LEqual
  558. AlphaToMask Off
  559. ColorMask 0
  560. HLSLPROGRAM
  561. #define _SPECULAR_SETUP 1
  562. #define _NORMAL_DROPOFF_TS 1
  563. #pragma multi_compile_instancing
  564. #pragma multi_compile _ LOD_FADE_CROSSFADE
  565. #pragma multi_compile_fog
  566. #define ASE_FOG 1
  567. #define _NORMALMAP 1
  568. #define ASE_SRP_VERSION 100500
  569. #pragma vertex vert
  570. #pragma fragment frag
  571. #if ASE_SRP_VERSION >= 110000
  572. #pragma multi_compile _ _CASTING_PUNCTUAL_LIGHT_SHADOW
  573. #endif
  574. #define SHADERPASS_SHADOWCASTER
  575. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  576. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  577. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  578. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  579. #define ASE_NEEDS_VERT_POSITION
  580. #define ASE_NEEDS_VERT_NORMAL
  581. #pragma shader_feature_local _BILLBOARD_ON
  582. struct VertexInput
  583. {
  584. float4 vertex : POSITION;
  585. float3 ase_normal : NORMAL;
  586. float4 ase_tangent : TANGENT;
  587. float4 ase_texcoord : TEXCOORD0;
  588. UNITY_VERTEX_INPUT_INSTANCE_ID
  589. };
  590. struct VertexOutput
  591. {
  592. float4 clipPos : SV_POSITION;
  593. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  594. float3 worldPos : TEXCOORD0;
  595. #endif
  596. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  597. float4 shadowCoord : TEXCOORD1;
  598. #endif
  599. float4 ase_texcoord2 : TEXCOORD2;
  600. UNITY_VERTEX_INPUT_INSTANCE_ID
  601. UNITY_VERTEX_OUTPUT_STEREO
  602. };
  603. CBUFFER_START(UnityPerMaterial)
  604. float4 _MainTex_ST;
  605. #ifdef _TRANSMISSION_ASE
  606. float _TransmissionShadow;
  607. #endif
  608. #ifdef _TRANSLUCENCY_ASE
  609. float _TransStrength;
  610. float _TransNormal;
  611. float _TransScattering;
  612. float _TransDirect;
  613. float _TransAmbient;
  614. float _TransShadow;
  615. #endif
  616. #ifdef TESSELLATION_ON
  617. float _TessPhongStrength;
  618. float _TessValue;
  619. float _TessMin;
  620. float _TessMax;
  621. float _TessEdgeLength;
  622. float _TessMaxDisp;
  623. #endif
  624. CBUFFER_END
  625. sampler2D _MainTex;
  626. float3 _LightDirection;
  627. #if ASE_SRP_VERSION >= 110000
  628. float3 _LightPosition;
  629. #endif
  630. VertexOutput VertexFunction( VertexInput v )
  631. {
  632. VertexOutput o;
  633. UNITY_SETUP_INSTANCE_ID(v);
  634. UNITY_TRANSFER_INSTANCE_ID(v, o);
  635. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
  636. //Calculate new billboard vertex position and normal;
  637. float3 upCamVec = float3( 0, 1, 0 );
  638. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  639. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  640. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  641. //This unfortunately must be made to take non-uniform scaling into account;
  642. //Transform to world coords, apply rotation and transform back to local;
  643. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  644. v.vertex = mul( v.vertex , rotationCamMatrix );
  645. v.vertex = mul( v.vertex , unity_WorldToObject );
  646. float3 temp_cast_0 = 0;
  647. #ifdef _BILLBOARD_ON
  648. float3 staticSwitch14 = 0;
  649. #else
  650. float3 staticSwitch14 = temp_cast_0;
  651. #endif
  652. o.ase_texcoord2.xy = v.ase_texcoord.xy;
  653. //setting value to unused interpolator channels and avoid initialization warnings
  654. o.ase_texcoord2.zw = 0;
  655. #ifdef ASE_ABSOLUTE_VERTEX_POS
  656. float3 defaultVertexValue = v.vertex.xyz;
  657. #else
  658. float3 defaultVertexValue = float3(0, 0, 0);
  659. #endif
  660. float3 vertexValue = staticSwitch14;
  661. #ifdef ASE_ABSOLUTE_VERTEX_POS
  662. v.vertex.xyz = vertexValue;
  663. #else
  664. v.vertex.xyz += vertexValue;
  665. #endif
  666. v.ase_normal = v.ase_normal;
  667. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  668. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  669. o.worldPos = positionWS;
  670. #endif
  671. float3 normalWS = TransformObjectToWorldDir(v.ase_normal);
  672. #if ASE_SRP_VERSION >= 110000
  673. #if _CASTING_PUNCTUAL_LIGHT_SHADOW
  674. float3 lightDirectionWS = normalize(_LightPosition - positionWS);
  675. #else
  676. float3 lightDirectionWS = _LightDirection;
  677. #endif
  678. float4 clipPos = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
  679. #if UNITY_REVERSED_Z
  680. clipPos.z = min(clipPos.z, UNITY_NEAR_CLIP_VALUE);
  681. #else
  682. clipPos.z = max(clipPos.z, UNITY_NEAR_CLIP_VALUE);
  683. #endif
  684. #else
  685. float4 clipPos = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, _LightDirection));
  686. #if UNITY_REVERSED_Z
  687. clipPos.z = min(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
  688. #else
  689. clipPos.z = max(clipPos.z, clipPos.w * UNITY_NEAR_CLIP_VALUE);
  690. #endif
  691. #endif
  692. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  693. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  694. vertexInput.positionWS = positionWS;
  695. vertexInput.positionCS = clipPos;
  696. o.shadowCoord = GetShadowCoord( vertexInput );
  697. #endif
  698. o.clipPos = clipPos;
  699. return o;
  700. }
  701. #if defined(TESSELLATION_ON)
  702. struct VertexControl
  703. {
  704. float4 vertex : INTERNALTESSPOS;
  705. float3 ase_normal : NORMAL;
  706. float4 ase_tangent : TANGENT;
  707. float4 ase_texcoord : TEXCOORD0;
  708. UNITY_VERTEX_INPUT_INSTANCE_ID
  709. };
  710. struct TessellationFactors
  711. {
  712. float edge[3] : SV_TessFactor;
  713. float inside : SV_InsideTessFactor;
  714. };
  715. VertexControl vert ( VertexInput v )
  716. {
  717. VertexControl o;
  718. UNITY_SETUP_INSTANCE_ID(v);
  719. UNITY_TRANSFER_INSTANCE_ID(v, o);
  720. o.vertex = v.vertex;
  721. o.ase_normal = v.ase_normal;
  722. o.ase_tangent = v.ase_tangent;
  723. o.ase_texcoord = v.ase_texcoord;
  724. return o;
  725. }
  726. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  727. {
  728. TessellationFactors o;
  729. float4 tf = 1;
  730. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  731. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  732. #if defined(ASE_FIXED_TESSELLATION)
  733. tf = FixedTess( tessValue );
  734. #elif defined(ASE_DISTANCE_TESSELLATION)
  735. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  736. #elif defined(ASE_LENGTH_TESSELLATION)
  737. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  738. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  739. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  740. #endif
  741. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  742. return o;
  743. }
  744. [domain("tri")]
  745. [partitioning("fractional_odd")]
  746. [outputtopology("triangle_cw")]
  747. [patchconstantfunc("TessellationFunction")]
  748. [outputcontrolpoints(3)]
  749. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  750. {
  751. return patch[id];
  752. }
  753. [domain("tri")]
  754. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  755. {
  756. VertexInput o = (VertexInput) 0;
  757. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  758. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  759. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  760. o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z;
  761. #if defined(ASE_PHONG_TESSELLATION)
  762. float3 pp[3];
  763. for (int i = 0; i < 3; ++i)
  764. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  765. float phongStrength = _TessPhongStrength;
  766. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  767. #endif
  768. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  769. return VertexFunction(o);
  770. }
  771. #else
  772. VertexOutput vert ( VertexInput v )
  773. {
  774. return VertexFunction( v );
  775. }
  776. #endif
  777. #if defined(ASE_EARLY_Z_DEPTH_OPTIMIZE)
  778. #define ASE_SV_DEPTH SV_DepthLessEqual
  779. #else
  780. #define ASE_SV_DEPTH SV_Depth
  781. #endif
  782. half4 frag( VertexOutput IN
  783. #ifdef ASE_DEPTH_WRITE_ON
  784. ,out float outputDepth : ASE_SV_DEPTH
  785. #endif
  786. ) : SV_TARGET
  787. {
  788. UNITY_SETUP_INSTANCE_ID( IN );
  789. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
  790. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  791. float3 WorldPosition = IN.worldPos;
  792. #endif
  793. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  794. #if defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  795. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  796. ShadowCoords = IN.shadowCoord;
  797. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  798. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  799. #endif
  800. #endif
  801. float2 uv_MainTex = IN.ase_texcoord2.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  802. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  803. float Alpha = tex2DNode11.a;
  804. float AlphaClipThreshold = 0.5;
  805. float AlphaClipThresholdShadow = 0.5;
  806. #ifdef ASE_DEPTH_WRITE_ON
  807. float DepthValue = 0;
  808. #endif
  809. #ifdef _ALPHATEST_ON
  810. #ifdef _ALPHATEST_SHADOW_ON
  811. clip(Alpha - AlphaClipThresholdShadow);
  812. #else
  813. clip(Alpha - AlphaClipThreshold);
  814. #endif
  815. #endif
  816. #ifdef LOD_FADE_CROSSFADE
  817. LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
  818. #endif
  819. #ifdef ASE_DEPTH_WRITE_ON
  820. outputDepth = DepthValue;
  821. #endif
  822. return 0;
  823. }
  824. ENDHLSL
  825. }
  826. Pass
  827. {
  828. Name "DepthOnly"
  829. Tags { "LightMode"="DepthOnly" }
  830. ZWrite On
  831. ColorMask 0
  832. AlphaToMask Off
  833. HLSLPROGRAM
  834. #define _SPECULAR_SETUP 1
  835. #define _NORMAL_DROPOFF_TS 1
  836. #pragma multi_compile_instancing
  837. #pragma multi_compile _ LOD_FADE_CROSSFADE
  838. #pragma multi_compile_fog
  839. #define ASE_FOG 1
  840. #define _NORMALMAP 1
  841. #define ASE_SRP_VERSION 100500
  842. #pragma vertex vert
  843. #pragma fragment frag
  844. #define SHADERPASS_DEPTHONLY
  845. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  846. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  847. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  848. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  849. #define ASE_NEEDS_VERT_POSITION
  850. #define ASE_NEEDS_VERT_NORMAL
  851. #pragma shader_feature_local _BILLBOARD_ON
  852. struct VertexInput
  853. {
  854. float4 vertex : POSITION;
  855. float3 ase_normal : NORMAL;
  856. float4 ase_tangent : TANGENT;
  857. float4 ase_texcoord : TEXCOORD0;
  858. UNITY_VERTEX_INPUT_INSTANCE_ID
  859. };
  860. struct VertexOutput
  861. {
  862. float4 clipPos : SV_POSITION;
  863. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  864. float3 worldPos : TEXCOORD0;
  865. #endif
  866. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  867. float4 shadowCoord : TEXCOORD1;
  868. #endif
  869. float4 ase_texcoord2 : TEXCOORD2;
  870. UNITY_VERTEX_INPUT_INSTANCE_ID
  871. UNITY_VERTEX_OUTPUT_STEREO
  872. };
  873. CBUFFER_START(UnityPerMaterial)
  874. float4 _MainTex_ST;
  875. #ifdef _TRANSMISSION_ASE
  876. float _TransmissionShadow;
  877. #endif
  878. #ifdef _TRANSLUCENCY_ASE
  879. float _TransStrength;
  880. float _TransNormal;
  881. float _TransScattering;
  882. float _TransDirect;
  883. float _TransAmbient;
  884. float _TransShadow;
  885. #endif
  886. #ifdef TESSELLATION_ON
  887. float _TessPhongStrength;
  888. float _TessValue;
  889. float _TessMin;
  890. float _TessMax;
  891. float _TessEdgeLength;
  892. float _TessMaxDisp;
  893. #endif
  894. CBUFFER_END
  895. sampler2D _MainTex;
  896. VertexOutput VertexFunction( VertexInput v )
  897. {
  898. VertexOutput o = (VertexOutput)0;
  899. UNITY_SETUP_INSTANCE_ID(v);
  900. UNITY_TRANSFER_INSTANCE_ID(v, o);
  901. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  902. //Calculate new billboard vertex position and normal;
  903. float3 upCamVec = float3( 0, 1, 0 );
  904. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  905. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  906. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  907. //This unfortunately must be made to take non-uniform scaling into account;
  908. //Transform to world coords, apply rotation and transform back to local;
  909. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  910. v.vertex = mul( v.vertex , rotationCamMatrix );
  911. v.vertex = mul( v.vertex , unity_WorldToObject );
  912. float3 temp_cast_0 = 0;
  913. #ifdef _BILLBOARD_ON
  914. float3 staticSwitch14 = 0;
  915. #else
  916. float3 staticSwitch14 = temp_cast_0;
  917. #endif
  918. o.ase_texcoord2.xy = v.ase_texcoord.xy;
  919. //setting value to unused interpolator channels and avoid initialization warnings
  920. o.ase_texcoord2.zw = 0;
  921. #ifdef ASE_ABSOLUTE_VERTEX_POS
  922. float3 defaultVertexValue = v.vertex.xyz;
  923. #else
  924. float3 defaultVertexValue = float3(0, 0, 0);
  925. #endif
  926. float3 vertexValue = staticSwitch14;
  927. #ifdef ASE_ABSOLUTE_VERTEX_POS
  928. v.vertex.xyz = vertexValue;
  929. #else
  930. v.vertex.xyz += vertexValue;
  931. #endif
  932. v.ase_normal = v.ase_normal;
  933. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  934. float4 positionCS = TransformWorldToHClip( positionWS );
  935. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  936. o.worldPos = positionWS;
  937. #endif
  938. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  939. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  940. vertexInput.positionWS = positionWS;
  941. vertexInput.positionCS = positionCS;
  942. o.shadowCoord = GetShadowCoord( vertexInput );
  943. #endif
  944. o.clipPos = positionCS;
  945. return o;
  946. }
  947. #if defined(TESSELLATION_ON)
  948. struct VertexControl
  949. {
  950. float4 vertex : INTERNALTESSPOS;
  951. float3 ase_normal : NORMAL;
  952. float4 ase_tangent : TANGENT;
  953. float4 ase_texcoord : TEXCOORD0;
  954. UNITY_VERTEX_INPUT_INSTANCE_ID
  955. };
  956. struct TessellationFactors
  957. {
  958. float edge[3] : SV_TessFactor;
  959. float inside : SV_InsideTessFactor;
  960. };
  961. VertexControl vert ( VertexInput v )
  962. {
  963. VertexControl o;
  964. UNITY_SETUP_INSTANCE_ID(v);
  965. UNITY_TRANSFER_INSTANCE_ID(v, o);
  966. o.vertex = v.vertex;
  967. o.ase_normal = v.ase_normal;
  968. o.ase_tangent = v.ase_tangent;
  969. o.ase_texcoord = v.ase_texcoord;
  970. return o;
  971. }
  972. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  973. {
  974. TessellationFactors o;
  975. float4 tf = 1;
  976. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  977. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  978. #if defined(ASE_FIXED_TESSELLATION)
  979. tf = FixedTess( tessValue );
  980. #elif defined(ASE_DISTANCE_TESSELLATION)
  981. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  982. #elif defined(ASE_LENGTH_TESSELLATION)
  983. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  984. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  985. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  986. #endif
  987. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  988. return o;
  989. }
  990. [domain("tri")]
  991. [partitioning("fractional_odd")]
  992. [outputtopology("triangle_cw")]
  993. [patchconstantfunc("TessellationFunction")]
  994. [outputcontrolpoints(3)]
  995. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  996. {
  997. return patch[id];
  998. }
  999. [domain("tri")]
  1000. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  1001. {
  1002. VertexInput o = (VertexInput) 0;
  1003. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  1004. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  1005. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  1006. o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z;
  1007. #if defined(ASE_PHONG_TESSELLATION)
  1008. float3 pp[3];
  1009. for (int i = 0; i < 3; ++i)
  1010. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  1011. float phongStrength = _TessPhongStrength;
  1012. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  1013. #endif
  1014. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  1015. return VertexFunction(o);
  1016. }
  1017. #else
  1018. VertexOutput vert ( VertexInput v )
  1019. {
  1020. return VertexFunction( v );
  1021. }
  1022. #endif
  1023. #if defined(ASE_EARLY_Z_DEPTH_OPTIMIZE)
  1024. #define ASE_SV_DEPTH SV_DepthLessEqual
  1025. #else
  1026. #define ASE_SV_DEPTH SV_Depth
  1027. #endif
  1028. half4 frag( VertexOutput IN
  1029. #ifdef ASE_DEPTH_WRITE_ON
  1030. ,out float outputDepth : ASE_SV_DEPTH
  1031. #endif
  1032. ) : SV_TARGET
  1033. {
  1034. UNITY_SETUP_INSTANCE_ID(IN);
  1035. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
  1036. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1037. float3 WorldPosition = IN.worldPos;
  1038. #endif
  1039. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  1040. #if defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1041. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1042. ShadowCoords = IN.shadowCoord;
  1043. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1044. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  1045. #endif
  1046. #endif
  1047. float2 uv_MainTex = IN.ase_texcoord2.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  1048. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  1049. float Alpha = tex2DNode11.a;
  1050. float AlphaClipThreshold = 0.5;
  1051. #ifdef ASE_DEPTH_WRITE_ON
  1052. float DepthValue = 0;
  1053. #endif
  1054. #ifdef _ALPHATEST_ON
  1055. clip(Alpha - AlphaClipThreshold);
  1056. #endif
  1057. #ifdef LOD_FADE_CROSSFADE
  1058. LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
  1059. #endif
  1060. #ifdef ASE_DEPTH_WRITE_ON
  1061. outputDepth = DepthValue;
  1062. #endif
  1063. return 0;
  1064. }
  1065. ENDHLSL
  1066. }
  1067. Pass
  1068. {
  1069. Name "Meta"
  1070. Tags { "LightMode"="Meta" }
  1071. Cull Off
  1072. HLSLPROGRAM
  1073. #define _SPECULAR_SETUP 1
  1074. #define _NORMAL_DROPOFF_TS 1
  1075. #pragma multi_compile_instancing
  1076. #pragma multi_compile _ LOD_FADE_CROSSFADE
  1077. #pragma multi_compile_fog
  1078. #define ASE_FOG 1
  1079. #define _NORMALMAP 1
  1080. #define ASE_SRP_VERSION 100500
  1081. #pragma vertex vert
  1082. #pragma fragment frag
  1083. #define SHADERPASS_META
  1084. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1085. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
  1086. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1087. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1088. #define ASE_NEEDS_VERT_POSITION
  1089. #define ASE_NEEDS_VERT_NORMAL
  1090. #pragma shader_feature_local _BILLBOARD_ON
  1091. #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  1092. struct VertexInput
  1093. {
  1094. float4 vertex : POSITION;
  1095. float3 ase_normal : NORMAL;
  1096. float4 texcoord1 : TEXCOORD1;
  1097. float4 texcoord2 : TEXCOORD2;
  1098. float4 ase_tangent : TANGENT;
  1099. float4 ase_texcoord : TEXCOORD0;
  1100. UNITY_VERTEX_INPUT_INSTANCE_ID
  1101. };
  1102. struct VertexOutput
  1103. {
  1104. float4 clipPos : SV_POSITION;
  1105. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1106. float3 worldPos : TEXCOORD0;
  1107. #endif
  1108. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1109. float4 shadowCoord : TEXCOORD1;
  1110. #endif
  1111. float4 ase_texcoord2 : TEXCOORD2;
  1112. UNITY_VERTEX_INPUT_INSTANCE_ID
  1113. UNITY_VERTEX_OUTPUT_STEREO
  1114. };
  1115. CBUFFER_START(UnityPerMaterial)
  1116. float4 _MainTex_ST;
  1117. #ifdef _TRANSMISSION_ASE
  1118. float _TransmissionShadow;
  1119. #endif
  1120. #ifdef _TRANSLUCENCY_ASE
  1121. float _TransStrength;
  1122. float _TransNormal;
  1123. float _TransScattering;
  1124. float _TransDirect;
  1125. float _TransAmbient;
  1126. float _TransShadow;
  1127. #endif
  1128. #ifdef TESSELLATION_ON
  1129. float _TessPhongStrength;
  1130. float _TessValue;
  1131. float _TessMin;
  1132. float _TessMax;
  1133. float _TessEdgeLength;
  1134. float _TessMaxDisp;
  1135. #endif
  1136. CBUFFER_END
  1137. sampler2D _MainTex;
  1138. VertexOutput VertexFunction( VertexInput v )
  1139. {
  1140. VertexOutput o = (VertexOutput)0;
  1141. UNITY_SETUP_INSTANCE_ID(v);
  1142. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1143. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  1144. //Calculate new billboard vertex position and normal;
  1145. float3 upCamVec = float3( 0, 1, 0 );
  1146. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  1147. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  1148. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  1149. //This unfortunately must be made to take non-uniform scaling into account;
  1150. //Transform to world coords, apply rotation and transform back to local;
  1151. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  1152. v.vertex = mul( v.vertex , rotationCamMatrix );
  1153. v.vertex = mul( v.vertex , unity_WorldToObject );
  1154. float3 temp_cast_0 = 0;
  1155. #ifdef _BILLBOARD_ON
  1156. float3 staticSwitch14 = 0;
  1157. #else
  1158. float3 staticSwitch14 = temp_cast_0;
  1159. #endif
  1160. o.ase_texcoord2.xy = v.ase_texcoord.xy;
  1161. //setting value to unused interpolator channels and avoid initialization warnings
  1162. o.ase_texcoord2.zw = 0;
  1163. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1164. float3 defaultVertexValue = v.vertex.xyz;
  1165. #else
  1166. float3 defaultVertexValue = float3(0, 0, 0);
  1167. #endif
  1168. float3 vertexValue = staticSwitch14;
  1169. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1170. v.vertex.xyz = vertexValue;
  1171. #else
  1172. v.vertex.xyz += vertexValue;
  1173. #endif
  1174. v.ase_normal = v.ase_normal;
  1175. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  1176. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1177. o.worldPos = positionWS;
  1178. #endif
  1179. o.clipPos = MetaVertexPosition( v.vertex, v.texcoord1.xy, v.texcoord1.xy, unity_LightmapST, unity_DynamicLightmapST );
  1180. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1181. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  1182. vertexInput.positionWS = positionWS;
  1183. vertexInput.positionCS = o.clipPos;
  1184. o.shadowCoord = GetShadowCoord( vertexInput );
  1185. #endif
  1186. return o;
  1187. }
  1188. #if defined(TESSELLATION_ON)
  1189. struct VertexControl
  1190. {
  1191. float4 vertex : INTERNALTESSPOS;
  1192. float3 ase_normal : NORMAL;
  1193. float4 texcoord1 : TEXCOORD1;
  1194. float4 texcoord2 : TEXCOORD2;
  1195. float4 ase_tangent : TANGENT;
  1196. float4 ase_texcoord : TEXCOORD0;
  1197. UNITY_VERTEX_INPUT_INSTANCE_ID
  1198. };
  1199. struct TessellationFactors
  1200. {
  1201. float edge[3] : SV_TessFactor;
  1202. float inside : SV_InsideTessFactor;
  1203. };
  1204. VertexControl vert ( VertexInput v )
  1205. {
  1206. VertexControl o;
  1207. UNITY_SETUP_INSTANCE_ID(v);
  1208. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1209. o.vertex = v.vertex;
  1210. o.ase_normal = v.ase_normal;
  1211. o.texcoord1 = v.texcoord1;
  1212. o.texcoord2 = v.texcoord2;
  1213. o.ase_tangent = v.ase_tangent;
  1214. o.ase_texcoord = v.ase_texcoord;
  1215. return o;
  1216. }
  1217. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  1218. {
  1219. TessellationFactors o;
  1220. float4 tf = 1;
  1221. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  1222. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  1223. #if defined(ASE_FIXED_TESSELLATION)
  1224. tf = FixedTess( tessValue );
  1225. #elif defined(ASE_DISTANCE_TESSELLATION)
  1226. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  1227. #elif defined(ASE_LENGTH_TESSELLATION)
  1228. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  1229. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  1230. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  1231. #endif
  1232. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  1233. return o;
  1234. }
  1235. [domain("tri")]
  1236. [partitioning("fractional_odd")]
  1237. [outputtopology("triangle_cw")]
  1238. [patchconstantfunc("TessellationFunction")]
  1239. [outputcontrolpoints(3)]
  1240. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  1241. {
  1242. return patch[id];
  1243. }
  1244. [domain("tri")]
  1245. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  1246. {
  1247. VertexInput o = (VertexInput) 0;
  1248. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  1249. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  1250. o.texcoord1 = patch[0].texcoord1 * bary.x + patch[1].texcoord1 * bary.y + patch[2].texcoord1 * bary.z;
  1251. o.texcoord2 = patch[0].texcoord2 * bary.x + patch[1].texcoord2 * bary.y + patch[2].texcoord2 * bary.z;
  1252. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  1253. o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z;
  1254. #if defined(ASE_PHONG_TESSELLATION)
  1255. float3 pp[3];
  1256. for (int i = 0; i < 3; ++i)
  1257. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  1258. float phongStrength = _TessPhongStrength;
  1259. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  1260. #endif
  1261. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  1262. return VertexFunction(o);
  1263. }
  1264. #else
  1265. VertexOutput vert ( VertexInput v )
  1266. {
  1267. return VertexFunction( v );
  1268. }
  1269. #endif
  1270. half4 frag(VertexOutput IN ) : SV_TARGET
  1271. {
  1272. UNITY_SETUP_INSTANCE_ID(IN);
  1273. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
  1274. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1275. float3 WorldPosition = IN.worldPos;
  1276. #endif
  1277. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  1278. #if defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1279. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1280. ShadowCoords = IN.shadowCoord;
  1281. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1282. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  1283. #endif
  1284. #endif
  1285. float2 uv_MainTex = IN.ase_texcoord2.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  1286. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  1287. float3 Albedo = tex2DNode11.rgb;
  1288. float3 Emission = 0;
  1289. float Alpha = tex2DNode11.a;
  1290. float AlphaClipThreshold = 0.5;
  1291. #ifdef _ALPHATEST_ON
  1292. clip(Alpha - AlphaClipThreshold);
  1293. #endif
  1294. MetaInput metaInput = (MetaInput)0;
  1295. metaInput.Albedo = Albedo;
  1296. metaInput.Emission = Emission;
  1297. return MetaFragment(metaInput);
  1298. }
  1299. ENDHLSL
  1300. }
  1301. Pass
  1302. {
  1303. Name "Universal2D"
  1304. Tags { "LightMode"="Universal2D" }
  1305. Blend One Zero, One Zero
  1306. ZWrite Off
  1307. ZTest LEqual
  1308. Offset 0 , 0
  1309. ColorMask RGBA
  1310. HLSLPROGRAM
  1311. #define _SPECULAR_SETUP 1
  1312. #define _NORMAL_DROPOFF_TS 1
  1313. #pragma multi_compile_instancing
  1314. #pragma multi_compile _ LOD_FADE_CROSSFADE
  1315. #pragma multi_compile_fog
  1316. #define ASE_FOG 1
  1317. #define _NORMALMAP 1
  1318. #define ASE_SRP_VERSION 100500
  1319. #pragma vertex vert
  1320. #pragma fragment frag
  1321. #define SHADERPASS_2D
  1322. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1323. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1324. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1325. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  1326. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1327. #define ASE_NEEDS_VERT_POSITION
  1328. #define ASE_NEEDS_VERT_NORMAL
  1329. #pragma shader_feature_local _BILLBOARD_ON
  1330. #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  1331. struct VertexInput
  1332. {
  1333. float4 vertex : POSITION;
  1334. float3 ase_normal : NORMAL;
  1335. float4 ase_tangent : TANGENT;
  1336. float4 ase_texcoord : TEXCOORD0;
  1337. UNITY_VERTEX_INPUT_INSTANCE_ID
  1338. };
  1339. struct VertexOutput
  1340. {
  1341. float4 clipPos : SV_POSITION;
  1342. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1343. float3 worldPos : TEXCOORD0;
  1344. #endif
  1345. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1346. float4 shadowCoord : TEXCOORD1;
  1347. #endif
  1348. float4 ase_texcoord2 : TEXCOORD2;
  1349. UNITY_VERTEX_INPUT_INSTANCE_ID
  1350. UNITY_VERTEX_OUTPUT_STEREO
  1351. };
  1352. CBUFFER_START(UnityPerMaterial)
  1353. float4 _MainTex_ST;
  1354. #ifdef _TRANSMISSION_ASE
  1355. float _TransmissionShadow;
  1356. #endif
  1357. #ifdef _TRANSLUCENCY_ASE
  1358. float _TransStrength;
  1359. float _TransNormal;
  1360. float _TransScattering;
  1361. float _TransDirect;
  1362. float _TransAmbient;
  1363. float _TransShadow;
  1364. #endif
  1365. #ifdef TESSELLATION_ON
  1366. float _TessPhongStrength;
  1367. float _TessValue;
  1368. float _TessMin;
  1369. float _TessMax;
  1370. float _TessEdgeLength;
  1371. float _TessMaxDisp;
  1372. #endif
  1373. CBUFFER_END
  1374. sampler2D _MainTex;
  1375. VertexOutput VertexFunction( VertexInput v )
  1376. {
  1377. VertexOutput o = (VertexOutput)0;
  1378. UNITY_SETUP_INSTANCE_ID( v );
  1379. UNITY_TRANSFER_INSTANCE_ID( v, o );
  1380. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
  1381. //Calculate new billboard vertex position and normal;
  1382. float3 upCamVec = float3( 0, 1, 0 );
  1383. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  1384. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  1385. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  1386. //This unfortunately must be made to take non-uniform scaling into account;
  1387. //Transform to world coords, apply rotation and transform back to local;
  1388. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  1389. v.vertex = mul( v.vertex , rotationCamMatrix );
  1390. v.vertex = mul( v.vertex , unity_WorldToObject );
  1391. float3 temp_cast_0 = 0;
  1392. #ifdef _BILLBOARD_ON
  1393. float3 staticSwitch14 = 0;
  1394. #else
  1395. float3 staticSwitch14 = temp_cast_0;
  1396. #endif
  1397. o.ase_texcoord2.xy = v.ase_texcoord.xy;
  1398. //setting value to unused interpolator channels and avoid initialization warnings
  1399. o.ase_texcoord2.zw = 0;
  1400. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1401. float3 defaultVertexValue = v.vertex.xyz;
  1402. #else
  1403. float3 defaultVertexValue = float3(0, 0, 0);
  1404. #endif
  1405. float3 vertexValue = staticSwitch14;
  1406. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1407. v.vertex.xyz = vertexValue;
  1408. #else
  1409. v.vertex.xyz += vertexValue;
  1410. #endif
  1411. v.ase_normal = v.ase_normal;
  1412. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  1413. float4 positionCS = TransformWorldToHClip( positionWS );
  1414. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1415. o.worldPos = positionWS;
  1416. #endif
  1417. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1418. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  1419. vertexInput.positionWS = positionWS;
  1420. vertexInput.positionCS = positionCS;
  1421. o.shadowCoord = GetShadowCoord( vertexInput );
  1422. #endif
  1423. o.clipPos = positionCS;
  1424. return o;
  1425. }
  1426. #if defined(TESSELLATION_ON)
  1427. struct VertexControl
  1428. {
  1429. float4 vertex : INTERNALTESSPOS;
  1430. float3 ase_normal : NORMAL;
  1431. float4 ase_tangent : TANGENT;
  1432. float4 ase_texcoord : TEXCOORD0;
  1433. UNITY_VERTEX_INPUT_INSTANCE_ID
  1434. };
  1435. struct TessellationFactors
  1436. {
  1437. float edge[3] : SV_TessFactor;
  1438. float inside : SV_InsideTessFactor;
  1439. };
  1440. VertexControl vert ( VertexInput v )
  1441. {
  1442. VertexControl o;
  1443. UNITY_SETUP_INSTANCE_ID(v);
  1444. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1445. o.vertex = v.vertex;
  1446. o.ase_normal = v.ase_normal;
  1447. o.ase_tangent = v.ase_tangent;
  1448. o.ase_texcoord = v.ase_texcoord;
  1449. return o;
  1450. }
  1451. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  1452. {
  1453. TessellationFactors o;
  1454. float4 tf = 1;
  1455. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  1456. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  1457. #if defined(ASE_FIXED_TESSELLATION)
  1458. tf = FixedTess( tessValue );
  1459. #elif defined(ASE_DISTANCE_TESSELLATION)
  1460. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  1461. #elif defined(ASE_LENGTH_TESSELLATION)
  1462. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  1463. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  1464. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  1465. #endif
  1466. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  1467. return o;
  1468. }
  1469. [domain("tri")]
  1470. [partitioning("fractional_odd")]
  1471. [outputtopology("triangle_cw")]
  1472. [patchconstantfunc("TessellationFunction")]
  1473. [outputcontrolpoints(3)]
  1474. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  1475. {
  1476. return patch[id];
  1477. }
  1478. [domain("tri")]
  1479. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  1480. {
  1481. VertexInput o = (VertexInput) 0;
  1482. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  1483. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  1484. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  1485. o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z;
  1486. #if defined(ASE_PHONG_TESSELLATION)
  1487. float3 pp[3];
  1488. for (int i = 0; i < 3; ++i)
  1489. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  1490. float phongStrength = _TessPhongStrength;
  1491. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  1492. #endif
  1493. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  1494. return VertexFunction(o);
  1495. }
  1496. #else
  1497. VertexOutput vert ( VertexInput v )
  1498. {
  1499. return VertexFunction( v );
  1500. }
  1501. #endif
  1502. half4 frag(VertexOutput IN ) : SV_TARGET
  1503. {
  1504. UNITY_SETUP_INSTANCE_ID( IN );
  1505. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
  1506. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1507. float3 WorldPosition = IN.worldPos;
  1508. #endif
  1509. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  1510. #if defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1511. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1512. ShadowCoords = IN.shadowCoord;
  1513. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1514. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  1515. #endif
  1516. #endif
  1517. float2 uv_MainTex = IN.ase_texcoord2.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  1518. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  1519. float3 Albedo = tex2DNode11.rgb;
  1520. float Alpha = tex2DNode11.a;
  1521. float AlphaClipThreshold = 0.5;
  1522. half4 color = half4( Albedo, Alpha );
  1523. #ifdef _ALPHATEST_ON
  1524. clip(Alpha - AlphaClipThreshold);
  1525. #endif
  1526. return color;
  1527. }
  1528. ENDHLSL
  1529. }
  1530. Pass
  1531. {
  1532. Name "DepthNormals"
  1533. Tags { "LightMode"="DepthNormals" }
  1534. ZWrite On
  1535. Blend One Zero
  1536. ZTest LEqual
  1537. ZWrite On
  1538. HLSLPROGRAM
  1539. #define _SPECULAR_SETUP 1
  1540. #define _NORMAL_DROPOFF_TS 1
  1541. #pragma multi_compile_instancing
  1542. #pragma multi_compile _ LOD_FADE_CROSSFADE
  1543. #pragma multi_compile_fog
  1544. #define ASE_FOG 1
  1545. #define _NORMALMAP 1
  1546. #define ASE_SRP_VERSION 100500
  1547. #pragma vertex vert
  1548. #pragma fragment frag
  1549. #define SHADERPASS_DEPTHNORMALSONLY
  1550. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1551. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1552. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1553. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1554. #define ASE_NEEDS_VERT_POSITION
  1555. #define ASE_NEEDS_VERT_NORMAL
  1556. #pragma shader_feature_local _BILLBOARD_ON
  1557. struct VertexInput
  1558. {
  1559. float4 vertex : POSITION;
  1560. float3 ase_normal : NORMAL;
  1561. float4 ase_tangent : TANGENT;
  1562. float4 ase_texcoord : TEXCOORD0;
  1563. UNITY_VERTEX_INPUT_INSTANCE_ID
  1564. };
  1565. struct VertexOutput
  1566. {
  1567. float4 clipPos : SV_POSITION;
  1568. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1569. float3 worldPos : TEXCOORD0;
  1570. #endif
  1571. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1572. float4 shadowCoord : TEXCOORD1;
  1573. #endif
  1574. float3 worldNormal : TEXCOORD2;
  1575. float4 ase_texcoord3 : TEXCOORD3;
  1576. UNITY_VERTEX_INPUT_INSTANCE_ID
  1577. UNITY_VERTEX_OUTPUT_STEREO
  1578. };
  1579. CBUFFER_START(UnityPerMaterial)
  1580. float4 _MainTex_ST;
  1581. #ifdef _TRANSMISSION_ASE
  1582. float _TransmissionShadow;
  1583. #endif
  1584. #ifdef _TRANSLUCENCY_ASE
  1585. float _TransStrength;
  1586. float _TransNormal;
  1587. float _TransScattering;
  1588. float _TransDirect;
  1589. float _TransAmbient;
  1590. float _TransShadow;
  1591. #endif
  1592. #ifdef TESSELLATION_ON
  1593. float _TessPhongStrength;
  1594. float _TessValue;
  1595. float _TessMin;
  1596. float _TessMax;
  1597. float _TessEdgeLength;
  1598. float _TessMaxDisp;
  1599. #endif
  1600. CBUFFER_END
  1601. sampler2D _MainTex;
  1602. VertexOutput VertexFunction( VertexInput v )
  1603. {
  1604. VertexOutput o = (VertexOutput)0;
  1605. UNITY_SETUP_INSTANCE_ID(v);
  1606. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1607. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  1608. //Calculate new billboard vertex position and normal;
  1609. float3 upCamVec = float3( 0, 1, 0 );
  1610. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  1611. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  1612. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  1613. //This unfortunately must be made to take non-uniform scaling into account;
  1614. //Transform to world coords, apply rotation and transform back to local;
  1615. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  1616. v.vertex = mul( v.vertex , rotationCamMatrix );
  1617. v.vertex = mul( v.vertex , unity_WorldToObject );
  1618. float3 temp_cast_0 = 0;
  1619. #ifdef _BILLBOARD_ON
  1620. float3 staticSwitch14 = 0;
  1621. #else
  1622. float3 staticSwitch14 = temp_cast_0;
  1623. #endif
  1624. o.ase_texcoord3.xy = v.ase_texcoord.xy;
  1625. //setting value to unused interpolator channels and avoid initialization warnings
  1626. o.ase_texcoord3.zw = 0;
  1627. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1628. float3 defaultVertexValue = v.vertex.xyz;
  1629. #else
  1630. float3 defaultVertexValue = float3(0, 0, 0);
  1631. #endif
  1632. float3 vertexValue = staticSwitch14;
  1633. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1634. v.vertex.xyz = vertexValue;
  1635. #else
  1636. v.vertex.xyz += vertexValue;
  1637. #endif
  1638. v.ase_normal = v.ase_normal;
  1639. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  1640. float3 normalWS = TransformObjectToWorldNormal( v.ase_normal );
  1641. float4 positionCS = TransformWorldToHClip( positionWS );
  1642. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1643. o.worldPos = positionWS;
  1644. #endif
  1645. o.worldNormal = normalWS;
  1646. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) && defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1647. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  1648. vertexInput.positionWS = positionWS;
  1649. vertexInput.positionCS = positionCS;
  1650. o.shadowCoord = GetShadowCoord( vertexInput );
  1651. #endif
  1652. o.clipPos = positionCS;
  1653. return o;
  1654. }
  1655. #if defined(TESSELLATION_ON)
  1656. struct VertexControl
  1657. {
  1658. float4 vertex : INTERNALTESSPOS;
  1659. float3 ase_normal : NORMAL;
  1660. float4 ase_tangent : TANGENT;
  1661. float4 ase_texcoord : TEXCOORD0;
  1662. UNITY_VERTEX_INPUT_INSTANCE_ID
  1663. };
  1664. struct TessellationFactors
  1665. {
  1666. float edge[3] : SV_TessFactor;
  1667. float inside : SV_InsideTessFactor;
  1668. };
  1669. VertexControl vert ( VertexInput v )
  1670. {
  1671. VertexControl o;
  1672. UNITY_SETUP_INSTANCE_ID(v);
  1673. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1674. o.vertex = v.vertex;
  1675. o.ase_normal = v.ase_normal;
  1676. o.ase_tangent = v.ase_tangent;
  1677. o.ase_texcoord = v.ase_texcoord;
  1678. return o;
  1679. }
  1680. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  1681. {
  1682. TessellationFactors o;
  1683. float4 tf = 1;
  1684. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  1685. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  1686. #if defined(ASE_FIXED_TESSELLATION)
  1687. tf = FixedTess( tessValue );
  1688. #elif defined(ASE_DISTANCE_TESSELLATION)
  1689. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  1690. #elif defined(ASE_LENGTH_TESSELLATION)
  1691. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  1692. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  1693. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  1694. #endif
  1695. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  1696. return o;
  1697. }
  1698. [domain("tri")]
  1699. [partitioning("fractional_odd")]
  1700. [outputtopology("triangle_cw")]
  1701. [patchconstantfunc("TessellationFunction")]
  1702. [outputcontrolpoints(3)]
  1703. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  1704. {
  1705. return patch[id];
  1706. }
  1707. [domain("tri")]
  1708. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  1709. {
  1710. VertexInput o = (VertexInput) 0;
  1711. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  1712. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  1713. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  1714. o.ase_texcoord = patch[0].ase_texcoord * bary.x + patch[1].ase_texcoord * bary.y + patch[2].ase_texcoord * bary.z;
  1715. #if defined(ASE_PHONG_TESSELLATION)
  1716. float3 pp[3];
  1717. for (int i = 0; i < 3; ++i)
  1718. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  1719. float phongStrength = _TessPhongStrength;
  1720. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  1721. #endif
  1722. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  1723. return VertexFunction(o);
  1724. }
  1725. #else
  1726. VertexOutput vert ( VertexInput v )
  1727. {
  1728. return VertexFunction( v );
  1729. }
  1730. #endif
  1731. #if defined(ASE_EARLY_Z_DEPTH_OPTIMIZE)
  1732. #define ASE_SV_DEPTH SV_DepthLessEqual
  1733. #else
  1734. #define ASE_SV_DEPTH SV_Depth
  1735. #endif
  1736. half4 frag( VertexOutput IN
  1737. #ifdef ASE_DEPTH_WRITE_ON
  1738. ,out float outputDepth : ASE_SV_DEPTH
  1739. #endif
  1740. ) : SV_TARGET
  1741. {
  1742. UNITY_SETUP_INSTANCE_ID(IN);
  1743. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
  1744. #if defined(ASE_NEEDS_FRAG_WORLD_POSITION)
  1745. float3 WorldPosition = IN.worldPos;
  1746. #endif
  1747. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  1748. #if defined(ASE_NEEDS_FRAG_SHADOWCOORDS)
  1749. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1750. ShadowCoords = IN.shadowCoord;
  1751. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  1752. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  1753. #endif
  1754. #endif
  1755. float2 uv_MainTex = IN.ase_texcoord3.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  1756. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  1757. float Alpha = tex2DNode11.a;
  1758. float AlphaClipThreshold = 0.5;
  1759. #ifdef ASE_DEPTH_WRITE_ON
  1760. float DepthValue = 0;
  1761. #endif
  1762. #ifdef _ALPHATEST_ON
  1763. clip(Alpha - AlphaClipThreshold);
  1764. #endif
  1765. #ifdef LOD_FADE_CROSSFADE
  1766. LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
  1767. #endif
  1768. #ifdef ASE_DEPTH_WRITE_ON
  1769. outputDepth = DepthValue;
  1770. #endif
  1771. return float4(PackNormalOctRectEncode(TransformWorldToViewDir(IN.worldNormal, true)), 0.0, 0.0);
  1772. }
  1773. ENDHLSL
  1774. }
  1775. Pass
  1776. {
  1777. Name "GBuffer"
  1778. Tags { "LightMode"="UniversalGBuffer" }
  1779. Blend One Zero, One Zero
  1780. ZWrite Off
  1781. ZTest LEqual
  1782. Offset 0 , 0
  1783. ColorMask RGBA
  1784. HLSLPROGRAM
  1785. #define _SPECULAR_SETUP 1
  1786. #define _NORMAL_DROPOFF_TS 1
  1787. #pragma multi_compile_instancing
  1788. #pragma multi_compile _ LOD_FADE_CROSSFADE
  1789. #pragma multi_compile_fog
  1790. #define ASE_FOG 1
  1791. #define _NORMALMAP 1
  1792. #define ASE_SRP_VERSION 100500
  1793. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  1794. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  1795. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  1796. #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  1797. #pragma multi_compile _ _SHADOWS_SOFT
  1798. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  1799. #pragma multi_compile _ _GBUFFER_NORMALS_OCT
  1800. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  1801. #pragma multi_compile _ LIGHTMAP_ON
  1802. #pragma vertex vert
  1803. #pragma fragment frag
  1804. #define SHADERPASS SHADERPASS_GBUFFER
  1805. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  1806. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  1807. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  1808. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  1809. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  1810. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"
  1811. #if ASE_SRP_VERSION <= 70108
  1812. #define REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR
  1813. #endif
  1814. #if defined(UNITY_INSTANCING_ENABLED) && defined(_TERRAIN_INSTANCED_PERPIXEL_NORMAL)
  1815. #define ENABLE_TERRAIN_PERPIXEL_NORMAL
  1816. #endif
  1817. #define ASE_NEEDS_VERT_POSITION
  1818. #define ASE_NEEDS_VERT_NORMAL
  1819. #define ASE_NEEDS_VERT_TANGENT
  1820. #pragma shader_feature_local _BILLBOARD_ON
  1821. struct VertexInput
  1822. {
  1823. float4 vertex : POSITION;
  1824. float3 ase_normal : NORMAL;
  1825. float4 ase_tangent : TANGENT;
  1826. float4 texcoord1 : TEXCOORD1;
  1827. float4 texcoord : TEXCOORD0;
  1828. UNITY_VERTEX_INPUT_INSTANCE_ID
  1829. };
  1830. struct VertexOutput
  1831. {
  1832. float4 clipPos : SV_POSITION;
  1833. float4 lightmapUVOrVertexSH : TEXCOORD0;
  1834. half4 fogFactorAndVertexLight : TEXCOORD1;
  1835. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1836. float4 shadowCoord : TEXCOORD2;
  1837. #endif
  1838. float4 tSpace0 : TEXCOORD3;
  1839. float4 tSpace1 : TEXCOORD4;
  1840. float4 tSpace2 : TEXCOORD5;
  1841. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  1842. float4 screenPos : TEXCOORD6;
  1843. #endif
  1844. float4 ase_texcoord7 : TEXCOORD7;
  1845. float3 ase_normal : NORMAL;
  1846. UNITY_VERTEX_INPUT_INSTANCE_ID
  1847. UNITY_VERTEX_OUTPUT_STEREO
  1848. };
  1849. CBUFFER_START(UnityPerMaterial)
  1850. float4 _MainTex_ST;
  1851. #ifdef _TRANSMISSION_ASE
  1852. float _TransmissionShadow;
  1853. #endif
  1854. #ifdef _TRANSLUCENCY_ASE
  1855. float _TransStrength;
  1856. float _TransNormal;
  1857. float _TransScattering;
  1858. float _TransDirect;
  1859. float _TransAmbient;
  1860. float _TransShadow;
  1861. #endif
  1862. #ifdef TESSELLATION_ON
  1863. float _TessPhongStrength;
  1864. float _TessValue;
  1865. float _TessMin;
  1866. float _TessMax;
  1867. float _TessEdgeLength;
  1868. float _TessMaxDisp;
  1869. #endif
  1870. CBUFFER_END
  1871. sampler2D _MainTex;
  1872. VertexOutput VertexFunction( VertexInput v )
  1873. {
  1874. VertexOutput o = (VertexOutput)0;
  1875. UNITY_SETUP_INSTANCE_ID(v);
  1876. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1877. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  1878. //Calculate new billboard vertex position and normal;
  1879. float3 upCamVec = float3( 0, 1, 0 );
  1880. float3 forwardCamVec = -normalize ( UNITY_MATRIX_V._m20_m21_m22 );
  1881. float3 rightCamVec = normalize( UNITY_MATRIX_V._m00_m01_m02 );
  1882. float4x4 rotationCamMatrix = float4x4( rightCamVec, 0, upCamVec, 0, forwardCamVec, 0, 0, 0, 0, 1 );
  1883. //This unfortunately must be made to take non-uniform scaling into account;
  1884. //Transform to world coords, apply rotation and transform back to local;
  1885. v.vertex = mul( v.vertex , unity_ObjectToWorld );
  1886. v.vertex = mul( v.vertex , rotationCamMatrix );
  1887. v.vertex = mul( v.vertex , unity_WorldToObject );
  1888. float3 temp_cast_0 = 0;
  1889. #ifdef _BILLBOARD_ON
  1890. float3 staticSwitch14 = 0;
  1891. #else
  1892. float3 staticSwitch14 = temp_cast_0;
  1893. #endif
  1894. o.ase_texcoord7.xy = v.texcoord.xy;
  1895. o.ase_normal = v.ase_normal;
  1896. //setting value to unused interpolator channels and avoid initialization warnings
  1897. o.ase_texcoord7.zw = 0;
  1898. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1899. float3 defaultVertexValue = v.vertex.xyz;
  1900. #else
  1901. float3 defaultVertexValue = float3(0, 0, 0);
  1902. #endif
  1903. float3 vertexValue = staticSwitch14;
  1904. #ifdef ASE_ABSOLUTE_VERTEX_POS
  1905. v.vertex.xyz = vertexValue;
  1906. #else
  1907. v.vertex.xyz += vertexValue;
  1908. #endif
  1909. v.ase_normal = v.ase_normal;
  1910. float3 positionWS = TransformObjectToWorld( v.vertex.xyz );
  1911. float3 positionVS = TransformWorldToView( positionWS );
  1912. float4 positionCS = TransformWorldToHClip( positionWS );
  1913. VertexNormalInputs normalInput = GetVertexNormalInputs( v.ase_normal, v.ase_tangent );
  1914. o.tSpace0 = float4( normalInput.normalWS, positionWS.x);
  1915. o.tSpace1 = float4( normalInput.tangentWS, positionWS.y);
  1916. o.tSpace2 = float4( normalInput.bitangentWS, positionWS.z);
  1917. OUTPUT_LIGHTMAP_UV( v.texcoord1, unity_LightmapST, o.lightmapUVOrVertexSH.xy );
  1918. OUTPUT_SH( normalInput.normalWS.xyz, o.lightmapUVOrVertexSH.xyz );
  1919. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  1920. o.lightmapUVOrVertexSH.zw = v.texcoord;
  1921. o.lightmapUVOrVertexSH.xy = v.texcoord * unity_LightmapST.xy + unity_LightmapST.zw;
  1922. #endif
  1923. half3 vertexLight = VertexLighting( positionWS, normalInput.normalWS );
  1924. #ifdef ASE_FOG
  1925. half fogFactor = ComputeFogFactor( positionCS.z );
  1926. #else
  1927. half fogFactor = 0;
  1928. #endif
  1929. o.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  1930. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  1931. VertexPositionInputs vertexInput = (VertexPositionInputs)0;
  1932. vertexInput.positionWS = positionWS;
  1933. vertexInput.positionCS = positionCS;
  1934. o.shadowCoord = GetShadowCoord( vertexInput );
  1935. #endif
  1936. o.clipPos = positionCS;
  1937. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  1938. o.screenPos = ComputeScreenPos(positionCS);
  1939. #endif
  1940. return o;
  1941. }
  1942. #if defined(TESSELLATION_ON)
  1943. struct VertexControl
  1944. {
  1945. float4 vertex : INTERNALTESSPOS;
  1946. float3 ase_normal : NORMAL;
  1947. float4 ase_tangent : TANGENT;
  1948. float4 texcoord : TEXCOORD0;
  1949. float4 texcoord1 : TEXCOORD1;
  1950. UNITY_VERTEX_INPUT_INSTANCE_ID
  1951. };
  1952. struct TessellationFactors
  1953. {
  1954. float edge[3] : SV_TessFactor;
  1955. float inside : SV_InsideTessFactor;
  1956. };
  1957. VertexControl vert ( VertexInput v )
  1958. {
  1959. VertexControl o;
  1960. UNITY_SETUP_INSTANCE_ID(v);
  1961. UNITY_TRANSFER_INSTANCE_ID(v, o);
  1962. o.vertex = v.vertex;
  1963. o.ase_normal = v.ase_normal;
  1964. o.ase_tangent = v.ase_tangent;
  1965. o.texcoord = v.texcoord;
  1966. o.texcoord1 = v.texcoord1;
  1967. return o;
  1968. }
  1969. TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
  1970. {
  1971. TessellationFactors o;
  1972. float4 tf = 1;
  1973. float tessValue = _TessValue; float tessMin = _TessMin; float tessMax = _TessMax;
  1974. float edgeLength = _TessEdgeLength; float tessMaxDisp = _TessMaxDisp;
  1975. #if defined(ASE_FIXED_TESSELLATION)
  1976. tf = FixedTess( tessValue );
  1977. #elif defined(ASE_DISTANCE_TESSELLATION)
  1978. tf = DistanceBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), _WorldSpaceCameraPos );
  1979. #elif defined(ASE_LENGTH_TESSELLATION)
  1980. tf = EdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams );
  1981. #elif defined(ASE_LENGTH_CULL_TESSELLATION)
  1982. tf = EdgeLengthBasedTessCull(v[0].vertex, v[1].vertex, v[2].vertex, edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), _WorldSpaceCameraPos, _ScreenParams, unity_CameraWorldClipPlanes );
  1983. #endif
  1984. o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
  1985. return o;
  1986. }
  1987. [domain("tri")]
  1988. [partitioning("fractional_odd")]
  1989. [outputtopology("triangle_cw")]
  1990. [patchconstantfunc("TessellationFunction")]
  1991. [outputcontrolpoints(3)]
  1992. VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
  1993. {
  1994. return patch[id];
  1995. }
  1996. [domain("tri")]
  1997. VertexOutput DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
  1998. {
  1999. VertexInput o = (VertexInput) 0;
  2000. o.vertex = patch[0].vertex * bary.x + patch[1].vertex * bary.y + patch[2].vertex * bary.z;
  2001. o.ase_normal = patch[0].ase_normal * bary.x + patch[1].ase_normal * bary.y + patch[2].ase_normal * bary.z;
  2002. o.ase_tangent = patch[0].ase_tangent * bary.x + patch[1].ase_tangent * bary.y + patch[2].ase_tangent * bary.z;
  2003. o.texcoord = patch[0].texcoord * bary.x + patch[1].texcoord * bary.y + patch[2].texcoord * bary.z;
  2004. o.texcoord1 = patch[0].texcoord1 * bary.x + patch[1].texcoord1 * bary.y + patch[2].texcoord1 * bary.z;
  2005. #if defined(ASE_PHONG_TESSELLATION)
  2006. float3 pp[3];
  2007. for (int i = 0; i < 3; ++i)
  2008. pp[i] = o.vertex.xyz - patch[i].ase_normal * (dot(o.vertex.xyz, patch[i].ase_normal) - dot(patch[i].vertex.xyz, patch[i].ase_normal));
  2009. float phongStrength = _TessPhongStrength;
  2010. o.vertex.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.vertex.xyz;
  2011. #endif
  2012. UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
  2013. return VertexFunction(o);
  2014. }
  2015. #else
  2016. VertexOutput vert ( VertexInput v )
  2017. {
  2018. return VertexFunction( v );
  2019. }
  2020. #endif
  2021. #if defined(ASE_EARLY_Z_DEPTH_OPTIMIZE)
  2022. #define ASE_SV_DEPTH SV_DepthLessEqual
  2023. #else
  2024. #define ASE_SV_DEPTH SV_Depth
  2025. #endif
  2026. FragmentOutput frag ( VertexOutput IN
  2027. #ifdef ASE_DEPTH_WRITE_ON
  2028. ,out float outputDepth : ASE_SV_DEPTH
  2029. #endif
  2030. )
  2031. {
  2032. UNITY_SETUP_INSTANCE_ID(IN);
  2033. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
  2034. #ifdef LOD_FADE_CROSSFADE
  2035. LODDitheringTransition( IN.clipPos.xyz, unity_LODFade.x );
  2036. #endif
  2037. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  2038. float2 sampleCoords = (IN.lightmapUVOrVertexSH.zw / _TerrainHeightmapRecipSize.zw + 0.5f) * _TerrainHeightmapRecipSize.xy;
  2039. float3 WorldNormal = TransformObjectToWorldNormal(normalize(SAMPLE_TEXTURE2D(_TerrainNormalmapTexture, sampler_TerrainNormalmapTexture, sampleCoords).rgb * 2 - 1));
  2040. float3 WorldTangent = -cross(GetObjectToWorldMatrix()._13_23_33, WorldNormal);
  2041. float3 WorldBiTangent = cross(WorldNormal, -WorldTangent);
  2042. #else
  2043. float3 WorldNormal = normalize( IN.tSpace0.xyz );
  2044. float3 WorldTangent = IN.tSpace1.xyz;
  2045. float3 WorldBiTangent = IN.tSpace2.xyz;
  2046. #endif
  2047. float3 WorldPosition = float3(IN.tSpace0.w,IN.tSpace1.w,IN.tSpace2.w);
  2048. float3 WorldViewDirection = _WorldSpaceCameraPos.xyz - WorldPosition;
  2049. float4 ShadowCoords = float4( 0, 0, 0, 0 );
  2050. #if defined(ASE_NEEDS_FRAG_SCREEN_POSITION)
  2051. float4 ScreenPos = IN.screenPos;
  2052. #endif
  2053. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  2054. ShadowCoords = IN.shadowCoord;
  2055. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  2056. ShadowCoords = TransformWorldToShadowCoord( WorldPosition );
  2057. #endif
  2058. WorldViewDirection = SafeNormalize( WorldViewDirection );
  2059. float2 uv_MainTex = IN.ase_texcoord7.xy * _MainTex_ST.xy + _MainTex_ST.zw;
  2060. float4 tex2DNode11 = tex2D( _MainTex, uv_MainTex );
  2061. float3 Albedo = tex2DNode11.rgb;
  2062. float3 Normal = IN.ase_normal;
  2063. float3 Emission = 0;
  2064. float3 Specular = 0.5;
  2065. float Metallic = 0;
  2066. float Smoothness = 0.5;
  2067. float Occlusion = 1;
  2068. float Alpha = tex2DNode11.a;
  2069. float AlphaClipThreshold = 0.5;
  2070. float AlphaClipThresholdShadow = 0.5;
  2071. float3 BakedGI = 0;
  2072. float3 RefractionColor = 1;
  2073. float RefractionIndex = 1;
  2074. float3 Transmission = 1;
  2075. float3 Translucency = 1;
  2076. #ifdef ASE_DEPTH_WRITE_ON
  2077. float DepthValue = 0;
  2078. #endif
  2079. #ifdef _ALPHATEST_ON
  2080. clip(Alpha - AlphaClipThreshold);
  2081. #endif
  2082. InputData inputData;
  2083. inputData.positionWS = WorldPosition;
  2084. inputData.viewDirectionWS = WorldViewDirection;
  2085. inputData.shadowCoord = ShadowCoords;
  2086. #ifdef _NORMALMAP
  2087. #if _NORMAL_DROPOFF_TS
  2088. inputData.normalWS = TransformTangentToWorld(Normal, half3x3( WorldTangent, WorldBiTangent, WorldNormal ));
  2089. #elif _NORMAL_DROPOFF_OS
  2090. inputData.normalWS = TransformObjectToWorldNormal(Normal);
  2091. #elif _NORMAL_DROPOFF_WS
  2092. inputData.normalWS = Normal;
  2093. #endif
  2094. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  2095. #else
  2096. inputData.normalWS = WorldNormal;
  2097. #endif
  2098. #ifdef ASE_FOG
  2099. inputData.fogCoord = IN.fogFactorAndVertexLight.x;
  2100. #endif
  2101. inputData.vertexLighting = IN.fogFactorAndVertexLight.yzw;
  2102. #if defined(ENABLE_TERRAIN_PERPIXEL_NORMAL)
  2103. float3 SH = SampleSH(inputData.normalWS.xyz);
  2104. #else
  2105. float3 SH = IN.lightmapUVOrVertexSH.xyz;
  2106. #endif
  2107. inputData.bakedGI = SAMPLE_GI( IN.lightmapUVOrVertexSH.xy, SH, inputData.normalWS );
  2108. #ifdef _ASE_BAKEDGI
  2109. inputData.bakedGI = BakedGI;
  2110. #endif
  2111. BRDFData brdfData;
  2112. InitializeBRDFData( Albedo, Metallic, Specular, Smoothness, Alpha, brdfData);
  2113. half4 color;
  2114. color.rgb = GlobalIllumination( brdfData, inputData.bakedGI, Occlusion, inputData.normalWS, inputData.viewDirectionWS);
  2115. color.a = Alpha;
  2116. #ifdef _TRANSMISSION_ASE
  2117. {
  2118. float shadow = _TransmissionShadow;
  2119. Light mainLight = GetMainLight( inputData.shadowCoord );
  2120. float3 mainAtten = mainLight.color * mainLight.distanceAttenuation;
  2121. mainAtten = lerp( mainAtten, mainAtten * mainLight.shadowAttenuation, shadow );
  2122. half3 mainTransmission = max(0 , -dot(inputData.normalWS, mainLight.direction)) * mainAtten * Transmission;
  2123. color.rgb += Albedo * mainTransmission;
  2124. #ifdef _ADDITIONAL_LIGHTS
  2125. int transPixelLightCount = GetAdditionalLightsCount();
  2126. for (int i = 0; i < transPixelLightCount; ++i)
  2127. {
  2128. Light light = GetAdditionalLight(i, inputData.positionWS);
  2129. float3 atten = light.color * light.distanceAttenuation;
  2130. atten = lerp( atten, atten * light.shadowAttenuation, shadow );
  2131. half3 transmission = max(0 , -dot(inputData.normalWS, light.direction)) * atten * Transmission;
  2132. color.rgb += Albedo * transmission;
  2133. }
  2134. #endif
  2135. }
  2136. #endif
  2137. #ifdef _TRANSLUCENCY_ASE
  2138. {
  2139. float shadow = _TransShadow;
  2140. float normal = _TransNormal;
  2141. float scattering = _TransScattering;
  2142. float direct = _TransDirect;
  2143. float ambient = _TransAmbient;
  2144. float strength = _TransStrength;
  2145. Light mainLight = GetMainLight( inputData.shadowCoord );
  2146. float3 mainAtten = mainLight.color * mainLight.distanceAttenuation;
  2147. mainAtten = lerp( mainAtten, mainAtten * mainLight.shadowAttenuation, shadow );
  2148. half3 mainLightDir = mainLight.direction + inputData.normalWS * normal;
  2149. half mainVdotL = pow( saturate( dot( inputData.viewDirectionWS, -mainLightDir ) ), scattering );
  2150. half3 mainTranslucency = mainAtten * ( mainVdotL * direct + inputData.bakedGI * ambient ) * Translucency;
  2151. color.rgb += Albedo * mainTranslucency * strength;
  2152. #ifdef _ADDITIONAL_LIGHTS
  2153. int transPixelLightCount = GetAdditionalLightsCount();
  2154. for (int i = 0; i < transPixelLightCount; ++i)
  2155. {
  2156. Light light = GetAdditionalLight(i, inputData.positionWS);
  2157. float3 atten = light.color * light.distanceAttenuation;
  2158. atten = lerp( atten, atten * light.shadowAttenuation, shadow );
  2159. half3 lightDir = light.direction + inputData.normalWS * normal;
  2160. half VdotL = pow( saturate( dot( inputData.viewDirectionWS, -lightDir ) ), scattering );
  2161. half3 translucency = atten * ( VdotL * direct + inputData.bakedGI * ambient ) * Translucency;
  2162. color.rgb += Albedo * translucency * strength;
  2163. }
  2164. #endif
  2165. }
  2166. #endif
  2167. #ifdef _REFRACTION_ASE
  2168. float4 projScreenPos = ScreenPos / ScreenPos.w;
  2169. float3 refractionOffset = ( RefractionIndex - 1.0 ) * mul( UNITY_MATRIX_V, float4( WorldNormal, 0 ) ).xyz * ( 1.0 - dot( WorldNormal, WorldViewDirection ) );
  2170. projScreenPos.xy += refractionOffset.xy;
  2171. float3 refraction = SHADERGRAPH_SAMPLE_SCENE_COLOR( projScreenPos.xy ) * RefractionColor;
  2172. color.rgb = lerp( refraction, color.rgb, color.a );
  2173. color.a = 1;
  2174. #endif
  2175. #ifdef ASE_FINAL_COLOR_ALPHA_MULTIPLY
  2176. color.rgb *= color.a;
  2177. #endif
  2178. #ifdef ASE_FOG
  2179. #ifdef TERRAIN_SPLAT_ADDPASS
  2180. color.rgb = MixFogColor(color.rgb, half3( 0, 0, 0 ), IN.fogFactorAndVertexLight.x );
  2181. #else
  2182. color.rgb = MixFog(color.rgb, IN.fogFactorAndVertexLight.x);
  2183. #endif
  2184. #endif
  2185. #ifdef ASE_DEPTH_WRITE_ON
  2186. outputDepth = DepthValue;
  2187. #endif
  2188. return BRDFDataToGbuffer(brdfData, inputData, Smoothness, Emission + color.rgb);
  2189. }
  2190. ENDHLSL
  2191. }
  2192. }
  2193. CustomEditor "UnityEditor.ShaderGraph.PBRMasterGUI"
  2194. Fallback "Hidden/InternalErrorShader"
  2195. }
  2196. /*ASEBEGIN
  2197. Version=18927
  2198. 166;69;1329;887;838.8149;389.7744;1;True;False
  2199. Node;AmplifyShaderEditor.BillboardNode;8;-417.5,207.5;Inherit;False;Cylindrical;False;False;0;1;FLOAT3;0
  2200. Node;AmplifyShaderEditor.IntNode;24;-460.8146,122.2256;Inherit;False;Constant;_Int0;Int 0;2;0;Create;True;0;0;0;False;0;False;0;0;False;0;1;INT;0
  2201. Node;AmplifyShaderEditor.NormalVertexDataNode;13;-387.5,-28.5;Inherit;False;0;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  2202. Node;AmplifyShaderEditor.SamplerNode;11;-432.5,-241.5;Inherit;True;Property;_MainTex;MainTex;0;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
  2203. Node;AmplifyShaderEditor.StaticSwitch;14;-198.8146,96.22565;Inherit;False;Property;_Billboard;Billboard;1;0;Create;True;0;0;0;True;0;False;0;1;1;True;;Toggle;2;Key0;Key1;Create;True;True;9;1;FLOAT3;0,0,0;False;0;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT3;0,0,0;False;5;FLOAT3;0,0,0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT3;0,0,0;False;1;FLOAT3;0
  2204. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;16;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;ExtraPrePass;0;0;ExtraPrePass;5;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;True;1;1;False;-1;0;False;-1;0;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;True;True;True;True;0;False;-1;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;True;1;False;-1;True;3;False;-1;True;True;0;False;-1;0;False;-1;True;0;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2205. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;18;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;ShadowCaster;0;2;ShadowCaster;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;False;False;True;False;False;False;False;0;False;-1;False;False;False;False;False;False;False;False;False;True;1;False;-1;True;3;False;-1;False;True;1;LightMode=ShadowCaster;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2206. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;19;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;DepthOnly;0;3;DepthOnly;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;False;False;True;False;False;False;False;0;False;-1;False;False;False;False;False;False;False;False;False;True;1;False;-1;False;False;True;1;LightMode=DepthOnly;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2207. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;20;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;Meta;0;4;Meta;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;1;LightMode=Meta;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2208. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;21;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;Universal2D;0;5;Universal2D;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;True;1;1;False;-1;0;False;-1;1;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;True;True;True;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;2;False;-1;True;3;False;-1;True;True;0;False;-1;0;False;-1;True;1;LightMode=Universal2D;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2209. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;22;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;DepthNormals;0;6;DepthNormals;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;True;1;1;False;-1;0;False;-1;0;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;1;False;-1;True;3;False;-1;False;True;1;LightMode=DepthNormals;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2210. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;23;10,-141;Float;False;False;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;1;New Amplify Shader;94348b07e5e8bab40bd6c8a1e3df54cd;True;GBuffer;0;7;GBuffer;0;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Opaque=RenderType;Queue=Geometry=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;True;1;1;False;-1;0;False;-1;1;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;True;True;True;True;0;False;-1;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;True;2;False;-1;True;3;False;-1;True;True;0;False;-1;0;False;-1;True;1;LightMode=UniversalGBuffer;False;False;0;Hidden/InternalErrorShader;0;0;Standard;0;False;0
  2211. Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;17;10,-141;Float;False;True;-1;2;UnityEditor.ShaderGraph.PBRMasterGUI;0;2;MTE/URP/Grass/Billboard;94348b07e5e8bab40bd6c8a1e3df54cd;True;Forward;0;1;Forward;18;False;False;False;False;False;False;False;False;False;False;False;False;True;0;False;-1;False;True;0;False;-1;False;False;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;False;False;False;True;3;RenderPipeline=UniversalPipeline;RenderType=Transparent=RenderType;Queue=Transparent=Queue=0;True;0;True;17;d3d9;d3d11;glcore;gles;gles3;metal;vulkan;xbox360;xboxone;xboxseries;ps4;playstation;psp2;n3ds;wiiu;switch;nomrt;0;False;True;1;1;False;-1;0;False;-1;1;1;False;-1;0;False;-1;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;True;True;True;True;0;False;-1;False;False;False;False;False;False;False;True;False;255;False;-1;255;False;-1;255;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;7;False;-1;1;False;-1;1;False;-1;1;False;-1;False;True;2;False;-1;True;3;False;-1;True;True;0;False;-1;0;False;-1;True;1;LightMode=UniversalForward;False;False;0;Hidden/InternalErrorShader;0;0;Standard;38;Workflow;0;Surface;0; Refraction Model;0; Blend;0;Two Sided;1;Fragment Normal Space,InvertActionOnDeselection;0;Transmission;0; Transmission Shadow;0.5,False,-1;Translucency;0; Translucency Strength;1,False,-1; Normal Distortion;0.5,False,-1; Scattering;2,False,-1; Direct;0.9,False,-1; Ambient;0.1,False,-1; Shadow;0.5,False,-1;Cast Shadows;1; Use Shadow Threshold;0;Receive Shadows;1;GPU Instancing;1;LOD CrossFade;1;Built-in Fog;1;_FinalColorxAlpha;0;Meta Pass;1;Override Baked GI;0;Extra Pre Pass;0;DOTS Instancing;0;Tessellation;0; Phong;0; Strength;0.5,False,-1; Type;0; Tess;16,False,-1; Min;10,False,-1; Max;25,False,-1; Edge Length;16,False,-1; Max Displacement;25,False,-1;Write Depth;0; Early Z;0;Vertex Position,InvertActionOnDeselection;1;0;8;False;True;True;True;True;True;True;True;False;;False;0
  2212. WireConnection;14;1;24;0
  2213. WireConnection;14;0;8;0
  2214. WireConnection;17;0;11;0
  2215. WireConnection;17;1;13;0
  2216. WireConnection;17;6;11;4
  2217. WireConnection;17;8;14;0
  2218. ASEEND*/
  2219. //CHKSM=8D76141239D256BF78ACB385B3C6BEA489BBD4DF