27 lines
999 B
GLSL
27 lines
999 B
GLSL
#version 330 core
|
|
out vec4 FragColor;
|
|
|
|
in vec2 TexCoords;
|
|
|
|
uniform sampler2D screenTexture;
|
|
uniform float threshold;
|
|
|
|
void main()
|
|
{
|
|
// Averaged, since a quarter size target would otherwise skip most of the screen's pixels
|
|
vec2 texel = 1.0 / vec2(textureSize(screenTexture, 0));
|
|
vec3 color = (texture(screenTexture, TexCoords + texel * vec2(-1.0, -1.0)).rgb
|
|
+ texture(screenTexture, TexCoords + texel * vec2(1.0, -1.0)).rgb
|
|
+ texture(screenTexture, TexCoords + texel * vec2(-1.0, 1.0)).rgb
|
|
+ texture(screenTexture, TexCoords + texel * vec2(1.0, 1.0)).rgb) * 0.25;
|
|
|
|
// A single blown out specular pixel would otherwise flash a huge glow
|
|
color = min(color, vec3(20.0));
|
|
|
|
// Keeps the hue of whatever is over the threshold, and fades in instead of cutting off
|
|
float brightness = max(color.r, max(color.g, color.b));
|
|
float contribution = max(brightness - threshold, 0.0) / max(brightness, 1e-4);
|
|
|
|
FragColor = vec4(color * contribution, 1.0);
|
|
}
|