Skip to content

Commit

Permalink
fix: ntsc tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Jun 12, 2024
1 parent e5042ef commit 3042fa7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
12 changes: 6 additions & 6 deletions tetanes-core/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn generate_ntsc_palette() -> Vec<u32> {
let mut ntsc_palette = vec![0; 512 * 64 * 3];

// Helper functions for converting YIQ to RGB
let gamma = 2.0; // Assumed display gamma
let gamma = 1.8; // Assumed display gamma
let gammafix = |color: f64| {
if color <= 0.0 {
0.0
Expand All @@ -225,8 +225,8 @@ fn generate_ntsc_palette() -> Vec<u32> {
for sample in 0..12 {
let noise = (sample + palette_offset * 4) % 12;
// Sample either the previous or the current pixel.
// Use pixel=color0 to disable artifacts.
let pixel = if noise < 6 - channel * 2 {
// Use pixel=color0_offset to disable artifacts.
let pixel = if noise < 5 - channel * 2 {
color0_offset
} else {
color1_offset
Expand Down Expand Up @@ -263,17 +263,17 @@ fn generate_ntsc_palette() -> Vec<u32> {
match channel {
2 => {
let rgb =
255.95 * gammafix(q.mul_add(0.623_557, i.mul_add(0.946_882, y)));
255.0 * gammafix(q.mul_add(0.623_557, i.mul_add(0.946_882, y)));
ntsc_palette[idx] += 0x10000 * rgb.clamp(0.0, 255.0) as u32;
}
1 => {
let rgb =
255.95 * gammafix(q.mul_add(-0.635_691, i.mul_add(-0.274_788, y)));
255.0 * gammafix(q.mul_add(-0.635_691, i.mul_add(-0.274_788, y)));
ntsc_palette[idx] += 0x00100 * rgb.clamp(0.0, 255.0) as u32;
}
0 => {
let rgb =
255.95 * gammafix(q.mul_add(1.709_007, i.mul_add(-1.108_545, y)));
255.0 * gammafix(q.mul_add(1.709_007, i.mul_add(-1.108_545, y)));
ntsc_palette[idx] += rgb.clamp(0.0, 255.0) as u32;
}
_ => (), // invalid channel
Expand Down
30 changes: 28 additions & 2 deletions tetanes/shaders/crt-easymode.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// Adapted from https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-easymode.glsl
// CRT Shader by EasyMode
// License: GPL
//
// A flat CRT shader ideally for 1080p or higher displays.
//
// Recommended Settings:
//
// Video
// - Aspect Ratio: 4:3
// - Integer Scale: Off
//
// Shader
// - Filter: Nearest
// - Scale: Don't Care
//
// Example RGB Mask Parameter Settings:
//
// Aperture Grille (Default)
// - Dot Width: 1
// - Dot Height: 1
// - Stagger: 0
//
// Lottes' Shadow Mask
// - Dot Width: 2
// - Dot Height: 1
// - Stagger: 3
//
// Adapted from https://github.com/libretro/glsl-shaders/blob/master/crt/shaders/crt-easymode.glsl

var<private> vertices: array<vec2<f32>, 3> = array<vec2<f32>, 3>(
vec2<f32>(-1.0, -1.0),
Expand Down Expand Up @@ -51,7 +78,6 @@ const GAMMA_OUTPUT = 2.2;
const BRIGHT_BOOST = 1.1;
const DILATION = 1.0;


// apply half-circle s-curve to distance for sharper (more pixelated) interpolation
fn curve_distance(x: f32, sharp: f32) -> f32 {
let x_step = step(0.5, x);
Expand Down
2 changes: 1 addition & 1 deletion tetanes/src/nes/renderer/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,7 @@ impl Gui {
ui.menu_button("🌉 Video Filter...", |ui| {
self.video_filter_radio(ui, cfg)
});
ui.menu_button(" Shader...", |ui| self.shader_radio(ui, cfg));
ui.menu_button("🕶 Shader...", |ui| self.shader_radio(ui, cfg));
ui.menu_button("🌎 Nes Region...", |ui| self.nes_region_radio(ui, cfg));
ui.menu_button("🎮 Four Player...", |ui| self.four_player_radio(ui, cfg));
ui.menu_button("📓 Game Genie Codes...", |ui| {
Expand Down

0 comments on commit 3042fa7

Please sign in to comment.