bjin / mpv-prescalers

prescalers for mpv, as user shaders
GNU Lesser General Public License v3.0
355 stars 34 forks source link

Play around with the texture order #13

Closed haasn closed 6 years ago

haasn commented 7 years ago

Is it possible that, due to the linear interpolation of weights, we would be better off with a different sampling order? As far as I can tell, you use the x coordinate to store multiple weights and the y coordinate to store a projected offset based on the entire key, using a 2D texture overall. But this is not a requirement - you could instead use a 3D texture, or even a “4D” texture (texture array / multiple textures) in theory.

Then you can use one “linear” coefficient for each coordinate, allowing possibly better linear interpolation of the values. Basically use vec3(angle, strength, coherence) as your base coordinate. To deal with the fact that you need to sample multiple times (for many weights), you can pick one coordinate (ideally the “smallest”) as your “offset” coordinate, and just repeat the entire texture a few times in that dimension - for the different rows of the weights.

Perhaps with this organization you can get a better result with a smaller weights texture, which benefits from better caching and therefore typically better performance.

bjin commented 6 years ago

Judging by the kernel visualizations, it make some sense to perform linear interpolation over angle and strength key (with a 3d texture), and use kernel mixed from four pre-calculated kernels. There are quite some downsides though,

  1. The kernel is not for samples angle/strength at specified value, but in a specified range. Performing linear interpolation would assume a center point (in specified range), which is incorrect.
  2. The kernels with similar angle/strength is very similar, I doubt the difference will be noticeable even in static frame comparison
  3. Linear interpolation won't work for strength out of the range