| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
- Shader "Hidden/FastBloom" {
- Properties {
- _MainTex ("Base (RGB)", 2D) = "white" {}
- _Bloom ("Bloom (RGB)", 2D) = "black" {}
- }
-
- CGINCLUDE
- #include "UnityCG.cginc"
- sampler2D _MainTex;
- sampler2D _Bloom;
-
- uniform half4 _MainTex_TexelSize;
-
- uniform half4 _Parameter;
- uniform half4 _OffsetsA;
- uniform half4 _OffsetsB;
-
- #define ONE_MINUS_THRESHHOLD_TIMES_INTENSITY _Parameter.w
- #define THRESHHOLD _Parameter.z
- struct v2f_simple
- {
- float4 pos : SV_POSITION;
- half2 uv : TEXCOORD0;
- #if UNITY_UV_STARTS_AT_TOP
- half2 uv2 : TEXCOORD1;
- #endif
- };
-
- v2f_simple vertBloom ( appdata_img v )
- {
- v2f_simple o;
-
- o.pos = UnityObjectToClipPos (v.vertex);
- o.uv = v.texcoord;
-
- #if UNITY_UV_STARTS_AT_TOP
- o.uv2 = v.texcoord;
- if (_MainTex_TexelSize.y < 0.0)
- o.uv.y = 1.0 - o.uv.y;
- #endif
-
- return o;
- }
- struct v2f_tap
- {
- float4 pos : SV_POSITION;
- half2 uv20 : TEXCOORD0;
- half2 uv21 : TEXCOORD1;
- half2 uv22 : TEXCOORD2;
- half2 uv23 : TEXCOORD3;
- };
- v2f_tap vert4Tap ( appdata_img v )
- {
- v2f_tap o;
- o.pos = UnityObjectToClipPos (v.vertex);
- o.uv20 = v.texcoord + _MainTex_TexelSize.xy;
- o.uv21 = v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,-0.5h);
- o.uv22 = v.texcoord + _MainTex_TexelSize.xy * half2(0.5h,-0.5h);
- o.uv23 = v.texcoord + _MainTex_TexelSize.xy * half2(-0.5h,0.5h);
- return o;
- }
-
- fixed4 fragBloom ( v2f_simple i ) : SV_Target
- {
- #if UNITY_UV_STARTS_AT_TOP
-
- fixed4 color = tex2D(_MainTex, i.uv2);
- return color + tex2D(_Bloom, i.uv);
-
- #else
- fixed4 color = tex2D(_MainTex, i.uv);
- return color + tex2D(_Bloom, i.uv);
-
- #endif
- }
-
- fixed4 fragDownsample ( v2f_tap i ) : SV_Target
- {
- fixed4 color = tex2D (_MainTex, i.uv20);
- color += tex2D (_MainTex, i.uv21);
- color += tex2D (_MainTex, i.uv22);
- color += tex2D (_MainTex, i.uv23);
- return max(color/4 - THRESHHOLD, 0) * ONE_MINUS_THRESHHOLD_TIMES_INTENSITY;
- }
-
- // weight curves
- static const half curve[7] = { 0.0205, 0.0855, 0.232, 0.324, 0.232, 0.0855, 0.0205 }; // gauss'ish blur weights
- static const half4 curve4[7] = { half4(0.0205,0.0205,0.0205,0), half4(0.0855,0.0855,0.0855,0), half4(0.232,0.232,0.232,0),
- half4(0.324,0.324,0.324,1), half4(0.232,0.232,0.232,0), half4(0.0855,0.0855,0.0855,0), half4(0.0205,0.0205,0.0205,0) };
- struct v2f_withBlurCoords8
- {
- float4 pos : SV_POSITION;
- half4 uv : TEXCOORD0;
- half2 offs : TEXCOORD1;
- };
-
- struct v2f_withBlurCoordsSGX
- {
- float4 pos : SV_POSITION;
- half2 uv : TEXCOORD0;
- half4 offs[3] : TEXCOORD1;
- };
- v2f_withBlurCoords8 vertBlurHorizontal (appdata_img v)
- {
- v2f_withBlurCoords8 o;
- o.pos = UnityObjectToClipPos (v.vertex);
-
- o.uv = half4(v.texcoord.xy,1,1);
- o.offs = _MainTex_TexelSize.xy * half2(1.0, 0.0) * _Parameter.x;
- return o;
- }
-
- v2f_withBlurCoords8 vertBlurVertical (appdata_img v)
- {
- v2f_withBlurCoords8 o;
- o.pos = UnityObjectToClipPos (v.vertex);
-
- o.uv = half4(v.texcoord.xy,1,1);
- o.offs = _MainTex_TexelSize.xy * half2(0.0, 1.0) * _Parameter.x;
-
- return o;
- }
- half4 fragBlur8 ( v2f_withBlurCoords8 i ) : SV_Target
- {
- half2 uv = i.uv.xy;
- half2 netFilterWidth = i.offs;
- half2 coords = uv - netFilterWidth * 3.0;
-
- half4 color = 0;
- for( int l = 0; l < 7; l++ )
- {
- half4 tap = tex2D(_MainTex, coords);
- color += tap * curve4[l];
- coords += netFilterWidth;
- }
- return color;
- }
- v2f_withBlurCoordsSGX vertBlurHorizontalSGX (appdata_img v)
- {
- v2f_withBlurCoordsSGX o;
- o.pos = UnityObjectToClipPos (v.vertex);
-
- o.uv = v.texcoord.xy;
- half2 netFilterWidth = _MainTex_TexelSize.xy * half2(1.0, 0.0) * _Parameter.x;
- half4 coords = -netFilterWidth.xyxy * 3.0;
-
- o.offs[0] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- coords += netFilterWidth.xyxy;
- o.offs[1] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- coords += netFilterWidth.xyxy;
- o.offs[2] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- return o;
- }
-
- v2f_withBlurCoordsSGX vertBlurVerticalSGX (appdata_img v)
- {
- v2f_withBlurCoordsSGX o;
- o.pos = UnityObjectToClipPos (v.vertex);
-
- o.uv = half4(v.texcoord.xy,1,1);
- half2 netFilterWidth = _MainTex_TexelSize.xy * half2(0.0, 1.0) * _Parameter.x;
- half4 coords = -netFilterWidth.xyxy * 3.0;
-
- o.offs[0] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- coords += netFilterWidth.xyxy;
- o.offs[1] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- coords += netFilterWidth.xyxy;
- o.offs[2] = v.texcoord.xyxy + coords * half4(1.0h,1.0h,-1.0h,-1.0h);
- return o;
- }
- half4 fragBlurSGX ( v2f_withBlurCoordsSGX i ) : SV_Target
- {
- half2 uv = i.uv.xy;
-
- half4 color = tex2D(_MainTex, i.uv) * curve4[3];
-
- for( int l = 0; l < 3; l++ )
- {
- half4 tapA = tex2D(_MainTex, i.offs[l].xy);
- half4 tapB = tex2D(_MainTex, i.offs[l].zw);
- color += (tapA + tapB) * curve4[l];
- }
- return color;
- }
-
- ENDCG
-
- SubShader {
- ZTest Off Cull Off ZWrite Off Blend Off
-
- // 0
- Pass {
-
- CGPROGRAM
- #pragma vertex vertBloom
- #pragma fragment fragBloom
-
- ENDCG
-
- }
- // 1
- Pass {
-
- CGPROGRAM
-
- #pragma vertex vert4Tap
- #pragma fragment fragDownsample
-
- ENDCG
-
- }
- // 2
- Pass {
- ZTest Always
- Cull Off
-
- CGPROGRAM
-
- #pragma vertex vertBlurVertical
- #pragma fragment fragBlur8
-
- ENDCG
- }
-
- // 3
- Pass {
- ZTest Always
- Cull Off
-
- CGPROGRAM
-
- #pragma vertex vertBlurHorizontal
- #pragma fragment fragBlur8
-
- ENDCG
- }
- // alternate blur
- // 4
- Pass {
- ZTest Always
- Cull Off
-
- CGPROGRAM
-
- #pragma vertex vertBlurVerticalSGX
- #pragma fragment fragBlurSGX
-
- ENDCG
- }
-
- // 5
- Pass {
- ZTest Always
- Cull Off
-
- CGPROGRAM
-
- #pragma vertex vertBlurHorizontalSGX
- #pragma fragment fragBlurSGX
-
- ENDCG
- }
- }
- FallBack Off
- }
|