2024-01-19 16:14:36 +11:00
|
|
|
/* clang-format off */
|
|
|
|
|
#[modes]
|
2024-05-08 10:04:47 +02:00
|
|
|
mode_default =
|
2024-01-19 16:14:36 +11:00
|
|
|
|
|
|
|
|
#[specializations]
|
|
|
|
|
|
|
|
|
|
USE_MULTIVIEW = false
|
|
|
|
|
USE_GLOW = false
|
|
|
|
|
USE_LUMINANCE_MULTIPLIER = false
|
2024-04-25 12:24:51 -07:00
|
|
|
USE_BCS = false
|
|
|
|
|
USE_COLOR_CORRECTION = false
|
|
|
|
|
USE_1D_LUT = false
|
2024-01-19 16:14:36 +11:00
|
|
|
|
|
|
|
|
#[vertex]
|
|
|
|
|
layout(location = 0) in vec2 vertex_attrib;
|
|
|
|
|
|
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
|
|
out vec2 uv_interp;
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
uv_interp = vertex_attrib * 0.5 + 0.5;
|
|
|
|
|
gl_Position = vec4(vertex_attrib, 1.0, 1.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* clang-format off */
|
|
|
|
|
#[fragment]
|
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
2024-04-25 12:24:51 -07:00
|
|
|
// If we reach this code, we always tonemap.
|
|
|
|
|
#define APPLY_TONEMAPPING
|
|
|
|
|
|
2024-01-19 16:14:36 +11:00
|
|
|
#include "../tonemap_inc.glsl"
|
|
|
|
|
|
|
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
|
uniform sampler2DArray source_color; // texunit:0
|
|
|
|
|
#else
|
|
|
|
|
uniform sampler2D source_color; // texunit:0
|
|
|
|
|
#endif // USE_MULTIVIEW
|
|
|
|
|
|
|
|
|
|
uniform float view;
|
|
|
|
|
uniform float luminance_multiplier;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_GLOW
|
|
|
|
|
uniform sampler2D glow_color; // texunit:1
|
|
|
|
|
uniform vec2 pixel_size;
|
|
|
|
|
uniform float glow_intensity;
|
2025-09-17 17:09:46 -04:00
|
|
|
uniform float srgb_white;
|
2024-01-19 16:14:36 +11:00
|
|
|
|
|
|
|
|
vec4 get_glow_color(vec2 uv) {
|
|
|
|
|
vec2 half_pixel = pixel_size * 0.5;
|
|
|
|
|
|
|
|
|
|
vec4 color = textureLod(glow_color, uv + vec2(-half_pixel.x * 2.0, 0.0), 0.0);
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(-half_pixel.x, half_pixel.y), 0.0) * 2.0;
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(0.0, half_pixel.y * 2.0), 0.0);
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(half_pixel.x, half_pixel.y), 0.0) * 2.0;
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(half_pixel.x * 2.0, 0.0), 0.0);
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(half_pixel.x, -half_pixel.y), 0.0) * 2.0;
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(0.0, -half_pixel.y * 2.0), 0.0);
|
|
|
|
|
color += textureLod(glow_color, uv + vec2(-half_pixel.x, -half_pixel.y), 0.0) * 2.0;
|
|
|
|
|
|
2025-09-17 17:09:46 -04:00
|
|
|
#ifdef USE_LUMINANCE_MULTIPLIER
|
|
|
|
|
color = color / luminance_multiplier;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-19 16:14:36 +11:00
|
|
|
return color / 12.0;
|
|
|
|
|
}
|
|
|
|
|
#endif // USE_GLOW
|
|
|
|
|
|
2024-04-25 12:24:51 -07:00
|
|
|
#ifdef USE_COLOR_CORRECTION
|
|
|
|
|
#ifdef USE_1D_LUT
|
|
|
|
|
uniform sampler2D source_color_correction; //texunit:2
|
|
|
|
|
|
|
|
|
|
vec3 apply_color_correction(vec3 color) {
|
|
|
|
|
color.r = texture(source_color_correction, vec2(color.r, 0.0f)).r;
|
|
|
|
|
color.g = texture(source_color_correction, vec2(color.g, 0.0f)).g;
|
|
|
|
|
color.b = texture(source_color_correction, vec2(color.b, 0.0f)).b;
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
uniform sampler3D source_color_correction; //texunit:2
|
|
|
|
|
|
|
|
|
|
vec3 apply_color_correction(vec3 color) {
|
|
|
|
|
return textureLod(source_color_correction, color, 0.0).rgb;
|
|
|
|
|
}
|
|
|
|
|
#endif // USE_1D_LUT
|
|
|
|
|
#endif // USE_COLOR_CORRECTION
|
|
|
|
|
|
|
|
|
|
#ifdef USE_BCS
|
|
|
|
|
vec3 apply_bcs(vec3 color) {
|
|
|
|
|
color = mix(vec3(0.0), color, brightness);
|
|
|
|
|
color = mix(vec3(0.5), color, contrast);
|
|
|
|
|
color = mix(vec3(dot(vec3(1.0), color) * 0.33333), color, saturation);
|
|
|
|
|
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-19 16:14:36 +11:00
|
|
|
in vec2 uv_interp;
|
|
|
|
|
|
|
|
|
|
layout(location = 0) out vec4 frag_color;
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
#ifdef USE_MULTIVIEW
|
|
|
|
|
vec4 color = texture(source_color, vec3(uv_interp, view));
|
|
|
|
|
#else
|
|
|
|
|
vec4 color = texture(source_color, uv_interp);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-09-17 17:09:46 -04:00
|
|
|
#ifdef USE_LUMINANCE_MULTIPLIER
|
|
|
|
|
color = color / luminance_multiplier;
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-19 16:14:36 +11:00
|
|
|
#ifdef USE_GLOW
|
2025-09-17 17:09:46 -04:00
|
|
|
// Glow blending is performed before srgb_to_linear because
|
|
|
|
|
// the glow texture was created from a nonlinear sRGB-encoded
|
|
|
|
|
// scene, so it only makes sense to add this glow to an equally
|
|
|
|
|
// nonlinear sRGB-encoded scene.
|
|
|
|
|
|
2024-01-19 16:14:36 +11:00
|
|
|
vec4 glow = get_glow_color(uv_interp) * glow_intensity;
|
|
|
|
|
|
2025-09-17 17:09:46 -04:00
|
|
|
// Glow always uses the screen blend mode in the Compatibility renderer:
|
2024-01-19 16:14:36 +11:00
|
|
|
|
2025-09-17 17:09:46 -04:00
|
|
|
// Glow cannot be above 1.0 after normalizing and should be non-negative
|
|
|
|
|
// to produce expected results. It is possible that glow can be negative
|
|
|
|
|
// if negative lights were used in the scene.
|
|
|
|
|
// We clamp to srgb_white because glow will be normalized to this range.
|
|
|
|
|
// Note: srgb_white cannot be smaller than the maximum output value (1.0).
|
|
|
|
|
glow.rgb = clamp(glow.rgb, 0.0, srgb_white);
|
|
|
|
|
|
|
|
|
|
// Normalize to srgb_white range.
|
|
|
|
|
//glow.rgb /= srgb_white;
|
|
|
|
|
//color.rgb /= srgb_white;
|
|
|
|
|
//color.rgb = (color.rgb + glow.rgb) - (color.rgb * glow.rgb);
|
|
|
|
|
// Expand back to original range.
|
|
|
|
|
//color.rgb *= srgb_white;
|
|
|
|
|
|
|
|
|
|
// The following is a mathematically simplified version of the above.
|
|
|
|
|
color.rgb = color.rgb + glow.rgb - (color.rgb * glow.rgb / srgb_white);
|
|
|
|
|
#endif // USE_GLOW
|
2024-01-19 16:14:36 +11:00
|
|
|
|
|
|
|
|
color.rgb = srgb_to_linear(color.rgb);
|
|
|
|
|
color.rgb = apply_tonemapping(color.rgb, white);
|
|
|
|
|
color.rgb = linear_to_srgb(color.rgb);
|
|
|
|
|
|
|
|
|
|
#ifdef USE_BCS
|
2024-04-25 12:24:51 -07:00
|
|
|
color.rgb = apply_bcs(color.rgb);
|
2024-01-19 16:14:36 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef USE_COLOR_CORRECTION
|
2024-04-25 12:24:51 -07:00
|
|
|
color.rgb = apply_color_correction(color.rgb);
|
2024-01-19 16:14:36 +11:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
frag_color = color;
|
|
|
|
|
}
|