1. Shader "Universal Render Pipeline/2D/Sprite-Unlit-Default"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Sprite Texture", 2D) = "white" {}
  6. _Color ("Tint", Color) = (1,1,1,1)
  7.  
  8. // Legacy properties. They're here so that materials using this shader can gracefully fallback to the legacy sprite shader.
  9. [HideInInspector] PixelSnap ("Pixel snap", Float) = 0
  10. [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
  11. [HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
  12. [HideInInspector] _AlphaTex ("External Alpha", 2D) = "white" {}
  13. [HideInInspector] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
  14. }
  15.  
  16. SubShader
  17. {
  18. Tags {"Queue" = "Transparent" "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" }
  19.  
  20. Blend SrcAlpha OneMinusSrcAlpha
  21. Cull Off
  22. ZWrite Off
  23.  
  24. Pass
  25. {
  26. Tags { "LightMode" = "Universal2D" }
  27.  
  28. HLSLPROGRAM
  29. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  30. #if defined(DEBUG_DISPLAY)
  31. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/InputData2D.hlsl"
  32. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
  33. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
  34. #endif
  35.  
  36. #pragma vertex UnlitVertex
  37. #pragma fragment UnlitFragment
  38.  
  39. #pragma multi_compile _ DEBUG_DISPLAY
  40.  
  41. struct Attributes
  42. {
  43. float3 positionOS : POSITION;
  44. float4 color : COLOR;
  45. float2 uv : TEXCOORD0;
  46. UNITY_VERTEX_INPUT_INSTANCE_ID
  47. };
  48.  
  49. struct Varyings
  50. {
  51. float4 positionCS : SV_POSITION;
  52. half4 color : COLOR;
  53. float2 uv : TEXCOORD0;
  54. #if defined(DEBUG_DISPLAY)
  55. float3 positionWS : TEXCOORD2;
  56. #endif
  57. UNITY_VERTEX_OUTPUT_STEREO
  58. };
  59.  
  60. TEXTURE2D(_MainTex);
  61. SAMPLER(sampler_MainTex);
  62. half4 _MainTex_ST;
  63.  
  64. Varyings UnlitVertex(Attributes v)
  65. {
  66. Varyings o = (Varyings)0;
  67. UNITY_SETUP_INSTANCE_ID(v);
  68. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  69.  
  70. o.positionCS = TransformObjectToHClip(v.positionOS);
  71. #if defined(DEBUG_DISPLAY)
  72. o.positionWS = TransformObjectToWorld(v.positionOS);
  73. #endif
  74. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  75. o.color = v.color;
  76. return o;
  77. }
  78.  
  79. half4 UnlitFragment(Varyings i) : SV_Target
  80. {
  81. float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
  82.  
  83. #if defined(DEBUG_DISPLAY)
  84. SurfaceData2D surfaceData;
  85. InputData2D inputData;
  86. half4 debugColor = 0;
  87.  
  88. InitializeSurfaceData(mainTex.rgb, mainTex.a, surfaceData);
  89. InitializeInputData(i.uv, inputData);
  90. SETUP_DEBUG_DATA_2D(inputData, i.positionWS);
  91.  
  92. if(CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
  93. {
  94. return debugColor;
  95. }
  96. #endif
  97.  
  98. return mainTex;
  99. }
  100. ENDHLSL
  101. }
  102.  
  103. Pass
  104. {
  105. Tags { "LightMode" = "UniversalForward" "Queue"="Transparent" "RenderType"="Transparent"}
  106.  
  107. HLSLPROGRAM
  108. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  109. #if defined(DEBUG_DISPLAY)
  110. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/InputData2D.hlsl"
  111. #include "Packages/com.unity.render-pipelines.universal/Shaders/2D/Include/SurfaceData2D.hlsl"
  112. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Debug/Debugging2D.hlsl"
  113. #endif
  114.  
  115. #pragma vertex UnlitVertex
  116. #pragma fragment UnlitFragment
  117.  
  118. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  119.  
  120. struct Attributes
  121. {
  122. float3 positionOS : POSITION;
  123. float4 color : COLOR;
  124. float2 uv : TEXCOORD0;
  125. UNITY_VERTEX_INPUT_INSTANCE_ID
  126. };
  127.  
  128. struct Varyings
  129. {
  130. float4 positionCS : SV_POSITION;
  131. float4 color : COLOR;
  132. float2 uv : TEXCOORD0;
  133. #if defined(DEBUG_DISPLAY)
  134. float3 positionWS : TEXCOORD2;
  135. #endif
  136. UNITY_VERTEX_OUTPUT_STEREO
  137. };
  138.  
  139. TEXTURE2D(_MainTex);
  140. SAMPLER(sampler_MainTex);
  141. float4 _MainTex_ST;
  142.  
  143. Varyings UnlitVertex(Attributes attributes)
  144. {
  145. Varyings o = (Varyings)0;
  146. UNITY_SETUP_INSTANCE_ID(attributes);
  147. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  148.  
  149. o.positionCS = TransformObjectToHClip(attributes.positionOS);
  150. #if defined(DEBUG_DISPLAY)
  151. o.positionWS = TransformObjectToWorld(attributes.positionOS);
  152. #endif
  153. o.uv = TRANSFORM_TEX(attributes.uv, _MainTex);
  154. o.color = attributes.color;
  155. return o;
  156. }
  157.  
  158. float4 UnlitFragment(Varyings i) : SV_Target
  159. {
  160. float4 mainTex = i.color * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
  161.  
  162. #if defined(DEBUG_DISPLAY)
  163. SurfaceData2D surfaceData;
  164. InputData2D inputData;
  165. half4 debugColor = 0;
  166.  
  167. InitializeSurfaceData(mainTex.rgb, mainTex.a, surfaceData);
  168. InitializeInputData(i.uv, inputData);
  169. SETUP_DEBUG_DATA_2D(inputData, i.positionWS);
  170.  
  171. if(CanDebugOverrideOutputColor(surfaceData, inputData, debugColor))
  172. {
  173. return debugColor;
  174. }
  175. #endif
  176.  
  177. return mainTex;
  178. }
  179. ENDHLSL
  180. }
  181. }
  182.  
  183. Fallback "Sprites/Default"
  184. }