2018-08-27 05:31:48 +00:00
/* clang-format off */
2017-12-04 12:41:34 +00:00
[vertex]
#ifdef USE_GLES_OVER_GL
2018-12-21 14:14:55 +00:00
#define lowp
2017-12-04 12:41:34 +00:00
#define mediump
#define highp
#else
2019-01-24 21:58:42 +00:00
precision highp float;
precision highp int;
2017-12-04 12:41:34 +00:00
#endif
attribute highp vec4 vertex_attrib; // attrib:0
2018-08-27 05:31:48 +00:00
/* clang-format on */
2018-02-24 13:48:22 +00:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
attribute vec3 cube_in; // attrib:4
#else
2017-12-04 12:41:34 +00:00
attribute vec2 uv_in; // attrib:4
2018-02-24 13:48:22 +00:00
#endif
2017-12-04 12:41:34 +00:00
attribute vec2 uv2_in; // attrib:5
2018-02-24 13:48:22 +00:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
varying vec3 cube_interp;
#else
2017-12-04 12:41:34 +00:00
varying vec2 uv_interp;
2018-02-24 13:48:22 +00:00
#endif
2017-12-04 12:41:34 +00:00
varying vec2 uv2_interp;
2017-08-20 14:17:24 +00:00
// These definitions are here because the shader-wrapper builder does
// not understand `#elif defined()`
#ifdef USE_DISPLAY_TRANSFORM
#endif
2017-12-04 12:41:34 +00:00
#ifdef USE_COPY_SECTION
2019-01-24 20:00:33 +00:00
uniform highp vec4 copy_section;
2017-08-20 14:17:24 +00:00
#elif defined(USE_DISPLAY_TRANSFORM)
uniform highp mat4 display_transform;
2017-12-04 12:41:34 +00:00
#endif
void main() {
2018-02-24 13:48:22 +00:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
cube_interp = cube_in;
2018-10-21 00:21:26 +00:00
#elif defined(USE_ASYM_PANO)
uv_interp = vertex_attrib.xy;
2018-02-24 13:48:22 +00:00
#else
2017-12-04 12:41:34 +00:00
uv_interp = uv_in;
2018-02-24 13:48:22 +00:00
#endif
2017-12-04 12:41:34 +00:00
uv2_interp = uv2_in;
gl_Position = vertex_attrib;
#ifdef USE_COPY_SECTION
uv_interp = copy_section.xy + uv_interp * copy_section.zw;
gl_Position.xy = (copy_section.xy + (gl_Position.xy * 0.5 + 0.5) * copy_section.zw) * 2.0 - 1.0;
2017-08-20 14:17:24 +00:00
#elif defined(USE_DISPLAY_TRANSFORM)
uv_interp = (display_transform * vec4(uv_in, 1.0, 1.0)).xy;
2017-12-04 12:41:34 +00:00
#endif
}
2018-08-27 05:31:48 +00:00
/* clang-format off */
2017-12-04 12:41:34 +00:00
[fragment]
2018-02-24 13:48:22 +00:00
#define M_PI 3.14159265359
2017-12-04 12:41:34 +00:00
#ifdef USE_GLES_OVER_GL
2018-12-21 14:14:55 +00:00
#define lowp
2017-12-04 12:41:34 +00:00
#define mediump
#define highp
#else
2019-01-24 21:58:42 +00:00
#if defined(USE_HIGHP_PRECISION)
precision highp float;
precision highp int;
#else
2017-12-04 12:41:34 +00:00
precision mediump float;
precision mediump int;
#endif
2019-01-24 21:58:42 +00:00
#endif
2017-12-04 12:41:34 +00:00
2018-02-24 13:48:22 +00:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
varying vec3 cube_interp;
#else
2017-12-04 12:41:34 +00:00
varying vec2 uv_interp;
2018-02-24 13:48:22 +00:00
#endif
2018-08-27 05:31:48 +00:00
/* clang-format on */
2018-02-24 13:48:22 +00:00
2018-10-21 00:21:26 +00:00
#ifdef USE_ASYM_PANO
uniform highp mat4 pano_transform;
uniform highp vec4 asym_proj;
#endif
2018-02-24 13:48:22 +00:00
#ifdef USE_CUBEMAP
uniform samplerCube source_cube; // texunit:0
#else
2017-12-04 12:41:34 +00:00
uniform sampler2D source; // texunit:0
2018-02-24 13:48:22 +00:00
#endif
2017-12-04 12:41:34 +00:00
2017-08-20 14:17:24 +00:00
#ifdef SEP_CBCR_TEXTURE
uniform sampler2D CbCr; //texunit:1
#endif
2017-12-04 12:41:34 +00:00
varying vec2 uv2_interp;
2018-02-24 13:48:22 +00:00
#ifdef USE_MULTIPLIER
uniform float multiplier;
#endif
2017-12-04 12:41:34 +00:00
#ifdef USE_CUSTOM_ALPHA
uniform float custom_alpha;
#endif
2018-02-24 13:48:22 +00:00
#if defined(USE_PANORAMA) || defined(USE_ASYM_PANO)
2018-12-15 05:27:03 +00:00
uniform highp mat4 sky_transform;
2018-02-24 13:48:22 +00:00
vec4 texturePanorama(sampler2D pano, vec3 normal) {
vec2 st = vec2(
2018-08-24 12:50:59 +00:00
atan(normal.x, normal.z),
acos(normal.y));
2018-02-24 13:48:22 +00:00
2018-08-24 12:50:59 +00:00
if (st.x < 0.0)
st.x += M_PI * 2.0;
2018-02-24 13:48:22 +00:00
2018-08-24 12:50:59 +00:00
st /= vec2(M_PI * 2.0, M_PI);
2018-02-24 13:48:22 +00:00
2018-08-24 12:50:59 +00:00
return texture2D(pano, st);
2018-02-24 13:48:22 +00:00
}
#endif
2017-12-04 12:41:34 +00:00
void main() {
2018-02-24 13:48:22 +00:00
#ifdef USE_PANORAMA
2018-12-15 05:27:03 +00:00
vec3 cube_normal = normalize(cube_interp);
cube_normal.z = -cube_normal.z;
cube_normal = mat3(sky_transform) * cube_normal;
cube_normal.z = -cube_normal.z;
vec4 color = texturePanorama(source, cube_normal);
2018-02-24 13:48:22 +00:00
2018-10-21 00:21:26 +00:00
#elif defined(USE_ASYM_PANO)
// When an asymmetrical projection matrix is used (applicable for stereoscopic rendering i.e. VR) we need to do this calculation per fragment to get a perspective correct result.
2019-09-22 16:53:38 +00:00
// Asymmetrical projection means the center of projection is no longer in the center of the screen but shifted.
2018-10-21 00:21:26 +00:00
// The Matrix[2][0] (= asym_proj.x) and Matrix[2][1] (= asym_proj.z) values are what provide the right shift in the image.
vec3 cube_normal;
2019-09-22 16:53:38 +00:00
cube_normal.z = -1.0;
2018-10-21 00:21:26 +00:00
cube_normal.x = (cube_normal.z * (-uv_interp.x - asym_proj.x)) / asym_proj.y;
cube_normal.y = (cube_normal.z * (-uv_interp.y - asym_proj.z)) / asym_proj.a;
2018-12-15 05:27:03 +00:00
cube_normal = mat3(sky_transform) * mat3(pano_transform) * cube_normal;
2018-10-21 00:21:26 +00:00
cube_normal.z = -cube_normal.z;
vec4 color = texturePanorama(source, normalize(cube_normal.xyz));
2018-02-24 13:48:22 +00:00
#elif defined(USE_CUBEMAP)
vec4 color = textureCube(source_cube, normalize(cube_interp));
2017-08-20 14:17:24 +00:00
#elif defined(SEP_CBCR_TEXTURE)
vec4 color;
color.r = texture2D(source, uv_interp).r;
color.gb = texture2D(CbCr, uv_interp).rg - vec2(0.5, 0.5);
color.a = 1.0;
2018-02-24 13:48:22 +00:00
#else
2018-08-24 12:50:59 +00:00
vec4 color = texture2D(source, uv_interp);
2018-02-24 13:48:22 +00:00
#endif
2017-12-04 12:41:34 +00:00
2017-08-20 14:17:24 +00:00
#ifdef YCBCR_TO_RGB
// YCbCr -> RGB conversion
// Using BT.601, which is the standard for SDTV is provided as a reference
color.rgb = mat3(
vec3(1.00000, 1.00000, 1.00000),
vec3(0.00000, -0.34413, 1.77200),
vec3(1.40200, -0.71414, 0.00000)) *
color.rgb;
#endif
2017-12-04 12:41:34 +00:00
#ifdef USE_NO_ALPHA
2018-08-24 12:50:59 +00:00
color.a = 1.0;
2017-12-04 12:41:34 +00:00
#endif
#ifdef USE_CUSTOM_ALPHA
2018-08-24 12:50:59 +00:00
color.a = custom_alpha;
2017-12-04 12:41:34 +00:00
#endif
2018-02-24 13:48:22 +00:00
#ifdef USE_MULTIPLIER
color.rgb *= multiplier;
#endif
2017-12-04 12:41:34 +00:00
2021-08-17 04:55:37 +00:00
#ifdef OUTPUT_LINEAR
// sRGB -> linear
color.rgb = mix(pow((color.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), color.rgb * (1.0 / 12.92), vec3(lessThan(color.rgb, vec3(0.04045))));
#endif
2017-12-04 12:41:34 +00:00
gl_FragColor = color;
}