Skip to content

Commit

Permalink
Vita: sharp-bilinear-simple shader removes wobble
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Nov 14, 2017
1 parent 5358e14 commit 50a6f01
Show file tree
Hide file tree
Showing 45 changed files with 907 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -26,7 +26,6 @@ mods/*/

# Libraries
*.lib
*.a
*.la
*.lo

Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Expand Up @@ -20,7 +20,14 @@ include("${VITASDK}/share/vita.cmake" REQUIRED)
# Flags and includes
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVITA -fno-exceptions")

include_directories(
${CMAKE_SOURCE_DIR}/vitashaderlibs/vita2d_fbo/includes/
${CMAKE_SOURCE_DIR}/vitashaderlibs/vita-shader-collection/includes/
)

link_directories(
${CMAKE_SOURCE_DIR}/vitashaderlibs/vita2d_fbo/lib/
${CMAKE_SOURCE_DIR}/vitashaderlibs/vita-shader-collection/lib/
${CMAKE_CURRENT_BINARY_DIR}
)

Expand All @@ -41,6 +48,7 @@ add_executable(${VITA_APPNAME}
src/seg008.c
src/seg009.c
src/seqtbl.c
src/psp2_shader.c
)

target_link_libraries(${VITA_APPNAME}
Expand All @@ -52,8 +60,9 @@ target_link_libraries(${VITA_APPNAME}
ogg
jpeg
png
vita2d
kbdvita
vita2d
vitashaders
z
m
SceAppUtil_stub
Expand Down
86 changes: 86 additions & 0 deletions src/psp2_shader.c
@@ -0,0 +1,86 @@
//
// Adapted for vanilla c by rsn8887 on 11/13/2017
// Created by cpasjuste on 18/12/16.
//

// use https://github.com/frangarcj/vita2dlib/tree/fbo
// and https://github.com/frangarcj/vita-shader-collection/releases

#include "psp2_shader.h"

#include <lcd3x_v.h>
#include <lcd3x_f.h>
#include <gtu_v.h>
#include <gtu_f.h>
#include <texture_v.h>
#include <texture_f.h>
#include <opaque_v.h>
#include <bicubic_f.h>
#include <xbr_2x_v.h>
#include <xbr_2x_f.h>
#include <xbr_2x_fast_v.h>
#include <xbr_2x_fast_f.h>
#include <advanced_aa_v.h>
#include <advanced_aa_f.h>
#include <scale2x_f.h>
#include <scale2x_v.h>
#include <sharp_bilinear_f.h>
#include <sharp_bilinear_v.h>
#include <sharp_bilinear_simple_f.h>
#include <sharp_bilinear_simple_v.h>
//#include "xbr_2x_noblend_f.h"
//#include "xbr_2x_noblend_v.h"
#include <fxaa_v.h>
#include <fxaa_f.h>
#include <crt_easymode_f.h>


vita2d_shader *setPSP2Shader(PSP2Shader shaderType) {

vita2d_shader *shader;
switch (shaderType) {

case LCD3X:
shader = vita2d_create_shader((SceGxmProgram *) lcd3x_v, (SceGxmProgram *) lcd3x_f);
break;
case SCALE2X:
shader = vita2d_create_shader((SceGxmProgram *) scale2x_v, (SceGxmProgram *) scale2x_f);
break;
case AAA:
shader = vita2d_create_shader((SceGxmProgram *) advanced_aa_v, (SceGxmProgram *) advanced_aa_f);
break;
case SHARP_BILINEAR:
shader = vita2d_create_shader((SceGxmProgram *) sharp_bilinear_v, (SceGxmProgram *) sharp_bilinear_f);
break;
case SHARP_BILINEAR_SIMPLE:
shader = vita2d_create_shader((SceGxmProgram *) sharp_bilinear_simple_v, (SceGxmProgram *) sharp_bilinear_simple_f);
break;
case FXAA:
shader = vita2d_create_shader((SceGxmProgram *) fxaa_v, (SceGxmProgram *) fxaa_f);
break;
default:
shader = vita2d_create_shader((SceGxmProgram *) texture_v, (SceGxmProgram *) texture_f);
break;
}

vita2d_texture_set_program(shader->vertexProgram, shader->fragmentProgram);
vita2d_texture_set_wvp(shader->wvpParam);
vita2d_texture_set_vertexInput(&shader->vertexInput);
vita2d_texture_set_fragmentInput(&shader->fragmentInput);

for(int i=0; i<3; i++) {
vita2d_start_drawing();
vita2d_clear_screen();
vita2d_wait_rendering_done();
vita2d_swap_buffers();
}

return shader;
}

void clearPSP2Shader(vita2d_shader *shader) {
if (shader != NULL) {
vita2d_wait_rendering_done();
vita2d_free_shader(shader);
}
}
25 changes: 25 additions & 0 deletions src/psp2_shader.h
@@ -0,0 +1,25 @@
//
// Adapted for vanilla c by rsn8887 on 11/13/2017
// Created by cpasjuste on 18/12/16.
//

#ifndef PSP2_SHADER_H
#define PSP2_SHADER_H

#include <vita2d.h>

enum PSP2Shader {
NONE = 0,
LCD3X,
SCALE2X,
AAA,
SHARP_BILINEAR,
SHARP_BILINEAR_SIMPLE,
FXAA,
};
typedef enum PSP2Shader PSP2Shader;

void clearPSP2Shader(vita2d_shader *shader);
vita2d_shader *setPSP2Shader(PSP2Shader shaderType);

#endif //PSP2_SHADER_H
80 changes: 80 additions & 0 deletions src/seg009.c
Expand Up @@ -27,6 +27,77 @@ The authors of this program may be contacted at http://forum.princed.org

#ifdef VITA
#include <kbdvita.h>
#include "psp2_shader.h"
#include <vita2d.h>
vita2d_shader *shader = NULL;

// these three internal structures from SDL2 are needed to gain access to the raw
// vita2d_texture pointer and be able to set the hw-filter to "linear" to make the
// sharp-bilinear-simple shader work correctly
#ifndef VITA_TEXTUREDATA
#define VITA_TEXTUREDATA

typedef struct SDL_SW_YUVTexture
{
Uint32 format;
Uint32 target_format;
int w, h;
Uint8 *pixels;
int *colortab;
Uint32 *rgb_2_pix;
void (*Display1X) (int *colortab, Uint32 * rgb_2_pix,
unsigned char *lum, unsigned char *cr,
unsigned char *cb, unsigned char *out,
int rows, int cols, int mod);
void (*Display2X) (int *colortab, Uint32 * rgb_2_pix,
unsigned char *lum, unsigned char *cr,
unsigned char *cb, unsigned char *out,
int rows, int cols, int mod);

/* These are just so we don't have to allocate them separately */
Uint16 pitches[3];
Uint8 *planes[3];

/* This is a temporary surface in case we have to stretch copy */
SDL_Surface *stretch;
SDL_Surface *display;
} SDL_SW_YUVTexture;

/* Define the SDL texture structure */
typedef struct SDL_Texture
{
const void *magic;
Uint32 format; /**< The pixel format of the texture */
int access; /**< SDL_TextureAccess */
int w; /**< The width of the texture */
int h; /**< The height of the texture */
int modMode; /**< The texture modulation mode */
SDL_BlendMode blendMode; /**< The texture blend mode */
Uint8 r, g, b, a; /**< Texture modulation values */

SDL_Renderer *renderer;

/* Support for formats not supported directly by the renderer */
SDL_Texture *native;
SDL_SW_YUVTexture *yuv;
void *pixels;
int pitch;
SDL_Rect locked_rect;

void *driverdata; /**< Driver specific texture representation */

SDL_Texture *prev;
SDL_Texture *next;
} SDL_Texture;

typedef struct VITA_TextureData
{
vita2d_texture *tex;
unsigned int pitch;
unsigned int w;
unsigned int h;
} VITA_TextureData;
#endif
#endif

// Most functions in this file are different from those in the original game.
Expand Down Expand Up @@ -2101,6 +2172,15 @@ void __pascal far set_gr_mode(byte grmode) {
#ifdef USE_TEXT
load_font();
#endif

#ifdef VITA
if (sdl_texture_!=NULL) {
VITA_TextureData *sdl_hwtex=(VITA_TextureData *) sdl_texture_->native->driverdata;
vita2d_texture_set_filters(sdl_hwtex->tex, SCE_GXM_TEXTURE_FILTER_POINT, SCE_GXM_TEXTURE_FILTER_LINEAR);
//set shader on Vita to sharp-bilinear-simple for sharp pixels without pixelwobble
shader = setPSP2Shader(SHARP_BILINEAR_SIMPLE);
}
#endif
}

void request_screen_update() {
Expand Down
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/advanced_aa_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _advanced_aa_f_h_
#define _advanced_aa_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char advanced_aa_f[];
extern const int advanced_aa_f_size;
//---------------------------------------------------------------------------------
#endif //_advanced_aa_f_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/advanced_aa_v.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _advanced_aa_v_h_
#define _advanced_aa_v_h_
//---------------------------------------------------------------------------------
extern const unsigned char advanced_aa_v[];
extern const int advanced_aa_v_size;
//---------------------------------------------------------------------------------
#endif //_advanced_aa_v_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/alpha_blend_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _alpha_blend_f_h_
#define _alpha_blend_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char alpha_blend_f[];
extern const int alpha_blend_f_size;
//---------------------------------------------------------------------------------
#endif //_alpha_blend_f_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/alpha_blend_v.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _alpha_blend_v_h_
#define _alpha_blend_v_h_
//---------------------------------------------------------------------------------
extern const unsigned char alpha_blend_v[];
extern const int alpha_blend_v_size;
//---------------------------------------------------------------------------------
#endif //_alpha_blend_v_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/bicubic_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _bicubic_f_h_
#define _bicubic_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char bicubic_f[];
extern const int bicubic_f_size;
//---------------------------------------------------------------------------------
#endif //_bicubic_f_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/clear_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _clear_f_h_
#define _clear_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char clear_f[];
extern const int clear_f_size;
//---------------------------------------------------------------------------------
#endif //_clear_f_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/clear_v.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _clear_v_h_
#define _clear_v_h_
//---------------------------------------------------------------------------------
extern const unsigned char clear_v[];
extern const int clear_v_size;
//---------------------------------------------------------------------------------
#endif //_clear_v_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/color_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _color_f_h_
#define _color_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char color_f[];
extern const int color_f_size;
//---------------------------------------------------------------------------------
#endif //_color_f_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/color_v.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _color_v_h_
#define _color_v_h_
//---------------------------------------------------------------------------------
extern const unsigned char color_v[];
extern const int color_v_size;
//---------------------------------------------------------------------------------
#endif //_color_v_h_
//---------------------------------------------------------------------------------
14 changes: 14 additions & 0 deletions vitashaderlibs/vita-shader-collection/includes/crt_easymode_f.h
@@ -0,0 +1,14 @@
/*
This file was autogenerated by raw2c.
Visit http://www.devkitpro.org
*/

//---------------------------------------------------------------------------------
#ifndef _crt_easymode_f_h_
#define _crt_easymode_f_h_
//---------------------------------------------------------------------------------
extern const unsigned char crt_easymode_f[];
extern const int crt_easymode_f_size;
//---------------------------------------------------------------------------------
#endif //_crt_easymode_f_h_
//---------------------------------------------------------------------------------

0 comments on commit 50a6f01

Please sign in to comment.