minetest/client/shaders/bloom_upsample/opengl_fragment.glsl
x2048 9b24041394
Improve bloom effect (#12916)
* Remove the built-in exposure factor of 2.5
* Add physics-based bloom (https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom)
* Add luminance scaling for bloom layer to simulate HDR
* Add setting to control bloom strength
2022-11-02 09:09:48 +01:00

36 lines
1.2 KiB
GLSL

#define current texture0
#define previous texture1
uniform sampler2D current;
uniform sampler2D previous;
uniform vec2 texelSize0;
uniform mediump float bloomRadius;
#ifdef GL_ES
varying mediump vec2 varTexCoord;
#else
centroid varying vec2 varTexCoord;
#endif
void main(void)
{
vec2 offset = bloomRadius * texelSize0;
vec3 a = texture2D(previous, varTexCoord.st + vec2(-1., -1.) * offset).rgb;
vec3 b = texture2D(previous, varTexCoord.st + vec2(0., -1.) * offset).rgb;
vec3 c = texture2D(previous, varTexCoord.st + vec2(1., -1.) * offset).rgb;
vec3 d = texture2D(previous, varTexCoord.st + vec2(-1., 0.) * offset).rgb;
vec3 e = texture2D(previous, varTexCoord.st + vec2(0., 0.) * offset).rgb;
vec3 f = texture2D(previous, varTexCoord.st + vec2(1., 0.) * offset).rgb;
vec3 g = texture2D(previous, varTexCoord.st + vec2(-1., 1.) * offset).rgb;
vec3 h = texture2D(previous, varTexCoord.st + vec2(0., 1.) * offset).rgb;
vec3 i = texture2D(previous, varTexCoord.st + vec2(1., 1.) * offset).rgb;
vec3 base = texture2D(current, varTexCoord.st).rgb;
gl_FragColor = max(vec4(base +
(a + c + g + i) * 0.0625 +
(b + d + f + h) * 0.125 +
e * 0.25, 1.), 1e-4);
}