Bumped.shader 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. Shader "MTE/Standard/3 Textures/Bumped"
  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. _Normal0 ("Normalmap 1", 2D) = "bump" {}
  10. _Normal1 ("Normalmap 2", 2D) = "bump" {}
  11. _Normal2 ("Normalmap 3", 2D) = "bump" {}
  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. _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0
  16. _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0
  17. _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 1.0
  18. [Toggle(SMOOTHNESS_TEXTURE)] SMOOTHNESS_TEXTURE ("Smoothness Texture", Float) = 0
  19. [Toggle(ENABLE_NORMAL_INTENSITY)] ENABLE_NORMAL_INTENSITY ("Normal Intensity", Float) = 0
  20. _NormalIntensity0 ("Normal Intensity 0", Range(0.01, 10)) = 1.0
  21. _NormalIntensity1 ("Normal Intensity 1", Range(0.01, 10)) = 1.0
  22. _NormalIntensity2 ("Normal Intensity 2", Range(0.01, 10)) = 1.0
  23. }
  24. CGINCLUDE
  25. #pragma surface surf Standard vertex:MTE_SplatmapVert finalcolor:MTE_SplatmapFinalColor finalprepass:MTE_SplatmapFinalPrepass finalgbuffer:MTE_SplatmapFinalGBuffer
  26. #pragma multi_compile_fog
  27. #pragma shader_feature ENABLE_NORMAL_INTENSITY
  28. struct Input
  29. {
  30. float4 tc_ControlSplat0 : TEXCOORD0;
  31. float4 tc_Splat12 : TEXCOORD1;
  32. UNITY_FOG_COORDS(2)
  33. };
  34. sampler2D _Control;
  35. float4 _Control_ST;
  36. sampler2D _Splat0,_Splat1,_Splat2;
  37. float4 _Splat0_ST,_Splat1_ST,_Splat2_ST;
  38. sampler2D _Normal0,_Normal1,_Normal2;
  39. #ifdef ENABLE_NORMAL_INTENSITY
  40. fixed _NormalIntensity0, _NormalIntensity1, _NormalIntensity2;
  41. #endif
  42. #define MTE_STANDARD_SHADER
  43. #include "UnityPBSLighting.cginc"
  44. #include "../../MTECommon.hlsl"
  45. half _Metallic0;
  46. half _Metallic1;
  47. half _Metallic2;
  48. half _Smoothness0;
  49. half _Smoothness1;
  50. half _Smoothness2;
  51. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  52. {
  53. UNITY_INITIALIZE_OUTPUT(Input, data);
  54. data.tc_ControlSplat0.xy = TRANSFORM_TEX(v.texcoord, _Control);
  55. data.tc_ControlSplat0.zw = TRANSFORM_TEX(v.texcoord, _Splat0);
  56. data.tc_Splat12.xy = TRANSFORM_TEX(v.texcoord, _Splat1);
  57. data.tc_Splat12.zw = TRANSFORM_TEX(v.texcoord, _Splat2);
  58. float4 pos = UnityObjectToClipPos (v.vertex);
  59. UNITY_TRANSFER_FOG(data, pos);
  60. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  61. v.tangent.w = -1;
  62. }
  63. void MTE_SplatmapMix(Input IN, half4 defaultAlpha, out half4 splat_control, out half weight, out fixed4 mixedDiffuse, inout float3 mixedNormal)
  64. {
  65. splat_control = tex2D(_Control, IN.tc_ControlSplat0.xy);
  66. weight = dot(splat_control, half4(1, 1, 1, 1));
  67. splat_control /= (weight + 1e-3f);
  68. mixedDiffuse = 0.0f;
  69. mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.tc_ControlSplat0.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.r);
  70. mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.tc_Splat12.xy) * half4(1.0, 1.0, 1.0, defaultAlpha.g);
  71. mixedDiffuse += splat_control.b * tex2D(_Splat2, IN.tc_Splat12.zw) * half4(1.0, 1.0, 1.0, defaultAlpha.b);
  72. #ifdef ENABLE_NORMAL_INTENSITY
  73. fixed3 nrm0 = UnpackNormal(tex2D(_Normal0, IN.tc_ControlSplat0.zw));
  74. fixed3 nrm1 = UnpackNormal(tex2D(_Normal1, IN.tc_Splat12.xy));
  75. fixed3 nrm2 = UnpackNormal(tex2D(_Normal2, IN.tc_Splat12.zw));
  76. nrm0 = splat_control.r * MTE_NormalIntensity_fixed(nrm0, _NormalIntensity0);
  77. nrm1 = splat_control.g * MTE_NormalIntensity_fixed(nrm1, _NormalIntensity1);
  78. nrm2 = splat_control.b * MTE_NormalIntensity_fixed(nrm2, _NormalIntensity2);
  79. mixedNormal = normalize(nrm0 + nrm1 + nrm2);
  80. #else
  81. fixed4 nrm = 0.0f;
  82. nrm += splat_control.r * tex2D(_Normal0, IN.tc_ControlSplat0.zw);
  83. nrm += splat_control.g * tex2D(_Normal1, IN.tc_Splat12.xy);
  84. nrm += splat_control.b * tex2D(_Normal2, IN.tc_Splat12.zw);
  85. mixedNormal = UnpackNormal(nrm);
  86. #endif
  87. }
  88. void surf(Input IN, inout SurfaceOutputStandard o)
  89. {
  90. half4 splat_control;
  91. fixed4 mixedDiffuse;
  92. half weight;
  93. half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, _Smoothness2, 0);
  94. MTE_SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, o.Normal);
  95. o.Albedo = mixedDiffuse.rgb;
  96. o.Alpha = weight;
  97. o.Smoothness = mixedDiffuse.a;
  98. o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, _Metallic2, 0));
  99. }
  100. ENDCG
  101. Category
  102. {
  103. Tags
  104. {
  105. "Queue" = "Geometry-99"
  106. "RenderType" = "Opaque"
  107. }
  108. SubShader//for target 3.0+
  109. {
  110. CGPROGRAM
  111. #pragma target 3.0
  112. ENDCG
  113. }
  114. //target 2.0 not supported
  115. }
  116. Fallback "MTE/Standard/3 Textures/Diffuse"
  117. CustomEditor "MTE.MTEShaderGUI"
  118. }