1
0

frame widening maths, cleanup

This commit is contained in:
2025-09-18 06:08:05 +02:00
parent 1385b3e6f3
commit 95175afb5d
2 changed files with 91 additions and 78 deletions

View File

@ -9,7 +9,6 @@
// #define debug_borders
// uniforms
uniform sampler2DRect myTextureY;
uniform sampler2DRect myTextureU;
uniform sampler2DRect myTextureV;
@ -17,42 +16,41 @@ uniform vec2 myResolution;
uniform float pts;
// parameters
const vec2 sensor_dimensions = vec2(5.949440, 5.205760);
const float fisheye_focal_length = 2.92;
const float rectilinear_focal_length = 2.102263;
const vec2 sensor_size = vec2(5.949440, 5.205760);
const vec2 pixel_scale = vec2(0.871558, 1.0);
const int subsampling = 4;
const float equidistant_focal_length = 2.920000;
const float rectilinear_focal_length = 2.102263;
// constants
const float subsampling_step = 1.0 / float(subsampling);
const float subsampling_start = subsampling_step * 0.5 - 0.5;
const float subsampling_denominator = 1.0 / float(subsampling * subsampling);
const int subsampling = 4;
const vec2 subsampling_step = vec2(1.0 / float(subsampling));
const vec2 subsampling_start = subsampling_step * 0.5 - vec2(0.5);
const float subsampling_scale = 1.0 / float(subsampling * subsampling);
// variables
vec2 texture_center;
vec2 texture_to_sensor;
vec2 sensor_to_texture;
void initialize() {
texture_center = myResolution * 0.5;
texture_to_sensor = (sensor_dimensions / myResolution) * pixel_scale;
sensor_to_texture = (myResolution / sensor_dimensions);
texture_to_sensor = (sensor_size / myResolution) * pixel_scale;
sensor_to_texture = (myResolution / sensor_size);
}
vec2 unfish_coord(const in vec2 coord) {
float rectilinear_distance = length(coord);
float rectilinear_angle = atan(rectilinear_distance / rectilinear_focal_length);
float fisheye_distance = rectilinear_angle * fisheye_focal_length;
return coord * (fisheye_distance / rectilinear_distance);
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;
#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, 1.0, 1.0, 1.0);
@ -74,13 +72,12 @@ void main() {
vec2 coord = gl_TexCoord[0].xy;
vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
float x, y = subsampling_start;
for (int column = 0; column < subsampling; column++, y += subsampling_step) {
x = subsampling_start;
for (int row = 0; row < subsampling; row++, x += subsampling_step) {
pixel += unfish_pixel(coord + vec2(x, y));
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);
}
}
gl_FragColor = pixel * subsampling_denominator;
gl_FragColor = pixel * subsampling_scale;
}