From 66d60bafddffc83e96ca02b9fcd67c404571eab4 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 14 Nov 2010 19:07:31 +0100 Subject: [PATCH 1/8] update config --- config.h | 14 +++++++------- config.mk | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/config.h b/config.h index 705b4ecc73..d694c9ce8b 100644 --- a/config.h +++ b/config.h @@ -54,19 +54,19 @@ static const float yscale = 4.0; // Real y res = 224 * yscale // Fullscreen static bool fullscreen = false; // To start in Fullscreen or not -static const unsigned fullscreen_x = 1280; -static const unsigned fullscreen_y = 720; +static const unsigned fullscreen_x = 1920; +static const unsigned fullscreen_y = 1200; // Video VSYNC (recommended) static const bool vsync = true; // Smooths picture -static const bool video_smooth = true; +static const bool video_smooth = false; // Path to custom Cg shader. If using custom shaders, it is recommended to disable video_smooth. #ifdef HAVE_CG extern char cg_shader_path[]; -#define DEFAULT_CG_SHADER "hqflt/cg/hq2x.cg" +#define DEFAULT_CG_SHADER "hqflt/cg/2xSaI.cg" #endif // On resize and fullscreen, rendering area will stay 4:3 @@ -93,17 +93,17 @@ static const bool force_aspect = true; static const bool audio_enable = true; // Output samplerate -static const unsigned out_rate = 48000; +static const unsigned out_rate = 44100; // Input samplerate from libSNES. // Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled. static const unsigned in_rate = 31950; // Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults. -static const char* audio_device = NULL; +static const char* audio_device = "hw:0"; // Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency. -static const int out_latency = 64; +static const int out_latency = 16; // Will sync audio. (recommended) static const bool audio_sync = true; diff --git a/config.mk b/config.mk index 64e9c95494..65face463c 100644 --- a/config.mk +++ b/config.mk @@ -1,6 +1,6 @@ BUILD_OPENGL = 1 -BUILD_CG = 0 +BUILD_CG = 1 BUILD_FILTER = 0 BUILD_RSOUND = 0 @@ -10,5 +10,4 @@ BUILD_ROAR = 0 BUILD_AL = 0 -PREFIX = /usr/local - +PREFIX = /usr From 7cbd595446babf84ca92ebf2fe39eceb97848dcd Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 14 Nov 2010 22:25:34 +0100 Subject: [PATCH 2/8] Update config --- config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index d694c9ce8b..47d10f1ca4 100644 --- a/config.h +++ b/config.h @@ -49,8 +49,8 @@ //////////////// // Windowed -static const float xscale = 4.0; // Real x res = 296 * xscale -static const float yscale = 4.0; // Real y res = 224 * yscale +static const float xscale = 3.0; // Real x res = 296 * xscale +static const float yscale = 3.0; // Real y res = 224 * yscale // Fullscreen static bool fullscreen = false; // To start in Fullscreen or not From c23958680b64b481e5fd29e82fdcd2fee6cc4370 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 14 Nov 2010 22:25:47 +0100 Subject: [PATCH 3/8] Add quad interpolation. --- hqflt/cg/quad.cg | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 hqflt/cg/quad.cg diff --git a/hqflt/cg/quad.cg b/hqflt/cg/quad.cg new file mode 100644 index 0000000000..41b771f5ae --- /dev/null +++ b/hqflt/cg/quad.cg @@ -0,0 +1,99 @@ +/* + + Copyright (C) 2007 guest(r) - guest.r@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +/* + + The 2xSaL shader processes a gfx. surface and redraws it 2x finer. + + A linear post-resize can fit the image to any resolution. + + Note: set scaler to normal2x. + +*/ + +/* Default Vertex shader */ +void main_vertex +( + float4 position : POSITION, + float4 color : COLOR, + float2 texCoord : TEXCOORD0, + + uniform float4x4 modelViewProj, + + out float4 oPosition : POSITION, + out float4 oColor : COLOR, + out float2 otexCoord : TEXCOORD + ) +{ + oPosition = mul(modelViewProj, position); + oColor = color; + otexCoord = texCoord; +} + +struct output +{ + float4 color : COLOR; +}; + +struct input +{ + float2 video_size; + float2 texture_size; + float2 output_size; +}; + +struct deltas +{ + float2 UL, UR, DL, DR; +}; + +float3 quad_inter(float3 x0, float3 x1, float3 x2, float x) +{ + float3 poly[3]; + poly[2] = 0.5*x0 - x1 + 0.5*x2; + poly[1] = -1.5*x0 + 2.0*x1 - 0.5*x2; + poly[0] = x0; + return poly[2] * x * x + poly[1] * x + poly[0]; +} + +output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s0 : TEXUNIT0) +{ + float2 texsize = IN.texture_size; + float vid_height = IN.output_size.y; + float dx = float(pow(2.0 * texsize.x, -1.0)); + float dy = float(pow(2.0 * texsize.y, -1.0)); + + float3 c01 = tex2D(s0, tex + float2(-dx, 0)).xyz; + float3 c10 = tex2D(s0, tex + float2(0, -dy)).xyz; + float3 c11 = tex2D(s0, tex + float2(0, 0)).xyz; + float3 c12 = tex2D(s0, tex + float2(0, dy)).xyz; + float3 c21 = tex2D(s0, tex + float2(dx, 0)).xyz; + + float3 xval0 = quad_inter(c01, c11, c21, tex.x * texsize.x - floor(tex.x * texsize.x) + 1.0); + float3 yval0 = quad_inter(c10, c11, c12, tex.y * texsize.y - floor(tex.y * texsize.y) + 1.0); + + output OUT; + //float scanline_mod = 1.0 - 0.1 * floor(fmod(vid_height * tex.y, 2.0)); + float scanline_mod = 1.0; + + OUT.color = float4(lerp(xval0, yval0, 0.5), 1.0) * scanline_mod; + return OUT; +} + From dcf5667e7342fcf8058a40570370d4477839bd5d Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 15 Nov 2010 00:45:21 +0100 Subject: [PATCH 4/8] hmm :v --- config.h | 20 ++++++++++---------- hqflt/cg/quad.cg | 44 ++++++++------------------------------------ 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/config.h b/config.h index 47d10f1ca4..b0c7a6c986 100644 --- a/config.h +++ b/config.h @@ -129,12 +129,12 @@ static const struct snes_keybind snes_keybinds_1[] = { { SNES_DEVICE_ID_JOYPAD_Y, 'A', 2 }, { SNES_DEVICE_ID_JOYPAD_L, 'Q', 4 }, { SNES_DEVICE_ID_JOYPAD_R, 'W', 5 }, - { SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 12 }, - { SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 13 }, - { SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 10 }, - { SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 11 }, + { SNES_DEVICE_ID_JOYPAD_LEFT, GLFW_KEY_LEFT, 11 }, + { SNES_DEVICE_ID_JOYPAD_RIGHT, GLFW_KEY_RIGHT, 12 }, + { SNES_DEVICE_ID_JOYPAD_UP, GLFW_KEY_UP, 13 }, + { SNES_DEVICE_ID_JOYPAD_DOWN, GLFW_KEY_DOWN, 14 }, { SNES_DEVICE_ID_JOYPAD_START, GLFW_KEY_ENTER, 6 }, - { SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 14 }, + { SNES_DEVICE_ID_JOYPAD_SELECT, GLFW_KEY_RSHIFT, 7 }, { SNES_FAST_FORWARD_KEY, GLFW_KEY_SPACE, 9 }, { -1 } }; @@ -148,12 +148,12 @@ static const struct snes_keybind snes_keybinds_2[] = { { SNES_DEVICE_ID_JOYPAD_Y, 'F', 2 }, { SNES_DEVICE_ID_JOYPAD_L, 'R', 4 }, { SNES_DEVICE_ID_JOYPAD_R, 'T', 5 }, - { SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 12 }, - { SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 13 }, - { SNES_DEVICE_ID_JOYPAD_UP, 'I', 10 }, - { SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 11 }, + { SNES_DEVICE_ID_JOYPAD_LEFT, 'J', 11 }, + { SNES_DEVICE_ID_JOYPAD_RIGHT, 'L', 12 }, + { SNES_DEVICE_ID_JOYPAD_UP, 'I', 13 }, + { SNES_DEVICE_ID_JOYPAD_DOWN, 'K', 14 }, { SNES_DEVICE_ID_JOYPAD_START, 'P', 6 }, - { SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 14 }, + { SNES_DEVICE_ID_JOYPAD_SELECT, 'O', 7 }, { -1 } }; diff --git a/hqflt/cg/quad.cg b/hqflt/cg/quad.cg index 41b771f5ae..60488c3282 100644 --- a/hqflt/cg/quad.cg +++ b/hqflt/cg/quad.cg @@ -1,31 +1,6 @@ /* - - Copyright (C) 2007 guest(r) - guest.r@gmail.com - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - -/* - - The 2xSaL shader processes a gfx. surface and redraws it 2x finer. - - A linear post-resize can fit the image to any resolution. - - Note: set scaler to normal2x. - + Author: Themaister + License: Public domain */ /* Default Vertex shader */ @@ -76,9 +51,8 @@ float3 quad_inter(float3 x0, float3 x1, float3 x2, float x) output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s0 : TEXUNIT0) { float2 texsize = IN.texture_size; - float vid_height = IN.output_size.y; - float dx = float(pow(2.0 * texsize.x, -1.0)); - float dy = float(pow(2.0 * texsize.y, -1.0)); + float dx = float(pow(1.0 * texsize.x, -1.0)); + float dy = float(pow(1.0 * texsize.y, -1.0)); float3 c01 = tex2D(s0, tex + float2(-dx, 0)).xyz; float3 c10 = tex2D(s0, tex + float2(0, -dy)).xyz; @@ -86,14 +60,12 @@ output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2 float3 c12 = tex2D(s0, tex + float2(0, dy)).xyz; float3 c21 = tex2D(s0, tex + float2(dx, 0)).xyz; - float3 xval0 = quad_inter(c01, c11, c21, tex.x * texsize.x - floor(tex.x * texsize.x) + 1.0); - float3 yval0 = quad_inter(c10, c11, c12, tex.y * texsize.y - floor(tex.y * texsize.y) + 1.0); + float blur = 1.5; + float3 xval0 = quad_inter(c01, c11, c21, blur*(frac(tex.x * texsize.x)) + (2.0 - blur) * 0.5); + float3 yval0 = quad_inter(c10, c11, c12, blur*(frac(tex.y * texsize.y)) + (2.0 - blur) * 0.5); output OUT; - //float scanline_mod = 1.0 - 0.1 * floor(fmod(vid_height * tex.y, 2.0)); - float scanline_mod = 1.0; - - OUT.color = float4(lerp(xval0, yval0, 0.5), 1.0) * scanline_mod; + OUT.color = float4(lerp(xval0, yval0, 0.5), 1.0); return OUT; } From c560ccbabc443eab215c2d978a1700d832b743ff Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 15 Nov 2010 21:51:16 +0100 Subject: [PATCH 5/8] Should fix quad shader. :P --- hqflt/cg/quad.cg | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/hqflt/cg/quad.cg b/hqflt/cg/quad.cg index 60488c3282..fa6832953d 100644 --- a/hqflt/cg/quad.cg +++ b/hqflt/cg/quad.cg @@ -51,21 +51,37 @@ float3 quad_inter(float3 x0, float3 x1, float3 x2, float x) output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s0 : TEXUNIT0) { float2 texsize = IN.texture_size; - float dx = float(pow(1.0 * texsize.x, -1.0)); - float dy = float(pow(1.0 * texsize.y, -1.0)); + float sharpness = 2.0; + float dx = float(pow(sharpness * texsize.x, -1.0)); + float dy = float(pow(sharpness * texsize.y, -1.0)); + float3 c00 = tex2D(s0, tex + float2(-dx, -dy)).xyz; float3 c01 = tex2D(s0, tex + float2(-dx, 0)).xyz; + float3 c02 = tex2D(s0, tex + float2(-dx, dy)).xyz; float3 c10 = tex2D(s0, tex + float2(0, -dy)).xyz; float3 c11 = tex2D(s0, tex + float2(0, 0)).xyz; float3 c12 = tex2D(s0, tex + float2(0, dy)).xyz; + float3 c20 = tex2D(s0, tex + float2(dx, -dy)).xyz; float3 c21 = tex2D(s0, tex + float2(dx, 0)).xyz; + float3 c22 = tex2D(s0, tex + float2(dx, dy)).xyz; - float blur = 1.5; - float3 xval0 = quad_inter(c01, c11, c21, blur*(frac(tex.x * texsize.x)) + (2.0 - blur) * 0.5); - float3 yval0 = quad_inter(c10, c11, c12, blur*(frac(tex.y * texsize.y)) + (2.0 - blur) * 0.5); + float frac_amt_x = frac(tex.x * texsize.x); + float frac_amt_y = frac(tex.y * texsize.y); + float3 loval = quad_inter(c00, c10, c20, frac_amt_x + 0.5); + float3 midval = quad_inter(c01, c11, c21, frac_amt_x + 0.5); + float3 hival = quad_inter(c02, c12, c22, frac_amt_x + 0.5); + float3 res = quad_inter(loval, midval, hival, frac_amt_y + 0.5); output OUT; - OUT.color = float4(lerp(xval0, yval0, 0.5), 1.0); + +// Bilinear! +// float3 first = lerp(c00, c20, frac(tex.x * texsize.x + 0.5)); +// float3 second = lerp(c02, c22, frac(tex.x * texsize.x + 0.5)); +// float3 res = lerp(first, second, frac(tex.y * texsize.y + 0.5)); +// OUT.color = float4(res, 1.0); + + + OUT.color = float4(res, 1.0); return OUT; } From 854516f9b1a51160fc9b52de7c6f3b1808ca7399 Mon Sep 17 00:00:00 2001 From: Themaister Date: Thu, 18 Nov 2010 03:17:59 +0100 Subject: [PATCH 6/8] stuff --- config.h | 2 +- hqflt/cg/bloom.cg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index b0c7a6c986..ebd6aa96cd 100644 --- a/config.h +++ b/config.h @@ -61,7 +61,7 @@ static const unsigned fullscreen_y = 1200; static const bool vsync = true; // Smooths picture -static const bool video_smooth = false; +static const bool video_smooth = true; // Path to custom Cg shader. If using custom shaders, it is recommended to disable video_smooth. #ifdef HAVE_CG diff --git a/hqflt/cg/bloom.cg b/hqflt/cg/bloom.cg index 64eb81ca99..d7017e9924 100644 --- a/hqflt/cg/bloom.cg +++ b/hqflt/cg/bloom.cg @@ -17,7 +17,7 @@ void main_vertex otexCoord = texCoord; } -float Luminance = 0.08f; +float Luminance = 0.09f; static const float fMiddleGray = 0.18f; static const float fWhiteCutoff = 0.8f; From d1a0500219dd71e9453aa065503a65d8c10889a4 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 19 Nov 2010 21:21:04 +0100 Subject: [PATCH 7/8] Adds support for vertex shader input params. :) --- Makefile | 2 +- config.h | 2 +- gl.c | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4ae946cb88..4fc8717b0c 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ TARGET = ssnes DEFINES = OBJ = ssnes.o -LIBS = -lsamplerate -lsnes +LIBS = -lsamplerate libsnes.a ifeq ($(BUILD_RSOUND), 1) OBJ += rsound.o diff --git a/config.h b/config.h index ebd6aa96cd..b9801052cd 100644 --- a/config.h +++ b/config.h @@ -103,7 +103,7 @@ static const unsigned in_rate = 31950; static const char* audio_device = "hw:0"; // Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency. -static const int out_latency = 16; +static const int out_latency = 32; // Will sync audio. (recommended) static const bool audio_sync = true; diff --git a/gl.c b/gl.c index 0d098611e2..f2cdfe14d7 100644 --- a/gl.c +++ b/gl.c @@ -61,6 +61,7 @@ typedef struct gl CGprofile cgFProf; CGprofile cgVProf; CGparameter cg_video_size, cg_texture_size, cg_output_size; + CGparameter cg_Vvideo_size, cg_Vtexture_size, cg_Voutput_size; // Vertexes #endif GLuint texture; GLuint tex_filter; @@ -248,6 +249,10 @@ static bool gl_frame(void *data, const uint16_t* frame, int width, int height, i cgGLSetParameter2f(gl->cg_video_size, width, height); cgGLSetParameter2f(gl->cg_texture_size, width, height); cgGLSetParameter2f(gl->cg_output_size, gl_width, gl_height); + + cgGLSetParameter2f(gl->cg_Vvideo_size, width, height); + cgGLSetParameter2f(gl->cg_Vtexture_size, width, height); + cgGLSetParameter2f(gl->cg_Voutput_size, gl_width, gl_height); #endif glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch >> 1); @@ -376,6 +381,9 @@ static void* gl_init(video_info_t *video, const input_driver_t **input) gl->cg_video_size = cgGetNamedParameter(gl->cgFPrg, "IN.video_size"); gl->cg_texture_size = cgGetNamedParameter(gl->cgFPrg, "IN.texture_size"); gl->cg_output_size = cgGetNamedParameter(gl->cgFPrg, "IN.output_size"); + gl->cg_Vvideo_size = cgGetNamedParameter(gl->cgVPrg, "IN.video_size"); + gl->cg_Vtexture_size = cgGetNamedParameter(gl->cgVPrg, "IN.texture_size"); + gl->cg_Voutput_size = cgGetNamedParameter(gl->cgVPrg, "IN.output_size"); cg_mvp_matrix = cgGetNamedParameter(gl->cgVPrg, "modelViewProj"); cgGLSetStateMatrixParameter(cg_mvp_matrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); #endif From 3835100101427165108b3657a5186a5e80ae3261 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 19 Nov 2010 21:26:31 +0100 Subject: [PATCH 8/8] Add possibility to specify libsnes. --- Makefile | 10 +++++----- config.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 4fc8717b0c..a26bc99020 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,9 @@ TARGET = ssnes DEFINES = OBJ = ssnes.o -LIBS = -lsamplerate libsnes.a +libsnes = -lsnes + +LIBS = -lsamplerate $(libsnes) ifeq ($(BUILD_RSOUND), 1) OBJ += rsound.o @@ -49,12 +51,10 @@ CFLAGS = -Wall -O3 -march=native -std=gnu99 -Wno-unused-variable -I. $(DEFINES) all: $(TARGET) ssnes: $(OBJ) - @$(CXX) -o $@ $(OBJ) $(LIBS) $(CFLAGS) - @echo "LD $@" + $(CXX) -o $@ $(OBJ) $(LIBS) $(CFLAGS) %.o: %.c config.h config.mk - @$(CC) $(CFLAGS) -c -o $@ $< - @echo "CC $<" + $(CC) $(CFLAGS) -c -o $@ $< install: $(TARGET) install -m755 $(TARGET) $(PREFIX)/bin diff --git a/config.h b/config.h index b9801052cd..d6aabf4d52 100644 --- a/config.h +++ b/config.h @@ -54,8 +54,8 @@ static const float yscale = 3.0; // Real y res = 224 * yscale // Fullscreen static bool fullscreen = false; // To start in Fullscreen or not -static const unsigned fullscreen_x = 1920; -static const unsigned fullscreen_y = 1200; +static const unsigned fullscreen_x = 1280; +static const unsigned fullscreen_y = 720; // Video VSYNC (recommended) static const bool vsync = true; @@ -93,17 +93,17 @@ static const bool force_aspect = true; static const bool audio_enable = true; // Output samplerate -static const unsigned out_rate = 44100; +static const unsigned out_rate = 48000; // Input samplerate from libSNES. // Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled. static const unsigned in_rate = 31950; // Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults. -static const char* audio_device = "hw:0"; +static const char* audio_device = NULL; // Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency. -static const int out_latency = 32; +static const int out_latency = 64; // Will sync audio. (recommended) static const bool audio_sync = true;