Diffuse.shader 2.6 KB

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