Diffuse.shader 3.0 KB

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