Skip to content

Commit

Permalink
Make bloom shaders compatible with GLES2 (minetest#12834)
Browse files Browse the repository at this point in the history
Co-authored-by: Muhammad Rifqi Priyo Susanto <[email protected]>
  • Loading branch information
x2048 and srifqi committed Oct 4, 2022
1 parent 7632af3 commit 579fc93
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/shaders/blur_h/opengl_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

uniform sampler2D rendered;
uniform vec2 texelSize0;
uniform mediump float bloomRadius = 3.0;
uniform mediump float bloomRadius;

#ifdef GL_ES
varying mediump vec2 varTexCoord;
Expand Down
2 changes: 1 addition & 1 deletion client/shaders/blur_v/opengl_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

uniform sampler2D rendered;
uniform vec2 texelSize0;
uniform mediump float bloomRadius = 3.0;
uniform mediump float bloomRadius;

#ifdef GL_ES
varying mediump vec2 varTexCoord;
Expand Down
4 changes: 2 additions & 2 deletions client/shaders/extract_bloom/opengl_fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define rendered texture0

uniform sampler2D rendered;
uniform mediump float exposureFactor = 2.5;
uniform float bloomLuminanceThreshold = 1.0;
uniform mediump float exposureFactor;
uniform float bloomLuminanceThreshold;

#ifdef GL_ES
varying mediump vec2 varTexCoord;
Expand Down
18 changes: 9 additions & 9 deletions client/shaders/second_stage/opengl_fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

uniform sampler2D rendered;
uniform sampler2D bloom;
uniform mediump float exposureFactor = 2.5;
uniform lowp float bloomIntensity = 1.0;
uniform mediump float exposureFactor;
uniform lowp float bloomIntensity;

#ifdef GL_ES
varying mediump vec2 varTexCoord;
#else
centroid varying vec2 varTexCoord;
#endif

#if ENABLE_BLOOM
#ifdef ENABLE_BLOOM

vec4 applyBloom(vec4 color, vec2 uv)
{
float bias = bloomIntensity;
vec4 bloom = texture2D(bloom, uv);
#if ENABLE_BLOOM_DEBUG
#ifdef ENABLE_BLOOM_DEBUG
if (uv.x > 0.5 && uv.y < 0.5)
return vec4(bloom.rgb, color.a);
if (uv.x < 0.5)
Expand All @@ -30,7 +30,7 @@ vec4 applyBloom(vec4 color, vec2 uv)

#endif

#if ENABLE_TONE_MAPPING
#ifdef ENABLE_TONE_MAPPING

/* Hable's UC2 Tone mapping parameters
A = 0.22;
Expand Down Expand Up @@ -68,23 +68,23 @@ void main(void)
// translate to linear colorspace (approximate)
color.rgb = pow(color.rgb, vec3(2.2));

#if ENABLE_BLOOM_DEBUG
#ifdef ENABLE_BLOOM_DEBUG
if (uv.x > 0.5 || uv.y > 0.5)
#endif
{
color.rgb *= exposureFactor;
}


#if ENABLE_BLOOM
#ifdef ENABLE_BLOOM
color = applyBloom(color, uv);
#endif

#if ENABLE_BLOOM_DEBUG
#ifdef ENABLE_BLOOM_DEBUG
if (uv.x > 0.5 || uv.y > 0.5)
#endif
{
#if ENABLE_TONE_MAPPING
#ifdef ENABLE_TONE_MAPPING
color = applyToneMapping(color);
#else
color.rgb /= 2.5; // default exposure factor, see also RenderingEngine::DEFAULT_EXPOSURE_FACTOR;
Expand Down

0 comments on commit 579fc93

Please sign in to comment.