Bumped.shader 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. Shader "MTE/Standard/8 Textures/Bumped"
  2. {
  3. Properties
  4. {
  5. _Control ("Control (RGBA)", 2D) = "red" {}
  6. _ControlExtra ("Control Extra (RGB)", 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. _Splat5 ("Layer 6", 2D) = "white" {}
  13. _Splat6 ("Layer 7", 2D) = "white" {}
  14. _Splat7 ("Layer 8", 2D) = "white" {}
  15. _Normal0("Normal 1", 2D) = "bump" {}
  16. _Normal1("Normal 2", 2D) = "bump" {}
  17. _Normal2("Normal 3", 2D) = "bump" {}
  18. _Normal3("Normal 4", 2D) = "bump" {}
  19. [Gamma] _Metallic0("Metallic 1", Range(0.0, 1.0)) = 0.0
  20. [Gamma] _Metallic1("Metallic 2", Range(0.0, 1.0)) = 0.0
  21. [Gamma] _Metallic2("Metallic 3", Range(0.0, 1.0)) = 0.0
  22. [Gamma] _Metallic3("Metallic 4", Range(0.0, 1.0)) = 0.0
  23. [Gamma] _Metallic4("Metallic 5", Range(0.0, 1.0)) = 0.0
  24. [Gamma] _Metallic5("Metallic 6", Range(0.0, 1.0)) = 0.0
  25. [Gamma] _Metallic6("Metallic 7", Range(0.0, 1.0)) = 0.0
  26. [Gamma] _Metallic7("Metallic 8", Range(0.0, 1.0)) = 0.0
  27. _Smoothness0("Smoothness 1", Range(0.0, 1.0)) = 1.0
  28. _Smoothness1("Smoothness 2", Range(0.0, 1.0)) = 1.0
  29. _Smoothness2("Smoothness 3", Range(0.0, 1.0)) = 1.0
  30. _Smoothness3("Smoothness 4", Range(0.0, 1.0)) = 1.0
  31. _Smoothness4("Smoothness 5", Range(0.0, 1.0)) = 1.0
  32. _Smoothness5("Smoothness 6", Range(0.0, 1.0)) = 1.0
  33. _Smoothness6("Smoothness 7", Range(0.0, 1.0)) = 1.0
  34. _Smoothness7("Smoothness 8", Range(0.0, 1.0)) = 1.0
  35. }
  36. CGINCLUDE
  37. #pragma surface surf Standard vertex:MTE_SplatmapVert finalcolor:MTE_SplatmapFinalColor finalprepass:MTE_SplatmapFinalPrepass finalgbuffer:MTE_SplatmapFinalGBuffer
  38. #pragma multi_compile_fog
  39. struct Input
  40. {
  41. float4 tc;
  42. UNITY_FOG_COORDS(0)
  43. };
  44. sampler2D _Control,_ControlExtra;
  45. float4 _Control_ST,_ControlExtra_ST;
  46. sampler2D _Splat0,_Splat1,_Splat2,_Splat3,_Splat4,_Splat5,_Splat6,_Splat7;
  47. float4 _Splat0_ST,_Splat1_ST,_Splat2_ST,_Splat3_ST,_Splat4_ST,_Splat5_ST,_Splat6_ST,_Splat7_ST;
  48. sampler2D _Normal0, _Normal1, _Normal2, _Normal3;
  49. #define MTE_STANDARD_SHADER
  50. #include "UnityPBSLighting.cginc"
  51. #include "../../MTECommon.hlsl"
  52. half _Metallic0;
  53. half _Metallic1;
  54. half _Metallic2;
  55. half _Metallic3;
  56. half _Metallic4;
  57. half _Metallic5;
  58. half _Metallic6;
  59. half _Metallic7;
  60. half _Smoothness0;
  61. half _Smoothness1;
  62. half _Smoothness2;
  63. half _Smoothness3;
  64. half _Smoothness4;
  65. half _Smoothness5;
  66. half _Smoothness6;
  67. half _Smoothness7;
  68. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  69. {
  70. UNITY_INITIALIZE_OUTPUT(Input, data);
  71. data.tc = v.texcoord;
  72. float4 pos = UnityObjectToClipPos(v.vertex);
  73. UNITY_TRANSFER_FOG(data, pos);
  74. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  75. v.tangent.w = -1;
  76. }
  77. void MTE_SplatmapMix(Input IN, half4 smoothness0, half4 smoothness1, out half4 splat_control, out half4 splat_control_extra, out half weight, out fixed4 mixedDiffuse, inout fixed3 mixedNormal)
  78. {
  79. float2 uvControl = TRANSFORM_TEX(IN.tc.xy, _Control);
  80. float2 uvControlExtra = TRANSFORM_TEX(IN.tc.xy, _ControlExtra);
  81. float2 uvSplat0 = TRANSFORM_TEX(IN.tc.xy, _Splat0);
  82. float2 uvSplat1 = TRANSFORM_TEX(IN.tc.xy, _Splat1);
  83. float2 uvSplat2 = TRANSFORM_TEX(IN.tc.xy, _Splat2);
  84. float2 uvSplat3 = TRANSFORM_TEX(IN.tc.xy, _Splat3);
  85. float2 uvSplat4 = TRANSFORM_TEX(IN.tc.xy, _Splat4);
  86. float2 uvSplat5 = TRANSFORM_TEX(IN.tc.xy, _Splat5);
  87. float2 uvSplat6 = TRANSFORM_TEX(IN.tc.xy, _Splat6);
  88. float2 uvSplat7 = TRANSFORM_TEX(IN.tc.xy, _Splat7);
  89. splat_control = tex2D(_Control, uvControl);
  90. splat_control_extra = tex2D(_ControlExtra, uvControlExtra);
  91. weight = dot(splat_control, half4(1, 1, 1, 1));
  92. weight += dot(splat_control_extra, half4(1, 1, 1, 1));
  93. splat_control /= (weight + 1e-3f);
  94. splat_control_extra /= (weight + 1e-3f);
  95. mixedDiffuse = 0;
  96. mixedDiffuse += splat_control.r * tex2D(_Splat0, uvSplat0) * half4(1.0, 1.0, 1.0, smoothness0.r);
  97. mixedDiffuse += splat_control.g * tex2D(_Splat1, uvSplat1) * half4(1.0, 1.0, 1.0, smoothness0.g);
  98. mixedDiffuse += splat_control.b * tex2D(_Splat2, uvSplat2) * half4(1.0, 1.0, 1.0, smoothness0.b);
  99. mixedDiffuse += splat_control.a * tex2D(_Splat3, uvSplat3) * half4(1.0, 1.0, 1.0, smoothness0.a);
  100. mixedDiffuse += splat_control_extra.r * tex2D(_Splat4, uvSplat4) * half4(1.0, 1.0, 1.0, smoothness1.r);
  101. mixedDiffuse += splat_control_extra.g * tex2D(_Splat5, uvSplat5) * half4(1.0, 1.0, 1.0, smoothness1.g);
  102. mixedDiffuse += splat_control_extra.b * tex2D(_Splat6, uvSplat6) * half4(1.0, 1.0, 1.0, smoothness1.b);
  103. mixedDiffuse += splat_control_extra.a * tex2D(_Splat7, uvSplat7) * half4(1.0, 1.0, 1.0, smoothness1.a);
  104. fixed4 nrm = 0.0f;
  105. nrm += splat_control.r * tex2D(_Normal0, uvSplat0);
  106. nrm += splat_control.g * tex2D(_Normal1, uvSplat1);
  107. nrm += splat_control.b * tex2D(_Normal2, uvSplat2);
  108. nrm += splat_control.a * tex2D(_Normal3, uvSplat3);
  109. nrm += splat_control_extra.r * fixed4(0.5, 0.5, 1, 0.5);
  110. nrm += splat_control_extra.g * fixed4(0.5, 0.5, 1, 0.5);
  111. nrm += splat_control_extra.b * fixed4(0.5, 0.5, 1, 0.5);
  112. nrm += splat_control_extra.a * fixed4(0.5, 0.5, 1, 0.5);
  113. mixedNormal = UnpackNormal(nrm);
  114. }
  115. void surf(Input IN, inout SurfaceOutputStandard o)
  116. {
  117. half4 splat_control, splat_control_extra;
  118. fixed4 mixedDiffuse;
  119. half weight;
  120. half4 defaultSmoothness0 = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
  121. half4 defaultSmoothness1 = half4(_Smoothness4, _Smoothness5, _Smoothness6, _Smoothness7);
  122. MTE_SplatmapMix(IN, defaultSmoothness0, defaultSmoothness1, 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)) + dot(splat_control_extra, half4(_Metallic4, _Metallic5, _Metallic6, _Metallic7));
  127. }
  128. ENDCG
  129. Category
  130. {
  131. Tags
  132. {
  133. "Queue" = "Geometry-99"
  134. "RenderType" = "Opaque"
  135. }
  136. SubShader//for target 3.0+
  137. {
  138. CGPROGRAM
  139. #pragma target 3.0
  140. ENDCG
  141. }
  142. }
  143. Fallback "MTE/Standard/8 Textures/Diffuse"
  144. CustomEditor "MTE.MTEShaderGUI"
  145. }