linear conversion
This commit is contained in:
		@ -17,7 +17,8 @@
 | 
			
		||||
 | 
			
		||||
#extension GL_ARB_texture_rectangle: enable
 | 
			
		||||
 | 
			
		||||
#define rotate_180
 | 
			
		||||
#define non_linear_decoding
 | 
			
		||||
//#define rotate_180
 | 
			
		||||
//#define debug_borders
 | 
			
		||||
 | 
			
		||||
#undef highp // defined by Qt-OpenGl
 | 
			
		||||
@ -62,34 +63,63 @@ vec2 equidistant_to_rectilinear(const in vec2 coord) {
 | 
			
		||||
    return coord * (equidistant_radius / rectilinear_radius);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec4 sample_texture(const in vec2 coord) {
 | 
			
		||||
vec3 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);
 | 
			
		||||
        return vec3(1.0);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    vec2 uv_coord = y_coord * 0.5;
 | 
			
		||||
    return vec4(
 | 
			
		||||
    return vec3(
 | 
			
		||||
        texture2DRect(myTextureY, y_coord).x,
 | 
			
		||||
        texture2DRect(myTextureU, uv_coord).x,
 | 
			
		||||
        texture2DRect(myTextureV, uv_coord).x,
 | 
			
		||||
        1.0);
 | 
			
		||||
        texture2DRect(myTextureV, uv_coord).x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef non_linear_decoding
 | 
			
		||||
 | 
			
		||||
// https://en.wikipedia.org/wiki/Rec._709
 | 
			
		||||
 | 
			
		||||
#define y_min    ( 16.0 / 255.0)
 | 
			
		||||
#define y_max    (235.0 / 255.0)
 | 
			
		||||
#define uv_min   ( 16.0 / 255.0)
 | 
			
		||||
#define uv_max   (240.0 / 255.0)
 | 
			
		||||
#define y_range  (y_max - y_min)
 | 
			
		||||
#define uv_range (uv_max - uv_min)
 | 
			
		||||
 | 
			
		||||
const vec3 yuv_min = vec3(y_min, uv_min, uv_min);
 | 
			
		||||
const vec3 yuv_range = vec3(y_range, uv_range, uv_range);
 | 
			
		||||
const vec3 yuv_center = vec3(0.0, 0.5, 0.5);
 | 
			
		||||
 | 
			
		||||
vec3 decode_pixel(const in vec3 pixel) {
 | 
			
		||||
    vec3 color = (pixel - yuv_min) / yuv_range - yuv_center;
 | 
			
		||||
    float l = (color.x < 0.081) ? (color.x / 4.5) : pow((color.x + 0.099) / 1.099, 1.0 / 0.45);
 | 
			
		||||
    return vec3(l, color.yz);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec3 encode_pixel(const in vec3 color) {
 | 
			
		||||
    float y = (color.x < 0.018) ? (color.x * 4.5) : (pow(color.x, 0.45) * 1.099 - 0.099);
 | 
			
		||||
    return (vec3(y, color.yz) + yuv_center) * yuv_range + yuv_min;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#define decode_pixel(_color) _color
 | 
			
		||||
#define encode_pixel(_color) _color
 | 
			
		||||
 | 
			
		||||
#endif // non_linear_decoding
 | 
			
		||||
 | 
			
		||||
void main() {
 | 
			
		||||
    initialize();
 | 
			
		||||
 | 
			
		||||
    vec2 coord = gl_TexCoord[0].xy;
 | 
			
		||||
    vec4 pixel = vec4(0.0);
 | 
			
		||||
 | 
			
		||||
    vec3 color = vec3(0.0);
 | 
			
		||||
    for (int y = 0; y < subsampling; y++) {
 | 
			
		||||
        for (int x = 0; x < subsampling; x++) {
 | 
			
		||||
            vec2 offset = subsampling_start + subsampling_step * vec2(x, y);
 | 
			
		||||
            pixel += sample_texture(coord + offset);
 | 
			
		||||
            color += decode_pixel(sample_texture(coord + offset));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    gl_FragColor = pixel * subsampling_scale;
 | 
			
		||||
    gl_FragColor = vec4(encode_pixel(color * subsampling_scale), 1.0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user