暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Sprite-Unlit-Default.shader 7.8KB

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