2020-11-18 18:11:30 +00:00
|
|
|
/* clang-format off */
|
2021-11-16 15:25:42 +00:00
|
|
|
#[modes]
|
|
|
|
|
2022-05-18 15:04:41 +00:00
|
|
|
mode_default = #define MODE_SIMPLE_COPY
|
2022-10-13 00:55:01 +00:00
|
|
|
mode_copy_section = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY
|
2022-05-18 15:04:41 +00: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 03:04:00 +00:00
|
|
|
mode_cube_to_octahedral = #define CUBE_TO_OCTAHEDRAL \n#define USE_COPY_SECTION
|
2021-11-16 15:25:42 +00:00
|
|
|
|
|
|
|
#[specializations]
|
|
|
|
|
|
|
|
#[vertex]
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2022-05-18 15:04:41 +00:00
|
|
|
layout(location = 0) in vec2 vertex_attrib;
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2021-10-26 15:18:39 +00:00
|
|
|
out vec2 uv_interp;
|
2022-05-18 15:04:41 +00:00
|
|
|
/* clang-format on */
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2023-06-13 04:51:23 +00:00
|
|
|
#if defined(USE_COPY_SECTION) || defined(MODE_GAUSSIAN_BLUR)
|
|
|
|
// Defined in 0-1 coords.
|
2020-11-18 18:11:30 +00:00
|
|
|
uniform highp vec4 copy_section;
|
|
|
|
#endif
|
2023-06-13 04:51:23 +00:00
|
|
|
#ifdef MODE_GAUSSIAN_BLUR
|
|
|
|
uniform highp vec4 source_section;
|
|
|
|
#endif
|
2020-11-18 18:11:30 +00:00
|
|
|
|
|
|
|
void main() {
|
2022-05-18 15:04:41 +00:00
|
|
|
uv_interp = vertex_attrib * 0.5 + 0.5;
|
|
|
|
gl_Position = vec4(vertex_attrib, 1.0, 1.0);
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2023-06-13 04:51:23 +00:00
|
|
|
#if defined(USE_COPY_SECTION) || defined(MODE_GAUSSIAN_BLUR)
|
2022-10-13 00:55:01 +00:00
|
|
|
gl_Position.xy = (copy_section.xy + uv_interp.xy * copy_section.zw) * 2.0 - 1.0;
|
2020-11-18 18:11:30 +00:00
|
|
|
#endif
|
2023-06-13 04:51:23 +00:00
|
|
|
#ifdef MODE_GAUSSIAN_BLUR
|
|
|
|
uv_interp = source_section.xy + uv_interp * source_section.zw;
|
|
|
|
#endif
|
2020-11-18 18:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* clang-format off */
|
2021-11-16 15:25:42 +00:00
|
|
|
#[fragment]
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2021-10-26 15:18:39 +00:00
|
|
|
in vec2 uv_interp;
|
2020-11-18 18:11:30 +00:00
|
|
|
/* clang-format on */
|
2022-05-18 15:04:41 +00:00
|
|
|
#ifdef MODE_SIMPLE_COLOR
|
|
|
|
uniform vec4 color_in;
|
2020-11-18 18:11:30 +00:00
|
|
|
#endif
|
|
|
|
|
2022-05-18 15:04:41 +00:00
|
|
|
#ifdef MODE_GAUSSIAN_BLUR
|
2023-06-13 04:51:23 +00:00
|
|
|
// Defined in 0-1 coords.
|
2022-05-18 15:04:41 +00:00
|
|
|
uniform highp vec2 pixel_size;
|
2020-11-18 18:11:30 +00:00
|
|
|
#endif
|
|
|
|
|
2023-05-26 03:04:00 +00:00
|
|
|
#ifdef CUBE_TO_OCTAHEDRAL
|
|
|
|
uniform samplerCube source_cube; // texunit:0
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
#else
|
2022-05-18 15:04:41 +00:00
|
|
|
uniform sampler2D source; // texunit:0
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2023-05-26 03:04:00 +00:00
|
|
|
#endif
|
|
|
|
|
2021-10-26 15:18:39 +00:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2020-11-18 18:11:30 +00:00
|
|
|
void main() {
|
2022-05-18 15:04:41 +00:00
|
|
|
#ifdef MODE_SIMPLE_COPY
|
2021-10-26 15:18:39 +00:00
|
|
|
vec4 color = texture(source, uv_interp);
|
2022-05-18 15:04:41 +00:00
|
|
|
frag_color = color;
|
2020-11-18 18:11:30 +00:00
|
|
|
#endif
|
|
|
|
|
2022-05-18 15:04:41 +00:00
|
|
|
#ifdef MODE_SIMPLE_COLOR
|
|
|
|
frag_color = color_in;
|
2020-11-18 18:11:30 +00:00
|
|
|
#endif
|
2023-06-13 04:51:23 +00: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 03:04:00 +00: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);
|
|
|
|
|
|
|
|
#endif
|
2020-11-18 18:11:30 +00:00
|
|
|
}
|