mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
vo_opengl: set uniform variable "pixel_size" for internal shaders
This commit is contained in:
parent
3d2fb9e9a8
commit
8bafd68fff
@ -131,23 +131,23 @@ void pass_nnedi3(GL *gl, struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
GLSLH(#pragma optionNV(fastprecision on))
|
GLSLH(#pragma optionNV(fastprecision on))
|
||||||
}
|
}
|
||||||
|
|
||||||
GLSLHF("float nnedi3(sampler2D tex, vec2 pos, vec2 tex_size, int plane, float tex_mul) {\n");
|
GLSLHF("float nnedi3(sampler2D tex, vec2 pos, vec2 tex_size, vec2 pixel_size, int plane, float tex_mul) {\n");
|
||||||
|
|
||||||
if (step == 0) {
|
if (step == 0) {
|
||||||
*transform = (struct gl_transform){{{1.0,0.0}, {0.0,2.0}}, {0.0,-0.5}};
|
*transform = (struct gl_transform){{{1.0,0.0}, {0.0,2.0}}, {0.0,-0.5}};
|
||||||
|
|
||||||
GLSLH(if (fract(pos.y * tex_size.y) < 0.5)
|
GLSLH(if (fract(pos.y * tex_size.y) < 0.5)
|
||||||
return texture(tex, pos + vec2(0, 0.25) / tex_size)[plane] * tex_mul;)
|
return texture(tex, pos + vec2(0, 0.25) * pixel_size)[plane] * tex_mul;)
|
||||||
GLSLHF("#define GET(i, j) "
|
GLSLHF("#define GET(i, j) "
|
||||||
"(texture(tex, pos+vec2((i)-(%f),(j)-(%f)+0.25)/tex_size)[plane]*tex_mul)\n",
|
"(texture(tex, pos+vec2((i)-(%f),(j)-(%f)+0.25) * pixel_size)[plane]*tex_mul)\n",
|
||||||
width / 2.0 - 1, (height - 1) / 2.0);
|
width / 2.0 - 1, (height - 1) / 2.0);
|
||||||
} else {
|
} else {
|
||||||
*transform = (struct gl_transform){{{2.0,0.0}, {0.0,1.0}}, {-0.5,0.0}};
|
*transform = (struct gl_transform){{{2.0,0.0}, {0.0,1.0}}, {-0.5,0.0}};
|
||||||
|
|
||||||
GLSLH(if (fract(pos.x * tex_size.x) < 0.5)
|
GLSLH(if (fract(pos.x * tex_size.x) < 0.5)
|
||||||
return texture(tex, pos + vec2(0.25, 0) / tex_size)[plane] * tex_mul;)
|
return texture(tex, pos + vec2(0.25, 0) * pixel_size)[plane] * tex_mul;)
|
||||||
GLSLHF("#define GET(i, j) "
|
GLSLHF("#define GET(i, j) "
|
||||||
"(texture(tex, pos+vec2((j)-(%f)+0.25,(i)-(%f))/tex_size)[plane]*tex_mul)\n",
|
"(texture(tex, pos+vec2((j)-(%f)+0.25,(i)-(%f)) * pixel_size)[plane]*tex_mul)\n",
|
||||||
(height - 1) / 2.0, width / 2.0 - 1);
|
(height - 1) / 2.0, width / 2.0 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,8 +229,8 @@ void pass_nnedi3(GL *gl, struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
GLSL(color = vec4(1.0);)
|
GLSL(color = vec4(1.0);)
|
||||||
|
|
||||||
for (int i = 0; i < planes; i++) {
|
for (int i = 0; i < planes; i++) {
|
||||||
GLSLF("color[%d] = nnedi3(texture%d, texcoord%d, texture_size%d, %d, %f);\n",
|
GLSLF("color[%d] = nnedi3(texture%d, texcoord%d, texture_size%d, pixel_size%d, %d, %f);\n",
|
||||||
i, tex_num, tex_num, tex_num, i, tex_mul);
|
i, tex_num, tex_num, tex_num, tex_num, i, tex_mul);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ void pass_superxbr(struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
GLSLHF("#define weight1 (%f*1.29633/10.0)\n", conf->sharpness);
|
GLSLHF("#define weight1 (%f*1.29633/10.0)\n", conf->sharpness);
|
||||||
GLSLHF("#define weight2 (%f*1.75068/10.0/2.0)\n", conf->sharpness);
|
GLSLHF("#define weight2 (%f*1.75068/10.0/2.0)\n", conf->sharpness);
|
||||||
|
|
||||||
GLSLH(#define Get(x, y) (texture(tex, pos + (vec2(x, y) - vec2(0.25, 0.25)) / tex_size)[plane] * tex_mul))
|
GLSLH(#define Get(x, y) (texture(tex, pos + (vec2(x, y) - vec2(0.25, 0.25)) * pixel_size)[plane] * tex_mul))
|
||||||
} else {
|
} else {
|
||||||
*transform = (struct gl_transform){{{1.0,0.0}, {0.0,1.0}}, {0.0,0.0}};
|
*transform = (struct gl_transform){{{1.0,0.0}, {0.0,1.0}}, {0.0,0.0}};
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ void pass_superxbr(struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
GLSLHF("#define weight1 (%f*1.75068/10.0)\n", conf->sharpness);
|
GLSLHF("#define weight1 (%f*1.75068/10.0)\n", conf->sharpness);
|
||||||
GLSLHF("#define weight2 (%f*1.29633/10.0/2.0)\n", conf->sharpness);
|
GLSLHF("#define weight2 (%f*1.29633/10.0/2.0)\n", conf->sharpness);
|
||||||
|
|
||||||
GLSLH(#define Get(x, y) (texture(tex, pos + (vec2((x) + (y) - 1, (y) - (x))) / tex_size)[plane] * tex_mul))
|
GLSLH(#define Get(x, y) (texture(tex, pos + (vec2((x) + (y) - 1, (y) - (x))) * pixel_size)[plane] * tex_mul))
|
||||||
}
|
}
|
||||||
GLSLH(float df(float A, float B)
|
GLSLH(float df(float A, float B)
|
||||||
{
|
{
|
||||||
@ -135,7 +135,7 @@ void pass_superxbr(struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
wp3*(df(i1,e2)+df(i3,e4)+df(e1,i2)+df(e3,i4)));
|
||||||
})
|
})
|
||||||
|
|
||||||
GLSLHF("float superxbr(sampler2D tex, vec2 pos, vec2 tex_size, int plane, float tex_mul) {\n");
|
GLSLHF("float superxbr(sampler2D tex, vec2 pos, vec2 tex_size, vec2 pixel_size, int plane, float tex_mul) {\n");
|
||||||
|
|
||||||
if (step == 0) {
|
if (step == 0) {
|
||||||
GLSLH(vec2 dir = fract(pos * tex_size) - 0.5;)
|
GLSLH(vec2 dir = fract(pos * tex_size) - 0.5;)
|
||||||
@ -147,7 +147,7 @@ void pass_superxbr(struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
return 0.0;)
|
return 0.0;)
|
||||||
|
|
||||||
GLSLH(if (dir.x < 0.0 || dir.y < 0.0 || dist.x < 1.0 || dist.y < 1.0)
|
GLSLH(if (dir.x < 0.0 || dir.y < 0.0 || dist.x < 1.0 || dist.y < 1.0)
|
||||||
return texture(tex, pos - dir / tex_size)[plane] * tex_mul;)
|
return texture(tex, pos - dir * pixel_size)[plane] * tex_mul;)
|
||||||
} else {
|
} else {
|
||||||
GLSLH(vec2 dir = fract(pos * tex_size / 2.0) - 0.5;)
|
GLSLH(vec2 dir = fract(pos * tex_size / 2.0) - 0.5;)
|
||||||
GLSLH(if (dir.x * dir.y > 0.0)
|
GLSLH(if (dir.x * dir.y > 0.0)
|
||||||
@ -223,7 +223,7 @@ void pass_superxbr(struct gl_shader_cache *sc, int planes, int tex_num,
|
|||||||
GLSL(color = vec4(1.0);)
|
GLSL(color = vec4(1.0);)
|
||||||
|
|
||||||
for (int i = 0; i < planes; i++) {
|
for (int i = 0; i < planes; i++) {
|
||||||
GLSLF("color[%d] = superxbr(texture%d, texcoord%d, texture_size%d, %d, %f);\n",
|
GLSLF("color[%d] = superxbr(texture%d, texcoord%d, texture_size%d, pixel_size%d, %d, %f);\n",
|
||||||
i, tex_num, tex_num, tex_num, i, tex_mul);
|
i, tex_num, tex_num, tex_num, tex_num, i, tex_mul);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -870,8 +870,10 @@ static void pass_prepare_src_tex(struct gl_video *p)
|
|||||||
|
|
||||||
char texture_name[32];
|
char texture_name[32];
|
||||||
char texture_size[32];
|
char texture_size[32];
|
||||||
|
char pixel_size[32];
|
||||||
snprintf(texture_name, sizeof(texture_name), "texture%d", n);
|
snprintf(texture_name, sizeof(texture_name), "texture%d", n);
|
||||||
snprintf(texture_size, sizeof(texture_size), "texture_size%d", n);
|
snprintf(texture_size, sizeof(texture_size), "texture_size%d", n);
|
||||||
|
snprintf(pixel_size, sizeof(pixel_size), "pixel_size%d", n);
|
||||||
|
|
||||||
if (s->use_integer) {
|
if (s->use_integer) {
|
||||||
gl_sc_uniform_sampler_ui(sc, texture_name, n);
|
gl_sc_uniform_sampler_ui(sc, texture_name, n);
|
||||||
@ -884,6 +886,8 @@ static void pass_prepare_src_tex(struct gl_video *p)
|
|||||||
f[1] = s->h;
|
f[1] = s->h;
|
||||||
}
|
}
|
||||||
gl_sc_uniform_vec2(sc, texture_size, f);
|
gl_sc_uniform_vec2(sc, texture_size, f);
|
||||||
|
gl_sc_uniform_vec2(sc, pixel_size, (GLfloat[]){1.0f / f[0],
|
||||||
|
1.0f / f[1]});
|
||||||
|
|
||||||
gl->ActiveTexture(GL_TEXTURE0 + n);
|
gl->ActiveTexture(GL_TEXTURE0 + n);
|
||||||
gl->BindTexture(s->gl_target, s->gl_tex);
|
gl->BindTexture(s->gl_target, s->gl_tex);
|
||||||
@ -1351,7 +1355,7 @@ static bool pass_prescale_luma(struct gl_video *p, float tex_mul,
|
|||||||
if (p->opts.deband) {
|
if (p->opts.deband) {
|
||||||
// apply debanding before upscaling.
|
// apply debanding before upscaling.
|
||||||
pass_sample_deband(p->sc, p->opts.deband_opts, 0, p->pass_tex[0].gl_target,
|
pass_sample_deband(p->sc, p->opts.deband_opts, 0, p->pass_tex[0].gl_target,
|
||||||
tex_mul, p->texture_w, p->texture_h, &p->lfg);
|
tex_mul, &p->lfg);
|
||||||
finish_pass_fbo(p, &p->deband_fbo, p->texture_w,
|
finish_pass_fbo(p, &p->deband_fbo, p->texture_w,
|
||||||
p->texture_h, 0, 0);
|
p->texture_h, 0, 0);
|
||||||
tex_backup[0] = p->pass_tex[0];
|
tex_backup[0] = p->pass_tex[0];
|
||||||
@ -1470,8 +1474,7 @@ static void pass_read_video(struct gl_video *p)
|
|||||||
|
|
||||||
if (p->opts.deband) {
|
if (p->opts.deband) {
|
||||||
pass_sample_deband(p->sc, p->opts.deband_opts, 1, p->pass_tex[1].gl_target,
|
pass_sample_deband(p->sc, p->opts.deband_opts, 1, p->pass_tex[1].gl_target,
|
||||||
p->use_normalized_range ? 1.0 : tex_mul,
|
p->use_normalized_range ? 1.0 : tex_mul, &p->lfg);
|
||||||
p->texture_w, p->texture_h, &p->lfg);
|
|
||||||
GLSL(color.zw = vec2(0.0, 1.0);) // skip unused
|
GLSL(color.zw = vec2(0.0, 1.0);) // skip unused
|
||||||
finish_pass_fbo(p, &p->chroma_deband_fbo, c_w, c_h, 1, 0);
|
finish_pass_fbo(p, &p->chroma_deband_fbo, c_w, c_h, 1, 0);
|
||||||
p->use_normalized_range = true;
|
p->use_normalized_range = true;
|
||||||
@ -1495,7 +1498,7 @@ static void pass_read_video(struct gl_video *p)
|
|||||||
// Sample the main (luma/RGB) plane.
|
// Sample the main (luma/RGB) plane.
|
||||||
if (!prescaled && p->opts.deband) {
|
if (!prescaled && p->opts.deband) {
|
||||||
pass_sample_deband(p->sc, p->opts.deband_opts, 0, p->pass_tex[0].gl_target,
|
pass_sample_deband(p->sc, p->opts.deband_opts, 0, p->pass_tex[0].gl_target,
|
||||||
tex_mul, p->texture_w, p->texture_h, &p->lfg);
|
tex_mul, &p->lfg);
|
||||||
p->use_normalized_range = true;
|
p->use_normalized_range = true;
|
||||||
} else {
|
} else {
|
||||||
if (!prescaled) {
|
if (!prescaled) {
|
||||||
@ -1503,7 +1506,7 @@ static void pass_read_video(struct gl_video *p)
|
|||||||
} else {
|
} else {
|
||||||
// just use bilinear for non-essential planes.
|
// just use bilinear for non-essential planes.
|
||||||
GLSLF("color = texture(texture0, "
|
GLSLF("color = texture(texture0, "
|
||||||
"texcoord0 + vec2(%f,%f) / texture_size0);\n",
|
"texcoord0 + vec2(%f,%f) * pixel_size0);\n",
|
||||||
-offset.t[0] / scale_factor_x,
|
-offset.t[0] / scale_factor_x,
|
||||||
-offset.t[1] / scale_factor_y);
|
-offset.t[1] / scale_factor_y);
|
||||||
}
|
}
|
||||||
@ -1531,7 +1534,7 @@ static void pass_read_video(struct gl_video *p)
|
|||||||
GLSL(color.a = texture(texture3, texcoord3).r;)
|
GLSL(color.a = texture(texture3, texcoord3).r;)
|
||||||
} else {
|
} else {
|
||||||
GLSLF("color.a = texture(texture3, "
|
GLSLF("color.a = texture(texture3, "
|
||||||
"texcoord3 + vec2(%f,%f) / texture_size3).r;",
|
"texcoord3 + vec2(%f,%f) * pixel_size3).r;",
|
||||||
-offset.t[0] / scale_factor_x,
|
-offset.t[0] / scale_factor_x,
|
||||||
-offset.t[1] / scale_factor_y);
|
-offset.t[1] / scale_factor_y);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ void sampler_prelude(struct gl_shader_cache *sc, int tex_num)
|
|||||||
GLSLF("#define tex texture%d\n", tex_num);
|
GLSLF("#define tex texture%d\n", tex_num);
|
||||||
GLSLF("vec2 pos = texcoord%d;\n", tex_num);
|
GLSLF("vec2 pos = texcoord%d;\n", tex_num);
|
||||||
GLSLF("vec2 size = texture_size%d;\n", tex_num);
|
GLSLF("vec2 size = texture_size%d;\n", tex_num);
|
||||||
GLSLF("vec2 pt = vec2(1.0) / size;\n");
|
GLSLF("vec2 pt = pixel_size%d;\n", tex_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pass_sample_separated_get_weights(struct gl_shader_cache *sc,
|
static void pass_sample_separated_get_weights(struct gl_shader_cache *sc,
|
||||||
@ -348,8 +348,7 @@ const struct m_sub_options deband_conf = {
|
|||||||
|
|
||||||
// Stochastically sample a debanded result from a given texture
|
// Stochastically sample a debanded result from a given texture
|
||||||
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
||||||
int tex_num, GLenum tex_target, float tex_mul,
|
int tex_num, GLenum tex_target, float tex_mul, AVLFG *lfg)
|
||||||
float img_w, float img_h, AVLFG *lfg)
|
|
||||||
{
|
{
|
||||||
// Set up common variables and initialize the PRNG
|
// Set up common variables and initialize the PRNG
|
||||||
GLSLF("// debanding (tex %d)\n", tex_num);
|
GLSLF("// debanding (tex %d)\n", tex_num);
|
||||||
@ -359,14 +358,13 @@ void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
|||||||
|
|
||||||
// Helper: Compute a stochastic approximation of the avg color around a
|
// Helper: Compute a stochastic approximation of the avg color around a
|
||||||
// pixel
|
// pixel
|
||||||
GLSLHF("vec4 average(%s tex, vec2 pos, float range, inout float h) {",
|
GLSLHF("vec4 average(%s tex, vec2 pos, vec2 pt, float range, inout float h) {",
|
||||||
mp_sampler_type(tex_target));
|
mp_sampler_type(tex_target));
|
||||||
// Compute a random rangle and distance
|
// Compute a random rangle and distance
|
||||||
GLSLH(float dist = rand(h) * range; h = permute(h);)
|
GLSLH(float dist = rand(h) * range; h = permute(h);)
|
||||||
GLSLH(float dir = rand(h) * 6.2831853; h = permute(h);)
|
GLSLH(float dir = rand(h) * 6.2831853; h = permute(h);)
|
||||||
|
|
||||||
bool r = tex_target == GL_TEXTURE_RECTANGLE;
|
GLSLHF("pt *= dist;\n");
|
||||||
GLSLHF("vec2 pt = dist / vec2(%f, %f);\n", r ? 1 : img_w, r ? 1 : img_h);
|
|
||||||
GLSLH(vec2 o = vec2(cos(dir), sin(dir));)
|
GLSLH(vec2 o = vec2(cos(dir), sin(dir));)
|
||||||
|
|
||||||
// Sample at quarter-turn intervals around the source pixel
|
// Sample at quarter-turn intervals around the source pixel
|
||||||
@ -386,7 +384,7 @@ void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
|||||||
for (int i = 1; i <= opts->iterations; i++) {
|
for (int i = 1; i <= opts->iterations; i++) {
|
||||||
// Sample the average pixel and use it instead of the original if
|
// Sample the average pixel and use it instead of the original if
|
||||||
// the difference is below the given threshold
|
// the difference is below the given threshold
|
||||||
GLSLF("avg = average(tex, pos, %f, h);\n", i * opts->range);
|
GLSLF("avg = average(tex, pos, pt, %f, h);\n", i * opts->range);
|
||||||
GLSL(diff = abs(color - avg);)
|
GLSL(diff = abs(color - avg);)
|
||||||
GLSLF("color = mix(avg, color, greaterThan(diff, vec4(%f)));\n",
|
GLSLF("color = mix(avg, color, greaterThan(diff, vec4(%f)));\n",
|
||||||
opts->threshold / (i * 16384.0));
|
opts->threshold / (i * 16384.0));
|
||||||
|
@ -39,8 +39,7 @@ void pass_linearize(struct gl_shader_cache *sc, enum mp_csp_trc trc);
|
|||||||
void pass_delinearize(struct gl_shader_cache *sc, enum mp_csp_trc trc);
|
void pass_delinearize(struct gl_shader_cache *sc, enum mp_csp_trc trc);
|
||||||
|
|
||||||
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
void pass_sample_deband(struct gl_shader_cache *sc, struct deband_opts *opts,
|
||||||
int tex_num, GLenum tex_target, float tex_mul,
|
int tex_num, GLenum tex_target, float tex_mul, AVLFG *lfg);
|
||||||
float img_w, float img_h, AVLFG *lfg);
|
|
||||||
|
|
||||||
void pass_sample_unsharp(struct gl_shader_cache *sc, float param);
|
void pass_sample_unsharp(struct gl_shader_cache *sc, float param);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user