123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- Shader "Hidden/Post FX/Uber Shader"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _AutoExposure ("", 2D) = "" {}
- _BloomTex ("", 2D) = "" {}
- _Bloom_DirtTex ("", 2D) = "" {}
- _GrainTex ("", 2D) = "" {}
- _LogLut ("", 2D) = "" {}
- _UserLut ("", 2D) = "" {}
- _Vignette_Mask ("", 2D) = "" {}
- _ChromaticAberration_Spectrum ("", 2D) = "" {}
- _DitheringTex ("", 2D) = "" {}
- }
- CGINCLUDE
- #pragma target 3.0
- #pragma multi_compile __ UNITY_COLORSPACE_GAMMA
- #pragma multi_compile __ CHROMATIC_ABERRATION
- #pragma multi_compile __ DEPTH_OF_FIELD DEPTH_OF_FIELD_COC_VIEW
- #pragma multi_compile __ BLOOM BLOOM_LENS_DIRT
- #pragma multi_compile __ COLOR_GRADING COLOR_GRADING_LOG_VIEW
- #pragma multi_compile __ USER_LUT
- #pragma multi_compile __ GRAIN
- #pragma multi_compile __ VIGNETTE_CLASSIC VIGNETTE_MASKED
- #pragma multi_compile __ DITHERING
- #include "UnityCG.cginc"
- #include "Bloom.cginc"
- #include "ColorGrading.cginc"
- #include "UberSecondPass.cginc"
-
- sampler2D _AutoExposure
-
- half _ChromaticAberration_Amount
- sampler2D _ChromaticAberration_Spectrum
-
- sampler2D_float _CameraDepthTexture
- sampler2D _DepthOfFieldTex
- sampler2D _DepthOfFieldCoCTex
- float4 _DepthOfFieldTex_TexelSize
- float3 _DepthOfFieldParams
-
- sampler2D _BloomTex
- float4 _BloomTex_TexelSize
- half2 _Bloom_Settings
- sampler2D _Bloom_DirtTex
- half _Bloom_DirtIntensity
-
- sampler2D _LogLut
- half3 _LogLut_Params
- half _ExposureEV
-
- sampler2D _UserLut
- half4 _UserLut_Params
-
- half3 _Vignette_Color
- half2 _Vignette_Center
- half4 _Vignette_Settings
- sampler2D _Vignette_Mask
- half _Vignette_Opacity
- struct VaryingsFlipped
- {
- float4 pos : SV_POSITION
- float2 uv : TEXCOORD0
- float2 uvSPR : TEXCOORD1
- float2 uvFlipped : TEXCOORD2
- float2 uvFlippedSPR : TEXCOORD3
- }
- VaryingsFlipped VertUber(AttributesDefault v)
- {
- VaryingsFlipped o
- o.pos = UnityObjectToClipPos(v.vertex)
- o.uv = v.texcoord.xy
- o.uvSPR = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST)
- o.uvFlipped = v.texcoord.xy
- #if UNITY_UV_STARTS_AT_TOP
- if (_MainTex_TexelSize.y < 0.0)
- o.uvFlipped.y = 1.0 - o.uvFlipped.y
- #endif
- o.uvFlippedSPR = UnityStereoScreenSpaceUVAdjust(o.uvFlipped, _MainTex_ST)
- return o
- }
- half4 FragUber(VaryingsFlipped i) : SV_Target
- {
- float2 uv = i.uv
- half autoExposure = tex2D(_AutoExposure, uv).r
- half3 color = (0.0).xxx
- #if DEPTH_OF_FIELD && CHROMATIC_ABERRATION
- half4 dof = (0.0).xxxx
- half ffa = 0.0
- #endif
-
-
-
-
-
-
- #if CHROMATIC_ABERRATION
- {
- float2 coords = 2.0 * uv - 1.0
- float2 end = uv - coords * dot(coords, coords) * _ChromaticAberration_Amount
- float2 diff = end - uv
- int samples = clamp(int(length(_MainTex_TexelSize.zw * diff / 2.0)), 3, 16)
- float2 delta = diff / samples
- float2 pos = uv
- half3 sum = (0.0).xxx, filterSum = (0.0).xxx
- #if DEPTH_OF_FIELD
- float2 dofDelta = delta
- float2 dofPos = pos
- if (_MainTex_TexelSize.y < 0.0)
- {
- dofDelta.y = -dofDelta.y
- dofPos.y = 1.0 - dofPos.y
- }
- half4 dofSum = (0.0).xxxx
- half ffaSum = 0.0
- #endif
- for (int i = 0
- {
- half t = (i + 0.5) / samples
- half3 s = tex2Dlod(_MainTex, float4(UnityStereoScreenSpaceUVAdjust(pos, _MainTex_ST), 0, 0)).rgb
- half3 filter = tex2Dlod(_ChromaticAberration_Spectrum, float4(t, 0, 0, 0)).rgb
- sum += s * filter
- filterSum += filter
- pos += delta
- #if DEPTH_OF_FIELD
- float4 uvDof = float4(UnityStereoScreenSpaceUVAdjust(dofPos, _MainTex_ST), 0, 0)
- half4 sdof = tex2Dlod(_DepthOfFieldTex, uvDof).rgba
- half scoc = tex2Dlod(_DepthOfFieldCoCTex, uvDof).r
- scoc = (scoc - 0.5) * 2 * _DepthOfFieldParams.z
- dofSum += sdof * half4(filter, 1)
- ffaSum += smoothstep(_MainTex_TexelSize.y * 2, _MainTex_TexelSize.y * 4, scoc)
- dofPos += dofDelta
- #endif
- }
- color = sum / filterSum
- #if DEPTH_OF_FIELD
- dof = dofSum / half4(filterSum, samples)
- ffa = ffaSum / samples
- #endif
- }
- #else
- {
- color = tex2D(_MainTex, i.uvSPR).rgb
- }
- #endif
-
- color *= autoExposure
-
- #if UNITY_COLORSPACE_GAMMA
- {
- color = GammaToLinearSpace(color)
- }
- #endif
-
- #if DEPTH_OF_FIELD_COC_VIEW
- {
-
- half4 src = tex2D(_DepthOfFieldTex, uv)
- float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uvFlippedSPR))
- float coc = (depth - _DepthOfFieldParams.x) * _DepthOfFieldParams.y / depth
- coc *= 80
-
- half3 rgb = lerp(half3(1, 0, 0), half3(1.0, 1.0, 1.0), saturate(-coc))
- rgb = lerp(rgb, half3(0.4, 0.4, 0.4), saturate(coc))
-
- rgb *= AcesLuminance(color) + 0.5
-
- #if !UNITY_COLORSPACE_GAMMA
- {
- rgb = GammaToLinearSpace(rgb)
- }
- #endif
- color = rgb
- }
- #elif DEPTH_OF_FIELD
- {
- #if !CHROMATIC_ABERRATION
- half4 dof = tex2D(_DepthOfFieldTex, i.uvFlippedSPR)
- half coc = tex2D(_DepthOfFieldCoCTex, i.uvFlippedSPR)
- coc = (coc - 0.5) * 2 * _DepthOfFieldParams.z
-
- float ffa = smoothstep(_MainTex_TexelSize.y * 2, _MainTex_TexelSize.y * 4, coc)
- #endif
-
- color = lerp(color, dof.rgb * autoExposure, ffa + dof.a - ffa * dof.a)
- }
- #endif
-
- #if BLOOM || BLOOM_LENS_DIRT
- {
- half3 bloom = UpsampleFilter(_BloomTex, i.uvFlippedSPR, _BloomTex_TexelSize.xy, _Bloom_Settings.x) * _Bloom_Settings.y
- color += bloom
- #if BLOOM_LENS_DIRT
- {
- half3 dirt = tex2D(_Bloom_DirtTex, i.uvFlipped).rgb * _Bloom_DirtIntensity
- color += bloom * dirt
- }
- #endif
- }
- #endif
-
- #if VIGNETTE_CLASSIC
- {
- half2 d = abs(uv - _Vignette_Center) * _Vignette_Settings.x
- d.x *= lerp(1.0, _ScreenParams.x / _ScreenParams.y, _Vignette_Settings.w)
- d = pow(d, _Vignette_Settings.z)
- half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y)
- color *= lerp(_Vignette_Color, (1.0).xxx, vfactor)
- }
-
- #elif VIGNETTE_MASKED
- {
- half vfactor = tex2D(_Vignette_Mask, uv).a
- half3 new_color = color * lerp(_Vignette_Color, (1.0).xxx, vfactor)
- color = lerp(color, new_color, _Vignette_Opacity)
- }
- #endif
-
- #if COLOR_GRADING_LOG_VIEW
- {
- color *= _ExposureEV
- color = saturate(LinearToLogC(color))
- }
- #elif COLOR_GRADING
- {
- color *= _ExposureEV
- half3 colorLogC = saturate(LinearToLogC(color))
- color = ApplyLut2d(_LogLut, colorLogC, _LogLut_Params)
- }
- #endif
-
-
-
- color = saturate(color)
-
- #if UNITY_COLORSPACE_GAMMA
- {
- color = LinearToGammaSpace(color)
- }
- #endif
-
- #if USER_LUT
- {
- color = saturate(color)
- half3 colorGraded
- #if !UNITY_COLORSPACE_GAMMA
- {
- colorGraded = ApplyLut2d(_UserLut, LinearToGammaSpace(color), _UserLut_Params.xyz)
- colorGraded = GammaToLinearSpace(colorGraded)
- }
- #else
- {
- colorGraded = ApplyLut2d(_UserLut, color, _UserLut_Params.xyz)
- }
- #endif
- color = lerp(color, colorGraded, _UserLut_Params.w)
- }
- #endif
- color = UberSecondPass(color, uv)
-
- return half4(color, 1.0)
- }
- ENDCG
- SubShader
- {
- Cull Off ZWrite Off ZTest Always
-
- Pass
- {
- CGPROGRAM
- #pragma vertex VertUber
- #pragma fragment FragUber
- ENDCG
- }
- }
- }
|