diff options
| author | x2048 <codeforsmile@gmail.com> | 2022-11-02 09:09:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-02 09:09:48 +0100 |
| commit | 9b24041394ecf8210514845372d965f8d65302c9 (patch) | |
| tree | bdd8f6beea3ae775e3d2dbafa452257bd8f01ff9 /client/shaders/bloom_upsample | |
| parent | fb3085a2c593e0671e3322fe0e7d0914a052acef (diff) | |
| download | minetest-9b24041394ecf8210514845372d965f8d65302c9.tar.xz | |
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
Diffstat (limited to 'client/shaders/bloom_upsample')
| -rw-r--r-- | client/shaders/bloom_upsample/opengl_fragment.glsl | 35 | ||||
| -rw-r--r-- | client/shaders/bloom_upsample/opengl_vertex.glsl | 11 |
2 files changed, 46 insertions, 0 deletions
diff --git a/client/shaders/bloom_upsample/opengl_fragment.glsl b/client/shaders/bloom_upsample/opengl_fragment.glsl new file mode 100644 index 000000000..99ec8e205 --- /dev/null +++ b/client/shaders/bloom_upsample/opengl_fragment.glsl @@ -0,0 +1,35 @@ +#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); +} diff --git a/client/shaders/bloom_upsample/opengl_vertex.glsl b/client/shaders/bloom_upsample/opengl_vertex.glsl new file mode 100644 index 000000000..12692c296 --- /dev/null +++ b/client/shaders/bloom_upsample/opengl_vertex.glsl @@ -0,0 +1,11 @@ +#ifdef GL_ES +varying mediump vec2 varTexCoord; +#else +centroid varying vec2 varTexCoord; +#endif + +void main(void) +{ + varTexCoord.st = inTexCoord0.st; + gl_Position = inVertexPosition; +} |
