2 Textures_realtime_shadow.shader 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. Shader "MTE/Unlit/2 Textures (realtime shadow, no baked lightmap)"
  2. {
  3. Properties
  4. {
  5. _Control("Control (RGBA)", 2D) = "red" {}
  6. _Splat0("Layer 1", 2D) = "white" {}
  7. _Splat1("Layer 2", 2D) = "white" {}
  8. }
  9. SubShader
  10. {
  11. Pass
  12. {
  13. Tags { "LIGHTMODE" = "ForwardBase" }
  14. CGPROGRAM
  15. #pragma multi_compile_fwdbase
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #pragma multi_compile _ LIGHTMAP_ON
  19. #pragma multi_compile_fog
  20. #include "UnityCG.cginc"
  21. #include "AutoLight.cginc"
  22. sampler2D _Control;
  23. float4 _Control_ST;
  24. sampler2D _Splat0,_Splat1;
  25. float4 _Splat0_ST,_Splat1_ST;
  26. struct v2f
  27. {
  28. float4 pos : SV_POSITION;
  29. float4 posWorld : TEXCOORD0;
  30. float4 tc_Control : TEXCOORD1;
  31. float4 tc_Splat01 : TEXCOORD2;
  32. SHADOW_COORDS(3)
  33. UNITY_FOG_COORDS(4)
  34. };
  35. struct appdata_lightmap
  36. {
  37. float4 vertex : POSITION;
  38. float2 texcoord : TEXCOORD0;
  39. float2 texcoord1 : TEXCOORD1;
  40. float2 fogCoord : TEXCOORD2;
  41. };
  42. v2f vert(appdata_lightmap v)
  43. {
  44. v2f o;
  45. UNITY_INITIALIZE_OUTPUT(v2f, o);
  46. o.pos = UnityObjectToClipPos(v.vertex);
  47. o.tc_Control.xy = TRANSFORM_TEX(v.texcoord, _Control);
  48. o.tc_Control.zw = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;//save lightmap uv in tc_Control.zw
  49. o.tc_Splat01.xy = TRANSFORM_TEX(v.texcoord, _Splat0);
  50. o.tc_Splat01.zw = TRANSFORM_TEX(v.texcoord, _Splat1);
  51. TRANSFER_SHADOW(o);
  52. UNITY_TRANSFER_FOG(o, o.pos);
  53. return o;
  54. }
  55. fixed4 frag(v2f i) : COLOR
  56. {
  57. half4 splat_control = tex2D(_Control, i.tc_Control.xy);
  58. half weight = dot(splat_control, half4(1, 1, 1, 1));
  59. splat_control /= (weight + 1e-3f);
  60. fixed4 mixedDiffuse = 0.0f;
  61. mixedDiffuse += splat_control.r * tex2D(_Splat0, i.tc_Splat01.xy);
  62. mixedDiffuse += splat_control.g * tex2D(_Splat1, i.tc_Splat01.zw);
  63. fixed4 color = mixedDiffuse;
  64. color.rgb *= SHADOW_ATTENUATION(i);
  65. UNITY_APPLY_FOG(i.fogCoord, color);
  66. return color;
  67. }
  68. ENDCG
  69. }
  70. }
  71. Fallback "Diffuse"
  72. CustomEditor "MTE.MTEShaderGUI"
  73. }