1
0
avidemux_shaders/gopro_8:7/unfish_gopro_8:7.glsl

37 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-06-15 10:57:43 +02:00
// RozK
2025-06-15 16:49:25 +02:00
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
// Adapted from https://github.com/duducosmos/defisheye
2025-06-15 10:57:43 +02:00
// itself based on http://www.fmwconcepts.com/imagemagick/defisheye/index.php
#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY;
uniform sampler2DRect myTextureU;
uniform sampler2DRect myTextureV;
uniform vec2 myResolution;
uniform float pts;
const vec2 half_pixel = vec2(0.5, 0.5);
2025-06-15 10:57:43 +02:00
const float input_fov = 156.0;
2025-06-15 16:49:25 +02:00
const float output_fov = 119.789529;
vec2 unfish(vec2 coord) {
float diameter = sqrt(dot(myResolution, myResolution));
2025-06-15 10:57:43 +02:00
vec2 center = myResolution * 0.5;
vec2 position = coord - center;
float input_distance = length(position);
2025-06-15 16:49:25 +02:00
float input_foc = diameter / radians(input_fov);
float output_foc = diameter / (2.0 * tan(radians(output_fov) * 0.5));
2025-06-15 10:57:43 +02:00
return center + position * (input_foc * atan(input_distance / output_foc) / input_distance);
}
void main() {
vec2 y_coord = unfish(gl_TexCoord[0].xy + half_pixel);
vec2 uv_coord = y_coord * 0.5;
vec4 y = texture2DRect(myTextureY, y_coord);
vec4 u = texture2DRect(myTextureU, uv_coord);
vec4 v = texture2DRect(myTextureV, uv_coord);
gl_FragColor = vec4(y.r, u.r, v.r, 1.0);
}