modified maps
modified maps
This commit is contained in:
@ -0,0 +1,78 @@
|
||||
|
||||
Shader "Hidden/Dof/Bokeh34" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||||
_Source ("Base (RGB)", 2D) = "black" {}
|
||||
}
|
||||
|
||||
SubShader {
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _Source;
|
||||
|
||||
uniform half4 _ArScale;
|
||||
uniform half _Intensity;
|
||||
uniform half4 _Source_TexelSize;
|
||||
|
||||
struct v2f {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv2 : TEXCOORD0;
|
||||
half4 source : TEXCOORD1;
|
||||
};
|
||||
|
||||
#define COC bokeh.a
|
||||
|
||||
v2f vert (appdata_full v)
|
||||
{
|
||||
v2f o;
|
||||
|
||||
o.pos = v.vertex;
|
||||
|
||||
o.uv2.xy = v.texcoord.xy;// * 2.0; <- needed when using Triangles.js and not Quads.js
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
float4 bokeh = tex2Dlod (_Source, half4 (v.texcoord1.xy * half2(1,-1) + half2(0,1), 0, 0));
|
||||
#else
|
||||
float4 bokeh = tex2Dlod (_Source, half4 (v.texcoord1.xy, 0, 0));
|
||||
#endif
|
||||
|
||||
o.source = bokeh;
|
||||
|
||||
o.pos.xy += (v.texcoord.xy * 2.0 - 1.0) * _ArScale.xy * COC;// + _ArScale.zw * coc;
|
||||
o.source.rgb *= _Intensity;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
half4 frag (v2f i) : SV_Target
|
||||
{
|
||||
half4 color = tex2D (_MainTex, i.uv2.xy);
|
||||
color.rgb *= i.source.rgb;
|
||||
color.a *= Luminance(i.source.rgb*0.25);
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Pass {
|
||||
Blend OneMinusDstColor One
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57cdacf9b217546aaa18edf39a6151c0
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,488 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/Dof/DepthOfField34" {
|
||||
Properties {
|
||||
_MainTex ("Base", 2D) = "" {}
|
||||
_TapLowBackground ("TapLowBackground", 2D) = "" {}
|
||||
_TapLowForeground ("TapLowForeground", 2D) = "" {}
|
||||
_TapMedium ("TapMedium", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv1 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2fDofApply {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2fRadius {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
half4 uv1[4] : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct v2fDown {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv0 : TEXCOORD0;
|
||||
half2 uv[2] : TEXCOORD1;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
sampler2D _TapLowBackground;
|
||||
sampler2D _TapLowForeground;
|
||||
sampler2D _TapMedium;
|
||||
|
||||
half4 _CurveParams;
|
||||
half _ForegroundBlurExtrude;
|
||||
uniform half3 _Threshhold;
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
uniform float2 _InvRenderTargetSize;
|
||||
|
||||
v2f vert( appdata_img v ) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv1.xy = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
v2fRadius vertWithRadius( appdata_img v ) {
|
||||
v2fRadius o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
|
||||
const half2 blurOffsets[4] = {
|
||||
half2(-0.5, +1.5),
|
||||
half2(+0.5, -1.5),
|
||||
half2(+1.5, +0.5),
|
||||
half2(-1.5, -0.5)
|
||||
};
|
||||
|
||||
o.uv1[0].xy = v.texcoord.xy + 5.0 * _MainTex_TexelSize.xy * blurOffsets[0];
|
||||
o.uv1[1].xy = v.texcoord.xy + 5.0 * _MainTex_TexelSize.xy * blurOffsets[1];
|
||||
o.uv1[2].xy = v.texcoord.xy + 5.0 * _MainTex_TexelSize.xy * blurOffsets[2];
|
||||
o.uv1[3].xy = v.texcoord.xy + 5.0 * _MainTex_TexelSize.xy * blurOffsets[3];
|
||||
|
||||
o.uv1[0].zw = v.texcoord.xy + 3.0 * _MainTex_TexelSize.xy * blurOffsets[0];
|
||||
o.uv1[1].zw = v.texcoord.xy + 3.0 * _MainTex_TexelSize.xy * blurOffsets[1];
|
||||
o.uv1[2].zw = v.texcoord.xy + 3.0 * _MainTex_TexelSize.xy * blurOffsets[2];
|
||||
o.uv1[3].zw = v.texcoord.xy + 3.0 * _MainTex_TexelSize.xy * blurOffsets[3];
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
v2fDofApply vertDofApply( appdata_img v ) {
|
||||
v2fDofApply o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
v2fDown vertDownsampleWithCocConserve(appdata_img v) {
|
||||
v2fDown o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv0.xy = v.texcoord.xy;
|
||||
o.uv[0].xy = v.texcoord.xy + half2(-1.0,-1.0) * _InvRenderTargetSize;
|
||||
o.uv[1].xy = v.texcoord.xy + half2(1.0,-1.0) * _InvRenderTargetSize;
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 BokehPrereqs (sampler2D tex, half4 uv1[4], half4 center, half considerCoc) {
|
||||
|
||||
// @NOTE 1:
|
||||
// we are checking for 3 things in order to create a bokeh.
|
||||
// goal is to get the highest bang for the buck.
|
||||
// 1.) contrast/frequency should be very high (otherwise bokeh mostly unvisible)
|
||||
// 2.) luminance should be high
|
||||
// 3.) no occluder nearby (stored in alpha channel)
|
||||
|
||||
// @NOTE 2: about the alpha channel in littleBlur:
|
||||
// the alpha channel stores an heuristic on how likely it is
|
||||
// that there is no bokeh occluder nearby.
|
||||
// if we didn't' check for that, we'd get very noise bokeh
|
||||
// popping because of the sudden contrast changes
|
||||
|
||||
half4 sampleA = tex2D(tex, uv1[0].zw);
|
||||
half4 sampleB = tex2D(tex, uv1[1].zw);
|
||||
half4 sampleC = tex2D(tex, uv1[2].zw);
|
||||
half4 sampleD = tex2D(tex, uv1[3].zw);
|
||||
|
||||
half4 littleBlur = 0.125 * (sampleA + sampleB + sampleC + sampleD);
|
||||
|
||||
sampleA = tex2D(tex, uv1[0].xy);
|
||||
sampleB = tex2D(tex, uv1[1].xy);
|
||||
sampleC = tex2D(tex, uv1[2].xy);
|
||||
sampleD = tex2D(tex, uv1[3].xy);
|
||||
|
||||
littleBlur += 0.125 * (sampleA + sampleB + sampleC + sampleD);
|
||||
|
||||
littleBlur = lerp (littleBlur, center, saturate(100.0 * considerCoc * abs(littleBlur.a - center.a)));
|
||||
|
||||
return littleBlur;
|
||||
}
|
||||
|
||||
half4 fragDownsampleWithCocConserve(v2fDown i) : SV_Target {
|
||||
half2 rowOfs[4];
|
||||
|
||||
rowOfs[0] = half2(0.0, 0.0);
|
||||
rowOfs[1] = half2(0.0, _InvRenderTargetSize.y);
|
||||
rowOfs[2] = half2(0.0, _InvRenderTargetSize.y) * 2.0;
|
||||
rowOfs[3] = half2(0.0, _InvRenderTargetSize.y) * 3.0;
|
||||
|
||||
half4 color = tex2D(_MainTex, i.uv0.xy);
|
||||
|
||||
half4 sampleA = tex2D(_MainTex, i.uv[0].xy + rowOfs[0]);
|
||||
half4 sampleB = tex2D(_MainTex, i.uv[1].xy + rowOfs[0]);
|
||||
half4 sampleC = tex2D(_MainTex, i.uv[0].xy + rowOfs[2]);
|
||||
half4 sampleD = tex2D(_MainTex, i.uv[1].xy + rowOfs[2]);
|
||||
|
||||
color += sampleA + sampleB + sampleC + sampleD;
|
||||
color *= 0.2;
|
||||
|
||||
// @NOTE we are doing max on the alpha channel for 2 reasons:
|
||||
// 1) foreground blur likes a slightly bigger radius
|
||||
// 2) otherwise we get an ugly outline between high blur- and medium blur-areas
|
||||
// drawback: we get a little bit of color bleeding
|
||||
|
||||
color.a = max(max(sampleA.a, sampleB.a), max(sampleC.a, sampleD.a));
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 fragDofApplyBg (v2fDofApply i) : SV_Target {
|
||||
half4 tapHigh = tex2D (_MainTex, i.uv.xy);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
i.uv.xy = i.uv.xy * half2(1,-1)+half2(0,1);
|
||||
#endif
|
||||
|
||||
half4 tapLow = tex2D (_TapLowBackground, i.uv.xy); // already mixed with medium blur
|
||||
tapHigh = lerp (tapHigh, tapLow, tapHigh.a);
|
||||
return tapHigh;
|
||||
}
|
||||
|
||||
half4 fragDofApplyBgDebug (v2fDofApply i) : SV_Target {
|
||||
half4 tapHigh = tex2D (_MainTex, i.uv.xy);
|
||||
|
||||
half4 tapLow = tex2D (_TapLowBackground, i.uv.xy);
|
||||
|
||||
half4 tapMedium = tex2D (_TapMedium, i.uv.xy);
|
||||
tapMedium.rgb = (tapMedium.rgb + half3 (1, 1, 0)) * 0.5;
|
||||
tapLow.rgb = (tapLow.rgb + half3 (0, 1, 0)) * 0.5;
|
||||
|
||||
tapLow = lerp (tapMedium, tapLow, saturate (tapLow.a * tapLow.a));
|
||||
tapLow = tapLow * 0.5 + tex2D (_TapLowBackground, i.uv.xy) * 0.5;
|
||||
|
||||
return lerp (tapHigh, tapLow, tapHigh.a);
|
||||
}
|
||||
|
||||
half4 fragDofApplyFg (v2fDofApply i) : SV_Target {
|
||||
half4 fgBlur = tex2D(_TapLowForeground, i.uv.xy);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
i.uv.xy = i.uv.xy * half2(1,-1)+half2(0,1);
|
||||
#endif
|
||||
|
||||
half4 fgColor = tex2D(_MainTex,i.uv.xy);
|
||||
|
||||
//fgBlur.a = saturate(fgBlur.a*_ForegroundBlurWeight+saturate(fgColor.a-fgBlur.a));
|
||||
//fgBlur.a = max (fgColor.a, (2.0 * fgBlur.a - fgColor.a)) * _ForegroundBlurExtrude;
|
||||
fgBlur.a = max(fgColor.a, fgBlur.a * _ForegroundBlurExtrude); //max (fgColor.a, (2.0*fgBlur.a-fgColor.a)) * _ForegroundBlurExtrude;
|
||||
|
||||
return lerp (fgColor, fgBlur, saturate(fgBlur.a));
|
||||
}
|
||||
|
||||
half4 fragDofApplyFgDebug (v2fDofApply i) : SV_Target {
|
||||
half4 fgBlur = tex2D(_TapLowForeground, i.uv.xy);
|
||||
|
||||
half4 fgColor = tex2D(_MainTex,i.uv.xy);
|
||||
|
||||
fgBlur.a = max(fgColor.a, fgBlur.a * _ForegroundBlurExtrude); //max (fgColor.a, (2.0*fgBlur.a-fgColor.a)) * _ForegroundBlurExtrude;
|
||||
|
||||
half4 tapMedium = half4 (1, 1, 0, fgBlur.a);
|
||||
tapMedium.rgb = 0.5 * (tapMedium.rgb + fgColor.rgb);
|
||||
|
||||
fgBlur.rgb = 0.5 * (fgBlur.rgb + half3(0,1,0));
|
||||
fgBlur.rgb = lerp (tapMedium.rgb, fgBlur.rgb, saturate (fgBlur.a * fgBlur.a));
|
||||
|
||||
return lerp ( fgColor, fgBlur, saturate(fgBlur.a));
|
||||
}
|
||||
|
||||
half4 fragCocBg (v2f i) : SV_Target {
|
||||
|
||||
float d = SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
half coc = 0.0;
|
||||
|
||||
half focalDistance01 = _CurveParams.w + _CurveParams.z;
|
||||
|
||||
if (d > focalDistance01)
|
||||
coc = (d - focalDistance01);
|
||||
|
||||
coc = saturate (coc * _CurveParams.y);
|
||||
return coc;
|
||||
}
|
||||
|
||||
half4 fragCocFg (v2f i) : SV_Target {
|
||||
half4 color = tex2D (_MainTex, i.uv1.xy);
|
||||
color.a = 0.0;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
i.uv1.xy = i.uv1.xy * half2(1,-1)+half2(0,1);
|
||||
#endif
|
||||
|
||||
float d = SAMPLE_DEPTH_TEXTURE (_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
|
||||
half focalDistance01 = (_CurveParams.w - _CurveParams.z);
|
||||
|
||||
if (d < focalDistance01)
|
||||
color.a = (focalDistance01 - d);
|
||||
|
||||
color.a = saturate (color.a * _CurveParams.x);
|
||||
return color;
|
||||
}
|
||||
|
||||
// not being used atm
|
||||
|
||||
half4 fragMask (v2f i) : SV_Target {
|
||||
return half4(0,0,0,0);
|
||||
}
|
||||
|
||||
// used for simple one one blend
|
||||
|
||||
half4 fragAddBokeh (v2f i) : SV_Target {
|
||||
half4 from = tex2D( _MainTex, i.uv1.xy );
|
||||
return from;
|
||||
}
|
||||
|
||||
half4 fragAddFgBokeh (v2f i) : SV_Target {
|
||||
half4 from = tex2D( _MainTex, i.uv1.xy );
|
||||
return from;
|
||||
}
|
||||
|
||||
half4 fragDarkenForBokeh(v2fRadius i) : SV_Target {
|
||||
half4 fromOriginal = tex2D(_MainTex, i.uv.xy);
|
||||
half4 lowRez = BokehPrereqs (_MainTex, i.uv1, fromOriginal, _Threshhold.z);
|
||||
half4 outColor = half4(0,0,0, fromOriginal.a);
|
||||
half modulate = fromOriginal.a;
|
||||
|
||||
// this code imitates the if-then-else conditions below
|
||||
half2 conditionCheck = half2( dot(abs(fromOriginal.rgb-lowRez.rgb), half3(0.3,0.5,0.2)), Luminance(fromOriginal.rgb));
|
||||
conditionCheck *= fromOriginal.a;
|
||||
conditionCheck = saturate(_Threshhold.xy - conditionCheck);
|
||||
outColor = lerp (outColor, fromOriginal, saturate (dot(conditionCheck, half2(1000.0,1000.0))));
|
||||
|
||||
/*
|
||||
if ( abs(dot(fromOriginal.rgb - lowRez.rgb, half3 (0.3,0.5,0.2))) * modulate < _Threshhold.x)
|
||||
outColor = fromOriginal; // no darkening
|
||||
if (Luminance(fromOriginal.rgb) * modulate < _Threshhold.y)
|
||||
outColor = fromOriginal; // no darkening
|
||||
if (lowRez.a < _Threshhold.z) // need to make foreground not cast false bokeh's
|
||||
outColor = fromOriginal; // no darkenin
|
||||
*/
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
half4 fragExtractAndAddToBokeh (v2fRadius i) : SV_Target {
|
||||
half4 from = tex2D(_MainTex, i.uv.xy);
|
||||
half4 lowRez = BokehPrereqs(_MainTex, i.uv1, from, _Threshhold.z);
|
||||
half4 outColor = from;
|
||||
|
||||
// this code imitates the if-then-else conditions below
|
||||
half2 conditionCheck = half2( dot(abs(from.rgb-lowRez.rgb), half3(0.3,0.5,0.2)), Luminance(from.rgb));
|
||||
conditionCheck *= from.a;
|
||||
conditionCheck = saturate(_Threshhold.xy - conditionCheck);
|
||||
outColor = lerp (outColor, half4(0,0,0,0), saturate (dot(conditionCheck, half2(1000.0,1000.0))));
|
||||
|
||||
/*
|
||||
if ( abs(dot(from.rgb - lowRez.rgb, half3 (0.3,0.5,0.2))) * modulate < _Threshhold.x)
|
||||
outColor = half4(0,0,0,0); // don't add
|
||||
if (Luminance(from.rgb) * modulate < _Threshhold.y)
|
||||
outColor = half4(0,0,0,0); // don't add
|
||||
if (lowRez.a < _Threshhold.z) // need to make foreground not cast false bokeh's
|
||||
outColor = half4(0,0,0,0); // don't add
|
||||
*/
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
|
||||
// pass 0
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertDofApply
|
||||
#pragma fragment fragDofApplyBg
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 1
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertDofApply
|
||||
#pragma fragment fragDofApplyFgDebug
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 2
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertDofApply
|
||||
#pragma fragment fragDofApplyBgDebug
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
|
||||
// pass 3
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask A
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCocBg
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// pass 4
|
||||
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask RGB
|
||||
//Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertDofApply
|
||||
#pragma fragment fragDofApplyFg
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 5
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask ARGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCocFg
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 6
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertDownsampleWithCocConserve
|
||||
#pragma fragment fragDownsampleWithCocConserve
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 7
|
||||
// not being used atm
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask RGBA
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragMask
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 8
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragAddBokeh
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 9
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
Blend One One
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertWithRadius
|
||||
#pragma fragment fragExtractAndAddToBokeh
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 10
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertWithRadius
|
||||
#pragma fragment fragDarkenForBokeh
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 11
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vertWithRadius
|
||||
#pragma fragment fragExtractAndAddToBokeh
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 987fb0677d01f43ce8a9dbf12271e668
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,259 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
|
||||
/*
|
||||
DX11 Depth Of Field
|
||||
pretty much just does bokeh texture splatting
|
||||
|
||||
basic algorithm:
|
||||
|
||||
* find bright spots
|
||||
* verify high frequency (otherwise dont care)
|
||||
* if possitive, replace with black pixel and add to append buffer
|
||||
* box blur buffer (thus smearing black pixels)
|
||||
* blend bokeh texture sprites via append buffer on top of box blurred buffer
|
||||
* composite with frame buffer
|
||||
*/
|
||||
|
||||
Shader "Hidden/Dof/DX11Dof"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("", 2D) = "white" {}
|
||||
_BlurredColor ("", 2D) = "white" {}
|
||||
_FgCocMask ("", 2D) = "white" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#define BOKEH_ZERO_VEC (float4(0,0,0,0))
|
||||
#define BOKEH_ONE_VEC (float4(1,1,1,1))
|
||||
|
||||
float4 _BokehParams; // legend: dx11BokehScale, dx11BokehIntensity,dx11BokehThreshhold, internalBlurWidth
|
||||
float4 _MainTex_TexelSize;
|
||||
float3 _Screen;
|
||||
float _SpawnHeuristic;
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
sampler2D _BlurredColor;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _FgCocMask;
|
||||
|
||||
struct appendStruct {
|
||||
float3 pos;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
struct gs_out {
|
||||
float4 pos : SV_POSITION;
|
||||
float3 uv : TEXCOORD0;
|
||||
float4 color : TEXCOORD1;
|
||||
float4 misc : TEXCOORD2;
|
||||
};
|
||||
|
||||
// TODO: activate border clamp tex sampler state instead?
|
||||
inline float4 clampBorderColor(float2 uv)
|
||||
{
|
||||
#if 1
|
||||
if(uv.x<=0) return BOKEH_ZERO_VEC; if(uv.x>=1) return BOKEH_ZERO_VEC;
|
||||
if(uv.y<=0) return BOKEH_ZERO_VEC; if(uv.y>=1) return BOKEH_ZERO_VEC;
|
||||
#endif
|
||||
return BOKEH_ONE_VEC;
|
||||
}
|
||||
|
||||
struct vs_out {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 color : TEXCOORD1;
|
||||
float cocOverlap : TEXCOORD2;
|
||||
};
|
||||
|
||||
StructuredBuffer<appendStruct> pointBuffer;
|
||||
|
||||
vs_out vertApply (uint id : SV_VertexID)
|
||||
{
|
||||
vs_out o;
|
||||
float2 pos = pointBuffer[id].pos.xy ;
|
||||
o.pos = float4(pos * 2.0 - 1.0, 0, 1);
|
||||
o.color = pointBuffer[id].color;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
o.pos.y *= -1;
|
||||
#endif
|
||||
o.cocOverlap = pointBuffer[id].pos.z;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
[maxvertexcount(4)]
|
||||
void geom (point vs_out input[1], inout TriangleStream<gs_out> outStream)
|
||||
{
|
||||
// NEW ENERGY CONSERVATION:
|
||||
|
||||
float2 scale2 = _BokehParams.ww * input[0].color.aa * _BokehParams.xx;
|
||||
float4 offs = 0;
|
||||
offs.xy = float2(3.0, 3.0) + 2.0f * floor(scale2 + float2(0.5,0.5));
|
||||
|
||||
float2 rs = ((float2(1.0, 1.0) + 2.0f * (scale2 + float2(0.5,0.5))));;
|
||||
float2 f2 = offs.xy / rs;
|
||||
|
||||
float energyAdjustment = (_BokehParams.y) / (rs.x*rs.y);
|
||||
offs.xy *= _Screen.xy;
|
||||
|
||||
gs_out output;
|
||||
|
||||
output.pos = input[0].pos + offs*float4(-1,1,0,0);
|
||||
output.misc = float4(f2,0,0);
|
||||
output.uv = float3(0, 1, input[0].cocOverlap);
|
||||
output.color = input[0].color * energyAdjustment;
|
||||
outStream.Append (output);
|
||||
|
||||
output.pos = input[0].pos + offs*float4(1,1,0,0);
|
||||
output.misc = float4(f2,0,0);
|
||||
output.uv = float3(1, 1, input[0].cocOverlap);
|
||||
output.color = input[0].color * energyAdjustment;
|
||||
outStream.Append (output);
|
||||
|
||||
output.pos = input[0].pos + offs*float4(-1,-1,0,0);
|
||||
output.misc = float4(f2,0,0);
|
||||
output.uv = float3(0, 0, input[0].cocOverlap);
|
||||
output.color = input[0].color * energyAdjustment;
|
||||
outStream.Append (output);
|
||||
|
||||
output.pos = input[0].pos + offs*float4(1,-1,0,0);
|
||||
output.misc = float4(f2,0,0);
|
||||
output.uv = float3(1, 0, input[0].cocOverlap);
|
||||
output.color = input[0].color * energyAdjustment;
|
||||
outStream.Append (output);
|
||||
|
||||
outStream.RestartStrip();
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
|
||||
// pass 0: append buffer "collect"
|
||||
|
||||
Pass
|
||||
{
|
||||
ZWrite Off ZTest Always Cull Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 5.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata {
|
||||
float4 vertex : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv_flip : TEXCOORD0;
|
||||
float2 uv : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv = v.texcoord;
|
||||
o.uv_flip = v.texcoord;
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if(_MainTex_TexelSize.y<0)
|
||||
o.uv_flip.y = 1.0-o.uv_flip.y;
|
||||
if(_MainTex_TexelSize.y<0)
|
||||
o.pos.y *= -1.0;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
AppendStructuredBuffer<appendStruct> pointBufferOutput : register(u1);
|
||||
|
||||
float4 frag (v2f i) : SV_Target
|
||||
{
|
||||
float4 c = tex2D (_MainTex, i.uv_flip);
|
||||
float lumc = Luminance (c.rgb);
|
||||
|
||||
float4 cblurred = tex2D (_BlurredColor, i.uv);
|
||||
float lumblurred = Luminance (cblurred.rgb);
|
||||
|
||||
float fgCoc = tex2D(_FgCocMask, i.uv).a;
|
||||
|
||||
[branch]
|
||||
if (c.a * _BokehParams.w > 1 && cblurred.a > 0.1 && lumc > _BokehParams.z && abs(lumc-lumblurred) > _SpawnHeuristic)
|
||||
{
|
||||
appendStruct append;
|
||||
append.pos = float3(i.uv, fgCoc);
|
||||
append.color.rgba = float4(c.rgb * saturate(c.a*4), c.a);
|
||||
pointBufferOutput.Append (append);
|
||||
return float4(c.rgb * saturate(1-c.a*4), c.a);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 1: bokeh splatting (low resolution)
|
||||
|
||||
Pass {
|
||||
|
||||
ZWrite Off ZTest Always Cull Off
|
||||
Blend One One, One One
|
||||
ColorMask RGBA
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 5.0
|
||||
#pragma vertex vertApply
|
||||
#pragma geometry geom
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
fixed4 frag (gs_out i) : SV_Target
|
||||
{
|
||||
float2 uv = (i.uv.xy) * i.misc.xy + (float2(1,1)-i.misc.xy) * 0.5; // smooth uv scale
|
||||
return float4(i.color.rgb, 1) * float4(tex2D(_MainTex, uv.xy).rgb, i.uv.z) * clampBorderColor (uv);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 2: bokeh splatting (high resolution)
|
||||
|
||||
Pass {
|
||||
|
||||
ZWrite Off ZTest Always Cull Off
|
||||
BlendOp Add, Add
|
||||
Blend DstAlpha One, Zero One
|
||||
ColorMask RGBA
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 5.0
|
||||
#pragma vertex vertApply
|
||||
#pragma geometry geom
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
fixed4 frag (gs_out i) : SV_Target
|
||||
{
|
||||
float2 uv = (i.uv.xy) * i.misc.xy + (float2(1,1)-i.misc.xy) * 0.5; // smooth uv scale
|
||||
return float4(i.color.rgb, 1) * float4(tex2D(_MainTex, uv.xy).rgb, i.uv.z) * clampBorderColor (uv);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Fallback Off
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8e82664aa8686642a424c88ab10164a
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,936 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/Dof/DepthOfFieldHdr" {
|
||||
Properties {
|
||||
_MainTex ("-", 2D) = "black" {}
|
||||
_FgOverlap ("-", 2D) = "black" {}
|
||||
_LowRez ("-", 2D) = "black" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct v2fRadius {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 uv1[4] : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct v2fBlur {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 uv01 : TEXCOORD1;
|
||||
float4 uv23 : TEXCOORD2;
|
||||
float4 uv45 : TEXCOORD3;
|
||||
float4 uv67 : TEXCOORD4;
|
||||
float4 uv89 : TEXCOORD5;
|
||||
};
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
uniform sampler2D_float _CameraDepthTexture;
|
||||
uniform sampler2D _FgOverlap;
|
||||
uniform sampler2D _LowRez;
|
||||
uniform float4 _CurveParams;
|
||||
uniform float4 _MainTex_TexelSize;
|
||||
uniform float4 _Offsets;
|
||||
|
||||
v2f vert( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv1.xy = v.texcoord.xy;
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv.y = 1-o.uv.y;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
v2f vertFlip( appdata_img v )
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv1.xy = v.texcoord.xy;
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv.y = 1-o.uv.y;
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv1.y = 1-o.uv1.y;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
v2fBlur vertBlurPlusMinus (appdata_img v)
|
||||
{
|
||||
v2fBlur o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
o.uv01 = v.texcoord.xyxy + _Offsets.xyxy * float4(1,1, -1,-1) * _MainTex_TexelSize.xyxy / 6.0;
|
||||
o.uv23 = v.texcoord.xyxy + _Offsets.xyxy * float4(2,2, -2,-2) * _MainTex_TexelSize.xyxy / 6.0;
|
||||
o.uv45 = v.texcoord.xyxy + _Offsets.xyxy * float4(3,3, -3,-3) * _MainTex_TexelSize.xyxy / 6.0;
|
||||
o.uv67 = v.texcoord.xyxy + _Offsets.xyxy * float4(4,4, -4,-4) * _MainTex_TexelSize.xyxy / 6.0;
|
||||
o.uv89 = v.texcoord.xyxy + _Offsets.xyxy * float4(5,5, -5,-5) * _MainTex_TexelSize.xyxy / 6.0;
|
||||
return o;
|
||||
}
|
||||
|
||||
#define SCATTER_OVERLAP_SMOOTH (-0.265)
|
||||
|
||||
inline float BokehWeightDisc(float4 theSample, float sampleDistance, float4 centerSample)
|
||||
{
|
||||
return smoothstep(SCATTER_OVERLAP_SMOOTH, 0.0, theSample.a - centerSample.a*sampleDistance);
|
||||
}
|
||||
|
||||
inline float2 BokehWeightDisc2(float4 sampleA, float4 sampleB, float2 sampleDistance2, float4 centerSample)
|
||||
{
|
||||
return smoothstep(float2(SCATTER_OVERLAP_SMOOTH, SCATTER_OVERLAP_SMOOTH), float2(0.0,0.0), float2(sampleA.a, sampleB.a) - centerSample.aa*sampleDistance2); }
|
||||
|
||||
static const int SmallDiscKernelSamples = 12;
|
||||
static const float2 SmallDiscKernel[SmallDiscKernelSamples] =
|
||||
{
|
||||
float2(-0.326212,-0.40581),
|
||||
float2(-0.840144,-0.07358),
|
||||
float2(-0.695914,0.457137),
|
||||
float2(-0.203345,0.620716),
|
||||
float2(0.96234,-0.194983),
|
||||
float2(0.473434,-0.480026),
|
||||
float2(0.519456,0.767022),
|
||||
float2(0.185461,-0.893124),
|
||||
float2(0.507431,0.064425),
|
||||
float2(0.89642,0.412458),
|
||||
float2(-0.32194,-0.932615),
|
||||
float2(-0.791559,-0.59771)
|
||||
};
|
||||
|
||||
static const int NumDiscSamples = 28;
|
||||
static const float3 DiscKernel[NumDiscSamples] =
|
||||
{
|
||||
float3(0.62463,0.54337,0.82790),
|
||||
float3(-0.13414,-0.94488,0.95435),
|
||||
float3(0.38772,-0.43475,0.58253),
|
||||
float3(0.12126,-0.19282,0.22778),
|
||||
float3(-0.20388,0.11133,0.23230),
|
||||
float3(0.83114,-0.29218,0.88100),
|
||||
float3(0.10759,-0.57839,0.58831),
|
||||
float3(0.28285,0.79036,0.83945),
|
||||
float3(-0.36622,0.39516,0.53876),
|
||||
float3(0.75591,0.21916,0.78704),
|
||||
float3(-0.52610,0.02386,0.52664),
|
||||
float3(-0.88216,-0.24471,0.91547),
|
||||
float3(-0.48888,-0.29330,0.57011),
|
||||
float3(0.44014,-0.08558,0.44838),
|
||||
float3(0.21179,0.51373,0.55567),
|
||||
float3(0.05483,0.95701,0.95858),
|
||||
float3(-0.59001,-0.70509,0.91938),
|
||||
float3(-0.80065,0.24631,0.83768),
|
||||
float3(-0.19424,-0.18402,0.26757),
|
||||
float3(-0.43667,0.76751,0.88304),
|
||||
float3(0.21666,0.11602,0.24577),
|
||||
float3(0.15696,-0.85600,0.87027),
|
||||
float3(-0.75821,0.58363,0.95682),
|
||||
float3(0.99284,-0.02904,0.99327),
|
||||
float3(-0.22234,-0.57907,0.62029),
|
||||
float3(0.55052,-0.66984,0.86704),
|
||||
float3(0.46431,0.28115,0.54280),
|
||||
float3(-0.07214,0.60554,0.60982),
|
||||
};
|
||||
|
||||
float4 fragBlurInsaneMQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
float4 sum = centerTap;
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w;
|
||||
|
||||
float sampleCount = max(centerTap.a * 0.25, _Offsets.z); // <- weighing with 0.25 looks nicer for small high freq spec
|
||||
sum *= sampleCount;
|
||||
|
||||
float weights = 0;
|
||||
|
||||
for(int l=0; l < NumDiscSamples; l++)
|
||||
{
|
||||
float2 sampleUV = i.uv1.xy + DiscKernel[l].xy * poissonScale.xy;
|
||||
float4 sample0 = tex2D(_MainTex, sampleUV.xy);
|
||||
|
||||
if( sample0.a > 0.0 )
|
||||
{
|
||||
weights = BokehWeightDisc(sample0, DiscKernel[l].z, centerTap);
|
||||
sum += sample0 * weights;
|
||||
sampleCount += weights;
|
||||
}
|
||||
}
|
||||
|
||||
float4 returnValue = sum / sampleCount;
|
||||
returnValue.a = centerTap.a;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
float4 fragBlurInsaneHQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
float4 sum = centerTap;
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w;
|
||||
|
||||
float sampleCount = max(centerTap.a * 0.25, _Offsets.z); // <- weighing with 0.25 looks nicer for small high freq spec
|
||||
sum *= sampleCount;
|
||||
|
||||
float2 weights = 0;
|
||||
|
||||
for(int l=0; l < NumDiscSamples; l++)
|
||||
{
|
||||
float4 sampleUV = i.uv1.xyxy + DiscKernel[l].xyxy * poissonScale.xyxy / float4(1.2,1.2,DiscKernel[l].zz);
|
||||
|
||||
float4 sample0 = tex2D(_MainTex, sampleUV.xy);
|
||||
float4 sample1 = tex2D(_MainTex, sampleUV.zw);
|
||||
|
||||
if( (sample0.a + sample1.a) > 0.0 )
|
||||
{
|
||||
weights = BokehWeightDisc2(sample0, sample1, float2(DiscKernel[l].z/1.2, 1.0), centerTap);
|
||||
sum += sample0 * weights.x + sample1 * weights.y;
|
||||
sampleCount += dot(weights, 1);
|
||||
}
|
||||
}
|
||||
|
||||
float4 returnValue = sum / sampleCount;
|
||||
returnValue.a = centerTap.a;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
inline float4 BlendLowWithHighHQ(float coc, float4 low, float4 high)
|
||||
{
|
||||
float blend = smoothstep(0.65,0.85, coc);
|
||||
return lerp(low, high, blend);
|
||||
}
|
||||
|
||||
inline float4 BlendLowWithHighMQ(float coc, float4 low, float4 high)
|
||||
{
|
||||
float blend = smoothstep(0.4,0.6, coc);
|
||||
return lerp(low, high, blend);
|
||||
}
|
||||
|
||||
float4 fragBlurUpsampleCombineHQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
|
||||
float4 smallBlur = centerTap;
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w ;
|
||||
|
||||
float sampleCount = max(centerTap.a * 0.25, 0.1f); // <- weighing with 0.25 looks nicer for small high freq spec
|
||||
smallBlur *= sampleCount;
|
||||
|
||||
for(int l=0; l < NumDiscSamples; l++)
|
||||
{
|
||||
float2 sampleUV = i.uv1.xy + DiscKernel[l].xy * poissonScale.xy;
|
||||
|
||||
float4 sample0 = tex2D(_MainTex, sampleUV);
|
||||
float weight0 = BokehWeightDisc(sample0, DiscKernel[l].z, centerTap);
|
||||
smallBlur += sample0 * weight0; sampleCount += weight0;
|
||||
}
|
||||
|
||||
smallBlur /= (sampleCount+1e-5f);
|
||||
smallBlur = BlendLowWithHighHQ(centerTap.a, smallBlur, bigBlur);
|
||||
|
||||
return centerTap.a < 1e-2f ? centerTap : float4(smallBlur.rgb,centerTap.a);
|
||||
}
|
||||
|
||||
float4 fragBlurUpsampleCombineMQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
|
||||
float4 smallBlur = centerTap;
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w ;
|
||||
|
||||
float sampleCount = max(centerTap.a * 0.25, 0.1f); // <- weighing with 0.25 looks nicer for small high freq spec
|
||||
smallBlur *= sampleCount;
|
||||
|
||||
for(int l=0; l < SmallDiscKernelSamples; l++)
|
||||
{
|
||||
float2 sampleUV = i.uv1.xy + SmallDiscKernel[l].xy * poissonScale.xy*1.1;
|
||||
|
||||
float4 sample0 = tex2D(_MainTex, sampleUV);
|
||||
float weight0 = BokehWeightDisc(sample0, length(SmallDiscKernel[l].xy*1.1), centerTap);
|
||||
smallBlur += sample0 * weight0; sampleCount += weight0;
|
||||
}
|
||||
|
||||
smallBlur /= (sampleCount+1e-5f);
|
||||
|
||||
smallBlur = BlendLowWithHighMQ(centerTap.a, smallBlur, bigBlur);
|
||||
|
||||
return centerTap.a < 1e-2f ? centerTap : float4(smallBlur.rgb,centerTap.a);
|
||||
}
|
||||
|
||||
float4 fragBlurUpsampleCheap (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
|
||||
|
||||
float fgCoc = tex2D(_FgOverlap, i.uv1.xy).a;
|
||||
float4 smallBlur = lerp(centerTap, bigBlur, saturate( max(centerTap.a,fgCoc)*8.0 ));
|
||||
|
||||
return float4(smallBlur.rgb, centerTap.a);
|
||||
}
|
||||
|
||||
float4 fragBlurBox (v2f i) : SV_Target
|
||||
{
|
||||
const int TAPS = 12;
|
||||
|
||||
float4 centerTap = tex2D(_MainTex, i.uv1.xy);
|
||||
|
||||
// TODO: important ? breaks when HR blur is being used
|
||||
//centerTap.a = max(centerTap.a, 0.1f);
|
||||
|
||||
float sampleCount = centerTap.a;
|
||||
float4 sum = centerTap * sampleCount;
|
||||
|
||||
float2 lenStep = centerTap.aa * (1.0 / (TAPS-1.0));
|
||||
float4 steps = (_Offsets.xyxy * _MainTex_TexelSize.xyxy) * lenStep.xyxy * float4(1,1, -1,-1);
|
||||
|
||||
for(int l=1; l<TAPS; l++)
|
||||
{
|
||||
float4 sampleUV = i.uv1.xyxy + steps * (float)l;
|
||||
|
||||
float4 sample0 = tex2D(_MainTex, sampleUV.xy);
|
||||
float4 sample1 = tex2D(_MainTex, sampleUV.zw);
|
||||
|
||||
float2 maxLen01 = float2(sample0.a, sample1.a);
|
||||
float2 r = lenStep.xx * (float)l;
|
||||
|
||||
float2 weight01 = smoothstep(float2(-0.4,-0.4),float2(0.0,0.0), maxLen01-r);
|
||||
sum += sample0 * weight01.x + sample1 * weight01.y;
|
||||
|
||||
sampleCount += dot(weight01,1);
|
||||
}
|
||||
|
||||
float4 returnValue = sum / (1e-5f + sampleCount);
|
||||
|
||||
//returnValue.a = centerTap.a;
|
||||
//return centerTap.a;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
float4 fragVisualize (v2f i) : SV_Target
|
||||
{
|
||||
float4 returnValue = tex2D(_MainTex, i.uv1.xy);
|
||||
returnValue.rgb = lerp(float3(0.0,0.0,0.0), float3(1.0,1.0,1.0), saturate(returnValue.a/_CurveParams.x));
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
float4 fragBoxDownsample (v2f i) : SV_Target
|
||||
{
|
||||
//float4 returnValue = tex2D(_MainTex, i.uv1.xy);
|
||||
float4 returnValue = tex2D(_MainTex, i.uv1.xy + 0.75*_MainTex_TexelSize.xy);
|
||||
returnValue += tex2D(_MainTex, i.uv1.xy - 0.75*_MainTex_TexelSize.xy);
|
||||
returnValue += tex2D(_MainTex, i.uv1.xy + 0.75*_MainTex_TexelSize.xy * float2(1,-1));
|
||||
returnValue += tex2D(_MainTex, i.uv1.xy - 0.75*_MainTex_TexelSize.xy * float2(1,-1));
|
||||
|
||||
return returnValue/4;
|
||||
}
|
||||
|
||||
float4 fragBlurAlphaWeighted (v2fBlur i) : SV_Target
|
||||
{
|
||||
const float ALPHA_WEIGHT = 2.0f;
|
||||
float4 sum = float4 (0,0,0,0);
|
||||
float w = 0;
|
||||
float weights = 0;
|
||||
const float G_WEIGHTS[6] = {1.0, 0.8, 0.675, 0.5, 0.2, 0.075};
|
||||
|
||||
float4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
|
||||
float4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
float4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
float4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
float4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
float4 sampleF = tex2D(_MainTex, i.uv45.xy);
|
||||
float4 sampleG = tex2D(_MainTex, i.uv45.zw);
|
||||
float4 sampleH = tex2D(_MainTex, i.uv67.xy);
|
||||
float4 sampleI = tex2D(_MainTex, i.uv67.zw);
|
||||
float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
|
||||
float4 sampleK = tex2D(_MainTex, i.uv89.zw);
|
||||
|
||||
w = sampleA.a * G_WEIGHTS[0]; sum += sampleA * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleB.a) * G_WEIGHTS[1]; sum += sampleB * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleC.a) * G_WEIGHTS[1]; sum += sampleC * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleD.a) * G_WEIGHTS[2]; sum += sampleD * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleE.a) * G_WEIGHTS[2]; sum += sampleE * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleF.a) * G_WEIGHTS[3]; sum += sampleF * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleG.a) * G_WEIGHTS[3]; sum += sampleG * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleH.a) * G_WEIGHTS[4]; sum += sampleH * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleI.a) * G_WEIGHTS[4]; sum += sampleI * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleJ.a) * G_WEIGHTS[5]; sum += sampleJ * w; weights += w;
|
||||
w = saturate(ALPHA_WEIGHT*sampleK.a) * G_WEIGHTS[5]; sum += sampleK * w; weights += w;
|
||||
|
||||
sum /= weights + 1e-4f;
|
||||
|
||||
sum.a = sampleA.a;
|
||||
if(sampleA.a<1e-2f) sum.rgb = sampleA.rgb;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
float4 fragBlurForFgCoc (v2fBlur i) : SV_Target
|
||||
{
|
||||
float4 sum = float4 (0,0,0,0);
|
||||
float w = 0;
|
||||
float weights = 0;
|
||||
const float G_WEIGHTS[6] = {1.0, 0.8, 0.675, 0.5, 0.2, 0.075};
|
||||
|
||||
float4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
|
||||
float4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
float4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
float4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
float4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
float4 sampleF = tex2D(_MainTex, i.uv45.xy);
|
||||
float4 sampleG = tex2D(_MainTex, i.uv45.zw);
|
||||
float4 sampleH = tex2D(_MainTex, i.uv67.xy);
|
||||
float4 sampleI = tex2D(_MainTex, i.uv67.zw);
|
||||
float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
|
||||
float4 sampleK = tex2D(_MainTex, i.uv89.zw);
|
||||
|
||||
w = sampleA.a * G_WEIGHTS[0]; sum += sampleA * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleB.a-sampleA.a) * G_WEIGHTS[1]; sum += sampleB * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleC.a-sampleA.a) * G_WEIGHTS[1]; sum += sampleC * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleD.a-sampleA.a) * G_WEIGHTS[2]; sum += sampleD * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleE.a-sampleA.a) * G_WEIGHTS[2]; sum += sampleE * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleF.a-sampleA.a) * G_WEIGHTS[3]; sum += sampleF * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleG.a-sampleA.a) * G_WEIGHTS[3]; sum += sampleG * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleH.a-sampleA.a) * G_WEIGHTS[4]; sum += sampleH * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleI.a-sampleA.a) * G_WEIGHTS[4]; sum += sampleI * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleJ.a-sampleA.a) * G_WEIGHTS[5]; sum += sampleJ * w; weights += w;
|
||||
w = smoothstep(-0.5,0.0,sampleK.a-sampleA.a) * G_WEIGHTS[5]; sum += sampleK * w; weights += w;
|
||||
|
||||
sum /= weights + 1e-4f;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
float4 fragGaussBlur (v2fBlur i) : SV_Target
|
||||
{
|
||||
float4 sum = float4 (0,0,0,0);
|
||||
float w = 0;
|
||||
float weights = 0;
|
||||
const float G_WEIGHTS[9] = {1.0, 0.8, 0.65, 0.5, 0.4, 0.2, 0.1, 0.05, 0.025};
|
||||
|
||||
float4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
|
||||
float4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
float4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
float4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
float4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
float4 sampleF = tex2D(_MainTex, i.uv45.xy);
|
||||
float4 sampleG = tex2D(_MainTex, i.uv45.zw);
|
||||
float4 sampleH = tex2D(_MainTex, i.uv67.xy);
|
||||
float4 sampleI = tex2D(_MainTex, i.uv67.zw);
|
||||
float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
|
||||
float4 sampleK = tex2D(_MainTex, i.uv89.zw);
|
||||
|
||||
w = sampleA.a * G_WEIGHTS[0]; sum += sampleA * w; weights += w;
|
||||
w = sampleB.a * G_WEIGHTS[1]; sum += sampleB * w; weights += w;
|
||||
w = sampleC.a * G_WEIGHTS[1]; sum += sampleC * w; weights += w;
|
||||
w = sampleD.a * G_WEIGHTS[2]; sum += sampleD * w; weights += w;
|
||||
w = sampleE.a * G_WEIGHTS[2]; sum += sampleE * w; weights += w;
|
||||
w = sampleF.a * G_WEIGHTS[3]; sum += sampleF * w; weights += w;
|
||||
w = sampleG.a * G_WEIGHTS[3]; sum += sampleG * w; weights += w;
|
||||
w = sampleH.a * G_WEIGHTS[4]; sum += sampleH * w; weights += w;
|
||||
w = sampleI.a * G_WEIGHTS[4]; sum += sampleI * w; weights += w;
|
||||
w = sampleJ.a * G_WEIGHTS[5]; sum += sampleJ * w; weights += w;
|
||||
w = sampleK.a * G_WEIGHTS[5]; sum += sampleK * w; weights += w;
|
||||
|
||||
sum /= weights + 1e-4f;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
float4 frag4TapBlurForLRSpawn (v2f i) : SV_Target
|
||||
{
|
||||
float4 tap = tex2D(_MainTex, i.uv.xy);
|
||||
|
||||
float4 tapA = tex2D(_MainTex, i.uv.xy + 0.75 * _MainTex_TexelSize.xy);
|
||||
float4 tapB = tex2D(_MainTex, i.uv.xy - 0.75 * _MainTex_TexelSize.xy);
|
||||
float4 tapC = tex2D(_MainTex, i.uv.xy + 0.75 * _MainTex_TexelSize.xy * float2(1,-1));
|
||||
float4 tapD = tex2D(_MainTex, i.uv.xy - 0.75 * _MainTex_TexelSize.xy * float2(1,-1));
|
||||
|
||||
float4 weights = saturate(10.0 * float4(tapA.a, tapB.a, tapC.a, tapD.a));
|
||||
float sumWeights = dot(weights, 1);
|
||||
|
||||
float4 color = (tapA*weights.x + tapB*weights.y + tapC*weights.z + tapD*weights.w);
|
||||
|
||||
float4 outColor = tap;
|
||||
if(tap.a * sumWeights * 8.0 > 1e-5f) outColor.rgb = color.rgb/sumWeights;
|
||||
|
||||
return outColor;
|
||||
}
|
||||
|
||||
float4 fragCaptureColorAndSignedCoc (v2f i) : SV_Target
|
||||
{
|
||||
float4 color = tex2D (_MainTex, i.uv1.xy);
|
||||
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d + 1e-5f);
|
||||
color.a = clamp( max(0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x) * sign(d - _CurveParams.w);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 fragCaptureCoc (v2f i) : SV_Target
|
||||
{
|
||||
float4 color = float4(0,0,0,0); //tex2D (_MainTex, i.uv1.xy);
|
||||
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d + 1e-5f);
|
||||
color.a = clamp( max(0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 AddFgCoc (v2f i) : SV_Target
|
||||
{
|
||||
return tex2D (_MainTex, i.uv1.xy);
|
||||
}
|
||||
|
||||
float4 fragMergeCoc (v2f i) : SV_Target
|
||||
{
|
||||
float4 color = tex2D (_FgOverlap, i.uv.xy); // this is the foreground overlap value
|
||||
float fgCoc = color.a;
|
||||
|
||||
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d + 1e-5f);
|
||||
color.a = clamp( max(0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
|
||||
|
||||
return max(color.aaaa, float4(fgCoc,fgCoc,fgCoc,fgCoc));
|
||||
}
|
||||
|
||||
float4 fragCombineCocWithMaskBlur (v2f i) : SV_Target
|
||||
{
|
||||
float bgAndFgCoc = tex2D (_MainTex, i.uv1.xy).a;
|
||||
float fgOverlapCoc = tex2D (_FgOverlap, i.uv1.xy).a;
|
||||
|
||||
return (bgAndFgCoc < 0.01) * saturate(fgOverlapCoc-bgAndFgCoc);
|
||||
}
|
||||
|
||||
float4 fragCaptureForegroundCoc (v2f i) : SV_Target
|
||||
{
|
||||
float4 color = float4(0,0,0,0); //tex2D (_MainTex, i.uv1.xy);
|
||||
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
color.a = _CurveParams.z * (_CurveParams.w-d) / (d + 1e-5f);
|
||||
color.a = clamp(max(0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 fragCaptureForegroundCocMask (v2f i) : SV_Target
|
||||
{
|
||||
float4 color = float4(0,0,0,0);
|
||||
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
|
||||
d = Linear01Depth (d);
|
||||
color.a = _CurveParams.z * (_CurveParams.w-d) / (d + 1e-5f);
|
||||
color.a = clamp(max(0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
|
||||
|
||||
return color.a > 0;
|
||||
}
|
||||
|
||||
float4 fragBlendInHighRez (v2f i) : SV_Target
|
||||
{
|
||||
float4 tapHighRez = tex2D(_MainTex, i.uv.xy);
|
||||
return float4(tapHighRez.rgb, 1.0-saturate(tapHighRez.a*5.0));
|
||||
}
|
||||
|
||||
float4 fragBlendInLowRezParts (v2f i) : SV_Target
|
||||
{
|
||||
float4 from = tex2D(_MainTex, i.uv1.xy);
|
||||
from.a = saturate(from.a * _Offsets.w) / (_CurveParams.x + 1e-5f);
|
||||
float square = from.a * from.a;
|
||||
from.a = square * square * _CurveParams.x;
|
||||
return from;
|
||||
}
|
||||
|
||||
float4 fragUpsampleWithAlphaMask(v2f i) : SV_Target
|
||||
{
|
||||
float4 c = tex2D(_MainTex, i.uv1.xy);
|
||||
return c;
|
||||
}
|
||||
|
||||
float4 fragAlphaMask(v2f i) : SV_Target
|
||||
{
|
||||
float4 c = tex2D(_MainTex, i.uv1.xy);
|
||||
c.a = saturate(c.a*100.0);
|
||||
return c;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader
|
||||
{
|
||||
|
||||
// pass 0
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask A
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCaptureCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 1
|
||||
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vertBlurPlusMinus
|
||||
#pragma fragment fragGaussBlur
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 2
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vertBlurPlusMinus
|
||||
#pragma fragment fragBlurForFgCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// pass 3
|
||||
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask A
|
||||
BlendOp Max, Max
|
||||
Blend One One, One One
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment AddFgCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// pass 4
|
||||
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask A
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCaptureForegroundCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 5
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurBox
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 6
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag4TapBlurForLRSpawn
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 7
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask RGB
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlendInHighRez
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 8
|
||||
|
||||
Pass
|
||||
{
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
ColorMask A
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCaptureForegroundCocMask
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
// pass 9
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurUpsampleCheap
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 10
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCaptureColorAndSignedCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 11
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurInsaneMQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 12
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurUpsampleCombineMQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 13
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
ColorMask A
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragMergeCoc
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 14
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
ColorMask A
|
||||
BlendOp Max, Max
|
||||
Blend One One, One One
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragCombineCocWithMaskBlur
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 15
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBoxDownsample
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 16
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragVisualize
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 17
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurInsaneHQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 18
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurUpsampleCombineHQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 19
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vertBlurPlusMinus
|
||||
#pragma fragment fragBlurAlphaWeighted
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 20
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragAlphaMask
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 21
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
BlendOp Add, Add
|
||||
Blend DstAlpha OneMinusDstAlpha, Zero One
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vertFlip
|
||||
#pragma fragment fragBlurBox
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// pass 22
|
||||
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
// destination alpha needs to stay intact as we have layed alpha before
|
||||
BlendOp Add, Add
|
||||
Blend DstAlpha One, Zero One
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragUpsampleWithAlphaMask
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acd613035ff3e455e8abf23fdc8c8c24
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,68 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/SeparableBlur" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
|
||||
float4 uv01 : TEXCOORD1;
|
||||
float4 uv23 : TEXCOORD2;
|
||||
float4 uv45 : TEXCOORD3;
|
||||
};
|
||||
|
||||
float4 offsets;
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
v2f vert (appdata_img v) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
|
||||
o.uv01 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1);
|
||||
o.uv23 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1) * 2.0;
|
||||
o.uv45 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1) * 3.0;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 frag (v2f i) : SV_Target {
|
||||
half4 color = float4 (0,0,0,0);
|
||||
|
||||
color += 0.40 * tex2D (_MainTex, i.uv);
|
||||
color += 0.15 * tex2D (_MainTex, i.uv01.xy);
|
||||
color += 0.15 * tex2D (_MainTex, i.uv01.zw);
|
||||
color += 0.10 * tex2D (_MainTex, i.uv23.xy);
|
||||
color += 0.10 * tex2D (_MainTex, i.uv23.zw);
|
||||
color += 0.05 * tex2D (_MainTex, i.uv45.xy);
|
||||
color += 0.05 * tex2D (_MainTex, i.uv45.zw);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
Pass {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
|
||||
} // shader
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e97c14fbb5ea04c3a902cc533d7fc5d1
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,244 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "Hidden/SeparableWeightedBlurDof34" {
|
||||
Properties {
|
||||
_MainTex ("Base (RGB)", 2D) = "" {}
|
||||
_TapMedium ("TapMedium (RGB)", 2D) = "" {}
|
||||
_TapLow ("TapLow (RGB)", 2D) = "" {}
|
||||
_TapHigh ("TapHigh (RGB)", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
half4 offsets;
|
||||
half4 _Threshhold;
|
||||
sampler2D _MainTex;
|
||||
sampler2D _TapHigh;
|
||||
|
||||
struct v2f {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
half4 uv01 : TEXCOORD1;
|
||||
half4 uv23 : TEXCOORD2;
|
||||
half4 uv45 : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct v2fSingle {
|
||||
half4 pos : SV_POSITION;
|
||||
half2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
//
|
||||
// VERT PROGRAMS
|
||||
//
|
||||
|
||||
v2f vert (appdata_img v) {
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
o.uv01 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1);
|
||||
o.uv23 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 2.0;
|
||||
o.uv45 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 3.0;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
v2fSingle vertSingleTex (appdata_img v) {
|
||||
v2fSingle o;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
o.uv.xy = v.texcoord.xy;
|
||||
return o;
|
||||
}
|
||||
|
||||
//
|
||||
// FRAG PROGRAMS
|
||||
//
|
||||
|
||||
// mostly used for foreground, so more gaussian-like
|
||||
|
||||
half4 fragBlurUnweighted (v2f i) : SV_Target {
|
||||
half4 blurredColor = half4 (0,0,0,0);
|
||||
|
||||
half4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
half4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
half4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
half4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
half4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
|
||||
blurredColor += sampleA;
|
||||
blurredColor += sampleB;
|
||||
blurredColor += sampleC;
|
||||
blurredColor += sampleD;
|
||||
blurredColor += sampleE;
|
||||
|
||||
blurredColor *= 0.2;
|
||||
|
||||
blurredColor.a = max(UNITY_SAMPLE_1CHANNEL(_TapHigh, i.uv.xy), blurredColor.a);
|
||||
|
||||
return blurredColor;
|
||||
}
|
||||
|
||||
// used for background, so more bone curve-like
|
||||
|
||||
half4 fragBlurWeighted (v2f i) : SV_Target {
|
||||
half4 blurredColor = half4 (0,0,0,0);
|
||||
|
||||
half4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
half4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
half4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
half4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
half4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
|
||||
half sum = sampleA.a + dot (half4 (1.25, 1.25, 1.5, 1.5), half4 (sampleB.a,sampleC.a,sampleD.a,sampleE.a));
|
||||
|
||||
sampleA.rgb = sampleA.rgb * sampleA.a;
|
||||
sampleB.rgb = sampleB.rgb * sampleB.a * 1.25;
|
||||
sampleC.rgb = sampleC.rgb * sampleC.a * 1.25;
|
||||
sampleD.rgb = sampleD.rgb * sampleD.a * 1.5;
|
||||
sampleE.rgb = sampleE.rgb * sampleE.a * 1.5;
|
||||
|
||||
blurredColor += sampleA;
|
||||
blurredColor += sampleB;
|
||||
blurredColor += sampleC;
|
||||
blurredColor += sampleD;
|
||||
blurredColor += sampleE;
|
||||
|
||||
blurredColor /= sum;
|
||||
half4 color = blurredColor;
|
||||
|
||||
color.a = sampleA.a;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
half4 fragBlurDark (v2f i) : SV_Target {
|
||||
half4 blurredColor = half4 (0,0,0,0);
|
||||
|
||||
half4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
half4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
half4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
half4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
half4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
|
||||
half sum = sampleA.a + dot (half4 (0.75, 0.75, 0.5, 0.5), half4 (sampleB.a,sampleC.a,sampleD.a,sampleE.a));
|
||||
|
||||
sampleA.rgb = sampleA.rgb * sampleA.a;
|
||||
sampleB.rgb = sampleB.rgb * sampleB.a * 0.75;
|
||||
sampleC.rgb = sampleC.rgb * sampleC.a * 0.75;
|
||||
sampleD.rgb = sampleD.rgb * sampleD.a * 0.5;
|
||||
sampleE.rgb = sampleE.rgb * sampleE.a * 0.5;
|
||||
|
||||
blurredColor += sampleA;
|
||||
blurredColor += sampleB;
|
||||
blurredColor += sampleC;
|
||||
blurredColor += sampleD;
|
||||
blurredColor += sampleE;
|
||||
|
||||
blurredColor /= sum;
|
||||
half4 color = blurredColor;
|
||||
|
||||
color.a = sampleA.a;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// not used atm
|
||||
|
||||
half4 fragBlurUnweightedDark (v2f i) : SV_Target {
|
||||
half4 blurredColor = half4 (0,0,0,0);
|
||||
|
||||
half4 sampleA = tex2D(_MainTex, i.uv.xy);
|
||||
half4 sampleB = tex2D(_MainTex, i.uv01.xy);
|
||||
half4 sampleC = tex2D(_MainTex, i.uv01.zw);
|
||||
half4 sampleD = tex2D(_MainTex, i.uv23.xy);
|
||||
half4 sampleE = tex2D(_MainTex, i.uv23.zw);
|
||||
|
||||
blurredColor += sampleA;
|
||||
blurredColor += sampleB * 0.75;
|
||||
blurredColor += sampleC * 0.75;
|
||||
blurredColor += sampleD * 0.5;
|
||||
blurredColor += sampleE * 0.5;
|
||||
|
||||
blurredColor /= 3.5;
|
||||
|
||||
blurredColor.a = max(UNITY_SAMPLE_1CHANNEL(_TapHigh, i.uv.xy), blurredColor.a);
|
||||
|
||||
return blurredColor;
|
||||
}
|
||||
|
||||
// fragMixMediumAndLowTap
|
||||
// happens before applying final coc/blur result to screen,
|
||||
// mixes defocus buffers of different resolutions / bluriness
|
||||
|
||||
sampler2D _TapMedium;
|
||||
sampler2D _TapLow;
|
||||
|
||||
half4 fragMixMediumAndLowTap (v2fSingle i) : SV_Target
|
||||
{
|
||||
half4 tapMedium = tex2D (_TapMedium, i.uv.xy);
|
||||
half4 tapLow = tex2D (_TapLow, i.uv.xy);
|
||||
tapMedium.a *= tapMedium.a;
|
||||
|
||||
tapLow.rgb = lerp (tapMedium.rgb, tapLow.rgb, (tapMedium.a * tapMedium.a));
|
||||
return tapLow;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurWeighted
|
||||
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurUnweighted
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// 2
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurUnweightedDark
|
||||
|
||||
ENDCG
|
||||
}
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vertSingleTex
|
||||
#pragma fragment fragMixMediumAndLowTap
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
// 4
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragBlurDark
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
} // shader
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb4af680337344a4abad65a4e8873c50
|
||||
ShaderImporter:
|
||||
userData:
|
@ -0,0 +1,311 @@
|
||||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
|
||||
Shader "Hidden/Dof/TiltShiftHdrLensBlur" {
|
||||
Properties {
|
||||
_MainTex ("-", 2D) = "" {}
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
sampler2D _Blurred;
|
||||
|
||||
float4 _MainTex_TexelSize;
|
||||
float _BlurSize;
|
||||
float _BlurArea;
|
||||
|
||||
#ifdef SHADER_API_D3D11
|
||||
#define SAMPLE_TEX(sampler, uv) tex2Dlod(sampler, float4(uv,0,1))
|
||||
#else
|
||||
#define SAMPLE_TEX(sampler, uv) tex2D(sampler, uv)
|
||||
#endif
|
||||
|
||||
v2f vert (appdata_img v)
|
||||
{
|
||||
v2f o;
|
||||
o.pos = UnityObjectToClipPos (v.vertex);
|
||||
o.uv.xy = v.texcoord;
|
||||
o.uv1.xy = v.texcoord;
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv1.y = 1-o.uv1.y;
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
static const int SmallDiscKernelSamples = 12;
|
||||
static const float2 SmallDiscKernel[SmallDiscKernelSamples] =
|
||||
{
|
||||
float2(-0.326212,-0.40581),
|
||||
float2(-0.840144,-0.07358),
|
||||
float2(-0.695914,0.457137),
|
||||
float2(-0.203345,0.620716),
|
||||
float2(0.96234,-0.194983),
|
||||
float2(0.473434,-0.480026),
|
||||
float2(0.519456,0.767022),
|
||||
float2(0.185461,-0.893124),
|
||||
float2(0.507431,0.064425),
|
||||
float2(0.89642,0.412458),
|
||||
float2(-0.32194,-0.932615),
|
||||
float2(-0.791559,-0.59771)
|
||||
};
|
||||
|
||||
static const int NumDiscSamples = 28;
|
||||
static const float3 DiscKernel[NumDiscSamples] =
|
||||
{
|
||||
float3(0.62463,0.54337,0.82790),
|
||||
float3(-0.13414,-0.94488,0.95435),
|
||||
float3(0.38772,-0.43475,0.58253),
|
||||
float3(0.12126,-0.19282,0.22778),
|
||||
float3(-0.20388,0.11133,0.23230),
|
||||
float3(0.83114,-0.29218,0.88100),
|
||||
float3(0.10759,-0.57839,0.58831),
|
||||
float3(0.28285,0.79036,0.83945),
|
||||
float3(-0.36622,0.39516,0.53876),
|
||||
float3(0.75591,0.21916,0.78704),
|
||||
float3(-0.52610,0.02386,0.52664),
|
||||
float3(-0.88216,-0.24471,0.91547),
|
||||
float3(-0.48888,-0.29330,0.57011),
|
||||
float3(0.44014,-0.08558,0.44838),
|
||||
float3(0.21179,0.51373,0.55567),
|
||||
float3(0.05483,0.95701,0.95858),
|
||||
float3(-0.59001,-0.70509,0.91938),
|
||||
float3(-0.80065,0.24631,0.83768),
|
||||
float3(-0.19424,-0.18402,0.26757),
|
||||
float3(-0.43667,0.76751,0.88304),
|
||||
float3(0.21666,0.11602,0.24577),
|
||||
float3(0.15696,-0.85600,0.87027),
|
||||
float3(-0.75821,0.58363,0.95682),
|
||||
float3(0.99284,-0.02904,0.99327),
|
||||
float3(-0.22234,-0.57907,0.62029),
|
||||
float3(0.55052,-0.66984,0.86704),
|
||||
float3(0.46431,0.28115,0.54280),
|
||||
float3(-0.07214,0.60554,0.60982),
|
||||
};
|
||||
|
||||
float WeightFieldMode (float2 uv)
|
||||
{
|
||||
float2 tapCoord = uv*2.0-1.0;
|
||||
return (abs(tapCoord.y * _BlurArea));
|
||||
}
|
||||
|
||||
float WeightIrisMode (float2 uv)
|
||||
{
|
||||
float2 tapCoord = (uv*2.0-1.0);
|
||||
return dot(tapCoord, tapCoord) * _BlurArea;
|
||||
}
|
||||
|
||||
float4 fragIrisPreview (v2f i) : SV_Target
|
||||
{
|
||||
return WeightIrisMode(i.uv.xy) * 0.5;
|
||||
}
|
||||
|
||||
float4 fragFieldPreview (v2f i) : SV_Target
|
||||
{
|
||||
return WeightFieldMode(i.uv.xy) * 0.5;
|
||||
}
|
||||
|
||||
float4 fragUpsample (v2f i) : SV_Target
|
||||
{
|
||||
float4 blurred = tex2D(_Blurred, i.uv1.xy);
|
||||
float4 frame = tex2D(_MainTex, i.uv.xy);
|
||||
|
||||
return lerp(frame, blurred, saturate(blurred.a));
|
||||
}
|
||||
|
||||
float4 fragIris (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv.xy);
|
||||
float4 sum = centerTap;
|
||||
|
||||
float w = clamp(WeightIrisMode(i.uv.xy), 0, _BlurSize);
|
||||
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * w;
|
||||
|
||||
#ifndef SHADER_API_D3D9
|
||||
if(w<1e-2f)
|
||||
return sum;
|
||||
#endif
|
||||
|
||||
for(int l=0; l<NumDiscSamples; l++)
|
||||
{
|
||||
float2 sampleUV = i.uv.xy + DiscKernel[l].xy * poissonScale.xy;
|
||||
float4 sample0 = SAMPLE_TEX(_MainTex, sampleUV.xy);
|
||||
sum += sample0;
|
||||
}
|
||||
return float4(sum.rgb / (1.0 + NumDiscSamples), w);
|
||||
}
|
||||
|
||||
float4 fragField (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv.xy);
|
||||
float4 sum = centerTap;
|
||||
|
||||
float w = clamp(WeightFieldMode(i.uv.xy), 0, _BlurSize);
|
||||
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * w;
|
||||
|
||||
#ifndef SHADER_API_D3D9
|
||||
if(w<1e-2f)
|
||||
return sum;
|
||||
#endif
|
||||
|
||||
for(int l=0; l<NumDiscSamples; l++)
|
||||
{
|
||||
float2 sampleUV = i.uv.xy + DiscKernel[l].xy * poissonScale.xy;
|
||||
float4 sample0 = SAMPLE_TEX(_MainTex, sampleUV.xy);
|
||||
sum += sample0;
|
||||
}
|
||||
return float4(sum.rgb / (1.0 + NumDiscSamples), w);
|
||||
}
|
||||
|
||||
float4 fragIrisHQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv.xy);
|
||||
float4 sum = centerTap;
|
||||
|
||||
float w = clamp(WeightIrisMode(i.uv.xy), 0, _BlurSize);
|
||||
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * float4(1,1,-1,-1) * 2;
|
||||
|
||||
#ifndef SHADER_API_D3D9
|
||||
if(w<1e-2f)
|
||||
return sum;
|
||||
#endif
|
||||
|
||||
for(int l=0; l<NumDiscSamples; l++)
|
||||
{
|
||||
float4 sampleUV = i.uv.xyxy + DiscKernel[l].xyxy * poissonScale;
|
||||
float4 sample0 = SAMPLE_TEX(_MainTex, sampleUV.xy);
|
||||
float4 sample1 = SAMPLE_TEX(_MainTex, sampleUV.zw);
|
||||
|
||||
sum += sample0 + sample1;
|
||||
}
|
||||
return float4(sum.rgb / (1.0 + 2.0 * NumDiscSamples), w);
|
||||
}
|
||||
|
||||
float4 fragFieldHQ (v2f i) : SV_Target
|
||||
{
|
||||
float4 centerTap = tex2D(_MainTex, i.uv.xy);
|
||||
float4 sum = centerTap;
|
||||
|
||||
float w = clamp(WeightFieldMode(i.uv.xy), 0, _BlurSize);
|
||||
|
||||
float4 poissonScale = _MainTex_TexelSize.xyxy * float4(1,1,-1,-1) * w;
|
||||
|
||||
#ifndef SHADER_API_D3D9
|
||||
if(w<1e-2f)
|
||||
return sum;
|
||||
#endif
|
||||
|
||||
for(int l=0; l<NumDiscSamples; l++)
|
||||
{
|
||||
float4 sampleUV = i.uv.xyxy + DiscKernel[l].xyxy * poissonScale;
|
||||
float4 sample0 = SAMPLE_TEX(_MainTex, sampleUV.xy);
|
||||
float4 sample1 = SAMPLE_TEX(_MainTex, sampleUV.zw);
|
||||
|
||||
sum += sample0 + sample1;
|
||||
}
|
||||
return float4(sum.rgb / (1.0 + 2.0 * NumDiscSamples), w);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Subshader {
|
||||
ZTest Always Cull Off ZWrite Off
|
||||
|
||||
Pass { // 0
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragFieldPreview
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 1
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragIrisPreview
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 2
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragField
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 3
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragIris
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 4
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragFieldHQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 5
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragIrisHQ
|
||||
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass { // 6
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment fragUpsample
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
Fallback off
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf34d2a25450349699e8ae6456fa7ca9
|
||||
ShaderImporter:
|
||||
userData:
|
Reference in New Issue
Block a user