GlowEffectDownsample.shader 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Glow Downsample" {
  3. Properties {
  4. _Color ("Color", color) = (1,1,1,0)
  5. _MainTex ("", 2D) = "white" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : POSITION;
  11. float4 uv[4] : TEXCOORD0;
  12. };
  13. float4 _MainTex_TexelSize;
  14. v2f vert (appdata_img v)
  15. {
  16. v2f o;
  17. o.pos = UnityObjectToClipPos (v.vertex);
  18. float4 uv;
  19. uv.xy = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
  20. uv.zw = 0;
  21. float offX = _MainTex_TexelSize.x;
  22. float offY = _MainTex_TexelSize.y;
  23. // Direct3D9 needs some texel offset!
  24. #ifdef UNITY_HALF_TEXEL_OFFSET
  25. uv.x += offX * 2.0f;
  26. uv.y += offY * 2.0f;
  27. #endif
  28. o.uv[0] = uv + float4(-offX,-offY,0,1);
  29. o.uv[1] = uv + float4( offX,-offY,0,1);
  30. o.uv[2] = uv + float4( offX, offY,0,1);
  31. o.uv[3] = uv + float4(-offX, offY,0,1);
  32. return o;
  33. }
  34. ENDCG
  35. Category {
  36. ZTest Always Cull Off ZWrite Off Fog { Mode Off }
  37. // -----------------------------------------------------------
  38. // ARB fragment program
  39. Subshader {
  40. Pass {
  41. CGPROGRAM
  42. #pragma vertex vert
  43. #pragma fragment frag
  44. #pragma fragmentoption ARB_precision_hint_fastest
  45. sampler2D _MainTex;
  46. fixed4 _Color;
  47. fixed4 frag( v2f i ) : COLOR
  48. {
  49. fixed4 c;
  50. c = tex2D( _MainTex, i.uv[0].xy );
  51. c += tex2D( _MainTex, i.uv[1].xy );
  52. c += tex2D( _MainTex, i.uv[2].xy );
  53. c += tex2D( _MainTex, i.uv[3].xy );
  54. c /= 4;
  55. c.rgb *= _Color.rgb;
  56. c.rgb *= (c.a + _Color.a);
  57. c.a = 0;
  58. return c;
  59. }
  60. ENDCG
  61. }
  62. }
  63. // -----------------------------------------------------------
  64. // Radeon 9000
  65. Subshader {
  66. Pass {
  67. CGPROGRAM
  68. #pragma vertex vert
  69. #pragma exclude_renderers gles xbox360 ps3
  70. // use the same vertex program as in FP path
  71. ENDCG
  72. // average 2x2 samples
  73. SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant alpha}
  74. SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
  75. SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
  76. SetTexture [_MainTex] {constantColor (0,0,0,0.25) combine texture * constant + previous}
  77. // apply glow tint and add additional glow
  78. SetTexture [_MainTex] {constantColor[_Color] combine previous * constant, previous + constant}
  79. SetTexture [_MainTex] {constantColor (0,0,0,0) combine previous * previous alpha, constant}
  80. }
  81. }
  82. }
  83. Fallback off
  84. }