Diffuse.shader 4.5 KB

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