StandardDS.shader 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. Shader "DevDen/DoubleSide/Standard DS"
  2. {
  3. Properties
  4. {
  5. _Color("Color", Color) = (1,1,1,1)
  6. _MainTex("Albedo", 2D) = "white" {}
  7. _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
  8. _Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
  9. _GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
  10. [Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel("Smoothness texture channel", Float) = 0
  11. [Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
  12. _MetallicGlossMap("Metallic", 2D) = "white" {}
  13. [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
  14. [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
  15. _BumpScale("Scale", Float) = 1.0
  16. _BumpMap("Normal Map", 2D) = "bump" {}
  17. _Parallax("Height Scale", Range(0.005, 0.08)) = 0.02
  18. _ParallaxMap("Height Map", 2D) = "black" {}
  19. _OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
  20. _OcclusionMap("Occlusion", 2D) = "white" {}
  21. _EmissionColor("Color", Color) = (0,0,0)
  22. _EmissionMap("Emission", 2D) = "white" {}
  23. _DetailMask("Detail Mask", 2D) = "white" {}
  24. _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
  25. _DetailNormalMapScale("Scale", Float) = 1.0
  26. _DetailNormalMap("Normal Map", 2D) = "bump" {}
  27. [Enum(UV0,0,UV1,1)] _UVSec("UV Set for secondary textures", Float) = 0
  28. // Blending state
  29. [HideInInspector] _Mode("__mode", Float) = 0.0
  30. [HideInInspector] _SrcBlend("__src", Float) = 1.0
  31. [HideInInspector] _DstBlend("__dst", Float) = 0.0
  32. [HideInInspector] _ZWrite("__zw", Float) = 1.0
  33. }
  34. CGINCLUDE
  35. #define UNITY_SETUP_BRDF_INPUT MetallicSetup
  36. ENDCG
  37. SubShader
  38. {
  39. Tags{ "RenderType" = "Opaque" "PerformanceChecks" = "False" }
  40. LOD 300
  41. // ------------------------------------------------------------------
  42. // Base forward pass (directional light, emission, lightmaps, ...)
  43. Pass
  44. {
  45. Name "FORWARD"
  46. Tags{ "LightMode" = "ForwardBase" }
  47. Blend[_SrcBlend][_DstBlend]
  48. ZWrite[_ZWrite]
  49. Cull Off
  50. CGPROGRAM
  51. #pragma target 3.0
  52. // -------------------------------------
  53. #pragma shader_feature _NORMALMAP
  54. #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
  55. #pragma shader_feature _EMISSION
  56. #pragma shader_feature _METALLICGLOSSMAP
  57. #pragma shader_feature ___ _DETAIL_MULX2
  58. #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  59. #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
  60. #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
  61. #pragma shader_feature _PARALLAXMAP
  62. #pragma multi_compile_fwdbase
  63. #pragma multi_compile_fog
  64. #pragma multi_compile_instancing
  65. // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
  66. //#pragma multi_compile _ LOD_FADE_CROSSFADE
  67. #pragma vertex vertBase
  68. #pragma fragment fragBaseDS
  69. #include "StandardDSCoreForward.cginc"
  70. ENDCG
  71. }
  72. // ------------------------------------------------------------------
  73. // Additive forward pass (one light per pass)
  74. Pass
  75. {
  76. Name "FORWARD_DELTA"
  77. Tags{ "LightMode" = "ForwardAdd" }
  78. Blend[_SrcBlend] One
  79. Fog{ Color(0,0,0,0) } // in additive pass fog should be black
  80. ZWrite Off
  81. ZTest LEqual
  82. Cull Off
  83. CGPROGRAM
  84. #pragma target 3.0
  85. // -------------------------------------
  86. #pragma shader_feature _NORMALMAP
  87. #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
  88. #pragma shader_feature _METALLICGLOSSMAP
  89. #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  90. #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
  91. #pragma shader_feature ___ _DETAIL_MULX2
  92. #pragma shader_feature _PARALLAXMAP
  93. #pragma multi_compile_fwdadd_fullshadows
  94. #pragma multi_compile_fog
  95. // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
  96. //#pragma multi_compile _ LOD_FADE_CROSSFADE
  97. #pragma vertex vertAdd
  98. #pragma fragment fragAddDS
  99. #include "StandardDSCoreForward.cginc"
  100. ENDCG
  101. }
  102. // ------------------------------------------------------------------
  103. // Shadow rendering pass
  104. Pass{
  105. Name "ShadowCaster"
  106. Tags{ "LightMode" = "ShadowCaster" }
  107. ZWrite On ZTest LEqual
  108. Cull Off
  109. CGPROGRAM
  110. #pragma target 3.0
  111. // -------------------------------------
  112. #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
  113. #pragma shader_feature _METALLICGLOSSMAP
  114. #pragma shader_feature _PARALLAXMAP
  115. #pragma multi_compile_shadowcaster
  116. #pragma multi_compile_instancing
  117. // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
  118. //#pragma multi_compile _ LOD_FADE_CROSSFADE
  119. #pragma vertex vertShadowCaster
  120. #pragma fragment fragShadowCaster
  121. #include "UnityStandardShadow.cginc"
  122. ENDCG
  123. }
  124. // ------------------------------------------------------------------
  125. // Deferred pass
  126. Pass
  127. {
  128. Name "DEFERRED"
  129. Tags{ "LightMode" = "Deferred" }
  130. Cull Off
  131. CGPROGRAM
  132. #pragma target 3.0
  133. #pragma exclude_renderers nomrt
  134. // -------------------------------------
  135. #pragma shader_feature _NORMALMAP
  136. #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
  137. #pragma shader_feature _EMISSION
  138. #pragma shader_feature _METALLICGLOSSMAP
  139. #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  140. #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
  141. #pragma shader_feature ___ _DETAIL_MULX2
  142. #pragma shader_feature _PARALLAXMAP
  143. #pragma multi_compile_prepassfinal
  144. #pragma multi_compile_instancing
  145. // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
  146. //#pragma multi_compile _ LOD_FADE_CROSSFADE
  147. #pragma vertex vertDeferred
  148. #pragma fragment fragDeferredDS
  149. #include "UnityStandardCore.cginc"
  150. void fragDeferredDS(
  151. VertexOutputDeferred i,
  152. in float face : VFACE,
  153. out half4 outGBuffer0 : SV_Target0,
  154. out half4 outGBuffer1 : SV_Target1,
  155. out half4 outGBuffer2 : SV_Target2,
  156. out half4 outEmission : SV_Target3 // RT3: emission (rgb), --unused-- (a)
  157. #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
  158. ,out half4 outShadowMask : SV_Target4 // RT4: shadowmask (rgba)
  159. #endif
  160. )
  161. {
  162. #if (SHADER_TARGET < 30)
  163. outGBuffer0 = 1;
  164. outGBuffer1 = 1;
  165. outGBuffer2 = 0;
  166. outEmission = 0;
  167. #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
  168. outShadowMask = 1;
  169. #endif
  170. return;
  171. #endif
  172. UNITY_APPLY_DITHER_CROSSFADE(i.pos.xy);
  173. FRAGMENT_SETUP(s)
  174. float _sign = sign(face);
  175. /// flip direction of normal based on sign of face
  176. float3 normal = s.normalWorld * _sign;
  177. s.normalWorld = normal;
  178. // no analytic lights in this pass
  179. UnityLight dummyLight = DummyLight();
  180. half atten = 1;
  181. // only GI
  182. half occlusion = Occlusion(i.tex.xy);
  183. #if UNITY_ENABLE_REFLECTION_BUFFERS
  184. bool sampleReflectionsInDeferred = false;
  185. #else
  186. bool sampleReflectionsInDeferred = true;
  187. #endif
  188. UnityGI gi = FragmentGI(s, occlusion, i.ambientOrLightmapUV, atten, dummyLight, sampleReflectionsInDeferred);
  189. half3 emissiveColor = UNITY_BRDF_PBS(s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect).rgb;
  190. #ifdef _EMISSION
  191. emissiveColor += Emission(i.tex.xy);
  192. #endif
  193. #ifndef UNITY_HDR_ON
  194. emissiveColor.rgb = exp2(-emissiveColor.rgb);
  195. #endif
  196. UnityStandardData data;
  197. data.diffuseColor = s.diffColor;
  198. data.occlusion = occlusion;
  199. data.specularColor = s.specColor;
  200. data.smoothness = s.smoothness;
  201. data.normalWorld = s.normalWorld;
  202. UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2);
  203. // Emissive lighting buffer
  204. outEmission = half4(emissiveColor, 1);
  205. // Baked direct lighting occlusion if any
  206. #if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
  207. outShadowMask = UnityGetRawBakedOcclusions(i.ambientOrLightmapUV.xy, IN_WORLDPOS(i));
  208. #endif
  209. }
  210. ENDCG
  211. }
  212. }
  213. FallBack "VertexLit"
  214. CustomEditor "StandardShaderGUI"
  215. }