Bumped-Fog.shader 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. Shader "MTE/Standard/5 Textures/Bumped/Fog"
  2. {
  3. Properties
  4. {
  5. _Control ("Control (RGBA)", 2D) = "red" {}
  6. _ControlExtra ("Control Extra (R)", 2D) = "black" {}
  7. _Splat0 ("Layer 1", 2D) = "white" {}
  8. _Splat1 ("Layer 2", 2D) = "white" {}
  9. _Splat2 ("Layer 3", 2D) = "white" {}
  10. _Splat3 ("Layer 4", 2D) = "white" {}
  11. _Splat4 ("Layer 5", 2D) = "white" {}
  12. _Normal0 ("Normalmap 1", 2D) = "bump" {}
  13. _Normal1 ("Normalmap 2", 2D) = "bump" {}
  14. _Normal2 ("Normalmap 3", 2D) = "bump" {}
  15. _Normal3 ("Normalmap 4", 2D) = "bump" {}
  16. _Normal4 ("Normalmap 5", 2D) = "bump" {}
  17. [Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0
  18. [Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0
  19. [Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0
  20. [Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0
  21. [Gamma] _Metallic4("Metallic 4", Range(0.0, 1.0)) = 0.0
  22. _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0
  23. _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0
  24. _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0
  25. _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0
  26. _Smoothness4("Smoothness 4", Range(0.0, 1.0)) = 1.0
  27. [Toggle(SMOOTHNESS_TEXTURE)] SMOOTHNESS_TEXTURE ("Smoothness Texture", Float) = 0
  28. [Toggle(ENABLE_NORMAL_INTENSITY)] ENABLE_NORMAL_INTENSITY ("Normal Intensity", Float) = 0
  29. _NormalIntensity0 ("Normal Intensity 0", Range(0.01, 10)) = 1.0
  30. _NormalIntensity1 ("Normal Intensity 1", Range(0.01, 10)) = 1.0
  31. _NormalIntensity2 ("Normal Intensity 2", Range(0.01, 10)) = 1.0
  32. _NormalIntensity3 ("Normal Intensity 3", Range(0.01, 10)) = 1.0
  33. _NormalIntensity4 ("Normal Intensity 4", Range(0.01, 10)) = 1.0
  34. }
  35. CGINCLUDE
  36. #pragma surface surf Standard vertex:MTE_SplatmapVert finalcolor:MTE_SplatmapFinalColor finalprepass:MTE_SplatmapFinalPrepass finalgbuffer:MTE_SplatmapFinalGBuffer
  37. #pragma multi_compile_fog
  38. #pragma shader_feature ENABLE_NORMAL_INTENSITY
  39. struct Input
  40. {
  41. float2 tc_Control : TEXCOORD0;
  42. float4 tc_Splat01 : TEXCOORD1;
  43. float4 tc_Splat23 : TEXCOORD2;
  44. UNITY_FOG_COORDS(3)
  45. };
  46. sampler2D _Control,_ControlExtra;
  47. float4 _Control_ST,_ControlExtra_ST;
  48. sampler2D _Splat0,_Splat1,_Splat2,_Splat3,_Splat4;
  49. float4 _Splat0_ST,_Splat1_ST,_Splat2_ST,_Splat3_ST;
  50. sampler2D _Normal0,_Normal1,_Normal2,_Normal3,_Normal4;
  51. #ifdef ENABLE_NORMAL_INTENSITY
  52. fixed _NormalIntensity0, _NormalIntensity1, _NormalIntensity2, _NormalIntensity3,
  53. _NormalIntensity4;
  54. #endif
  55. #define MTE_STANDARD_SHADER
  56. #include "UnityPBSLighting.cginc"
  57. #include "../../MTECommon.hlsl"
  58. half _Metallic0;
  59. half _Metallic1;
  60. half _Metallic2;
  61. half _Metallic3;
  62. half _Metallic4;
  63. half _Smoothness0;
  64. half _Smoothness1;
  65. half _Smoothness2;
  66. half _Smoothness3;
  67. half _Smoothness4;
  68. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  69. {
  70. UNITY_INITIALIZE_OUTPUT(Input, data);
  71. data.tc_Control.xy = TRANSFORM_TEX(v.texcoord, _Control);
  72. data.tc_Splat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  73. data.tc_Splat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  74. data.tc_Splat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
  75. data.tc_Splat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
  76. // Because the UNITY_FOG_COORDS(3) occupied one TEXCOORD, Splat4 have to share texcoord with Splat3 - both using tc_Splat23.zw.
  77. float4 pos = UnityObjectToClipPos (v.vertex);
  78. UNITY_TRANSFER_FOG(data, pos);
  79. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  80. v.tangent.w = -1;
  81. }
  82. void MTE_SplatmapMix(Input IN, half smoothness[5], out half4 splat_control, out half4 splat_control_extra, out half weight, out fixed4 mixedDiffuse, inout float3 mixedNormal)
  83. {
  84. splat_control = tex2D(_Control, IN.tc_Control.xy);
  85. splat_control_extra = tex2D(_ControlExtra, IN.tc_Control.xy);
  86. weight = dot(splat_control, half4(1, 1, 1, 1));
  87. weight += dot(splat_control_extra.r, half(1));
  88. splat_control /= (weight + 1e-3f);
  89. splat_control_extra /= (weight + 1e-3f);
  90. mixedDiffuse = 0;
  91. mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.tc_Splat01.xy) * half4(1.0, 1.0, 1.0, smoothness[0]);
  92. mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.tc_Splat01.zw) * half4(1.0, 1.0, 1.0, smoothness[1]);
  93. mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.tc_Splat23.xy) * half4(1.0, 1.0, 1.0, smoothness[2]);
  94. mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.tc_Splat23.zw) * half4(1.0, 1.0, 1.0, smoothness[3]);
  95. mixedDiffuse += splat_control_extra.r * tex2D(_Splat4, IN.tc_Splat23.zw) * half4(1.0, 1.0, 1.0, smoothness[4]);
  96. #ifdef ENABLE_NORMAL_INTENSITY
  97. fixed3 nrm0 = UnpackNormal(tex2D(_Normal0, IN.tc_Splat01.xy));
  98. fixed3 nrm1 = UnpackNormal(tex2D(_Normal1, IN.tc_Splat01.xy));
  99. fixed3 nrm2 = UnpackNormal(tex2D(_Normal2, IN.tc_Splat23.xy));
  100. fixed3 nrm3 = UnpackNormal(tex2D(_Normal3, IN.tc_Splat23.zw));
  101. fixed3 nrm4 = UnpackNormal(tex2D(_Normal4, IN.tc_Splat23.zw));
  102. nrm0 = splat_control.r * MTE_NormalIntensity_fixed(nrm0, _NormalIntensity0);
  103. nrm1 = splat_control.g * MTE_NormalIntensity_fixed(nrm1, _NormalIntensity1);
  104. nrm2 = splat_control.b * MTE_NormalIntensity_fixed(nrm2, _NormalIntensity2);
  105. nrm3 = splat_control.a * MTE_NormalIntensity_fixed(nrm3, _NormalIntensity3);
  106. nrm4 = splat_control_extra.r * MTE_NormalIntensity_fixed(nrm4, _NormalIntensity4);
  107. mixedNormal = normalize(nrm0 + nrm1 + nrm2 + nrm3 + nrm4);
  108. #else
  109. fixed4 nrm = 0.0f;
  110. nrm += splat_control.r * tex2D(_Normal0, IN.tc_Splat01.xy);
  111. nrm += splat_control.g * tex2D(_Normal1, IN.tc_Splat01.zw);
  112. nrm += splat_control.b * tex2D(_Normal2, IN.tc_Splat23.xy);
  113. nrm += splat_control.a * tex2D(_Normal3, IN.tc_Splat23.zw);
  114. nrm += splat_control_extra.r * tex2D(_Normal4, IN.tc_Splat23.zw);
  115. mixedNormal = UnpackNormal(nrm);
  116. #endif
  117. }
  118. void surf(Input IN, inout SurfaceOutputStandard o)
  119. {
  120. half4 splat_control, splat_control_extra;
  121. fixed4 mixedDiffuse;
  122. half weight;
  123. half smoothness[5]={_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3, _Smoothness4};
  124. MTE_SplatmapMix(IN, smoothness, splat_control, splat_control_extra, weight,
  125. mixedDiffuse, o.Normal);
  126. o.Albedo = mixedDiffuse.rgb;
  127. o.Alpha = weight;
  128. o.Smoothness = mixedDiffuse.a;
  129. o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3))
  130. + dot(splat_control_extra.r, half(_Metallic4));
  131. }
  132. ENDCG
  133. Category
  134. {
  135. Tags
  136. {
  137. "Queue" = "Geometry-99"
  138. "RenderType" = "Opaque"
  139. }
  140. SubShader//for target 3.0+
  141. {
  142. CGPROGRAM
  143. #pragma target 3.0
  144. ENDCG
  145. }
  146. //target 2.0 not supported
  147. }
  148. Fallback "MTE/Standard/5 Textures/Diffuse/Fog"
  149. CustomEditor "MTE.MTEShaderGUI"
  150. }