From 0f34a7427b9f762039c25057a891481030b1bead Mon Sep 17 00:00:00 2001 From: RokkumanX <50436544+RokkumanX@users.noreply.github.com> Date: Mon, 28 Sep 2020 09:31:33 +0200 Subject: [PATCH] Add PSP color shader This adds the PSP color shader ported from RetroArch courtesy from @jdgleaver (https://forums.ppsspp.org/showthread.php?tid=6594&pid=130635#pid130635) to PPSSPP Also updated with up to date changes found here (https://github.com/libretro/glsl-shaders/blob/master/handheld/shaders/color/psp-color.glsl) --- assets/shaders/psp_color.fsh | 58 ++++++++++++++++++++++++++++++++++++ assets/shaders/psp_color.ini | 6 ++++ assets/shaders/psp_color.vsh | 23 ++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 assets/shaders/psp_color.fsh create mode 100644 assets/shaders/psp_color.ini create mode 100644 assets/shaders/psp_color.vsh diff --git a/assets/shaders/psp_color.fsh b/assets/shaders/psp_color.fsh new file mode 100644 index 0000000000..aad99df883 --- /dev/null +++ b/assets/shaders/psp_color.fsh @@ -0,0 +1,58 @@ +/* + psp_color vertex shader + + Original code written by hunterk, modified by Pokefan531 and + released into the public domain + + 'Ported' (i.e. copy/paste) to PPSSPP format by jdgleaver + + 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. + + Notes: This shader replicates the LCD dynamics of the PSP 1000 and PSP 2000 +*/ + +//================ +#ifdef GL_ES +precision mediump float; +precision mediump int; +// For android, use this instead... +//precision highp float; +//precision highp int; +// +#endif + +//================ +#define target_gamma 2.21 +#define display_gamma 2.2 +#define r 0.98 +#define g 0.795 +#define b 0.98 +#define rg 0.04 +#define rb 0.01 +#define gr 0.20 +#define gb 0.01 +#define br -0.18 +#define bg 0.165 + +//================ +uniform sampler2D sampler0; +varying vec2 v_texcoord0; + +//================ +void main() +{ + // Apply colour correction + vec3 screen = pow(texture2D(sampler0, v_texcoord0.xy).rgb, vec3(target_gamma)); + screen = clamp(screen, 0.0, 1.0); + screen = pow( + mat3(r, rg, rb, + gr, g, gb, + br, bg, b) * screen, + vec3(1.0 / display_gamma) + ); + + gl_FragColor = vec4(screen, 1.0); +} diff --git a/assets/shaders/psp_color.ini b/assets/shaders/psp_color.ini new file mode 100644 index 0000000000..73cae04bb2 --- /dev/null +++ b/assets/shaders/psp_color.ini @@ -0,0 +1,6 @@ +[PSP Color] +Name=PSP Color +Author=hunterk, Pokefan531 (ported by jdgleaver) +Fragment=psp_color.fsh +Vertex=psp_color.vsh +OutputResolution=True diff --git a/assets/shaders/psp_color.vsh b/assets/shaders/psp_color.vsh new file mode 100644 index 0000000000..0353e17dae --- /dev/null +++ b/assets/shaders/psp_color.vsh @@ -0,0 +1,23 @@ +/* + psp_color vertex shader + + Original code written by hunterk, modified by Pokefan531 and + released into the public domain + + 'Ported' (i.e. copy/paste) to PPSSPP format by jdgleaver + + 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. +*/ + +attribute vec4 a_position; +attribute vec2 a_texcoord0; +varying vec2 v_texcoord0; + +void main() +{ + v_texcoord0 = a_texcoord0; // + 0.000001; // HLSL precision workaround (is this needed???) + gl_Position = a_position; +}