focal length, preset and license
This commit is contained in:
@ -1,13 +1,26 @@
|
||||
#version 130
|
||||
// RozK
|
||||
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
||||
// Copyright (C) 2025 Jean-Baptiste Berlioz
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#extension GL_ARB_texture_rectangle: enable
|
||||
|
||||
#undef highp // defined by Qt-OpenGl
|
||||
#define rotate_180
|
||||
//#define debug_borders
|
||||
|
||||
#undef highp // defined by Qt-OpenGl
|
||||
precision highp float;
|
||||
|
||||
// uniforms
|
||||
@ -19,9 +32,8 @@ uniform float pts;
|
||||
|
||||
// parameters
|
||||
const vec2 sensor_size = vec2(5.949440, 5.205760);
|
||||
const vec2 pixel_scale = vec2(0.871558, 1.0);
|
||||
const float equidistant_focal_length = 2.920000;
|
||||
const float rectilinear_focal_length = 2.102263;
|
||||
const float equidistant_focal_length = 3.020000;
|
||||
const float rectilinear_focal_length = 2.232346;
|
||||
|
||||
// constants
|
||||
const int subsampling = 4;
|
||||
@ -36,39 +48,34 @@ vec2 sensor_to_texture;
|
||||
|
||||
void initialize() {
|
||||
texture_center = myResolution * 0.5;
|
||||
texture_to_sensor = (sensor_size / myResolution) * pixel_scale;
|
||||
texture_to_sensor = sensor_size / myResolution;
|
||||
#ifdef rotate_180
|
||||
texture_to_sensor *= -1.0;
|
||||
#endif
|
||||
sensor_to_texture = (myResolution / sensor_size);
|
||||
sensor_to_texture = myResolution / sensor_size;
|
||||
}
|
||||
|
||||
vec2 unfish_coord(const in vec2 coord) {
|
||||
vec2 equidistant_to_rectilinear(const in vec2 coord) {
|
||||
float rectilinear_radius = length(coord);
|
||||
float rectilinear_angle = atan(rectilinear_radius / rectilinear_focal_length);
|
||||
float equidistant_radius = rectilinear_angle * equidistant_focal_length;
|
||||
return coord * (equidistant_radius / rectilinear_radius);
|
||||
}
|
||||
|
||||
vec4 unfish_pixel(const in vec2 coord) {
|
||||
vec2 unfished = unfish_coord((coord - texture_center) * texture_to_sensor);
|
||||
vec2 y_coord = texture_center + unfished * sensor_to_texture;
|
||||
|
||||
// y_coord.y = coord.y;
|
||||
|
||||
vec4 sample_texture(const in vec2 coord) {
|
||||
vec2 rectilinear = equidistant_to_rectilinear((coord - texture_center) * texture_to_sensor);
|
||||
vec2 y_coord = texture_center + rectilinear * sensor_to_texture;
|
||||
#ifdef debug_borders
|
||||
if (y_coord.x < 0.0 || y_coord.y < 0.0 || y_coord.x > myResolution.x || y_coord.y > myResolution.y) {
|
||||
return vec4(1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
vec2 uv_coord = y_coord * 0.5;
|
||||
return vec4(
|
||||
texture2DRect(myTextureY, y_coord).r,
|
||||
texture2DRect(myTextureU, uv_coord).r,
|
||||
texture2DRect(myTextureV, uv_coord).r,
|
||||
1.0
|
||||
);
|
||||
texture2DRect(myTextureY, y_coord).x,
|
||||
texture2DRect(myTextureU, uv_coord).x,
|
||||
texture2DRect(myTextureV, uv_coord).x,
|
||||
1.0);
|
||||
}
|
||||
|
||||
void main() {
|
||||
@ -80,7 +87,7 @@ void main() {
|
||||
for (int y = 0; y < subsampling; y++) {
|
||||
for (int x = 0; x < subsampling; x++) {
|
||||
vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
|
||||
pixel += unfish_pixel(coord + offset);
|
||||
pixel += sample_texture(coord + offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user