Unlit.shader 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. Shader "Universal Render Pipeline/Unlit"
  2. {
  3. Properties
  4. {
  5. [MainTexture] _BaseMap("Texture", 2D) = "white" {}
  6. [MainColor] _BaseColor("Color", Color) = (1, 1, 1, 1)
  7. _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5
  8. // BlendMode
  9. [HideInInspector] _Surface("__surface", Float) = 0.0
  10. [HideInInspector] _Blend("__blend", Float) = 0.0
  11. [HideInInspector] _AlphaClip("__clip", Float) = 0.0
  12. [HideInInspector] _SrcBlend("Src", Float) = 1.0
  13. [HideInInspector] _DstBlend("Dst", Float) = 0.0
  14. [HideInInspector] _ZWrite("ZWrite", Float) = 1.0
  15. [HideInInspector] _Cull("__cull", Float) = 2.0
  16. // Editmode props
  17. [HideInInspector] _QueueOffset("Queue offset", Float) = 0.0
  18. // ObsoleteProperties
  19. [HideInInspector] _MainTex("BaseMap", 2D) = "white" {}
  20. [HideInInspector] _Color("Base Color", Color) = (0.5, 0.5, 0.5, 1)
  21. [HideInInspector] _SampleGI("SampleGI", float) = 0.0 // needed from bakedlit
  22. }
  23. SubShader
  24. {
  25. Tags {"RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" "ShaderModel"="4.5"}
  26. LOD 100
  27. Blend [_SrcBlend][_DstBlend]
  28. ZWrite [_ZWrite]
  29. Cull [_Cull]
  30. Pass
  31. {
  32. Name "Unlit"
  33. HLSLPROGRAM
  34. #pragma exclude_renderers gles gles3 glcore
  35. #pragma target 4.5
  36. #pragma vertex vert
  37. #pragma fragment frag
  38. #pragma shader_feature_local_fragment _ALPHATEST_ON
  39. #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
  40. // -------------------------------------
  41. // Unity defined keywords
  42. #pragma multi_compile_fog
  43. #pragma multi_compile_instancing
  44. #pragma multi_compile _ DOTS_INSTANCING_ON
  45. #include "UnlitInput.hlsl"
  46. struct Attributes
  47. {
  48. float4 positionOS : POSITION;
  49. float2 uv : TEXCOORD0;
  50. UNITY_VERTEX_INPUT_INSTANCE_ID
  51. };
  52. struct Varyings
  53. {
  54. float2 uv : TEXCOORD0;
  55. float fogCoord : TEXCOORD1;
  56. float4 vertex : SV_POSITION;
  57. UNITY_VERTEX_INPUT_INSTANCE_ID
  58. UNITY_VERTEX_OUTPUT_STEREO
  59. };
  60. Varyings vert(Attributes input)
  61. {
  62. Varyings output = (Varyings)0;
  63. UNITY_SETUP_INSTANCE_ID(input);
  64. UNITY_TRANSFER_INSTANCE_ID(input, output);
  65. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  66. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  67. output.vertex = vertexInput.positionCS;
  68. output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
  69. output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
  70. return output;
  71. }
  72. half4 frag(Varyings input) : SV_Target
  73. {
  74. UNITY_SETUP_INSTANCE_ID(input);
  75. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  76. half2 uv = input.uv;
  77. half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
  78. half3 color = texColor.rgb * _BaseColor.rgb;
  79. half alpha = texColor.a * _BaseColor.a;
  80. AlphaDiscard(alpha, _Cutoff);
  81. #ifdef _ALPHAPREMULTIPLY_ON
  82. color *= alpha;
  83. #endif
  84. color = MixFog(color, input.fogCoord);
  85. return half4(color, alpha);
  86. }
  87. ENDHLSL
  88. }
  89. Pass
  90. {
  91. Name "DepthOnly"
  92. Tags{"LightMode" = "DepthOnly"}
  93. ZWrite On
  94. ColorMask 0
  95. HLSLPROGRAM
  96. #pragma exclude_renderers gles gles3 glcore
  97. #pragma target 4.5
  98. #pragma vertex DepthOnlyVertex
  99. #pragma fragment DepthOnlyFragment
  100. // -------------------------------------
  101. // Material Keywords
  102. #pragma shader_feature_local_fragment _ALPHATEST_ON
  103. //--------------------------------------
  104. // GPU Instancing
  105. #pragma multi_compile_instancing
  106. #pragma multi_compile _ DOTS_INSTANCING_ON
  107. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  108. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
  109. ENDHLSL
  110. }
  111. // This pass it not used during regular rendering, only for lightmap baking.
  112. Pass
  113. {
  114. Name "Meta"
  115. Tags{"LightMode" = "Meta"}
  116. Cull Off
  117. HLSLPROGRAM
  118. #pragma exclude_renderers gles gles3 glcore
  119. #pragma target 4.5
  120. #pragma vertex UniversalVertexMeta
  121. #pragma fragment UniversalFragmentMetaUnlit
  122. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  123. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl"
  124. ENDHLSL
  125. }
  126. }
  127. SubShader
  128. {
  129. Tags {"RenderType" = "Opaque" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" "ShaderModel"="2.0"}
  130. LOD 100
  131. Blend [_SrcBlend][_DstBlend]
  132. ZWrite [_ZWrite]
  133. Cull [_Cull]
  134. Pass
  135. {
  136. Name "Unlit"
  137. HLSLPROGRAM
  138. #pragma only_renderers gles gles3 glcore d3d11
  139. #pragma target 2.0
  140. #pragma vertex vert
  141. #pragma fragment frag
  142. #pragma shader_feature_local_fragment _ALPHATEST_ON
  143. #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON
  144. // -------------------------------------
  145. // Unity defined keywords
  146. #pragma multi_compile_fog
  147. #pragma multi_compile_instancing
  148. #include "UnlitInput.hlsl"
  149. struct Attributes
  150. {
  151. float4 positionOS : POSITION;
  152. float2 uv : TEXCOORD0;
  153. UNITY_VERTEX_INPUT_INSTANCE_ID
  154. };
  155. struct Varyings
  156. {
  157. float2 uv : TEXCOORD0;
  158. float fogCoord : TEXCOORD1;
  159. float4 vertex : SV_POSITION;
  160. UNITY_VERTEX_INPUT_INSTANCE_ID
  161. UNITY_VERTEX_OUTPUT_STEREO
  162. };
  163. Varyings vert(Attributes input)
  164. {
  165. Varyings output = (Varyings)0;
  166. UNITY_SETUP_INSTANCE_ID(input);
  167. UNITY_TRANSFER_INSTANCE_ID(input, output);
  168. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  169. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  170. output.vertex = vertexInput.positionCS;
  171. output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
  172. output.fogCoord = ComputeFogFactor(vertexInput.positionCS.z);
  173. return output;
  174. }
  175. half4 frag(Varyings input) : SV_Target
  176. {
  177. UNITY_SETUP_INSTANCE_ID(input);
  178. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  179. half2 uv = input.uv;
  180. half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
  181. half3 color = texColor.rgb * _BaseColor.rgb;
  182. half alpha = texColor.a * _BaseColor.a;
  183. AlphaDiscard(alpha, _Cutoff);
  184. #ifdef _ALPHAPREMULTIPLY_ON
  185. color *= alpha;
  186. #endif
  187. color = MixFog(color, input.fogCoord);
  188. alpha = OutputAlpha(alpha, _Surface);
  189. return half4(color, alpha);
  190. }
  191. ENDHLSL
  192. }
  193. Pass
  194. {
  195. Name "DepthOnly"
  196. Tags{"LightMode" = "DepthOnly"}
  197. ZWrite On
  198. ColorMask 0
  199. HLSLPROGRAM
  200. #pragma only_renderers gles gles3 glcore d3d11
  201. #pragma target 2.0
  202. #pragma vertex DepthOnlyVertex
  203. #pragma fragment DepthOnlyFragment
  204. // -------------------------------------
  205. // Material Keywords
  206. #pragma shader_feature_local_fragment _ALPHATEST_ON
  207. //--------------------------------------
  208. // GPU Instancing
  209. #pragma multi_compile_instancing
  210. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  211. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
  212. ENDHLSL
  213. }
  214. // This pass it not used during regular rendering, only for lightmap baking.
  215. Pass
  216. {
  217. Name "Meta"
  218. Tags{"LightMode" = "Meta"}
  219. Cull Off
  220. HLSLPROGRAM
  221. #pragma only_renderers gles gles3 glcore d3d11
  222. #pragma target 2.0
  223. #pragma vertex UniversalVertexMeta
  224. #pragma fragment UniversalFragmentMetaUnlit
  225. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  226. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl"
  227. ENDHLSL
  228. }
  229. }
  230. FallBack "Hidden/Universal Render Pipeline/FallbackError"
  231. CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.UnlitShader"
  232. }