Unlit.shader 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Shader "Universal Render Pipeline/Unlit"
  2. {
  3. Properties
  4. {
  5. _BaseMap("Texture", 2D) = "white" {}
  6. _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" }
  26. LOD 100
  27. Blend [_SrcBlend][_DstBlend]
  28. ZWrite [_ZWrite]
  29. Cull [_Cull]
  30. Pass
  31. {
  32. Name "Unlit"
  33. HLSLPROGRAM
  34. // Required to compile gles 2.0 with standard srp library
  35. #pragma prefer_hlslcc gles
  36. #pragma exclude_renderers d3d11_9x
  37. #pragma vertex vert
  38. #pragma fragment frag
  39. #pragma shader_feature _ALPHATEST_ON
  40. #pragma shader_feature _ALPHAPREMULTIPLY_ON
  41. // -------------------------------------
  42. // Unity defined keywords
  43. #pragma multi_compile_fog
  44. #pragma multi_compile_instancing
  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. Tags{"LightMode" = "DepthOnly"}
  92. ZWrite On
  93. ColorMask 0
  94. HLSLPROGRAM
  95. // Required to compile gles 2.0 with standard srp library
  96. #pragma prefer_hlslcc gles
  97. #pragma exclude_renderers d3d11_9x
  98. #pragma target 2.0
  99. #pragma vertex DepthOnlyVertex
  100. #pragma fragment DepthOnlyFragment
  101. // -------------------------------------
  102. // Material Keywords
  103. #pragma shader_feature _ALPHATEST_ON
  104. //--------------------------------------
  105. // GPU Instancing
  106. #pragma multi_compile_instancing
  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. // Required to compile gles 2.0 with standard srp library
  119. #pragma prefer_hlslcc gles
  120. #pragma exclude_renderers d3d11_9x
  121. #pragma vertex UniversalVertexMeta
  122. #pragma fragment UniversalFragmentMetaUnlit
  123. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  124. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitMetaPass.hlsl"
  125. ENDHLSL
  126. }
  127. }
  128. FallBack "Hidden/Universal Render Pipeline/FallbackError"
  129. CustomEditor "UnityEditor.Rendering.Universal.ShaderGUI.UnlitShader"
  130. }