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
|
2023-11-10 23:17:26 +00:00
|
|
|
mode_copy_section_source = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY \n#define MODE_COPY_FROM
|
2023-08-07 08:41:09 +00:00
|
|
|
mode_copy_section_3d = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY \n#define USE_TEXTURE_3D
|
|
|
|
mode_copy_section_2d_array = #define USE_COPY_SECTION \n#define MODE_SIMPLE_COPY \n#define USE_TEXTURE_2D_ARRAY
|
2024-01-19 05:14:36 +00:00
|
|
|
mode_screen = #define MODE_SIMPLE_COPY \n#define MODE_MULTIPLY
|
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
|
2024-01-19 20:39:26 +00:00
|
|
|
mode_cube_to_panorama = #define CUBE_TO_PANORAMA
|
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-11-10 23:17:26 +00:00
|
|
|
#if defined(MODE_GAUSSIAN_BLUR) || defined(MODE_COPY_FROM)
|
2023-06-13 04:51:23 +00:00
|
|
|
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-11-10 23:17:26 +00:00
|
|
|
#if defined(MODE_GAUSSIAN_BLUR) || defined(MODE_COPY_FROM)
|
2023-06-13 04:51:23 +00:00
|
|
|
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 */
|
2023-08-07 08:41:09 +00:00
|
|
|
#if defined(USE_TEXTURE_3D) || defined(USE_TEXTURE_2D_ARRAY)
|
|
|
|
uniform float layer;
|
|
|
|
uniform float lod;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
2024-01-19 05:14:36 +00:00
|
|
|
#ifdef MODE_MULTIPLY
|
|
|
|
uniform float multiply;
|
|
|
|
#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
|
|
|
|
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 20:39:26 +00:00
|
|
|
#endif
|
2020-11-18 18:11:30 +00:00
|
|
|
|
2024-01-19 20:39:26 +00:00
|
|
|
#ifdef CUBE_TO_PANORAMA
|
|
|
|
uniform lowp float mip_level;
|
2023-05-26 03:04:00 +00:00
|
|
|
#endif
|
|
|
|
|
2024-01-19 20:39:26 +00: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))
|
2023-08-07 08:41:09 +00:00
|
|
|
|
|
|
|
#if defined(USE_TEXTURE_3D)
|
|
|
|
uniform sampler3D source_3d; // texunit:0
|
|
|
|
#elif defined(USE_TEXTURE_2D_ARRAY)
|
|
|
|
uniform sampler2DArray source_2d_array; // texunit:0
|
|
|
|
#else
|
2024-01-19 20:39:26 +00:00
|
|
|
uniform sampler2D source; // texunit:0
|
2023-08-07 08:41:09 +00:00
|
|
|
#endif
|
2024-01-19 20:39:26 +00:00
|
|
|
|
|
|
|
#endif // !(defined(CUBE_TO_OCTAHEDRAL) || defined(CUBE_TO_PANORAMA))
|
|
|
|
|
2021-10-26 15:18:39 +00:00
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
2024-01-19 20:39:26 +00: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 18:11:30 +00:00
|
|
|
void main() {
|
2022-05-18 15:04:41 +00:00
|
|
|
#ifdef MODE_SIMPLE_COPY
|
2023-08-07 08:41:09 +00:00
|
|
|
|
|
|
|
#ifdef USE_TEXTURE_3D
|
|
|
|
vec4 color = textureLod(source_3d, vec3(uv_interp, layer), lod);
|
|
|
|
#elif defined(USE_TEXTURE_2D_ARRAY)
|
|
|
|
vec4 color = textureLod(source_2d_array, vec3(uv_interp, layer), lod);
|
|
|
|
#else
|
2021-10-26 15:18:39 +00:00
|
|
|
vec4 color = texture(source, uv_interp);
|
2024-01-19 05:14:36 +00:00
|
|
|
#endif // USE_TEXTURE_3D
|
|
|
|
|
|
|
|
#ifdef MODE_MULTIPLY
|
|
|
|
color *= multiply;
|
|
|
|
#endif // MODE_MULTIPLY
|
2023-08-07 08:41:09 +00:00
|
|
|
|
2022-05-18 15:04:41 +00:00
|
|
|
frag_color = color;
|
2024-01-19 05:14:36 +00:00
|
|
|
#endif // MODE_SIMPLE_COPY
|
2020-11-18 18:11:30 +00:00
|
|
|
|
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);
|
|
|
|
|
2024-01-19 20:39:26 +00: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 03:04:00 +00:00
|
|
|
#endif
|
2020-11-18 18:11:30 +00:00
|
|
|
}
|