The primary and bloom textures are now combined with a weight so that fainter bloom doesn't create a fainter overall effect.

This commit is contained in:
Rezmason
2021-12-24 21:33:39 -08:00
parent a962a6128d
commit 928067996d
20 changed files with 113 additions and 35 deletions

View File

@@ -2,13 +2,20 @@ precision mediump float;
uniform sampler2D tex;
uniform sampler2D bloomTex;
uniform sampler2D backgroundTex;
uniform float bloomStrength;
varying vec2 vUV;
vec4 getBrightness(vec2 uv) {
vec4 primary = texture2D(tex, uv);
vec4 bloom = texture2D(bloomTex, uv) * bloomStrength;
return min((primary + bloom) * (2.0 - bloomStrength), 1.0);
}
void main() {
vec3 bgColor = texture2D(backgroundTex, vUV).rgb;
// Combine the texture and bloom, then blow it out to reveal more of the image
float brightness = pow(min(1., texture2D(tex, vUV).r * 2.) + texture2D(bloomTex, vUV).r, 1.5);
float brightness = pow(getBrightness(vUV).r, 1.5);
gl_FragColor = vec4(bgColor * brightness, 1.0);
}

View File

@@ -4,6 +4,7 @@ precision mediump float;
uniform sampler2D tex;
uniform sampler2D bloomTex;
uniform sampler2D palette;
uniform float bloomStrength;
uniform float ditherMagnitude;
uniform float time;
uniform vec3 backgroundColor;
@@ -15,8 +16,14 @@ highp float rand( const in vec2 uv, const in float t ) {
return fract(sin(sn) * c + t);
}
vec4 getBrightness(vec2 uv) {
vec4 primary = texture2D(tex, uv);
vec4 bloom = texture2D(bloomTex, uv) * bloomStrength;
return min((primary + bloom) * (2.0 - bloomStrength), 1.0);
}
void main() {
vec4 brightnessRGB = texture2D( tex, vUV ) + texture2D( bloomTex, vUV );
vec4 brightnessRGB = getBrightness(vUV);
// Combine the texture and bloom
float brightness = brightnessRGB.r + brightnessRGB.g + brightnessRGB.b;

View File

@@ -3,6 +3,7 @@ precision mediump float;
uniform sampler2D tex;
uniform sampler2D bloomTex;
uniform float bloomStrength;
uniform float ditherMagnitude;
uniform float time;
uniform vec3 backgroundColor;
@@ -38,7 +39,7 @@ void main() {
// Mix the texture and bloom based on distance from center,
// to approximate a lens blur
vec3 brightness = mix(
texture2D( bloomTex, vUV ).rgb,
texture2D( bloomTex, vUV ).rgb * bloomStrength,
texture2D( tex, vUV ).rgb,
(0.7 - length(vUV - 0.5))
) * 1.25;

View File

@@ -3,6 +3,7 @@ precision mediump float;
uniform sampler2D tex;
uniform sampler2D bloomTex;
uniform float bloomStrength;
uniform sampler2D stripes;
uniform float ditherMagnitude;
uniform float time;
@@ -15,10 +16,16 @@ highp float rand( const in vec2 uv, const in float t ) {
return fract(sin(sn) * c + t);
}
vec4 getBrightness(vec2 uv) {
vec4 primary = texture2D(tex, uv);
vec4 bloom = texture2D(bloomTex, uv) * bloomStrength;
return min((primary + bloom) * (2.0 - bloomStrength), 1.0);
}
void main() {
vec3 color = texture2D(stripes, vUV).rgb;
// Combine the texture and bloom
float brightness = min(1., texture2D(tex, vUV).r * 2.) + texture2D(bloomTex, vUV).r;
float brightness = getBrightness(vUV).r;
// Dither: subtract a random value from the brightness
brightness = brightness - rand( gl_FragCoord.xy, time ) * ditherMagnitude;