2020-11-18 19:11:30 +01:00
|
|
|
/* clang-format off */
|
2021-11-16 16:25:42 +01:00
|
|
|
#[modes]
|
|
|
|
|
2022-05-18 17:04:41 +02:00
|
|
|
mode_default = #define MODE_SIMPLE_COPY
|
2022-10-13 02:55:01 +02:00
|
|
|
mode_copy_section = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY
|
2023-11-11 00:17:26 +01:00
|
|
|
mode_copy_section_source = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY \n#define MODE_COPY_FROM
|
2022-05-18 17:04:41 +02:00
|
|
|
mode_gaussian_blur = #define MODE_GAUSSIAN_BLUR
|
|
|
|
mode_mipmap = #define MODE_MIPMAP
|
|
|
|
mode_simple_color = #define MODE_SIMPLE_COLOR \n#define USE_COPY_SECTION
|
2023-05-26 05:04:00 +02:00
|
|
|
mode_cube_to_octahedral = #define CUBE_TO_OCTAHEDRAL \n#define USE_COPY_SECTION
|
2024-01-19 21:39:26 +01:00
|
|
|
mode_cube_to_panorama = #define CUBE_TO_PANORAMA
|
2021-11-16 16:25:42 +01:00
|
|
|
|
|
|
|
#[specializations]
|
|
|
|
|
|
|
|
#[vertex]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2022-05-18 17:04:41 +02:00
|
|
|
layout(location = 0) in vec2 vertex_attrib;
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
out vec2 uv_interp;
|
2022-05-18 17:04:41 +02:00
|
|
|
/* clang-format on */
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2023-06-13 06:51:23 +02:00
|
|
|
#if defined(USE_COPY_SECTION) || defined(MODE_GAUSSIAN_BLUR)
|
|
|
|
// Defined in 0-1 coords.
|
2020-11-18 19:11:30 +01:00
|
|
|
uniform highp vec4 copy_section;
|
|
|
|
#endif
|
2023-11-11 00:17:26 +01:00
|
|
|
#if defined(MODE_GAUSSIAN_BLUR) || defined(MODE_COPY_FROM)
|
2023-06-13 06:51:23 +02:00
|
|
|
uniform highp vec4 source_section;
|
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
|
|
|
void main() {
|
2022-05-18 17:04:41 +02:00
|
|
|
uv_interp = vertex_attrib * 0.5 + 0.5;
|
|
|
|
gl_Position = vec4(vertex_attrib, 1.0, 1.0);
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2023-06-13 06:51:23 +02:00
|
|
|
#if defined(USE_COPY_SECTION) || defined(MODE_GAUSSIAN_BLUR)
|
2022-10-13 02:55:01 +02:00
|
|
|
gl_Position.xy = (copy_section.xy + uv_interp.xy * copy_section.zw) * 2.0 - 1.0;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2023-11-11 00:17:26 +01:00
|
|
|
#if defined(MODE_GAUSSIAN_BLUR) || defined(MODE_COPY_FROM)
|
2023-06-13 06:51:23 +02:00
|
|
|
uv_interp = source_section.xy + uv_interp * source_section.zw;
|
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clang-format off */
|
2021-11-16 16:25:42 +01:00
|
|
|
#[fragment]
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
in vec2 uv_interp;
|
2020-11-18 19:11:30 +01:00
|
|
|
/* clang-format on */
|
2022-05-18 17:04:41 +02:00
|
|
|
#ifdef MODE_SIMPLE_COLOR
|
|
|
|
uniform vec4 color_in;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2022-05-18 17:04:41 +02:00
|
|
|
#ifdef MODE_GAUSSIAN_BLUR
|
2023-06-13 06:51:23 +02:00
|
|
|
// Defined in 0-1 coords.
|
2022-05-18 17:04:41 +02:00
|
|
|
uniform highp vec2 pixel_size;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2023-05-26 05:04:00 +02:00
|
|
|
#ifdef CUBE_TO_OCTAHEDRAL
|
|
|
|
vec3 oct_to_vec3(vec2 e) {
|
|
|
|
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
|
|
|
|
float t = max(-v.z, 0.0);
|
|
|
|
v.xy += t * -sign(v.xy);
|
|
|
|
return normalize(v);
|
|
|
|
}
|
2024-01-19 21:39:26 +01:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
|
2024-01-19 21:39:26 +01:00
|
|
|
#ifdef CUBE_TO_PANORAMA
|
|
|
|
uniform lowp float mip_level;
|
2023-05-26 05:04:00 +02:00
|
|
|
#endif
|
|
|
|
|
2024-01-19 21:39:26 +01:00
|
|
|
#if defined(CUBE_TO_OCTAHEDRAL) || defined(CUBE_TO_PANORAMA)
|
|
|
|
uniform samplerCube source_cube; // texunit:0
|
|
|
|
|
|
|
|
#else // ~(defined(CUBE_TO_OCTAHEDRAL) || defined(CUBE_TO_PANORAMA))
|
|
|
|
uniform sampler2D source; // texunit:0
|
|
|
|
|
|
|
|
#endif // !(defined(CUBE_TO_OCTAHEDRAL) || defined(CUBE_TO_PANORAMA))
|
|
|
|
|
2021-10-26 17:18:39 +02:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2024-01-19 21:39:26 +01:00
|
|
|
// This expects 0-1 range input, outside that range it behaves poorly.
|
|
|
|
vec3 srgb_to_linear(vec3 color) {
|
|
|
|
// Approximation from http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
|
|
|
|
return color * (color * (color * 0.305306011 + 0.682171111) + 0.012522878);
|
|
|
|
}
|
|
|
|
|
2020-11-18 19:11:30 +01:00
|
|
|
void main() {
|
2022-05-18 17:04:41 +02:00
|
|
|
#ifdef MODE_SIMPLE_COPY
|
2021-10-26 17:18:39 +02:00
|
|
|
vec4 color = texture(source, uv_interp);
|
2022-05-18 17:04:41 +02:00
|
|
|
frag_color = color;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
|
|
|
|
2022-05-18 17:04:41 +02:00
|
|
|
#ifdef MODE_SIMPLE_COLOR
|
|
|
|
frag_color = color_in;
|
2020-11-18 19:11:30 +01:00
|
|
|
#endif
|
2023-06-13 06:51:23 +02:00
|
|
|
|
|
|
|
// Efficient box filter from Jimenez: http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare
|
|
|
|
// Approximates a Gaussian in a single pass.
|
|
|
|
#ifdef MODE_GAUSSIAN_BLUR
|
|
|
|
vec4 A = textureLod(source, uv_interp + pixel_size * vec2(-1.0, -1.0), 0.0);
|
|
|
|
vec4 B = textureLod(source, uv_interp + pixel_size * vec2(0.0, -1.0), 0.0);
|
|
|
|
vec4 C = textureLod(source, uv_interp + pixel_size * vec2(1.0, -1.0), 0.0);
|
|
|
|
vec4 D = textureLod(source, uv_interp + pixel_size * vec2(-0.5, -0.5), 0.0);
|
|
|
|
vec4 E = textureLod(source, uv_interp + pixel_size * vec2(0.5, -0.5), 0.0);
|
|
|
|
vec4 F = textureLod(source, uv_interp + pixel_size * vec2(-1.0, 0.0), 0.0);
|
|
|
|
vec4 G = textureLod(source, uv_interp, 0.0);
|
|
|
|
vec4 H = textureLod(source, uv_interp + pixel_size * vec2(1.0, 0.0), 0.0);
|
|
|
|
vec4 I = textureLod(source, uv_interp + pixel_size * vec2(-0.5, 0.5), 0.0);
|
|
|
|
vec4 J = textureLod(source, uv_interp + pixel_size * vec2(0.5, 0.5), 0.0);
|
|
|
|
vec4 K = textureLod(source, uv_interp + pixel_size * vec2(-1.0, 1.0), 0.0);
|
|
|
|
vec4 L = textureLod(source, uv_interp + pixel_size * vec2(0.0, 1.0), 0.0);
|
|
|
|
vec4 M = textureLod(source, uv_interp + pixel_size * vec2(1.0, 1.0), 0.0);
|
|
|
|
|
|
|
|
float weight = 0.5 / 4.0;
|
|
|
|
float lesser_weight = 0.125 / 4.0;
|
|
|
|
|
|
|
|
frag_color = (D + E + I + J) * weight;
|
|
|
|
frag_color += (A + B + G + F) * lesser_weight;
|
|
|
|
frag_color += (B + C + H + G) * lesser_weight;
|
|
|
|
frag_color += (F + G + L + K) * lesser_weight;
|
|
|
|
frag_color += (G + H + M + L) * lesser_weight;
|
|
|
|
#endif
|
2023-05-26 05:04:00 +02:00
|
|
|
|
|
|
|
#ifdef CUBE_TO_OCTAHEDRAL
|
|
|
|
// Treat the UV coordinates as 0-1 encoded octahedral coordinates.
|
|
|
|
vec3 dir = oct_to_vec3(uv_interp * 2.0 - 1.0);
|
|
|
|
frag_color = texture(source_cube, dir);
|
|
|
|
|
2024-01-19 21:39:26 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CUBE_TO_PANORAMA
|
|
|
|
|
|
|
|
const float PI = 3.14159265359;
|
|
|
|
|
|
|
|
float phi = uv_interp.x * 2.0 * PI;
|
|
|
|
float theta = uv_interp.y * PI;
|
|
|
|
|
|
|
|
vec3 normal;
|
|
|
|
normal.x = sin(phi) * sin(theta) * -1.0;
|
|
|
|
normal.y = cos(theta);
|
|
|
|
normal.z = cos(phi) * sin(theta) * -1.0;
|
|
|
|
|
|
|
|
vec3 color = srgb_to_linear(textureLod(source_cube, normal, mip_level).rgb);
|
|
|
|
frag_color = vec4(color, 1.0);
|
|
|
|
|
2023-05-26 05:04:00 +02:00
|
|
|
#endif
|
2020-11-18 19:11:30 +01:00
|
|
|
}
|