2018-08-27 07:31:48 +02:00
/* clang-format off */
2016-10-03 21:33:42 +02:00
[vertex]
2018-08-24 13:42:18 +02:00
layout(location = 0) in highp vec4 vertex_attrib;
2018-08-27 07:31:48 +02:00
/* clang-format on */
2017-05-25 18:53:59 +02:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
2018-08-24 13:42:18 +02:00
layout(location = 4) in vec3 cube_in;
2016-10-03 21:33:42 +02:00
#else
2018-08-24 13:42:18 +02:00
layout(location = 4) in vec2 uv_in;
2016-10-03 21:33:42 +02:00
#endif
2018-08-24 13:42:18 +02:00
layout(location = 5) in vec2 uv2_in;
2016-10-03 21:33:42 +02:00
2017-05-25 18:53:59 +02:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
2016-10-03 21:33:42 +02:00
out vec3 cube_interp;
#else
out vec2 uv_interp;
#endif
out vec2 uv2_interp;
2017-06-27 03:58:03 +02:00
#ifdef USE_COPY_SECTION
uniform vec4 copy_section;
#endif
2016-10-03 21:33:42 +02:00
void main() {
2017-05-25 18:53:59 +02:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
2016-10-03 21:33:42 +02:00
cube_interp = cube_in;
2017-10-09 14:27:20 +02:00
#elif defined(USE_ASYM_PANO)
uv_interp = vertex_attrib.xy;
2016-10-03 21:33:42 +02:00
#else
uv_interp = uv_in;
2017-06-09 05:23:50 +02:00
#ifdef V_FLIP
2018-08-24 13:42:18 +02:00
uv_interp.y = 1.0 - uv_interp.y;
2017-06-09 05:23:50 +02:00
#endif
2016-10-03 21:33:42 +02:00
#endif
uv2_interp = uv2_in;
gl_Position = vertex_attrib;
2017-06-27 03:58:03 +02:00
#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;
#endif
2016-10-03 21:33:42 +02:00
}
2018-08-27 07:31:48 +02:00
/* clang-format off */
2016-10-03 21:33:42 +02:00
[fragment]
2017-05-25 18:53:59 +02:00
#define M_PI 3.14159265359
2016-10-03 21:33:42 +02:00
2017-07-22 19:07:38 +02:00
#if !defined(USE_GLES_OVER_GL)
precision mediump float;
#endif
2017-05-25 18:53:59 +02:00
#if defined(USE_CUBEMAP) || defined(USE_PANORAMA)
2016-10-03 21:33:42 +02:00
in vec3 cube_interp;
#else
in vec2 uv_interp;
2017-05-25 18:53:59 +02:00
#endif
2017-10-09 14:27:20 +02:00
#ifdef USE_ASYM_PANO
uniform highp mat4 pano_transform;
uniform highp vec4 asym_proj;
#endif
2019-01-23 14:17:42 +01:00
// These definitions are here because the shader-wrapper builder does
// not understand `#elif defined()`
#ifdef USE_TEXTURE3D
#endif
#ifdef USE_TEXTURE2DARRAY
#endif
2017-05-25 18:53:59 +02:00
#ifdef USE_CUBEMAP
uniform samplerCube source_cube; //texunit:0
2019-01-23 14:17:42 +01:00
#elif defined(USE_TEXTURE3D)
uniform sampler3D source_3d; //texunit:0
#elif defined(USE_TEXTURE2DARRAY)
uniform sampler2DArray source_2d_array; //texunit:0
2017-05-25 18:53:59 +02:00
#else
2016-10-21 12:27:13 +02:00
uniform sampler2D source; //texunit:0
2016-10-03 21:33:42 +02:00
#endif
2019-01-23 14:17:42 +01:00
/* clang-format on */
#if defined(USE_TEXTURE3D) || defined(USE_TEXTURE2DARRAY)
uniform float layer;
#endif
2017-05-30 03:11:33 +02:00
#ifdef USE_MULTIPLIER
uniform float multiplier;
#endif
2017-10-09 14:27:20 +02:00
#if defined(USE_PANORAMA) || defined(USE_ASYM_PANO)
2018-12-15 06:27:03 +01:00
uniform highp mat4 sky_transform;
2017-05-25 18:53:59 +02:00
2018-08-24 13:42:18 +02:00
vec4 texturePanorama(vec3 normal, sampler2D pano) {
2017-05-25 18:53:59 +02:00
vec2 st = vec2(
2018-08-24 13:42:18 +02:00
atan(normal.x, normal.z),
acos(normal.y));
2017-05-25 18:53:59 +02:00
2018-08-24 13:42:18 +02:00
if (st.x < 0.0)
st.x += M_PI * 2.0;
2017-05-25 18:53:59 +02:00
2018-08-24 13:42:18 +02:00
st /= vec2(M_PI * 2.0, M_PI);
2017-05-25 18:53:59 +02:00
2018-08-24 13:42:18 +02:00
return textureLod(pano, st, 0.0);
2017-05-25 18:53:59 +02:00
}
#endif
2016-10-21 12:27:13 +02:00
2016-11-29 23:55:12 +01:00
uniform vec2 pixel_size;
2016-10-21 12:27:13 +02:00
2016-10-03 21:33:42 +02:00
in vec2 uv2_interp;
2017-06-06 03:33:01 +02:00
#ifdef USE_BCS
uniform vec3 bcs;
#endif
#ifdef USE_COLOR_CORRECTION
uniform sampler2D color_correction; //texunit:1
#endif
2016-10-21 12:27:13 +02:00
layout(location = 0) out vec4 frag_color;
2016-10-03 21:33:42 +02:00
void main() {
//vec4 color = color_interp;
2017-05-25 18:53:59 +02:00
#ifdef USE_PANORAMA
2018-12-15 06:27:03 +01: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(cube_normal, source);
2017-05-25 18:53:59 +02:00
2017-10-09 14:27:20 +02:00
#elif defined(USE_ASYM_PANO)
2018-08-24 13:42:18 +02:00
// 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.
2017-10-09 14:27:20 +02:00
// Note that we're ignoring the x-offset for IPD, with Z sufficiently in the distance it becomes neglectible, as a result we could probably just set cube_normal.z to -1.
// 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;
cube_normal.z = -1000000.0;
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 06:27:03 +01:00
cube_normal = mat3(sky_transform) * mat3(pano_transform) * cube_normal;
2017-10-09 14:27:20 +02:00
cube_normal.z = -cube_normal.z;
2018-08-24 13:42:18 +02:00
vec4 color = texturePanorama(normalize(cube_normal.xyz), source);
2017-10-09 14:27:20 +02:00
2017-05-25 18:53:59 +02:00
#elif defined(USE_CUBEMAP)
2018-08-24 13:42:18 +02:00
vec4 color = texture(source_cube, normalize(cube_interp));
2016-10-21 12:27:13 +02:00
2019-01-23 14:17:42 +01:00
#elif defined(USE_TEXTURE3D)
vec4 color = textureLod(source_3d, vec3(uv_interp, layer), 0.0);
#elif defined(USE_TEXTURE2DARRAY)
vec4 color = textureLod(source_2d_array, vec3(uv_interp, layer), 0.0);
2016-10-21 12:27:13 +02:00
#else
2018-08-24 13:42:18 +02:00
vec4 color = textureLod(source, uv_interp, 0.0);
2016-10-21 12:27:13 +02:00
#endif
2016-10-30 01:48:09 +02:00
#ifdef LINEAR_TO_SRGB
//regular Linear -> SRGB conversion
vec3 a = vec3(0.055);
2018-08-24 13:42:18 +02:00
color.rgb = mix((vec3(1.0) + a) * pow(color.rgb, vec3(1.0 / 2.4)) - a, 12.92 * color.rgb, lessThan(color.rgb, vec3(0.0031308)));
2016-10-30 01:48:09 +02:00
#endif
2017-06-24 13:58:27 +02:00
#ifdef SRGB_TO_LINEAR
2018-08-24 13:42:18 +02:00
color.rgb = mix(pow((color.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), color.rgb * (1.0 / 12.92), lessThan(color.rgb, vec3(0.04045)));
2017-06-24 13:58:27 +02:00
#endif
2016-10-30 01:48:09 +02:00
#ifdef DEBUG_GRADIENT
2018-08-24 13:42:18 +02:00
color.rg = uv_interp;
color.b = 0.0;
2016-10-30 01:48:09 +02:00
#endif
#ifdef DISABLE_ALPHA
2018-08-24 13:42:18 +02:00
color.a = 1.0;
2016-10-30 01:48:09 +02:00
#endif
2016-10-21 12:27:13 +02:00
2016-11-29 23:55:12 +01:00
#ifdef GAUSSIAN_HORIZONTAL
2018-08-24 13:42:18 +02:00
color *= 0.38774;
color += texture(source, uv_interp + vec2(1.0, 0.0) * pixel_size) * 0.24477;
color += texture(source, uv_interp + vec2(2.0, 0.0) * pixel_size) * 0.06136;
color += texture(source, uv_interp + vec2(-1.0, 0.0) * pixel_size) * 0.24477;
color += texture(source, uv_interp + vec2(-2.0, 0.0) * pixel_size) * 0.06136;
2016-11-29 23:55:12 +01:00
#endif
#ifdef GAUSSIAN_VERTICAL
2018-08-24 13:42:18 +02:00
color *= 0.38774;
color += texture(source, uv_interp + vec2(0.0, 1.0) * pixel_size) * 0.24477;
color += texture(source, uv_interp + vec2(0.0, 2.0) * pixel_size) * 0.06136;
color += texture(source, uv_interp + vec2(0.0, -1.0) * pixel_size) * 0.24477;
color += texture(source, uv_interp + vec2(0.0, -2.0) * pixel_size) * 0.06136;
2016-11-29 23:55:12 +01:00
#endif
2017-06-06 03:33:01 +02:00
#ifdef USE_BCS
2018-08-24 13:42:18 +02:00
color.rgb = mix(vec3(0.0), color.rgb, bcs.x);
color.rgb = mix(vec3(0.5), color.rgb, bcs.y);
color.rgb = mix(vec3(dot(vec3(1.0), color.rgb) * 0.33333), color.rgb, bcs.z);
2017-06-06 03:33:01 +02:00
#endif
#ifdef USE_COLOR_CORRECTION
2018-08-24 13:42:18 +02:00
color.r = texture(color_correction, vec2(color.r, 0.0)).r;
color.g = texture(color_correction, vec2(color.g, 0.0)).g;
color.b = texture(color_correction, vec2(color.b, 0.0)).b;
2017-06-06 03:33:01 +02:00
#endif
2017-05-30 03:11:33 +02:00
#ifdef USE_MULTIPLIER
2018-08-24 13:42:18 +02:00
color.rgb *= multiplier;
2017-05-30 03:11:33 +02:00
#endif
2016-10-03 21:33:42 +02:00
frag_color = color;
}