Diffuse-Fog.shader 4.2 KB

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