forked from libretro/common-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanczos6.cg
126 lines (103 loc) · 4.04 KB
/
lanczos6.cg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright (C) 2010 Team XBMC
http://www.xbmc.org
Copyright (C) 2011 Stefanos A.
http://www.opentk.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, 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 XBMC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
From this forum post:
http://board.byuu.org/viewtopic.php?p=33488#p33488
*/
/* 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;
float frame_count;
float frame_direction;
float frame_rotation;
};
#define FIX(c) max(abs(c), 1e-5);
const float PI = 3.1415926535897932384626433832795;
float3 weight3(float x)
{
const float radius = 3.0;
float3 sample = FIX(2.0 * PI * float3(x - 1.5, x - 0.5, x + 0.5));
// Lanczos3. Note: we normalize outside this function, so no point in multiplying by radius.
return /*radius **/ sin(sample) * sin(sample / radius) / (sample * sample);
}
float3 pixel(float xpos, float ypos, uniform sampler2D s_p)
{
return tex2D(s_p, float2(xpos, ypos)).rgb;
}
float3 line_run(float ypos, float3 xpos1, float3 xpos2, float3 linetaps1, float3 linetaps2, uniform sampler2D s_p)
{
return
pixel(xpos1.r, ypos, s_p) * linetaps1.r +
pixel(xpos1.g, ypos, s_p) * linetaps2.r +
pixel(xpos1.b, ypos, s_p) * linetaps1.g +
pixel(xpos2.r, ypos, s_p) * linetaps2.g +
pixel(xpos2.g, ypos, s_p) * linetaps1.b +
pixel(xpos2.b, ypos, s_p) * linetaps2.b;
}
output main_fragment (float2 tex : TEXCOORD0, uniform input IN, uniform sampler2D s_p : TEXUNIT0)
{
float2 stepxy = 1.0 / IN.texture_size.xy;
float2 pos = tex.xy + stepxy * 0.5;
float2 f = frac(pos / stepxy);
float3 linetaps1 = weight3(0.5 - f.x * 0.5);
float3 linetaps2 = weight3(1.0 - f.x * 0.5);
float3 columntaps1 = weight3(0.5 - f.y * 0.5);
float3 columntaps2 = weight3(1.0 - f.y * 0.5);
// make sure all taps added together is exactly 1.0, otherwise some
// (very small) distortion can occur
float suml = dot(linetaps1, float3(1.0)) + dot(linetaps2, float3(1.0));
float sumc = dot(columntaps1, float3(1.0)) + dot(columntaps2, float3(1.0));
linetaps1 /= suml;
linetaps2 /= suml;
columntaps1 /= sumc;
columntaps2 /= sumc;
float2 xystart = (-2.5 - f) * stepxy + pos;
float3 xpos1 = float3(xystart.x, xystart.x + stepxy.x, xystart.x + stepxy.x * 2.0);
float3 xpos2 = float3(xystart.x + stepxy.x * 3.0, xystart.x + stepxy.x * 4.0, xystart.x + stepxy.x * 5.0);
// final sum and weight normalization
output OUT;
OUT.color = float4(
line_run(xystart.y , xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps1.r +
line_run(xystart.y + stepxy.y , xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps2.r +
line_run(xystart.y + stepxy.y * 2.0, xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps1.g +
line_run(xystart.y + stepxy.y * 3.0, xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps2.g +
line_run(xystart.y + stepxy.y * 4.0, xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps1.b +
line_run(xystart.y + stepxy.y * 5.0, xpos1, xpos2, linetaps1, linetaps2, s_p) * columntaps2.b,1.0);
return OUT;
}