Bumped.shader 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. Shader "MTE/Standard/2 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. _Normal0 ("Normalmap 1", 2D) = "bump" {}
  9. _Normal1 ("Normalmap 2", 2D) = "bump" {}
  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. _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 1.0
  13. _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 1.0
  14. [Toggle(SMOOTHNESS_TEXTURE)] SMOOTHNESS_TEXTURE ("Smoothness Texture", Float) = 0
  15. [Toggle(ENABLE_NORMAL_INTENSITY)] ENABLE_NORMAL_INTENSITY ("Normal Intensity", Float) = 0
  16. _NormalIntensity0 ("Normal Intensity 0", Range(0.01, 10)) = 1.0
  17. _NormalIntensity1 ("Normal Intensity 1", Range(0.01, 10)) = 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. #pragma shader_feature ENABLE_NORMAL_INTENSITY
  23. struct Input
  24. {
  25. float2 tc_Control : TEXCOORD0;
  26. float4 tc_Splat01 : TEXCOORD1;
  27. UNITY_FOG_COORDS(2)
  28. };
  29. sampler2D _Control;
  30. float4 _Control_ST;
  31. sampler2D _Splat0,_Splat1;
  32. float4 _Splat0_ST,_Splat1_ST;
  33. sampler2D _Normal0,_Normal1;
  34. #ifdef ENABLE_NORMAL_INTENSITY
  35. fixed _NormalIntensity0, _NormalIntensity1;
  36. #endif
  37. #define MTE_STANDARD_SHADER
  38. #include "UnityPBSLighting.cginc"
  39. #include "../../MTECommon.hlsl"
  40. half _Metallic0;
  41. half _Metallic1;
  42. half _Smoothness0;
  43. half _Smoothness1;
  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. float4 pos = UnityObjectToClipPos(v.vertex);
  51. UNITY_TRANSFER_FOG(data, pos);
  52. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  53. v.tangent.w = -1;
  54. }
  55. void MTE_SplatmapMix(Input IN, half4 defaultAlpha, out half4 splat_control, out half weight, out fixed4 mixedDiffuse, inout float3 mixedNormal)
  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. #ifdef ENABLE_NORMAL_INTENSITY
  64. fixed3 nrm0 = UnpackNormal(tex2D(_Normal0, IN.tc_Splat01.xy));
  65. fixed3 nrm1 = UnpackNormal(tex2D(_Normal1, IN.tc_Splat01.zw));
  66. nrm0 = splat_control.r * MTE_NormalIntensity_fixed(nrm0, _NormalIntensity0);
  67. nrm1 = splat_control.g * MTE_NormalIntensity_fixed(nrm1, _NormalIntensity1);
  68. mixedNormal = normalize(nrm0 + nrm1);
  69. #else
  70. fixed4 nrm = 0.0f;
  71. nrm += splat_control.r * tex2D(_Normal0, IN.tc_Splat01.xy);
  72. nrm += splat_control.g * tex2D(_Normal1, IN.tc_Splat01.zw);
  73. mixedNormal = UnpackNormal(nrm);
  74. #endif
  75. }
  76. void surf(Input IN, inout SurfaceOutputStandard o)
  77. {
  78. half4 splat_control;
  79. fixed4 mixedDiffuse;
  80. half weight;
  81. half4 defaultSmoothness = half4(_Smoothness0, _Smoothness1, 0, 0);
  82. MTE_SplatmapMix(IN, defaultSmoothness, splat_control, weight, mixedDiffuse, o.Normal);
  83. o.Albedo = mixedDiffuse.rgb;
  84. o.Alpha = weight;
  85. o.Smoothness = mixedDiffuse.a;
  86. o.Metallic = dot(splat_control, half4(_Metallic0, _Metallic1, 0, 0));
  87. }
  88. ENDCG
  89. Category
  90. {
  91. Tags
  92. {
  93. "Queue" = "Geometry-99"
  94. "RenderType" = "Opaque"
  95. }
  96. SubShader//for target 3.0+
  97. {
  98. CGPROGRAM
  99. #pragma target 3.0
  100. ENDCG
  101. }
  102. SubShader//for target 2.0
  103. {
  104. CGPROGRAM
  105. ENDCG
  106. }
  107. }
  108. Fallback "MTE/Standard/2 Textures/Diffuse"
  109. CustomEditor "MTE.MTEShaderGUI"
  110. }