Blend.shader 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Blend" {
  3. Properties {
  4. _MainTex ("Screen Blended", 2D) = "" {}
  5. _ColorBuffer ("Color", 2D) = "" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : SV_POSITION;
  11. float2 uv[2] : TEXCOORD0;
  12. };
  13. struct v2f_mt {
  14. float4 pos : SV_POSITION;
  15. float2 uv[4] : TEXCOORD0;
  16. };
  17. sampler2D _ColorBuffer;
  18. sampler2D _MainTex;
  19. half _Intensity;
  20. half4 _ColorBuffer_TexelSize;
  21. half4 _MainTex_TexelSize;
  22. v2f vert( appdata_img v ) {
  23. v2f o;
  24. o.pos = UnityObjectToClipPos(v.vertex);
  25. o.uv[0] = v.texcoord.xy;
  26. o.uv[1] = v.texcoord.xy;
  27. #if UNITY_UV_STARTS_AT_TOP
  28. if (_ColorBuffer_TexelSize.y < 0)
  29. o.uv[1].y = 1-o.uv[1].y;
  30. #endif
  31. return o;
  32. }
  33. v2f_mt vertMultiTap( appdata_img v ) {
  34. v2f_mt o;
  35. o.pos = UnityObjectToClipPos(v.vertex);
  36. o.uv[0] = v.texcoord.xy + _MainTex_TexelSize.xy * 0.5;
  37. o.uv[1] = v.texcoord.xy - _MainTex_TexelSize.xy * 0.5;
  38. o.uv[2] = v.texcoord.xy - _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
  39. o.uv[3] = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
  40. return o;
  41. }
  42. half4 fragScreen (v2f i) : SV_Target {
  43. half4 toBlend = saturate (tex2D(_MainTex, i.uv[0]) * _Intensity);
  44. return 1-(1-toBlend)*(1-tex2D(_ColorBuffer, i.uv[1]));
  45. }
  46. half4 fragAdd (v2f i) : SV_Target {
  47. return tex2D(_MainTex, i.uv[0].xy) * _Intensity + tex2D(_ColorBuffer, i.uv[1]);
  48. }
  49. half4 fragVignetteBlend (v2f i) : SV_Target {
  50. return tex2D(_MainTex, i.uv[0].xy) * tex2D(_ColorBuffer, i.uv[0]);
  51. }
  52. half4 fragMultiTap (v2f_mt i) : SV_Target {
  53. half4 outColor = tex2D(_MainTex, i.uv[0].xy);
  54. outColor += tex2D(_MainTex, i.uv[1].xy);
  55. outColor += tex2D(_MainTex, i.uv[2].xy);
  56. outColor += tex2D(_MainTex, i.uv[3].xy);
  57. return outColor * 0.25;
  58. }
  59. ENDCG
  60. Subshader {
  61. ZTest Always Cull Off ZWrite Off
  62. // 0: nicer & softer "screen" blend mode
  63. Pass {
  64. CGPROGRAM
  65. #pragma vertex vert
  66. #pragma fragment fragScreen
  67. ENDCG
  68. }
  69. // 1: simple "add" blend mode
  70. Pass {
  71. CGPROGRAM
  72. #pragma vertex vert
  73. #pragma fragment fragAdd
  74. ENDCG
  75. }
  76. // 2: used for "stable" downsampling
  77. Pass {
  78. CGPROGRAM
  79. #pragma vertex vertMultiTap
  80. #pragma fragment fragMultiTap
  81. ENDCG
  82. }
  83. // 3: vignette blending
  84. Pass {
  85. CGPROGRAM
  86. #pragma vertex vert
  87. #pragma fragment fragVignetteBlend
  88. ENDCG
  89. }
  90. }
  91. Fallback off
  92. } // shader