1/* 2 * Copyright (C) 2018 Solarus - http://www.solarus-games.org 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18// Scale2X shader adapted from bsnes 19// https://gitorious.org/bsnes/xml-shaders/ 20 21#if __VERSION__ >= 130 22#define COMPAT_VARYING out 23#define COMPAT_ATTRIBUTE in 24#define COMPAT_TEXTURE texture 25#else 26#define COMPAT_VARYING varying 27#define COMPAT_ATTRIBUTE attribute 28#define COMPAT_TEXTURE texture2D 29#endif 30 31#ifdef GL_ES 32precision mediump float; 33#define COMPAT_PRECISION mediump 34#else 35#define COMPAT_PRECISION 36#endif 37 38COMPAT_ATTRIBUTE vec2 sol_vertex; 39COMPAT_ATTRIBUTE vec2 sol_tex_coord; 40 41uniform vec2 sol_input_size; 42uniform vec2 sol_output_size; 43uniform mat4 sol_mvp_matrix; 44uniform mat3 sol_uv_matrix; 45vec2 sol_texture_size = sol_input_size; 46 47COMPAT_VARYING vec2 tex_coords[5]; 48 49void main() { 50 vec2 offsetx; 51 vec2 offsety; 52 53 gl_Position = sol_mvp_matrix * vec4(sol_vertex, 0, 1); 54 55 offsetx.x = 1.0 / sol_texture_size.x; 56 offsetx.y = 0.0; 57 offsety.y = 1.0 / sol_texture_size.y; 58 offsety.x = 0.0; 59 60 tex_coords[0] = vec2(sol_uv_matrix * vec3(sol_tex_coord, 1)); // center 61 tex_coords[1] = tex_coords[0] - offsetx; // left 62 tex_coords[2] = tex_coords[0] + offsetx; // right 63 tex_coords[3] = tex_coords[0] - offsety; // top 64 tex_coords[4] = tex_coords[0] + offsety; // bottom 65} 66