mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 22:09:28 -07:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
struct Config {
|
||||
bloomStrength : f32;
|
||||
pyramidHeight : f32;
|
||||
};
|
||||
|
||||
@@ -63,5 +62,5 @@ struct ComputeInput {
|
||||
sum = sum + textureSampleLevel( tex4, linearSampler, uv, i + 1.0 ) * weight;
|
||||
}
|
||||
|
||||
textureStore(outputTex, coord, sum * config.bloomStrength);
|
||||
textureStore(outputTex, coord, sum);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
[[group(0), binding(0)]] var linearSampler : sampler;
|
||||
[[group(0), binding(1)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(2)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(3)]] var backgroundTex : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
struct Config {
|
||||
bloomStrength : f32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> config : Config;
|
||||
[[group(0), binding(1)]] var linearSampler : sampler;
|
||||
[[group(0), binding(2)]] var tex : texture_2d<f32>;
|
||||
[[group(0), binding(3)]] var bloomTex : texture_2d<f32>;
|
||||
[[group(0), binding(4)]] var backgroundTex : texture_2d<f32>;
|
||||
[[group(0), binding(5)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
struct ComputeInput {
|
||||
[[builtin(global_invocation_id)]] id : vec3<u32>;
|
||||
};
|
||||
|
||||
fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
var primary = textureSampleLevel(tex, linearSampler, uv, 0.0);
|
||||
var bloom = textureSampleLevel(bloomTex, linearSampler, uv, 0.0) * config.bloomStrength;
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(1.0));
|
||||
}
|
||||
|
||||
[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) {
|
||||
|
||||
// Resolve the invocation ID to a texel coordinate
|
||||
@@ -23,8 +34,7 @@ struct ComputeInput {
|
||||
var bgColor = textureSampleLevel( backgroundTex, linearSampler, uv, 0.0 ).rgb;
|
||||
|
||||
// Combine the texture and bloom, then blow it out to reveal more of the image
|
||||
var brightness = min(1.0, textureSampleLevel( tex, linearSampler, uv, 0.0 ).r * 2.0);
|
||||
brightness = brightness + textureSampleLevel( bloomTex, linearSampler, uv, 0.0 ).r;
|
||||
var brightness = getBrightness(uv).r;
|
||||
brightness = pow(brightness, 1.5);
|
||||
|
||||
textureStore(outputTex, coord, vec4<f32>(bgColor * brightness, 1.0));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
struct Config {
|
||||
bloomStrength : f32;
|
||||
ditherMagnitude : f32;
|
||||
backgroundColor : vec3<f32>;
|
||||
};
|
||||
@@ -35,6 +36,11 @@ fn randomFloat( uv : vec2<f32> ) -> f32 {
|
||||
return fract(sin(sn) * c);
|
||||
}
|
||||
|
||||
fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
var primary = textureSampleLevel(tex, linearSampler, uv, 0.0);
|
||||
var bloom = textureSampleLevel(bloomTex, linearSampler, uv, 0.0) * config.bloomStrength;
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(1.0));
|
||||
}
|
||||
|
||||
[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) {
|
||||
|
||||
@@ -48,7 +54,7 @@ fn randomFloat( uv : vec2<f32> ) -> f32 {
|
||||
|
||||
var uv = vec2<f32>(coord) / vec2<f32>(screenSize);
|
||||
|
||||
var brightnessRGB = textureSampleLevel( tex, linearSampler, uv, 0.0 ) + textureSampleLevel( bloomTex, linearSampler, uv, 0.0 );
|
||||
var brightnessRGB = getBrightness(uv);
|
||||
|
||||
// Combine the texture and bloom
|
||||
var brightness = brightnessRGB.r + brightnessRGB.g + brightnessRGB.b;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
struct Config {
|
||||
bloomStrength : f32;
|
||||
ditherMagnitude : f32;
|
||||
backgroundColor : vec3<f32>;
|
||||
};
|
||||
@@ -71,7 +72,7 @@ fn hslToRgb(h : f32, s : f32, l : f32) -> vec3<f32> {
|
||||
// to approximate a lens blur
|
||||
var brightness = mix(
|
||||
textureSampleLevel( tex, linearSampler, uv, 0.0 ).rgb,
|
||||
textureSampleLevel( bloomTex, linearSampler, uv, 0.0 ).rgb,
|
||||
textureSampleLevel( bloomTex, linearSampler, uv, 0.0 ).rgb * config.bloomStrength,
|
||||
(0.7 - length(uv - 0.5))
|
||||
) * 1.25;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
struct Config {
|
||||
bloomStrength : f32;
|
||||
ditherMagnitude : f32;
|
||||
backgroundColor : vec3<f32>;
|
||||
};
|
||||
@@ -31,6 +32,12 @@ fn randomFloat( uv : vec2<f32> ) -> f32 {
|
||||
return fract(sin(sn) * c);
|
||||
}
|
||||
|
||||
fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
|
||||
var primary = textureSampleLevel(tex, linearSampler, uv, 0.0);
|
||||
var bloom = textureSampleLevel(bloomTex, linearSampler, uv, 0.0) * config.bloomStrength;
|
||||
return min((primary + bloom) * (2.0 - config.bloomStrength), vec4<f32>(1.0));
|
||||
}
|
||||
|
||||
[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain(input : ComputeInput) {
|
||||
|
||||
// Resolve the invocation ID to a texel coordinate
|
||||
@@ -45,9 +52,7 @@ fn randomFloat( uv : vec2<f32> ) -> f32 {
|
||||
|
||||
var color = textureSampleLevel( stripeTexture, linearSampler, uv, 0.0 ).rgb;
|
||||
|
||||
// Combine the texture and bloom
|
||||
var brightness = min(1.0, textureSampleLevel( tex, linearSampler, uv, 0.0 ).r * 2.0);
|
||||
brightness = brightness + textureSampleLevel( bloomTex, linearSampler, uv, 0.0 ).r;
|
||||
var brightness = getBrightness(uv).r;
|
||||
|
||||
// Dither: subtract a random value from the brightness
|
||||
brightness = brightness - randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
|
||||
|
||||
Reference in New Issue
Block a user