Diffuse.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Shader "MTE/Standard/4 Textures/Diffuse"
  2. {
  3. Properties
  4. {
  5. _Control ("Control (RGBA)", 2D) = "red" {}
  6. _Splat0 ("Layer 1", 2D) = "white" {}
  7. _Splat1 ("Layer 2", 2D) = "white" {}
  8. _Splat2 ("Layer 3", 2D) = "white" {}
  9. _Splat3 ("Layer 4", 2D) = "white" {}
  10. [Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0
  11. [Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0
  12. [Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0
  13. [Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0
  14. _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0
  15. _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0
  16. _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0
  17. _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 1.0
  18. }
  19. CGINCLUDE
  20. #pragma surface surf Standard vertex:MTE_SplatmapVert finalcolor:MTE_SplatmapFinalColor finalprepass:MTE_SplatmapFinalPrepass finalgbuffer:MTE_SplatmapFinalGBuffer
  21. #pragma multi_compile_fog
  22. struct Input
  23. {
  24. float2 tc_Control : TEXCOORD0;
  25. float4 tc_Splat01 : TEXCOORD1;
  26. float4 tc_Splat23 : TEXCOORD2;
  27. UNITY_FOG_COORDS(3)
  28. };
  29. sampler2D _Control;
  30. float4 _Control_ST;
  31. sampler2D _Splat0,_Splat1,_Splat2,_Splat3;
  32. float4 _Splat0_ST,_Splat1_ST,_Splat2_ST,_Splat3_ST;
  33. #define MTE_STANDARD_SHADER
  34. #include "UnityPBSLighting.cginc"
  35. #include "../../MTECommon.hlsl"
  36. half _Metallic0;
  37. half _Metallic1;
  38. half _Metallic2;
  39. half _Metallic3;
  40. half _Smoothness0;
  41. half _Smoothness1;
  42. half _Smoothness2;
  43. half _Smoothness3;
  44. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  45. {
  46. UNITY_INITIALIZE_OUTPUT(Input, data);
  47. data.tc_Control.xy = TRANSFORM_TEX(v.texcoord, _Control);
  48. data.tc_Splat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  49. data.tc_Splat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  50. data.tc_Splat23.xy = TRANSFORM_TEX(v.texcoord, _Splat2);
  51. data.tc_Splat23.zw = TRANSFORM_TEX(v.texcoord, _Splat3);
  52. float4 pos = UnityObjectToClipPos (v.vertex);
  53. UNITY_TRANSFER_FOG(data, pos);
  54. }
  55. void MTE_SplatmapMix(Input IN, half4 defaultAlpha, out half4 splat_control, out half weight, out fixed4 mixedDiffuse)
  56. {
  57. splat_control = tex2D(_Control, IN.tc_Control.xy);
  58. weight = dot(splat_control, half4(1, 1, 1, 1));
  59. splat_control /= (weight + 1e-3f);
  60. mixedDiffuse = 0.0f;
  61. mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.tc_Splat01.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.r);
  62. mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.tc_Splat01.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.g);
  63. mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.tc_Splat23.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.b);
  64. mixedDiffuse += splat_control.a * tex2D(_Splat3, IN.tc_Splat23.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.a);
  65. }
  66. void surf(Input IN, inout SurfaceOutputStandard o)
  67. {
  68. half4 splat_control;
  69. fixed4 mixedDiffuse;
  70. half weight;
  71. half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3);
  72. MTE_SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse);
  73. o.Albedo = mixedDiffuse.rgb;
  74. o.Alpha = weight;
  75. o.Smoothness = mixedDiffuse.a;
  76. o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3));
  77. }
  78. ENDCG
  79. Category
  80. {
  81. Tags
  82. {
  83. "Queue" = "Geometry-99"
  84. "RenderType" = "Opaque"
  85. }
  86. SubShader//for target 3.0+
  87. {
  88. CGPROGRAM
  89. #pragma target 3.0
  90. ENDCG
  91. }
  92. SubShader//for target 2.0
  93. {
  94. CGPROGRAM
  95. ENDCG
  96. }
  97. }
  98. Fallback "Diffuse"
  99. CustomEditor "MTE.MTEShaderGUI"
  100. }