1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2026-02-08 00:32:27 +00:00

Fix some bloom behaviour issues and simplify effects colorization.

This commit is contained in:
Filippo Scognamiglio
2025-12-24 19:14:15 +01:00
parent 384fb1da7c
commit a8ec5d6f16
75 changed files with 49 additions and 89 deletions

View File

@@ -59,18 +59,16 @@ for(raster_mode, RASTER_MODES) {
} }
for(rgb_shift, BINARY_FLAGS) { for(rgb_shift, BINARY_FLAGS) {
for(chroma_on, BINARY_FLAGS) { for(bloom_on, BINARY_FLAGS) {
for(bloom_on, BINARY_FLAGS) { for(curve_on, BINARY_FLAGS) {
for(curve_on, BINARY_FLAGS) { for(shine_on, BINARY_FLAGS) {
for(shine_on, BINARY_FLAGS) { static_variant = terminal_static_rgb$${rgb_shift}_bloom$${bloom_on}_curve$${curve_on}_shine$${shine_on}
static_variant = terminal_static_rgb$${rgb_shift}_chroma$${chroma_on}_bloom$${bloom_on}_curve$${curve_on}_shine$${shine_on} static_output = $${VARIANT_SHADER_DIR}/$${static_variant}.frag.qsb
static_output = $${VARIANT_SHADER_DIR}/$${static_variant}.frag.qsb static_target = shader_variant_$${static_variant}
static_target = shader_variant_$${static_variant} $${static_target}.target = $${static_output}
$${static_target}.target = $${static_output} $${static_target}.depends = $$STATIC_SHADER
$${static_target}.depends = $$STATIC_SHADER $${static_target}.commands = $$QSB_BIN --glsl \"100 es,120,150\" --hlsl 50 --msl 12 --qt6 -DCRT_RGB_SHIFT=$${rgb_shift} -DCRT_BLOOM=$${bloom_on} -DCRT_CURVATURE=$${curve_on} -DCRT_FRAME_SHININESS=$${shine_on} -o $${static_output} $$STATIC_SHADER
$${static_target}.commands = $$QSB_BIN --glsl \"100 es,120,150\" --hlsl 50 --msl 12 --qt6 -DCRT_RGB_SHIFT=$${rgb_shift} -DCRT_CHROMA=$${chroma_on} -DCRT_BLOOM=$${bloom_on} -DCRT_CURVATURE=$${curve_on} -DCRT_FRAME_SHININESS=$${shine_on} -o $${static_output} $$STATIC_SHADER QMAKE_EXTRA_TARGETS += $${static_target}
QMAKE_EXTRA_TARGETS += $${static_target}
}
} }
} }
} }

View File

@@ -37,12 +37,10 @@ Item {
function staticFragmentPath() { function staticFragmentPath() {
var rgbShiftOn = appSettings.rbgShift > 0 ? 1 : 0; var rgbShiftOn = appSettings.rbgShift > 0 ? 1 : 0;
var chromaOn = appSettings.chromaColor > 0 ? 1 : 0;
var bloomOn = appSettings.bloom > 0 ? 1 : 0; var bloomOn = appSettings.bloom > 0 ? 1 : 0;
var curvatureOn = (appSettings.screenCurvature > 0 || appSettings.frameSize > 0) ? 1 : 0; var curvatureOn = (appSettings.screenCurvature > 0 || appSettings.frameSize > 0) ? 1 : 0;
var shineOn = appSettings.frameShininess > 0 ? 1 : 0; var shineOn = appSettings.frameShininess > 0 ? 1 : 0;
return "qrc:/shaders/terminal_static_rgb" + rgbShiftOn + return "qrc:/shaders/terminal_static_rgb" + rgbShiftOn +
"_chroma" + chromaOn +
"_bloom" + bloomOn + "_bloom" + bloomOn +
"_curve" + curvatureOn + "_curve" + curvatureOn +
"_shine" + shineOn + "_shine" + shineOn +
@@ -112,6 +110,7 @@ Item {
property real frameSize: appSettings.frameSize property real frameSize: appSettings.frameSize
property real frameShininess: appSettings.frameShininess property real frameShininess: appSettings.frameShininess
property real bloom: parent.bloomSource ? appSettings.bloom * 2.5 : 0
anchors.fill: parent anchors.fill: parent
blending: false blending: false

View File

@@ -80,38 +80,22 @@
<file>../shaders/terminal_dynamic_raster3_burn1_frame0_chroma1.frag.qsb</file> <file>../shaders/terminal_dynamic_raster3_burn1_frame0_chroma1.frag.qsb</file>
<file>../shaders/terminal_dynamic_raster3_burn1_frame1_chroma0.frag.qsb</file> <file>../shaders/terminal_dynamic_raster3_burn1_frame1_chroma0.frag.qsb</file>
<file>../shaders/terminal_dynamic_raster3_burn1_frame1_chroma1.frag.qsb</file> <file>../shaders/terminal_dynamic_raster3_burn1_frame1_chroma1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom0_curve0_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom0_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom0_curve0_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom0_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom0_curve1_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom0_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom0_curve1_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom0_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom1_curve0_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom1_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom1_curve0_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom1_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom1_curve1_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom1_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma0_bloom1_curve1_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb0_bloom1_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom0_curve0_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom0_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom0_curve0_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom0_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom0_curve1_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom0_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom0_curve1_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom0_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom1_curve0_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom1_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom1_curve0_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom1_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom1_curve1_shine0.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom1_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb0_chroma1_bloom1_curve1_shine1.frag.qsb</file> <file>../shaders/terminal_static_rgb1_bloom1_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom0_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom0_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom0_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom0_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom1_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom1_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom1_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma0_bloom1_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom0_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom0_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom0_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom0_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom1_curve0_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom1_curve0_shine1.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom1_curve1_shine0.frag.qsb</file>
<file>../shaders/terminal_static_rgb1_chroma1_bloom1_curve1_shine1.frag.qsb</file>
<file>../shaders/terminal_frame.frag.qsb</file> <file>../shaders/terminal_frame.frag.qsb</file>
<file>../shaders/burn_in.frag.qsb</file> <file>../shaders/burn_in.frag.qsb</file>
<file>fonts/unscii/unscii-8-thin.ttf</file> <file>fonts/unscii/unscii-8-thin.ttf</file>

View File

@@ -29,8 +29,10 @@ void main() {
float blurDecay = clamp((burnInLastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0); float blurDecay = clamp((burnInLastUpdate - prevLastUpdate) * burnInTime, 0.0, 1.0);
blurDecay = max(0.0, blurDecay - prevMask); blurDecay = max(0.0, blurDecay - prevMask);
vec3 blurColor = accColor.rgb - vec3(blurDecay); float blurValue = rgb2grey(accColor.rgb) - blurDecay;
vec3 color = max(blurColor, txtColor); float txtValue = rgb2grey(txtColor);
float colorValue = max(blurValue, txtValue);
vec3 color = vec3(colorValue);
fragColor = vec4(color, currMask) * qt_Opacity; fragColor = vec4(color, currMask) * qt_Opacity;
} }

Binary file not shown.

View File

@@ -45,6 +45,7 @@ layout(std140, binding = 0) uniform ubuf {
vec2 scaleNoiseSize; vec2 scaleNoiseSize;
float frameShininess; float frameShininess;
float frameSize; float frameSize;
float bloom;
}; };
layout(binding = 0) uniform sampler2D noiseSource; layout(binding = 0) uniform sampler2D noiseSource;
@@ -123,11 +124,12 @@ float randomPass(vec2 coords){
vec3 convertWithChroma(vec3 inColor) { vec3 convertWithChroma(vec3 inColor) {
#if CRT_CHROMA == 1 #if CRT_CHROMA == 1
vec3 outColor = fontColor.rgb * rgb2grey(inColor); float grey = rgb2grey(inColor);
outColor = fontColor.rgb * mix(vec3(rgb2grey(inColor)), inColor, chromaColor); float denom = max(grey, 0.0001);
return outColor; vec3 foregroundColor = mix(fontColor.rgb, inColor * fontColor.rgb / denom, chromaColor);
return mix(backgroundColor.rgb, foregroundColor, grey);
#else #else
return fontColor.rgb * rgb2grey(inColor); return mix(backgroundColor.rgb, fontColor.rgb, rgb2grey(inColor));
#endif #endif
} }
@@ -150,18 +152,20 @@ void main() {
color += randomPass(coords * virtualResolution) * glowingLine; color += randomPass(coords * virtualResolution) * glowingLine;
vec3 txt_color = texture(screenBuffer, txt_coords).rgb; vec3 txt_color = texture(screenBuffer, txt_coords).rgb;
float bloomScale = 1.0 + max(bloom, 0.0);
txt_color *= bloomScale;
#if CRT_BURN_IN == 1 #if CRT_BURN_IN == 1
vec4 txt_blur = texture(burnInSource, staticCoords); vec4 txt_blur = texture(burnInSource, staticCoords);
float blurDecay = clamp((time - burnInLastUpdate) * burnInTime, 0.0, 1.0); float blurDecay = clamp((time - burnInLastUpdate) * burnInTime, 0.0, 1.0);
vec3 burnInColor = 0.65 * (txt_blur.rgb - vec3(blurDecay)); vec3 burnInColor = 0.65 * (txt_blur.rgb - vec3(blurDecay));
txt_color = max(txt_color, convertWithChroma(burnInColor)); txt_color = max(txt_color, burnInColor);
#endif #endif
txt_color += fontColor.rgb * vec3(color); txt_color += vec3(color);
txt_color = applyRasterization(staticCoords, txt_color, virtualResolution, rasterizationIntensity); txt_color = applyRasterization(staticCoords, txt_color, virtualResolution, rasterizationIntensity);
vec3 finalColor = txt_color; vec3 finalColor = convertWithChroma(txt_color);
float brightness = mix(1.0, vBrightness, step(0.0, flickering)); float brightness = mix(1.0, vBrightness, step(0.0, flickering));
finalColor *= brightness; finalColor *= brightness;

View File

@@ -28,6 +28,7 @@ layout(std140, binding = 0) uniform ubuf {
vec2 scaleNoiseSize; vec2 scaleNoiseSize;
float frameShininess; float frameShininess;
float frameSize; float frameSize;
float bloom;
}; };
layout(binding = 0) uniform sampler2D noiseSource; layout(binding = 0) uniform sampler2D noiseSource;

View File

@@ -3,9 +3,6 @@
#ifndef CRT_RGB_SHIFT #ifndef CRT_RGB_SHIFT
#define CRT_RGB_SHIFT 1 #define CRT_RGB_SHIFT 1
#endif #endif
#ifndef CRT_CHROMA
#define CRT_CHROMA 1
#endif
#ifndef CRT_BLOOM #ifndef CRT_BLOOM
#define CRT_BLOOM 1 #define CRT_BLOOM 1
#endif #endif
@@ -22,10 +19,7 @@ layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform ubuf { layout(std140, binding = 0) uniform ubuf {
mat4 qt_Matrix; mat4 qt_Matrix;
float qt_Opacity; float qt_Opacity;
vec4 fontColor;
vec4 backgroundColor;
float screenCurvature; float screenCurvature;
float chromaColor;
float rbgShift; float rbgShift;
float frameShininess; float frameShininess;
float frameSize; float frameSize;
@@ -38,8 +32,6 @@ layout(binding = 2) uniform sampler2D bloomSource;
float min2(vec2 v) { return min(v.x, v.y); } float min2(vec2 v) { return min(v.x, v.y); }
float max2(vec2 v) { return max(v.x, v.y); } float max2(vec2 v) { return max(v.x, v.y); }
float rgb2grey(vec3 v) { return dot(v, vec3(0.21, 0.72, 0.04)); }
vec2 distortCoordinates(vec2 coords){ vec2 distortCoordinates(vec2 coords){
vec2 paddedCoords = coords * (vec2(1.0) + frameSize * 2.0) - frameSize; vec2 paddedCoords = coords * (vec2(1.0) + frameSize * 2.0) - frameSize;
vec2 cc = (paddedCoords - vec2(0.5)); vec2 cc = (paddedCoords - vec2(0.5));
@@ -47,16 +39,6 @@ vec2 distortCoordinates(vec2 coords){
return (paddedCoords + cc * (1.0 + dist) * dist); return (paddedCoords + cc * (1.0 + dist) * dist);
} }
vec3 convertWithChroma(vec3 inColor) {
#if CRT_CHROMA == 1
vec3 outColor = fontColor.rgb * rgb2grey(inColor);
outColor = fontColor.rgb * mix(vec3(rgb2grey(inColor)), inColor, chromaColor);
return outColor;
#else
return fontColor.rgb * rgb2grey(inColor);
#endif
}
void main() { void main() {
vec2 cc = vec2(0.5) - qt_TexCoord0; vec2 cc = vec2(0.5) - qt_TexCoord0;
@@ -84,32 +66,25 @@ void main() {
txt_color.b = leftColor.b * 0.30 + rightColor.b * 0.10 + txt_color.b * 0.60; txt_color.b = leftColor.b * 0.30 + rightColor.b * 0.10 + txt_color.b * 0.60;
#endif #endif
txt_color += vec3(0.0001); vec3 finalColor = txt_color * shownDraw;
float greyscale_color = rgb2grey(txt_color);
vec3 finalColor; vec3 bloomColor = txt_color;
#if CRT_CHROMA == 1
vec3 foregroundColor = mix(fontColor.rgb, txt_color * fontColor.rgb / greyscale_color, chromaColor);
finalColor = mix(backgroundColor.rgb, foregroundColor, greyscale_color * shownDraw);
#else
finalColor = mix(backgroundColor.rgb, fontColor.rgb, greyscale_color * shownDraw);
#endif
vec3 bloomColor = finalColor;
float bloomAlpha = 0.0; float bloomAlpha = 0.0;
#if CRT_BLOOM == 1 || CRT_FRAME_SHININESS == 1 #if CRT_BLOOM == 1 || CRT_FRAME_SHININESS == 1
vec4 bloomFullColor = texture(bloomSource, txt_coords); vec4 bloomFullColor = texture(bloomSource, txt_coords);
bloomColor = convertWithChroma(bloomFullColor.rgb); bloomColor = bloomFullColor.rgb;
bloomAlpha = bloomFullColor.a; bloomAlpha = bloomFullColor.a;
#endif #endif
#if CRT_BLOOM == 1 #if CRT_BLOOM == 1
vec3 bloomOnScreen = bloomColor * isScreen; vec3 bloomOnScreen = bloomColor * isScreen;
finalColor += clamp(bloomOnScreen * bloom * bloomAlpha, 0.0, 0.5); finalColor += clamp(bloomOnScreen * bloom * bloomAlpha, 0.0, 0.5);
float bloomScale = 1.0 + max(bloom, 0.0);
finalColor /= bloomScale;
#endif #endif
#if CRT_FRAME_SHININESS == 1 #if CRT_FRAME_SHININESS == 1
vec3 reflectionColor = mix(backgroundColor.rgb + bloomColor, finalColor, frameShininess * 0.5); vec3 reflectionColor = mix(bloomColor, finalColor, frameShininess * 0.5);
finalColor = mix(finalColor, reflectionColor, isReflection); finalColor = mix(finalColor, reflectionColor, isReflection);
#endif #endif

View File

@@ -6,10 +6,7 @@ layout(location = 1) in vec2 qt_MultiTexCoord0;
layout(std140, binding = 0) uniform ubuf { layout(std140, binding = 0) uniform ubuf {
mat4 qt_Matrix; mat4 qt_Matrix;
float qt_Opacity; float qt_Opacity;
vec4 fontColor;
vec4 backgroundColor;
float screenCurvature; float screenCurvature;
float chromaColor;
float rbgShift; float rbgShift;
float frameShininess; float frameShininess;
float frameSize; float frameSize;

Binary file not shown.