Bumped-NoFog.shader 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. Shader "MTE/Standard/5 Textures/Bumped/NoFog"
  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 shader_feature ENABLE_NORMAL_INTENSITY
  38. struct Input
  39. {
  40. float2 tc_Control : TEXCOORD0;
  41. float4 tc_Splat01 : TEXCOORD1;
  42. float4 tc_Splat23 : TEXCOORD2;
  43. float2 tc_Splat4 : TEXCOORD3;
  44. };
  45. sampler2D _Control,_ControlExtra;
  46. float4 _Control_ST,_ControlExtra_ST;
  47. sampler2D _Splat0,_Splat1,_Splat2,_Splat3,_Splat4;
  48. float4 _Splat0_ST,_Splat1_ST,_Splat2_ST,_Splat3_ST,_Splat4_ST;
  49. sampler2D _Normal0,_Normal1,_Normal2,_Normal3,_Normal4;
  50. #ifdef ENABLE_NORMAL_INTENSITY
  51. fixed _NormalIntensity0, _NormalIntensity1, _NormalIntensity2, _NormalIntensity3,
  52. _NormalIntensity4;
  53. #endif
  54. #define MTE_STANDARD_SHADER
  55. #include "UnityPBSLighting.cginc"
  56. #include "../../MTECommon.hlsl"
  57. half _Metallic0;
  58. half _Metallic1;
  59. half _Metallic2;
  60. half _Metallic3;
  61. half _Metallic4;
  62. half _Smoothness0;
  63. half _Smoothness1;
  64. half _Smoothness2;
  65. half _Smoothness3;
  66. half _Smoothness4;
  67. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  68. {
  69. UNITY_INITIALIZE_OUTPUT(Input, data);
  70. data.tc_Control.xy = TRANSFORM_TEX(v.texcoord, _Control);
  71. data.tc_Splat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  72. data.tc_Splat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  73. data.tc_Splat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
  74. data.tc_Splat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
  75. data.tc_Splat4.xy = TRANSFORM_TEX(v.texcoord, _Splat4);
  76. float4 pos = UnityObjectToClipPos (v.vertex);
  77. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  78. v.tangent.w = -1;
  79. }
  80. 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)
  81. {
  82. splat_control = tex2D(_Control, IN.tc_Control.xy);
  83. splat_control_extra = tex2D(_ControlExtra, IN.tc_Control.xy);
  84. weight = dot(splat_control, half4(1, 1, 1, 1));
  85. weight += dot(splat_control_extra.r, half(1));
  86. splat_control /= (weight + 1e-3f);
  87. splat_control_extra /= (weight + 1e-3f);
  88. mixedDiffuse = 0;
  89. mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.tc_Splat01.xy) * half4(1.0, 1.0, 1.0, smoothness[0]);
  90. mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.tc_Splat01.zw) * half4(1.0, 1.0, 1.0, smoothness[1]);
  91. mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.tc_Splat23.xy) * half4(1.0, 1.0, 1.0, smoothness[2]);
  92. mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.tc_Splat23.zw) * half4(1.0, 1.0, 1.0, smoothness[3]);
  93. mixedDiffuse += splat_control_extra.r * tex2D(_Splat4, IN.tc_Splat4) * half4(1.0, 1.0, 1.0, smoothness[4]);
  94. #ifdef ENABLE_NORMAL_INTENSITY
  95. fixed3 nrm0 = UnpackNormal(tex2D(_Normal0, IN.tc_Splat01.xy));
  96. fixed3 nrm1 = UnpackNormal(tex2D(_Normal1, IN.tc_Splat01.xy));
  97. fixed3 nrm2 = UnpackNormal(tex2D(_Normal2, IN.tc_Splat23.xy));
  98. fixed3 nrm3 = UnpackNormal(tex2D(_Normal3, IN.tc_Splat23.zw));
  99. fixed3 nrm4 = UnpackNormal(tex2D(_Normal4, IN.tc_Splat4));
  100. nrm0 = splat_control.r * MTE_NormalIntensity_fixed(nrm0, _NormalIntensity0);
  101. nrm1 = splat_control.g * MTE_NormalIntensity_fixed(nrm1, _NormalIntensity1);
  102. nrm2 = splat_control.b * MTE_NormalIntensity_fixed(nrm2, _NormalIntensity2);
  103. nrm3 = splat_control.a * MTE_NormalIntensity_fixed(nrm3, _NormalIntensity3);
  104. nrm4 = splat_control_extra.r * MTE_NormalIntensity_fixed(nrm4, _NormalIntensity4);
  105. mixedNormal = normalize(nrm0 + nrm1 + nrm2 + nrm3 + nrm4);
  106. #else
  107. fixed4 nrm = 0.0f;
  108. nrm += splat_control.r * tex2D(_Normal0, IN.tc_Splat01.xy);
  109. nrm += splat_control.g * tex2D(_Normal1, IN.tc_Splat01.zw);
  110. nrm += splat_control.b * tex2D(_Normal2, IN.tc_Splat23.xy);
  111. nrm += splat_control.a * tex2D(_Normal3, IN.tc_Splat23.zw);
  112. nrm += splat_control_extra.r * tex2D(_Normal4, IN.tc_Splat4);
  113. mixedNormal = UnpackNormal(nrm);
  114. #endif
  115. }
  116. void surf(Input IN, inout SurfaceOutputStandard o)
  117. {
  118. half4 splat_control, splat_control_extra;
  119. fixed4 mixedDiffuse;
  120. half weight;
  121. half smoothness[5]={_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3, _Smoothness4};
  122. MTE_SplatmapMix(IN, smoothness, splat_control, splat_control_extra, weight, mixedDiffuse, o.Normal);
  123. o.Albedo = mixedDiffuse.rgb;
  124. o.Alpha = weight;
  125. o.Smoothness = mixedDiffuse.a;
  126. o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3))
  127. + dot(splat_control_extra.r, half(_Metallic4));
  128. }
  129. ENDCG
  130. Category
  131. {
  132. Tags
  133. {
  134. "Queue" = "Geometry-99"
  135. "RenderType" = "Opaque"
  136. }
  137. SubShader//for target 3.0+
  138. {
  139. CGPROGRAM
  140. #pragma target 3.0
  141. ENDCG
  142. }
  143. //target 2.0 not supported
  144. }
  145. Fallback "MTE/Standard/5 Textures/Diffuse/NoFog"
  146. CustomEditor "MTE.MTEShaderGUI"
  147. }