Specular.shader 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Shader "MTE/Surface/2 Textures/Specular"
  2. {
  3. Properties
  4. {
  5. _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
  6. _Shininess("Shininess", Range(0.03, 1)) = 0.078125
  7. _Control ("Control (RGBA)", 2D) = "red" {}
  8. _Splat0 ("Layer 1", 2D) = "white" {}
  9. _Splat1 ("Layer 2", 2D) = "white" {}
  10. _Normal0 ("Normalmap 1", 2D) = "bump" {}
  11. _Normal1 ("Normalmap 2", 2D) = "bump" {}
  12. [Toggle(ENABLE_NORMAL_INTENSITY)] ENABLE_NORMAL_INTENSITY ("Normal Intensity", Float) = 0
  13. _NormalIntensity0 ("Normal Intensity 0", Range(0.01, 10)) = 1.0
  14. _NormalIntensity1 ("Normal Intensity 1", Range(0.01, 10)) = 1.0
  15. }
  16. CGINCLUDE
  17. #pragma surface surf BlinnPhong vertex:MTE_SplatmapVert finalcolor:MTE_SplatmapFinalColor finalprepass:MTE_SplatmapFinalPrepass finalgbuffer:MTE_SplatmapFinalGBuffer
  18. #pragma multi_compile_fog
  19. #pragma shader_feature ENABLE_NORMAL_INTENSITY
  20. struct Input
  21. {
  22. float2 tc_Control : TEXCOORD0;
  23. float4 tc_Splat01 : TEXCOORD1;
  24. UNITY_FOG_COORDS(2)
  25. };
  26. sampler2D _Control;
  27. float4 _Control_ST;
  28. sampler2D _Splat0,_Splat1;
  29. float4 _Splat0_ST,_Splat1_ST;
  30. sampler2D _Normal0,_Normal1;
  31. #ifdef ENABLE_NORMAL_INTENSITY
  32. fixed _NormalIntensity0, _NormalIntensity1;
  33. #endif
  34. #include "../../MTECommon.hlsl"
  35. half _Shininess;
  36. void MTE_SplatmapVert(inout appdata_full v, out Input data)
  37. {
  38. UNITY_INITIALIZE_OUTPUT(Input, data);
  39. data.tc_Control.xy = TRANSFORM_TEX(v.texcoord, _Control);
  40. data.tc_Splat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  41. data.tc_Splat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  42. float4 pos = UnityObjectToClipPos(v.vertex);
  43. UNITY_TRANSFER_FOG(data, pos);
  44. v.tangent.xyz = cross(v.normal, float3(0,0,1));
  45. v.tangent.w = -1;
  46. }
  47. void MTE_SplatmapMix(Input IN, out half weight, out fixed4 mixedDiffuse, inout fixed3 mixedNormal)
  48. {
  49. half4 splat_control = tex2D(_Control, IN.tc_Control.xy);
  50. weight = dot(splat_control, half4(1, 1, 1, 1));
  51. splat_control /= (weight + 1e-3f);
  52. mixedDiffuse = 0.0f;
  53. mixedDiffuse += splat_control.r * tex2D(_Splat0, IN.tc_Splat01.xy);
  54. mixedDiffuse += splat_control.g * tex2D(_Splat1, IN.tc_Splat01.zw);
  55. #ifdef ENABLE_NORMAL_INTENSITY
  56. fixed3 nrm0 = UnpackNormal(tex2D(_Normal0, IN.tc_Splat01.xy));
  57. fixed3 nrm1 = UnpackNormal(tex2D(_Normal1, IN.tc_Splat01.zw));
  58. nrm0 = splat_control.r * MTE_NormalIntensity_fixed(nrm0, _NormalIntensity0);
  59. nrm1 = splat_control.g * MTE_NormalIntensity_fixed(nrm1, _NormalIntensity1);
  60. mixedNormal = normalize(nrm0 + nrm1);
  61. #else
  62. fixed4 nrm = 0.0f;
  63. nrm += splat_control.r * tex2D(_Normal0, IN.tc_Splat01.xy);
  64. nrm += splat_control.g * tex2D(_Normal1, IN.tc_Splat01.zw);
  65. mixedNormal = UnpackNormal(nrm);
  66. #endif
  67. }
  68. void surf(Input IN, inout SurfaceOutput o)
  69. {
  70. fixed4 mixedDiffuse;
  71. half weight;
  72. MTE_SplatmapMix(IN, weight, mixedDiffuse, o.Normal);
  73. o.Albedo = mixedDiffuse.rgb;
  74. o.Alpha = weight;
  75. o.Gloss = mixedDiffuse.a;
  76. o.Specular = _Shininess;
  77. }
  78. ENDCG
  79. Category
  80. {
  81. Tags
  82. {
  83. "Queue" = "Geometry-99"
  84. "RenderType" = "Opaque"
  85. }
  86. SubShader//for target 3.0+
  87. {
  88. CGPROGRAM
  89. #pragma target 3.0
  90. ENDCG
  91. }
  92. SubShader//for target 2.5
  93. {
  94. CGPROGRAM
  95. #pragma target 2.5
  96. ENDCG
  97. }
  98. SubShader//for target 2.0
  99. {
  100. CGPROGRAM
  101. #pragma target 2.0
  102. ENDCG
  103. }
  104. }
  105. Fallback "MTE/Surface/2 Textures/Bumped"
  106. CustomEditor "MTE.MTEShaderGUI"
  107. }