Skip to content

Commit e464f4a

Browse files
committed
Add blur parameter to CRT settings
Closes #30
1 parent 72d313d commit e464f4a

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/common/gfx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ gfx_crt_params_t gfx_crt_default_params(void) {
188188
.curvature = 0.10f,
189189
.gamma = 1.10f,
190190
.vignette = 0.25f,
191+
.blur = 0.35f,
191192
};
192193
}
193194

@@ -608,6 +609,7 @@ void gfx_draw(chips_display_info_t display_info) {
608609
.curvature = state.display.crt_params.curvature,
609610
.gamma = state.display.crt_params.gamma,
610611
.vignette = state.display.crt_params.vignette,
612+
.blur = state.display.crt_params.blur,
611613
};
612614
sg_apply_uniforms(UB_display_crt_fs_params, &SG_RANGE(crt_uniforms));
613615
} else {

src/common/gfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct {
4040
float curvature;
4141
float gamma;
4242
float vignette;
43+
float blur;
4344
} gfx_crt_params_t;
4445

4546
void gfx_init(const gfx_desc_t* desc);

src/common/shaders.glsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ layout(binding=0) uniform display_crt_fs_params {
6969
float curvature;
7070
float gamma;
7171
float vignette;
72-
float _pad0;
73-
float _pad1;
72+
float blur;
7473
};
7574
in vec2 uv;
7675
out vec4 frag_color;
@@ -97,7 +96,13 @@ void main() {
9796
frag_color = vec4(0.0, 0.0, 0.0, 1.0);
9897
return;
9998
}
100-
vec3 col = texture(sampler2D(crt_tex, crt_smp), wuv).rgb;
99+
// 3-tap horizontal blur — simulates CRT analog bandwidth limit.
100+
// Offset is in UV scaled by output_size so the blur is ~1 output pixel
101+
// wide at blur=1.0; weights collapse to identity when blur=0.
102+
float ox = blur / max(output_size.x, 1.0);
103+
vec3 col = texture(sampler2D(crt_tex, crt_smp), wuv).rgb * 0.5
104+
+ texture(sampler2D(crt_tex, crt_smp), vec2(wuv.x - ox, wuv.y)).rgb * 0.25
105+
+ texture(sampler2D(crt_tex, crt_smp), vec2(wuv.x + ox, wuv.y)).rgb * 0.25;
101106
float scan_phase = wuv.y * output_size.y;
102107
float scan = 1.0 - scanline_intensity * (1.0 - cos(scan_phase * 3.14159265)) * 0.5;
103108
col *= scan;

src/ui/ui_crt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void ui_crt_draw(ui_crt_t* win) {
107107
changed |= ImGui::SliderFloat("RGB mask", &p.mask_intensity, 0.0f, 1.0f);
108108
changed |= ImGui::SliderFloat("Curvature", &p.curvature, 0.0f, 1.0f);
109109
changed |= ImGui::SliderFloat("Vignette", &p.vignette, 0.0f, 1.0f);
110+
changed |= ImGui::SliderFloat("Blur", &p.blur, 0.0f, 1.0f);
110111
changed |= ImGui::SliderFloat("Gamma", &p.gamma, 0.5f, 2.5f);
111112
if (changed) {
112113
gfx_crt_set_params(p);

0 commit comments

Comments
 (0)