bsnes/snesshader/Scale2x.OpenGL.shader

52 lines
1.6 KiB
Plaintext
Raw Normal View History

Update to v083 release. byuu says: This release adds preliminary Nintendo / Famicom emulation. It's only a week or two old, so a lot of work still needs to be done before it can compete with the most popular NES emulators. It's important to clarify: bsnes is primarily an SNES emulator. That will always be its forte and my core focus. I have added Game Boy support previously for Super Game Boy emulation, and I've added NES support mostly for something fun to work on to break up the monotony of working on one system for seven years now. Obviously, I'd like the emulation to be accurate and highly compatible, but I simply cannot afford to invest the same amount of time and money into any other systems. Still, either way the NES and GB emulation serve as fun side-diversions, and allow for a unified emulator interface with all of bsnes' unique features applied to all systems. My personal favorite feature is mightymo's extended built-in cheat code database that now also includes NES and Game Boy codes. And it even works in Super Game Boy mode now, too! I'm also not worried about speed at all: so long as NES/GB are faster than SNES/compatibility, it's fine by me. Note that due to the NES audio running at 1.78MHz, and Game Boy audio at 4MHz stereo, a more sophisticated audio resampler was needed: Ryphecha (Mednafen author) has graciously written a first-rate resampler: it is a band-limited Kaiser-windowed polyphase sinc resampler. It is combined with two highpass filters to remove DC bias. The filter itself is SSE optimized, but even still, approximately 50% of CPU usage for NES/GB emulation goes to the audio filtering alone. However, you now have the best sound possible for NES and Game Boy emulation as a result. The GUI has also been heavily re-structured to accommodate multiple emulators from the same interface. As such, it's quite likely a few bugs are still lurking here and there. Please report them and I'll iron them out for the next release. Changelog: - license is now GPLv3 - re-structured GUI as a multi-system emulator - added NES emulation [byuu, Ryphecha] - added NES ICs: MMC1, MMC2, MMC3, MMC4, MMC5, VRC4, VRC6+audio, VRC7, Sunsoft-5B+audio, Bandai-LZ93D50 - added NES boards: AxROM, BNROM, CNROM, ExROM, FxROM, GxROM, NROM, PxROM, SxROM, TxROM, UxROM - Game Boy emulation improvements [Jonas Quinn] - SNES core outputs full 19-bit color (4-bit luma included) for more accurate color reproduction (~5% speed hit) - audio resampler is now a band-limited polyphase resampler [Ryphecha] - cheat database includes NES+GB codes as well [mightymo, tukuyomi] - lots of other changes
2011-10-14 10:05:25 +00:00
shader language=GLSL
vertex~
uniform vec2 rubyTextureSize;
void main() {
vec4 offsetx;
vec4 offsety;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
offsetx.x = 1.0 / rubyTextureSize.x;
offsetx.y = 0.0;
offsetx.w = 0.0;
offsetx.z = 0.0;
offsety.y = 1.0 / rubyTextureSize.y;
offsety.x = 0.0;
offsety.w = 0.0;
offsety.z = 0.0;
gl_TexCoord[0] = gl_MultiTexCoord0; //center
gl_TexCoord[1] = gl_TexCoord[0] - offsetx; //left
gl_TexCoord[2] = gl_TexCoord[0] + offsetx; //right
gl_TexCoord[3] = gl_TexCoord[0] - offsety; //top
gl_TexCoord[4] = gl_TexCoord[0] + offsety; //bottom
}
fragment~ filter=nearest
uniform sampler2D rubyTexture;
uniform vec2 rubyTextureSize;
void main() {
vec4 colD, colF, colB, colH, col, tmp;
vec2 sel;
col = texture2DProj(rubyTexture, gl_TexCoord[0]); //central (can be E0-E3)
colD = texture2DProj(rubyTexture, gl_TexCoord[1]); //D (left)
colF = texture2DProj(rubyTexture, gl_TexCoord[2]); //F (right)
colB = texture2DProj(rubyTexture, gl_TexCoord[3]); //B (top)
colH = texture2DProj(rubyTexture, gl_TexCoord[4]); //H (bottom)
sel = fract(gl_TexCoord[0].xy * rubyTextureSize.xy); //where are we (E0-E3)? E0 is default
if(sel.y >= 0.5) { tmp = colB; colB = colH; colH = tmp; } //E1 (or E3): swap B and H
if(sel.x >= 0.5) { tmp = colF; colF = colD; colD = tmp; } //E2 (or E3): swap D and F
if(colB == colD && colB != colF && colD != colH) { //do the Scale2x rule
col = colD;
}
gl_FragColor = col;
}