Mercurial > repos > blastem
annotate shaders/xBRZ.f.glsl @ 2507:aa888682faa0 default tip
Fix debug windows not filling window in GL mode. Thanks Sik!
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 14 Aug 2024 22:29:11 -0700 |
parents | d437b8e8ba62 |
children |
rev | line source |
---|---|
2495
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 // xBRZ freescale |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 // based on : |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 /* |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 Hyllian's xBR-vertex code and texel mapping |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 Copyright (C) 2011/2016 Hyllian - sergiogdb@gmail.com |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 Permission is hereby granted, free of charge, to any person obtaining a copy |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 of this software and associated documentation files (the "Software"), to deal |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 in the Software without restriction, including without limitation the rights |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 copies of the Software, and to permit persons to whom the Software is |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 furnished to do so, subject to the following conditions: |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 The above copyright notice and this permission notice shall be included in |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 all copies or substantial portions of the Software. |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 THE SOFTWARE. |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 */ |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 // This shader also uses code and/or concepts from xBRZ as it appears |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 // in the Desmume source code. The license for which is as follows: |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 // **************************************************************************** |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 // * This file is part of the HqMAME project. It is distributed under * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 // * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 // * * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 // * Additionally and as a special exception, the author gives permission * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 // * to link the code of this program with the MAME library (or with modified * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 // * versions of MAME that use the same license as MAME), and distribute * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 // * linked combinations including the two. You must obey the GNU General * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 // * Public License in all respects for all of the code used other than MAME. * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 // * If you modify this file, you may extend this exception to your version * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 // * of the file, but you are not obligated to do so. If you do not wish to * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 // * do so, delete this exception statement from your version. * |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 // **************************************************************************** |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 // ported to blastem shader format by hunterk |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 uniform sampler2D textures[2]; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 uniform mediump vec2 texsize; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 varying mediump vec2 texcoord; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 #define BLEND_NONE 0 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 #define BLEND_NORMAL 1 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 #define BLEND_DOMINANT 2 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 #define LUMINANCE_WEIGHT 1.0 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 #define EQUAL_COLOR_TOLERANCE 30.0/255.0 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 #define STEEP_DIRECTION_THRESHOLD 2.2 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 #define DOMINANT_DIRECTION_THRESHOLD 3.6 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 // this is usually handled automatically but blastem doesn't expose output size? |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 #define scale vec2(10.0, 10.0) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 mediump float DistYCbCr(vec3 pixA, vec3 pixB) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 const vec3 w = vec3(0.2627, 0.6780, 0.0593); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 const float scaleB = 0.5 / (1.0 - w.b); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 const float scaleR = 0.5 / (1.0 - w.r); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 vec3 diff = pixA - pixB; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 float Y = dot(diff.rgb, w); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 float Cb = scaleB * (diff.b - Y); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 float Cr = scaleR * (diff.r - Y); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 return sqrt(((LUMINANCE_WEIGHT * Y) * (LUMINANCE_WEIGHT * Y)) + (Cb * Cb) + (Cr * Cr)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 bool IsPixEqual(const vec3 pixA, const vec3 pixB) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 return (DistYCbCr(pixA, pixB) < EQUAL_COLOR_TOLERANCE); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 mediump float get_left_ratio(vec2 center, vec2 origin, vec2 direction, vec2 scale_) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 vec2 P0 = center - origin; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 vec2 proj = direction * (dot(P0, direction) / dot(direction, direction)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 vec2 distv = P0 - proj; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 vec2 orth = vec2(-direction.y, direction.x); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 float side = sign(dot(P0, orth)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 float v = side * length(distv * scale_); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 // return step(0, v); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 return smoothstep(-sqrt(2.0)/2.0, sqrt(2.0)/2.0, v); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 #define eq(a,b) (a == b) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 #define neq(a,b) (a != b) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 #define P(x,y) texture2D(textures[0], coord + (1.0 / texsize) * vec2(x, y)).rgb |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 void main() |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 //--------------------------------------- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 // Input Pixel Mapping: -|x|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 // x|A|B|C|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 // x|D|E|F|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 // x|G|H|I|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 // -|x|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 vec2 pos = fract(texcoord * texsize.xy) - vec2(0.5, 0.5); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 vec2 coord = texcoord - pos * (1.0 / texsize.xy); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 vec3 A = P(-1,-1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 vec3 B = P( 0,-1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 vec3 C = P( 1,-1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 vec3 D = P(-1, 0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 vec3 E = P( 0, 0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 vec3 F = P( 1, 0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 vec3 G = P(-1, 1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 vec3 H = P( 0, 1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 vec3 I = P( 1, 1); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 // blendResult Mapping: x|y| |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 // w|z| |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 ivec4 blendResult = ivec4(BLEND_NONE,BLEND_NONE,BLEND_NONE,BLEND_NONE); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 // Preprocess corners |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 // Pixel Tap Mapping: -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 // -|-|B|C|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 // -|D|E|F|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 // -|G|H|I|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 // -|-|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 if (!((eq(E,F) && eq(H,I)) || (eq(E,H) && eq(F,I)))) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 float dist_H_F = DistYCbCr(G, E) + DistYCbCr(E, C) + DistYCbCr(P(0,2), I) + DistYCbCr(I, P(2,0)) + (4.0 * DistYCbCr(H, F)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 float dist_E_I = DistYCbCr(D, H) + DistYCbCr(H, P(1,2)) + DistYCbCr(B, F) + DistYCbCr(F, P(2,1)) + (4.0 * DistYCbCr(E, I)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_H_F) < dist_E_I; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 blendResult.z = ((dist_H_F < dist_E_I) && neq(E,F) && neq(E,H)) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 // Pixel Tap Mapping: -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 // -|A|B|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 // x|D|E|F|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 // x|G|H|I|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 // -|x|x|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 if (!((eq(D,E) && eq(G,H)) || (eq(D,G) && eq(E,H)))) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 float dist_G_E = DistYCbCr(P(-2,1) , D) + DistYCbCr(D, B) + DistYCbCr(P(-1,2), H) + DistYCbCr(H, F) + (4.0 * DistYCbCr(G, E)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 float dist_D_H = DistYCbCr(P(-2,0) , G) + DistYCbCr(G, P(0,2)) + DistYCbCr(A, E) + DistYCbCr(E, I) + (4.0 * DistYCbCr(D, H)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_D_H) < dist_G_E; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 blendResult.w = ((dist_G_E > dist_D_H) && neq(E,D) && neq(E,H)) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 // Pixel Tap Mapping: -|-|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 // -|A|B|C|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 // -|D|E|F|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 // -|-|H|I|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 // -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 if (!((eq(B,C) && eq(E,F)) || (eq(B,E) && eq(C,F)))) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 float dist_E_C = DistYCbCr(D, B) + DistYCbCr(B, P(1,-2)) + DistYCbCr(H, F) + DistYCbCr(F, P(2,-1)) + (4.0 * DistYCbCr(E, C)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 float dist_B_F = DistYCbCr(A, E) + DistYCbCr(E, I) + DistYCbCr(P(0,-2), C) + DistYCbCr(C, P(2,0)) + (4.0 * DistYCbCr(B, F)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_B_F) < dist_E_C; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 blendResult.y = ((dist_E_C > dist_B_F) && neq(E,B) && neq(E,F)) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 // Pixel Tap Mapping: -|x|x|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 // x|A|B|C|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 // x|D|E|F|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 // -|G|H|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 // -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 if (!((eq(A,B) && eq(D,E)) || (eq(A,D) && eq(B,E)))) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 float dist_D_B = DistYCbCr(P(-2,0), A) + DistYCbCr(A, P(0,-2)) + DistYCbCr(G, E) + DistYCbCr(E, C) + (4.0 * DistYCbCr(D, B)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 float dist_A_E = DistYCbCr(P(-2,-1), D) + DistYCbCr(D, H) + DistYCbCr(P(-1,-2), B) + DistYCbCr(B, F) + (4.0 * DistYCbCr(A, E)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 bool dominantGradient = (DOMINANT_DIRECTION_THRESHOLD * dist_D_B) < dist_A_E; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 blendResult.x = ((dist_D_B < dist_A_E) && neq(E,D) && neq(E,B)) ? ((dominantGradient) ? BLEND_DOMINANT : BLEND_NORMAL) : BLEND_NONE; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 vec3 res = E; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 // Pixel Tap Mapping: -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 // -|-|B|C|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 // -|D|E|F|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 // -|G|H|I|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 // -|-|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 if(blendResult.z != BLEND_NONE) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 float dist_F_G = DistYCbCr(F, G); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 float dist_H_C = DistYCbCr(H, C); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 bool doLineBlend = (blendResult.z == BLEND_DOMINANT || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 !((blendResult.y != BLEND_NONE && !IsPixEqual(E, G)) || (blendResult.w != BLEND_NONE && !IsPixEqual(E, C)) || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 (IsPixEqual(G, H) && IsPixEqual(H, I) && IsPixEqual(I, F) && IsPixEqual(F, C) && !IsPixEqual(E, I)))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 vec2 origin = vec2(0.0, 1.0 / sqrt(2.0)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 vec2 direction = vec2(1.0, -1.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 if(doLineBlend) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 bool haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_F_G <= dist_H_C) && neq(E,G) && neq(D,G); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 bool haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_H_C <= dist_F_G) && neq(E,C) && neq(B,C); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 origin = haveShallowLine? vec2(0.0, 0.25) : vec2(0.0, 0.5); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 direction.x += haveShallowLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 direction.y -= haveSteepLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 vec3 blendPix = mix(H,F, step(DistYCbCr(E, F), DistYCbCr(E, H))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 res = mix(res, blendPix, get_left_ratio(pos, origin, direction, scale)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 // Pixel Tap Mapping: -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 // -|A|B|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 // x|D|E|F|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 // x|G|H|I|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 // -|x|x|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 if(blendResult.w != BLEND_NONE) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 float dist_H_A = DistYCbCr(H, A); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 float dist_D_I = DistYCbCr(D, I); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 bool doLineBlend = (blendResult.w == BLEND_DOMINANT || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 !((blendResult.z != BLEND_NONE && !IsPixEqual(E, A)) || (blendResult.x != BLEND_NONE && !IsPixEqual(E, I)) || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 (IsPixEqual(A, D) && IsPixEqual(D, G) && IsPixEqual(G, H) && IsPixEqual(H, I) && !IsPixEqual(E, G)))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 vec2 origin = vec2(-1.0 / sqrt(2.0), 0.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 vec2 direction = vec2(1.0, 1.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 if(doLineBlend) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 bool haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_H_A <= dist_D_I) && neq(E,A) && neq(B,A); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 bool haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_D_I <= dist_H_A) && neq(E,I) && neq(F,I); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 origin = haveShallowLine? vec2(-0.25, 0.0) : vec2(-0.5, 0.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 direction.y += haveShallowLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 direction.x += haveSteepLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 origin = origin; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 direction = direction; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 vec3 blendPix = mix(H,D, step(DistYCbCr(E, D), DistYCbCr(E, H))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 res = mix(res, blendPix, get_left_ratio(pos, origin, direction, scale)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 // Pixel Tap Mapping: -|-|x|x|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 // -|A|B|C|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 // -|D|E|F|x |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 // -|-|H|I|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 // -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 if(blendResult.y != BLEND_NONE) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 float dist_B_I = DistYCbCr(B, I); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 float dist_F_A = DistYCbCr(F, A); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 bool doLineBlend = (blendResult.y == BLEND_DOMINANT || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 !((blendResult.x != BLEND_NONE && !IsPixEqual(E, I)) || (blendResult.z != BLEND_NONE && !IsPixEqual(E, A)) || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 (IsPixEqual(I, F) && IsPixEqual(F, C) && IsPixEqual(C, B) && IsPixEqual(B, A) && !IsPixEqual(E, C)))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 vec2 origin = vec2(1.0 / sqrt(2.0), 0.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 vec2 direction = vec2(-1.0, -1.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 if(doLineBlend) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 bool haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_B_I <= dist_F_A) && neq(E,I) && neq(H,I); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 bool haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_F_A <= dist_B_I) && neq(E,A) && neq(D,A); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 origin = haveShallowLine? vec2(0.25, 0.0) : vec2(0.5, 0.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 direction.y -= haveShallowLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 direction.x -= haveSteepLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 vec3 blendPix = mix(F,B, step(DistYCbCr(E, B), DistYCbCr(E, F))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 res = mix(res, blendPix, get_left_ratio(pos, origin, direction, scale)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 // Pixel Tap Mapping: -|x|x|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 // x|A|B|C|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 // x|D|E|F|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 // -|G|H|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 // -|-|-|-|- |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 if(blendResult.x != BLEND_NONE) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 float dist_D_C = DistYCbCr(D, C); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 float dist_B_G = DistYCbCr(B, G); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 bool doLineBlend = (blendResult.x == BLEND_DOMINANT || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 !((blendResult.w != BLEND_NONE && !IsPixEqual(E, C)) || (blendResult.y != BLEND_NONE && !IsPixEqual(E, G)) || |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 (IsPixEqual(C, B) && IsPixEqual(B, A) && IsPixEqual(A, D) && IsPixEqual(D, G) && !IsPixEqual(E, A)))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 vec2 origin = vec2(0.0, -1.0 / sqrt(2.0)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 vec2 direction = vec2(-1.0, 1.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 if(doLineBlend) |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 { |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 bool haveShallowLine = (STEEP_DIRECTION_THRESHOLD * dist_D_C <= dist_B_G) && neq(E,C) && neq(F,C); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 bool haveSteepLine = (STEEP_DIRECTION_THRESHOLD * dist_B_G <= dist_D_C) && neq(E,G) && neq(H,G); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 origin = haveShallowLine? vec2(0.0, -0.25) : vec2(0.0, -0.5); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 direction.x -= haveShallowLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 direction.y += haveSteepLine? 1.0: 0.0; |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 vec3 blendPix = mix(D,B, step(DistYCbCr(E, B), DistYCbCr(E, D))); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 res = mix(res, blendPix, get_left_ratio(pos, origin, direction, scale)); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 } |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 gl_FragColor = vec4(res, 1.0); |
d437b8e8ba62
Add xBRZ and bandlimit pixel footprint shaders ported by hunterk
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 } |