Skip to content

Commit

Permalink
beta8
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKoun committed Jun 25, 2019
1 parent 8533686 commit 2a322e5
Show file tree
Hide file tree
Showing 15 changed files with 404 additions and 177 deletions.
99 changes: 72 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,144 @@
# bsnes-hd

- [github project](https://github.com/DerKoun/bsnes-hd)
- [downloads](https://github.com/DerKoun/bsnes-hd/releases) for the latest betas
- [posts](https://www.reddit.com/r/emulation/search/?q=hd%20mode%207&restrict_sr=1&sort=new) and discussions for every beta on Reddit *r/emulation*
- [bsneshd-dev](https://discord.gg/3bVaNcK) at *Emulator Nexus* Discord (not just for developers, feel free to post suggestions, issues, game specific settings, recommended games, broken games, videos, screenshots, ...)



## What is it?

bsnes-hd (formally "*HD Mode 7 mod, for bsnes*") is a fork of bsnes (currently 107r3) that adds HD video features, such as:
bsnes-hd (called "*HD Mode 7 mod, for bsnes*" in early betas) is a fork of bsnes (great SNES emulator by *byuu*, currently based on version 107r3) that adds HD video features, such as:

### HD Mode 7

Rendering the rotated, scaled or pseudo perspective backgrounds at higher resolutions. This does not involve new custom imagery or upscaling algorithms. It is a higher resolution version of the process the SNES uses.
- [image comparison](http://www.framecompare.com/image-compare/screenshotcomparison/EB9MNNNU) (framecompare)
- [video comparison](https://www.youtube.com/watch?v=6VrzJ6Y1kjQ) by *reznoire* (youtube)

### Widescreen

Mostly for Mode 7 scenes, but also works for some other scenes/games here and there. Some setting tweaking required...
Extending the scenes to the left and right, without distorting them. Works for most Mode 7 scenes, but also for some other scenes/games, after some setting tweaking.
- **Demo video**: *Chrono Trigger* ending credits: [Beyond Time](https://www.youtube.com/watch?v=YE1gp6BWilg) by *retroprez* (youtube)
- **Demo video**: *Chrono Trigger* ending credits: [Float Away](https://www.youtube.com/watch?v=Ss49vVbULOQ) by *retroprez* (youtube)

### more to come

For example higher color depth and interpolation for the colors blending that help the sense of depth.

### plus some none-HD related features
### plus some non-HD related features

like the ability to disable background layers, sprites and window effects for screenshots for wallpapers or soft crop to zoom in, leaving maps or static art off the sides of the screen.



## Help Wanted

### Converting C++ Rendering Code to Shaders for Optimization

Currently all the HD rendering is running on the CPU cores. This will have to be moved to the GPU to achieve usable performance. I'd really appreciate any help with that, even if it's just to get started. Please open an issue if you want to contribute, or contact me on Reddit.



## Settings

all in Settings / Emulator

### Scale

The resolution Mode 7 is rendered at. Higher setting drastically increase CPU usage. "*disable*" uses the classic Mode 7 code, disabling some of the following features.
The resolution Mode 7 is rendered at. Higher setting drastically increase CPU usage. "*disable*" uses the classic Mode 7 code, disabling some of the following features. (defaults to 2x, to show the effect with the smallest possible CPU impact)

### Perspective correction

Whether and how pseudo 3D perspective are optimized, avoiding limitations of SNES integer math.
- **off**: disable correction
- **on**: enable correction
- **auto**(default): enable correction, but try to detect when it breaks the image and automatically disable it
- **auto**(default): enable correction, but try to detect when it breaks the image and automatically disable it.
- **wide**(default)/**medium**/**narrow**: the distance between the lines used for the interpolation (and also for the detection, if enabled). Use "*wide*" unless it causes issues. Only currently known game that requires this is "*Tales of Phantasia*", requiring "*narrow*".

### Supersampling
### Mosaic

Allows basing every resulting pixel on the average of multiple pixels. At 1x scale it allows using the higher precision at the original resolution, e.g. for use with CRT-shaders. At higher resolutions it is basically expensive anti-aliasing. Keep in mind that to estimate the performance impact you have to multiply(!) this value with the "*scale*" value.
How to handle Mosaic effects on Mode 7 backgrounds.
- **non-HD**: use 'classic' Mode 7 with Mosaic applied. Looks as intended, but disables HD and widescreen.
- **1x scale**(default): instead of the set *Scale* use "*1x*". Provides a good compromise between the other two options.
- **ignore**: ignore the Mosaic effect completely.

### Keep Mosaics non-HD
### Supersampling

When unchecked mosaic effects are ignored on Mode 7 backgrounds. When checked the affected lines fall back to classic Mode 7.
Allows basing every resulting pixel on the average of multiple pixels. At 1x scale it allows using the higher precision at the original resolution, e.g. for use with CRT-shaders. At higher resolutions it is basically expensive anti-aliasing. (defaults to "*none*") *Keep in mind that to estimate the performance impact you have to multiply(!) this value with the "*scale*" value.*

### Widescreen

Enables experimental widescreen (works best for Mode 7 scenes, rest is hit and miss) and sets its AR. The actual AR are slightly wider than the selection, use some "*soft crop*" "*left*" and "*right*" for the ideal fullscreen experience. "*HDcrop*" at 5x scale results in a width of 1920, which (combined with "*soft crop*" "*top*" and "*bottom*" at 10, output/center and shader/none) results in perfect 1080p fullscreen.
Enables experimental widescreen functionality
- **none**: do not enable widescreen
- **Mode 7**(default): enable widescreen for Mode 7 scenes (works for most games)
- **all**: enable widescreen for all scenes (non-Mode 7 scenes only work acceptable in some games, but many have mostly artifacts)

### Aspect ratio

Specifies the widescreen aspect ratio. The actual AR are slightly wider than the selection, use some "*soft crop*" "*left*" and "*right*" for the ideal fullscreen experience. "*HD*" at 5x scale results in a width of 1920, which (combined with "*soft crop*" "*top*" and "*bottom*" at 10, output/center and shader/none) results in perfect 1080p fullscreen. (defaults to 16:9)

### WS bg

Sets how the backgrounds of the widescreen areas are filled
- **color**: always fill the widescreen areas with the scanline background colors.
- **auto**(default): fill the widescreen areas with the scanline background colors, except when the "*Widescreen:Mode 7*" setting disables widescreen for the scene, then use black.
- **black**: the widescreen areas always have a black background, ignoring the background color, even when the scene is widescreen. (do not use unless a a game specifically requires it, none known for now)

### WS marker

Allows highlighting the edges of the widescreen areas in some ways.
- **none**(default): no highlighting
- **lines**: shows a dashed lined at the edges of each widescreen area
- **darken**: darkens the widescreen areas

### WSM alpha

Specifies how translucent the widescreen markers are. (defaults to 1/1)

### BG1/BG2/BG2/BG4

Settings for the background layers:
Settings for the background layers.
- **off**: no widescreen (e.g. for HUDs)
- **on**: widescreen enabled
- **< xy**/**> xy**: widescreen enabled above/below a certain scanline (for backgrounds that contain HUDs and backgrounds).
- **autoHor**: Disables widescreen for this background when it is as wide as the screen and has a horizontal position of 0.
- **autoHor&Ver**(default): Disables widescreen for this background when it is as wide as the screen and has a horizontal and vertical position of 0.
- **crop**: do not draw the left- and right-most 8 pixels (next to the widescreen areas) of the background (for backgrounds blanking some edge pixels, leaving black lines in widescreen, e.g. "*Top Gear 2*").
- **cAuto**: same as "*crop*", except for 2 differences. Only black pixel are not rendered. And lines of black pixel starting in the left crop area are removed entirely, e.g. for "*Super Mario Kart*".
- **dis.**: Disable the background entirely, e.g. to remove HUDs for screenshots for wallpapers.
- **cropAuto**: same as "*crop*", except for 2 differences. Only black pixel are not rendered. And lines of black pixel starting in the left crop area are removed entirely, e.g. for "*Super Mario Kart*".
- **disable**: Disable the background entirely, e.g. to remove HUDs for screenshots for wallpapers.

### Sprites

- **normal**: Sprites are rendered if they are at least partially in the classic content area. So they can only partially reach into the widescreen areas.
Settings for sprites/objects.
- **clip**: Sprites are clipped at the edges of the widescreen areas.
- **safe**(default): Sprites are rendered if they are at least partially in the classic content area. So they can only partially reach into the widescreen areas.
- **unsafe**: Sprites are rendered, even if they are entirely in a widescreen area. Works fine for a view games, like "*Super Mario World*", causes artifacts in many.
- **disab.**: Disable sprites entirely, e.g. to remove characters or HUD elements for screenshots for wallpapers.
- **disable**: Disable sprites entirely, e.g. to remove characters or HUD elements for screenshots for wallpapers.

### Ignore window

- **none**: Apply window effects normally. Widescreen pixels are treated like the nearest non-widescreen pixel.
- **outside**: "*outside*" window effects are ignored, i.e. all pixels are treated like they are at the "*fallback x-coordinate*" for this purpose. This allows Mode 7 widescreen in "*Final Fantasy III*"
- **outside&alw**: Same as outside, but also for "*always*" window effects.
- **all**: Same as outside, but for all window effects. Can for example be used to remove the shadow and meter from "*F-Zero*" for screenshots for wallpapers (requires a "*fallback x-coordinate*" other than 128).
- **outside**(default): "*outside*" window effects are ignored, i.e. all pixels are treated like they are at the "*fallback x-coordinate*" for this purpose. This allows Mode 7 widescreen in "*Final Fantasy III*"
- **outside&always**: Same as outside, but also for "*always*" window effects.
- **all**: Same as outside, but for all window effects. Can for example be used to remove the shadow and meter from "*F-Zero*" for screenshots for wallpapers (requires changing "*fallback x-coordinate*" from 128 to something like 40).

### Fallback x-coordinate

The x-coordinate used as fallback for "*ignore window*"
The x-coordinate used as fallback for "*ignore window*". (defaults to 128 (the center))

### Soft crop

Allows widths at the four edges of the image to be declared uninteresting. So when sizing and placing the image, especially in fullscreen, they can overflow the screen, allowing the significant parts of the image to be larger. So to focus on the top part of "*Super Mario Kart*" set "*bottom*" to 130 and "*top*" to 0. Further tweaking based on your monitor AR and liking may be required.
- **none**: disable soft crop
- **center**: enable soft crop for output/center
- **center**(default): enable soft crop for output/center
- **scale**: enable soft crop for output/center and output/scale

### Top/Bottom/Left/Right

The soft crop widths for all four edges.

### SC Top/Bottom/Left/Right

The soft crop widths for all four edges. (defaults to 10, 10, 20, 20)

## Help Wanted

### Converting C++ Rendering Code to Shaders for Optimization

Currently all the HD rendering is running on the CPU cores. This will have to be moved to the GPU to achieve usable performance. I'd really appreciate any help with that, even if it's just to get started. Please open an issue if you want to contribute, or contact me on Reddit.
## More documentation to come...
6 changes: 5 additions & 1 deletion bsnes/sfc/interface/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ auto Configuration::process(Markup::Node document, bool load) -> void {
bind(natural, "Hacks/PPU/Mode7/Wsobj", hacks.ppu.mode7.wsobj);
bind(natural, "Hacks/PPU/Mode7/Igwin", hacks.ppu.mode7.igwin);
bind(natural, "Hacks/PPU/Mode7/Igwinx", hacks.ppu.mode7.igwinx);
bind(natural, "Hacks/PPU/Mode7/WsMode", hacks.ppu.mode7.wsMode);
bind(natural, "Hacks/PPU/Mode7/WsBgCol", hacks.ppu.mode7.wsBgCol);
bind(natural, "Hacks/PPU/Mode7/UnintrMode", hacks.ppu.mode7.unintrMode);
bind(natural, "Hacks/PPU/Mode7/UnintrTop", hacks.ppu.mode7.unintrTop);
bind(natural, "Hacks/PPU/Mode7/UnintrBottom", hacks.ppu.mode7.unintrBottom);
bind(natural, "Hacks/PPU/Mode7/UnintrLeft", hacks.ppu.mode7.unintrLeft);
bind(natural, "Hacks/PPU/Mode7/UnintrRight", hacks.ppu.mode7.unintrRight);
bind(natural, "Hacks/PPU/Mode7/WsMarker", hacks.ppu.mode7.wsMarker);
bind(natural, "Hacks/PPU/Mode7/WsMarkerAlpha", hacks.ppu.mode7.wsMarkerAlpha);
bind(natural, "Hacks/PPU/Mode7/Supersample", hacks.ppu.mode7.supersample);
bind(boolean, "Hacks/PPU/Mode7/Mosaic", hacks.ppu.mode7.mosaic);
bind(natural, "Hacks/PPU/Mode7/Mosaic", hacks.ppu.mode7.mosaic);
bind(boolean, "Hacks/DSP/Fast", hacks.dsp.fast);
bind(boolean, "Hacks/DSP/Cubic", hacks.dsp.cubic);
bind(boolean, "Hacks/Coprocessors/HLE", hacks.coprocessors.hle);
Expand Down
16 changes: 10 additions & 6 deletions bsnes/sfc/interface/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,24 @@ struct Configuration {
uint scale = 2;
uint perspective = 1;
uint widescreen = 72;
uint wsbg1 = 1;
uint wsbg2 = 1;
uint wsbg3 = 1;
uint wsbg4 = 1;
uint wsbg1 = 16;
uint wsbg2 = 16;
uint wsbg3 = 16;
uint wsbg4 = 16;
uint wsobj = 0;
uint igwin = 0;
uint igwin = 1;
uint igwinx = 128;
uint wsMode = 1;
uint wsBgCol = 1;
uint unintrMode = 1;
uint unintrTop = 10;
uint unintrBottom = 10;
uint unintrLeft = 20;
uint unintrRight = 20;
uint wsMarker = 0;
uint wsMarkerAlpha = 1;
uint supersample = 1;
bool mosaic = false;
uint mosaic = 1;
} mode7;
} ppu;
struct DSP {
Expand Down
10 changes: 8 additions & 2 deletions bsnes/sfc/ppu-fast/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ auto PPUfast::Line::renderBackground(PPUfast::IO::Background& self, uint source)
bool autoCrop = false;
int ws = (int)ppufast.widescreen();
if(ws > 0) {
if(wsConf == 12) {
if(ppufast.wsOverride()) {
ws = 0;
} else if(wsConf == 12) {
ws = -8;
} else if(wsConf == 13) {
ws = 0;
autoCrop = true;
} else if(wsConf == 15) {
if (self.tileSize == 0 && self.hoffset == 0) ws = 0;
} else if(wsConf == 16) {
if (self.tileSize == 0 && self.hoffset == 0 && self.voffset == 0) ws = 0;
} else if(wsConf == 0 || (wsConf != 1 && (((wsConf % 2) != 0) == (y < (((int)(wsConf / 2)) * 40))))) {
ws = 0;
}
}
}

array<bool[256]> windowAbove;
array<bool[256]> windowBelow;
Expand Down
69 changes: 55 additions & 14 deletions bsnes/sfc/ppu-fast/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ uint PPUfast::Line::start = 0;
uint PPUfast::Line::count = 0;

auto PPUfast::Line::flush() -> void {
ppufast.ind = 0;
uint perspCorMode = ppufast.hdPerspective();
if(perspCorMode > 0) {
#define isLineMode7(l) (l.io.bg1.tileMode == TileMode::Mode7 \
&& !l.io.displayDisable && (l.io.bg1.aboveEnable || l.io.bg1.belowEnable))
ppufast.ind = 0;
bool state = false;
uint y;
int offsPart = 8;
Expand Down Expand Up @@ -104,6 +104,20 @@ auto PPUfast::Line::flush() -> void {
}
}
}
} else if(ppufast.wsOverrideCandidate()) {
#define isLineMode7(l) (l.io.bg1.tileMode == TileMode::Mode7 \
&& !l.io.displayDisable && (l.io.bg1.aboveEnable || l.io.bg1.belowEnable))
for(uint y = 0; y < Line::count; y++) {
if(isLineMode7(ppufast.lines[Line::start + y])) {
ppufast.ind = 1;
ppufast.starts[0] = -1;
ppufast.ends[0] = -1;
ppufast.startsp[0] = -1;
ppufast.endsp[0] = -1;
break;
}
}
#undef isLineMode7
}

if(Line::count) {
Expand Down Expand Up @@ -138,9 +152,22 @@ auto PPUfast::Line::render() -> void {
auto belowColor = hires ? cgram[0] : io.col.fixedColor;
uint xa = (hd || ss) && ppufast.interlace() && ppufast.field() ? 256 * scale * scale / 2 : 0;
uint xb = !(hd || ss) ? 256 : ppufast.interlace() && !ppufast.field() ? (256+2*ppufast.widescreen()) * scale * scale / 2 : (256+2*ppufast.widescreen()) * scale * scale;
for(uint x = xa; x < xb; x++) {
above[x] = {Source::COL, 0, aboveColor};
below[x] = {Source::COL, 0, belowColor};
if (hd && ppufast.wsBgCol()) {
for(uint x = xa; x < xb; x++) {
int cx = (x % ((256+2*ppufast.widescreen()) * scale)) - (ppufast.widescreen() * scale);
if (cx >= 0 && cx <= (256 * scale)) {
above[x] = {Source::COL, 0, aboveColor};
below[x] = {Source::COL, 0, belowColor};
} else {
above[x] = {Source::COL, 0, 0};
below[x] = {Source::COL, 0, 0};
}
}
} else {
for(uint x = xa; x < xb; x++) {
above[x] = {Source::COL, 0, aboveColor};
below[x] = {Source::COL, 0, belowColor};
}
}

renderBackground(io.bg1, Source::BG1);
Expand All @@ -152,27 +179,41 @@ auto PPUfast::Line::render() -> void {
renderWindow(io.col.window, io.col.window.aboveMask, windowAbove);
renderWindow(io.col.window, io.col.window.belowMask, windowBelow);

uint wsm = (ppufast.widescreen() == 0 || ppufast.wsOverride()) ? 0 : ppufast.wsMarker();
uint wsma = ppufast.wsMarkerAlpha();

auto luma = io.displayBrightness << 15;
if(hd) for(uint x : range((256+2*ppufast.widescreen()) * scale * scale)) {
*output++ = luma | pixel((x / scale % (256+2*ppufast.widescreen()) - ppufast.widescreen()), above[x], below[x]);
*output++ = luma | pixel((x / scale % (256+2*ppufast.widescreen()) - ppufast.widescreen()), above[x], below[x], wsm, wsma);
} else if(width == 256) for(uint x : range(256)) {
*output++ = luma | pixel(x, above[x], below[x]);
*output++ = luma | pixel(x, above[x], below[x], wsm, wsma);
} else if(!hires) for(uint x : range(256)) {
auto color = luma | pixel(x, above[x], below[x]);
auto color = luma | pixel(x, above[x], below[x], wsm, wsma);
*output++ = color;
*output++ = color;
} else for(uint x : range(256)) {
*output++ = luma | pixel(x, below[x], above[x]);
*output++ = luma | pixel(x, above[x], below[x]);
*output++ = luma | pixel(x, below[x], above[x], wsm, wsma);
*output++ = luma | pixel(x, above[x], below[x], wsm, wsma);
}
}

auto PPUfast::Line::pixel(uint x, Pixel above, Pixel below) const -> uint15 {
auto PPUfast::Line::pixel(uint x, Pixel above, Pixel below, uint wsm, uint wsma) const -> uint15 {
uint15 r = 0;
if(!windowAbove[ppufast.winXad(x, false)]) above.color = 0x0000;
if(!windowBelow[ppufast.winXad(x, true)]) return above.color;
if(!io.col.enable[above.source]) return above.color;
if(!io.col.blendMode) return blend(above.color, io.col.fixedColor, io.col.halve && windowAbove[ppufast.winXad(x, false)]);
return blend(above.color, below.color, io.col.halve && windowAbove[ppufast.winXad(x, false)] && below.source != Source::COL);
else if(!windowBelow[ppufast.winXad(x, true)]) r = above.color;
else if(!io.col.enable[above.source]) r = above.color;
else if(!io.col.blendMode) r = blend(above.color, io.col.fixedColor, io.col.halve && windowAbove[ppufast.winXad(x, false)]);
else r = blend(above.color, below.color, io.col.halve && windowAbove[ppufast.winXad(x, false)] && below.source != Source::COL);
if(wsm > 0) {
if(wsm == 1 && (x == 0 || x == 255)
|| wsm == 2 && (!(x >= 0 && x <= 255))) {
int b = wsm == 2 ? 0 : ((y / 4) % 2 == 0) ? 0 : 31;
r = ((((((r >> 10) & 31) * wsma) + b) / (wsma + 1)) << 10)
+ ((((((r >> 5) & 31) * wsma) + b) / (wsma + 1)) << 5)
+ ((((((r >> 0) & 31) * wsma) + b) / (wsma + 1)) << 0);
}
}
return r;
}

auto PPUfast::Line::blend(uint x, uint y, bool halve) const -> uint15 {
Expand Down
Loading

0 comments on commit 2a322e5

Please sign in to comment.