| 1 |
/* |
| 2 |
* This file is part of Bino, a 3D video player. |
| 3 |
* |
| 4 |
* Copyright (C) 2022 |
| 5 |
* Martin Lambers <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
uniform sampler2D frameTex; |
| 22 |
uniform sampler2D subtitleTex; |
| 23 |
uniform float relative_width; |
| 24 |
uniform float relative_height; |
| 25 |
uniform float view_offset_x; |
| 26 |
uniform float view_factor_x; |
| 27 |
uniform float view_offset_y; |
| 28 |
uniform float view_factor_y; |
| 29 |
int surroundDegrees = $SURROUND_DEGREES; |
| 30 |
const bool nonlinear_output = $NONLINEAR_OUTPUT; |
| 31 |
|
| 32 |
smooth in vec2 vtexcoord; |
| 33 |
smooth in vec3 vdirection; |
| 34 |
|
| 35 |
const float pi = 3.14159265358979323846; |
| 36 |
|
| 37 |
layout(location = 0) out vec4 fcolor; |
| 38 |
|
| 39 |
// linear RGB to non-linear RGB |
| 40 |
float to_nonlinear(float x) |
| 41 |
{ |
| 42 |
const float c0 = 0.416666666667; // 1.0 / 2.4 |
| 43 |
return (x <= 0.0031308 ? (x * 12.92) : (1.055 * pow(x, c0) - 0.055)); |
| 44 |
} |
| 45 |
vec3 rgb_to_nonlinear(vec3 rgb) |
| 46 |
{ |
| 47 |
return vec3(to_nonlinear(rgb.r), to_nonlinear(rgb.g), to_nonlinear(rgb.b)); |
| 48 |
} |
| 49 |
|
| 50 |
void main(void) |
| 51 |
{ |
| 52 |
vec3 rgb; |
| 53 |
if (surroundDegrees > 0) { |
| 54 |
vec3 dir = normalize(vdirection); |
| 55 |
float theta = asin(clamp(-dir.y, -1.0, 1.0)); |
| 56 |
float phi = atan(dir.x, -dir.z); |
| 57 |
float tmp = (surroundDegrees == 360 ? 2.0f * pi : pi); |
| 58 |
float u = phi / tmp + 0.5; |
| 59 |
float v = theta / pi + 0.5; |
| 60 |
float vtx = view_offset_x + view_factor_x * u; |
| 61 |
float vty = view_offset_y + view_factor_y * v; |
| 62 |
rgb = texture(frameTex, vec2(vtx, vty)).rgb; |
| 63 |
} else { |
| 64 |
float vtx = view_offset_x + view_factor_x * vtexcoord.x; |
| 65 |
float vty = view_offset_y + view_factor_y * vtexcoord.y; |
| 66 |
float tx = ( vtx - 0.5 * (1.0 - relative_width )) / relative_width; |
| 67 |
float ty = (1.0 - vty - 0.5 * (1.0 - relative_height)) / relative_height; |
| 68 |
rgb = texture(frameTex, vec2(tx, ty)).rgb; |
| 69 |
vec4 sub = texture(subtitleTex, vec2(vtexcoord.x, 1.0 - vtexcoord.y)).rgba; |
| 70 |
rgb = mix(rgb, sub.rgb, sub.a); |
| 71 |
} |
| 72 |
if (nonlinear_output) { |
| 73 |
rgb = rgb_to_nonlinear(rgb); |
| 74 |
} |
| 75 |
fcolor = vec4(rgb, 1.0); |
| 76 |
} |