2011-11-30 21:42:41 +00:00
|
|
|
//#version 420 // Keep it for editor detection
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
#ifdef FRAGMENT_SHADER
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2021-11-30 10:35:45 +00:00
|
|
|
in vec4 PSin_p;
|
|
|
|
in vec2 PSin_t;
|
|
|
|
in vec4 PSin_c;
|
|
|
|
|
2022-11-05 20:35:06 +00:00
|
|
|
uniform vec4 ZrH;
|
2016-06-05 14:42:52 +00:00
|
|
|
|
2011-12-07 22:05:46 +00:00
|
|
|
layout(location = 0) out vec4 SV_Target0;
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
// TODO ensure that clip (discard) is < 0 and not <= 0 ???
|
|
|
|
void ps_main0()
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2022-05-20 15:31:54 +00:00
|
|
|
if ((int(gl_FragCoord.y) & 1) == 0)
|
2013-07-11 17:08:42 +00:00
|
|
|
discard;
|
2011-11-30 21:42:41 +00:00
|
|
|
// I'm not sure it impact us but be safe to lookup texture before conditional if
|
|
|
|
// see: http://www.opengl.org/wiki/GLSL_Sampler#Non-uniform_flow_control
|
2021-11-30 10:35:45 +00:00
|
|
|
vec4 c = texture(TextureSampler, PSin_t);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
SV_Target0 = c;
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
void ps_main1()
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2022-05-20 15:31:54 +00:00
|
|
|
if ((int(gl_FragCoord.y) & 1) != 0)
|
2013-07-11 17:08:42 +00:00
|
|
|
discard;
|
2011-11-30 21:42:41 +00:00
|
|
|
// I'm not sure it impact us but be safe to lookup texture before conditional if
|
|
|
|
// see: http://www.opengl.org/wiki/GLSL_Sampler#Non-uniform_flow_control
|
2021-11-30 10:35:45 +00:00
|
|
|
vec4 c = texture(TextureSampler, PSin_t);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
SV_Target0 = c;
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
void ps_main2()
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2022-11-05 20:35:06 +00:00
|
|
|
vec2 vstep = vec2(0.0f, ZrH.y);
|
|
|
|
vec4 c0 = texture(TextureSampler, PSin_t - vstep);
|
2021-11-30 10:35:45 +00:00
|
|
|
vec4 c1 = texture(TextureSampler, PSin_t);
|
2022-11-05 20:35:06 +00:00
|
|
|
vec4 c2 = texture(TextureSampler, PSin_t + vstep);
|
2011-11-21 22:36:03 +00:00
|
|
|
|
2013-07-12 21:12:34 +00:00
|
|
|
SV_Target0 = (c0 + c1 * 2.0f + c2) / 4.0f;
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 21:42:41 +00:00
|
|
|
void ps_main3()
|
2011-11-21 22:36:03 +00:00
|
|
|
{
|
2021-11-30 10:35:45 +00:00
|
|
|
SV_Target0 = texture(TextureSampler, PSin_t);
|
2011-11-21 22:36:03 +00:00
|
|
|
}
|
|
|
|
|
2022-11-05 20:35:06 +00:00
|
|
|
|
|
|
|
void ps_main4()
|
|
|
|
{
|
|
|
|
const int vres = int(round(ZrH.z));
|
|
|
|
const int idx = int(round(ZrH.x));
|
|
|
|
const int bank = idx >> 1;
|
|
|
|
const int field = idx & 1;
|
|
|
|
const int vpos = int(gl_FragCoord.y) + (((((vres + 1) >> 1) << 1) - vres) & bank);
|
|
|
|
const vec2 bofs = vec2(0.0f, 0.5f * bank);
|
|
|
|
const vec2 vscale = vec2(1.0f, 2.0f);
|
|
|
|
const vec2 optr = PSin_t - bofs;
|
|
|
|
const vec2 iptr = optr * vscale;
|
|
|
|
|
|
|
|
if ((optr.y >= 0.0f) && (optr.y < 0.5f) && ((vpos & 1) == field))
|
|
|
|
//if ((optr.y >= 0.0f) && (optr.y < 0.5f) && (int(iptr.y * vres) & 1) == field)
|
|
|
|
SV_Target0 = texture(TextureSampler, iptr);
|
|
|
|
else
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ps_main5()
|
|
|
|
{
|
|
|
|
const float sensitivity = ZrH.w;
|
|
|
|
const vec3 motion_thr = vec3(1.0, 1.0, 1.0) * sensitivity;
|
|
|
|
const vec2 vofs = vec2(0.0f, 0.5f);
|
|
|
|
const vec2 vscale = vec2(1.0f, 0.5f);
|
|
|
|
const int idx = int(round(ZrH.x));
|
|
|
|
const int bank = idx >> 1;
|
|
|
|
const int field = idx & 1;
|
|
|
|
const vec2 line_ofs = vec2(0.0f, ZrH.y);
|
|
|
|
const vec2 iptr = PSin_t * vscale;
|
|
|
|
|
|
|
|
vec2 p_new_cf;
|
|
|
|
vec2 p_old_cf;
|
|
|
|
vec2 p_new_af;
|
|
|
|
vec2 p_old_af;
|
|
|
|
|
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
p_new_cf = iptr;
|
|
|
|
p_new_af = iptr + vofs;
|
|
|
|
p_old_cf = iptr + vofs;
|
|
|
|
p_old_af = iptr;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
p_new_cf = iptr;
|
|
|
|
p_new_af = iptr;
|
|
|
|
p_old_cf = iptr + vofs;
|
|
|
|
p_old_af = iptr + vofs;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
p_new_cf = iptr + vofs;
|
|
|
|
p_new_af = iptr;
|
|
|
|
p_old_cf = iptr;
|
|
|
|
p_old_af = iptr + vofs;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
p_new_cf = iptr + vofs;
|
|
|
|
p_new_af = iptr + vofs;
|
|
|
|
p_old_cf = iptr;
|
|
|
|
p_old_af = iptr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculating motion
|
|
|
|
|
|
|
|
vec4 hn = texture(TextureSampler, p_new_cf - line_ofs); // high
|
|
|
|
vec4 cn = texture(TextureSampler, p_new_af); // center
|
|
|
|
vec4 ln = texture(TextureSampler, p_new_cf + line_ofs); // low
|
|
|
|
|
|
|
|
vec4 ho = texture(TextureSampler, p_old_cf - line_ofs); // high
|
|
|
|
vec4 co = texture(TextureSampler, p_old_af); // center
|
|
|
|
vec4 lo = texture(TextureSampler, p_old_cf + line_ofs); // low
|
|
|
|
|
|
|
|
vec3 mh = hn.rgb - ho.rgb;
|
|
|
|
vec3 mc = cn.rgb - co.rgb;
|
|
|
|
vec3 ml = ln.rgb - lo.rgb;
|
|
|
|
|
|
|
|
mh = max(mh, -mh) - motion_thr;
|
|
|
|
mc = max(mc, -mc) - motion_thr;
|
|
|
|
ml = max(ml, -ml) - motion_thr;
|
|
|
|
|
|
|
|
// float mh_max = max(max(mh.x, mh.y), mh.z);
|
|
|
|
// float mc_max = max(max(mc.x, mc.y), mc.z);
|
|
|
|
// float ml_max = max(max(ml.x, ml.y), ml.z);
|
|
|
|
|
|
|
|
float mh_max = mh.x + mh.y + mh.z;
|
|
|
|
float mc_max = mc.x + mc.y + mc.z;
|
|
|
|
float ml_max = ml.x + ml.y + ml.z;
|
|
|
|
|
|
|
|
// selecting deinterlacing output
|
|
|
|
|
|
|
|
if (((int(gl_FragCoord.y) & 1) == field)) // output coordinate present on current field
|
|
|
|
{
|
|
|
|
SV_Target0 = texture(TextureSampler, p_new_cf);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if ((iptr.y > 0.5f - line_ofs.y) || (iptr.y < 0.0 + line_ofs.y))
|
|
|
|
{
|
|
|
|
SV_Target0 = texture(TextureSampler, p_new_af);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(((mh_max > 0.0f) || (ml_max > 0.0f)) || (mc_max > 0.0f))
|
|
|
|
{
|
|
|
|
SV_Target0 = (hn + ln) / 2.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SV_Target0 = texture(TextureSampler, p_new_af);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-21 22:36:03 +00:00
|
|
|
#endif
|