mirror of
https://github.com/godotengine/godot.git
synced 2024-12-27 11:24:59 +08:00
97 lines
2.4 KiB
GLSL
97 lines
2.4 KiB
GLSL
/* clang-format off */
|
|
#[modes]
|
|
mode_default = #define MODE_DEFAULT
|
|
// mode_glow = #define MODE_GLOW
|
|
|
|
#[specializations]
|
|
|
|
USE_MULTIVIEW = false
|
|
USE_GLOW = false
|
|
USE_LUMINANCE_MULTIPLIER = false
|
|
|
|
#[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 */
|
|
|
|
#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;
|
|
|
|
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;
|
|
|
|
return color / 12.0;
|
|
}
|
|
#endif // USE_GLOW
|
|
|
|
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
|
|
|
|
#ifdef USE_GLOW
|
|
vec4 glow = get_glow_color(uv_interp) * glow_intensity;
|
|
|
|
// Just use softlight...
|
|
glow.rgb = clamp(glow.rgb, vec3(0.0f), vec3(1.0f));
|
|
color.rgb = max((color.rgb + glow.rgb) - (color.rgb * glow.rgb), vec3(0.0));
|
|
#endif // USE_GLOW
|
|
|
|
#ifdef USE_LUMINANCE_MULTIPLIER
|
|
color = color / luminance_multiplier;
|
|
#endif
|
|
|
|
color.rgb = srgb_to_linear(color.rgb);
|
|
color.rgb = apply_tonemapping(color.rgb, white);
|
|
color.rgb = linear_to_srgb(color.rgb);
|
|
|
|
#ifdef USE_BCS
|
|
color.rgb = apply_bcs(color.rgb, bcs);
|
|
#endif
|
|
|
|
#ifdef USE_COLOR_CORRECTION
|
|
color.rgb = apply_color_correction(color.rgb, color_correction);
|
|
#endif
|
|
|
|
frag_color = color;
|
|
}
|