Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback request for Contrast Adaptive Sharpening shader port #9711

Closed
agyild opened this issue Jan 15, 2022 · 5 comments
Closed

Feedback request for Contrast Adaptive Sharpening shader port #9711

agyild opened this issue Jan 15, 2022 · 5 comments

Comments

@agyild
Copy link

agyild commented Jan 15, 2022

I have ported AMD's Contrast Adaptive Sharpening shader to mpv along with ReShade's modifications. However, since this is my first shader port, I would appreciate some feedback from more experienced mpv shader developers before possibly including it in the wiki.

@haasn
Copy link
Member

haasn commented Jan 15, 2022

Hi, I added HOOKED_gather etc. functions to mpv master, which you can conditionally depend on (#ifdef HOOKED_gather):

#ifdef HOOKED_gather
	vec4 red_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 0);

	vec3 e = vec3( red_efhi.w, red_efhi.w, red_efhi.w);
	vec3 f = vec3( red_efhi.z, red_efhi.z, red_efhi.z);
	vec3 h = vec3( red_efhi.x, red_efhi.x, red_efhi.x);
	vec3 i = vec3( red_efhi.y, red_efhi.y, red_efhi.y);

	vec4 green_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 1);

	e.g = green_efhi.w;
	f.g = green_efhi.z;
	h.g = green_efhi.x;
	i.g = green_efhi.y;

	vec4 blue_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 2);

	e.b = blue_efhi.w;
	f.b = blue_efhi.z;
	h.b = blue_efhi.x;
	i.b = blue_efhi.y;

#else
	vec3 e = ori.rgb;
	vec3 f = HOOKED_texOff(vec2(1.0, 0.0)).rgb;

	vec3 h = HOOKED_texOff(vec2(0.0, -1.0)).rgb;
	vec3 i = HOOKED_texOff(vec2(1.0, -1.0)).rgb;

#endif

@agyild
Copy link
Author

agyild commented Jan 15, 2022

Hi, I added HOOKED_gather etc. functions to mpv master, which you can conditionally depend on (#ifdef HOOKED_gather):

#ifdef HOOKED_gather
	vec4 red_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 0);

	vec3 e = vec3( red_efhi.w, red_efhi.w, red_efhi.w);
	vec3 f = vec3( red_efhi.z, red_efhi.z, red_efhi.z);
	vec3 h = vec3( red_efhi.x, red_efhi.x, red_efhi.x);
	vec3 i = vec3( red_efhi.y, red_efhi.y, red_efhi.y);

	vec4 green_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 1);

	e.g = green_efhi.w;
	f.g = green_efhi.z;
	h.g = green_efhi.x;
	i.g = green_efhi.y;

	vec4 blue_efhi = HOOKED_gather(HOOKED_pos + 0.5 * HOOKED_pt, 2);

	e.b = blue_efhi.w;
	f.b = blue_efhi.z;
	h.b = blue_efhi.x;
	i.b = blue_efhi.y;

#else
	vec3 e = ori.rgb;
	vec3 f = HOOKED_texOff(vec2(1.0, 0.0)).rgb;

	vec3 h = HOOKED_texOff(vec2(0.0, -1.0)).rgb;
	vec3 i = HOOKED_texOff(vec2(1.0, -1.0)).rgb;

#endif

Did you test it? Does it work on your end? On mpv 0.34.0-127-g777628e761 on Windows, I get the following errors when I force it to use that branch:

[vo/gpu/d3d11] input:58: error: 'HOOKED_gather' : no matching overloaded function found
[vo/gpu/d3d11] input:58: error: '=' :  cannot convert from ' const float' to ' temp highp 4-component vector of float'

Edit: I just saw that you added them very recently. So it makes sense that my build does not have that macro yet. As long as it works as it should, it should be fine though.

@haasn
Copy link
Member

haasn commented Jan 15, 2022

I tested that it compiles, not that the output is correct. It's possible that the channel order is different between HLSL and GLSL gather functions, which would require changing the indices.

@agyild
Copy link
Author

agyild commented Jan 17, 2022

I tested that it compiles, not that the output is correct. It's possible that the channel order is different between HLSL and GLSL gather functions, which would require changing the indices.

I have modified the code to take into account gather operations and texture coordinates. I think it should work properly, assuming i refers to x-coordinates and j refers to y-coordinates in the reference documentation.

@agyild
Copy link
Author

agyild commented Jan 19, 2022

@haasn Do you know which colorspace is used during the processing of mpv pixel shaders? Apparently CAS should be working in linear colorspace and I would like to know if there is a way to request linear colorspace from the shader code.

Edit: So, I have implemented sRGB to linear and vice versa conversions via in-shader operations. Hopefully, the implementation is correct. If there is a mistake or a better way to lookup linear values, I would like to know.

@agyild agyild closed this as completed Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants