-
Notifications
You must be signed in to change notification settings - Fork 1
/
GTUv031-multipass.shader
198 lines (169 loc) · 5.19 KB
/
GTUv031-multipass.shader
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?xml version="1.0" encoding="UTF-8"?>
<!--
Gaussian-kernel TV Upscaler
version : 0.31
Author: aliaspider - aliaspider@gmail.com
License: GPLv3
-->
<shader language="GLSL" style="GLES2">
<!-- PASS1 -->
<vertex><![CDATA[
#version 120
uniform mat4 rubyMVPMatrix;
attribute vec2 rubyVertexCoord;
attribute vec2 rubyTexCoord;
varying vec2 tex_coord;
void main()
{
gl_Position = rubyMVPMatrix * vec4(rubyVertexCoord, 0.0, 1.0);
tex_coord = rubyTexCoord;
}
]]></vertex>
<fragment filter="nearest" scale="1.0" float_framebuffer="true"><![CDATA[
#version 120
varying vec2 tex_coord;
uniform sampler2D rubyTexture;
//------------------------------------------------------------------------------------//
// CONFIG :
// gamma of the emulated CRT-TV
#define INPUTG2 2.4
// use tv levels (16-235) instead of the full range
// comment to disable
#define COMPOSITE_LEVELS
//------------------------------------------------------------------------------------//
#ifdef COMPOSITE_LEVELS
#define LEVELS(c) clamp((c -16.0/ 256.0)*256.0/(236.0-16.0) ,0.0,1.0)
#else
#define LEVELS(c) c
#endif
#define GAMMAIN(c) (pow(c, vec3(INPUTG2)))
void main() {
gl_FragColor = vec4(GAMMAIN(LEVELS(texture2D(rubyTexture, tex_coord).xyz)), 1.0);
}
]]></fragment>
<!-- PASS2 -->
<vertex><![CDATA[
#version 120
uniform mat4 rubyMVPMatrix;
attribute vec2 rubyVertexCoord;
attribute vec2 rubyTexCoord;
varying vec2 tex_coord;
void main()
{
gl_Position = rubyMVPMatrix * vec4(rubyVertexCoord, 0.0, 1.0);
tex_coord = rubyTexCoord;
}
]]></vertex>
<fragment filter="nearest" outscale_x="1.0" scale_y="1.0" float_framebuffer="true"><![CDATA[
#version 120
uniform sampler2D rubyTexture;
uniform vec2 rubyTextureSize;
uniform vec2 rubyInputSize;
varying vec2 tex_coord;
//------------------------------------------------------------------------------------//
// CONFIG :
// this will define the bandwidth of the signal per scanline
// a value of 640.0 or double the game horizontal resolution
// work well for most cases.
// you can set it to 512 to get full transparancy in snes
// games that use the pseudo-hires video mode.
// higher BANDWIDTH = sharper image
#define BANDWIDTH 512.0
// horizontal computation range or the shader,
// increasing this value will increase performance requieremnts
// you might need to increase it if you notice
// some artifacts appearing with lower bandwidth settings.
// you only need to set this to the lowest value that doesn't
// cause artifacts to appears.
// default : 2
#define X_RANGE 2
//------------------------------------------------------------------------------------//
#define pi 3.14159265358
#define a(x) abs(x)
#define d(x,b) (pi*b*min(a(x)+0.5,1.0/b))
#define e(x,b) (pi*b*min(max(a(x)-0.5,-1.0/b),1.0/b))
#define STU(x,b) ((d(x,b)+sin(d(x,b))-e(x,b)-sin(e(x,b)))/(2.0*pi))
#define X(i) (offset.x-(i))
#define SOURCE(i) vec2(tex_coord.x - X(i)/rubyTextureSize.x,tex_coord.y)
#define C(i) (texture2D(rubyTexture, SOURCE(i)).xyz)
#define VAL(i) (C(i)*STU(X(i),((BANDWIDTH/2.0)/rubyInputSize.x)))
void main() {
vec2 offset = fract((tex_coord * rubyTextureSize) - 0.5);
vec3 tempColor = vec3(0.0);
#if (X_RANGE > 6)
tempColor+=VAL(-6.0);
tempColor+=VAL(7.0);
#endif
#if (X_RANGE > 5)
tempColor+=VAL(-5.0);
tempColor+=VAL(6.0);
#endif
#if (X_RANGE > 4)
tempColor+=VAL(-4.0);
tempColor+=VAL(5.0);
#endif
#if (X_RANGE > 3)
tempColor+=VAL(-3.0);
tempColor+=VAL(4.0);
#endif
#if (X_RANGE > 2)
tempColor+=VAL(-2.0);
tempColor+=VAL(3.0);
#endif
#if (X_RANGE > 1)
tempColor+=VAL(-1.0);
tempColor+=VAL(2.0);
#endif
tempColor+=VAL(0.0);
tempColor+=VAL(1.0);
gl_FragColor = vec4((tempColor),1.0);
}
]]></fragment>
<!-- PASS3 -->
<vertex><![CDATA[
#version 120
uniform mat4 rubyMVPMatrix;
attribute vec2 rubyVertexCoord;
attribute vec2 rubyTexCoord;
varying vec2 tex_coord;
void main()
{
gl_Position = rubyMVPMatrix * vec4(rubyVertexCoord, 0.0, 1.0);
tex_coord = rubyTexCoord;
}
]]></vertex>
<fragment filter="nearest"><![CDATA[
#version 120
varying vec2 tex_coord;
uniform sampler2D rubyTexture;
uniform vec2 rubyTextureSize;
//------------------------------------------------------------------------------------//
// CONFIG :
// scanline width
// scanlines will start to disappear with a value of 1.5.
// a value of 2.0 will produce a scanlines free image.
// lower values might require a higher resolution
// to display correctly
#define SCANLINE_WIDTH 1.0
// gamma of the current display device
// try reducing this value if the image feels too bright
#define OUTPUTG2 2.2
//------------------------------------------------------------------------------------//
#define GAMMAOUT(c0) (pow(c0, vec3(1.0/OUTPUTG2)))
#define pi 3.14159265358
#define GAUSS(x,w) ((sqrt(2.0) / (w)) * (exp((-2.0 * pi / ((w) * (w)))* (x) * (x) )))
#define Y(j) (offset.y-(j))
#define SOURCE(j) vec2(tex_coord.x,tex_coord.y - Y(j)/rubyTextureSize.y)
#define C(j) (texture2D(rubyTexture, SOURCE(j)).xyz)
#define VAL(j) (C(j)*GAUSS(Y(j),SCANLINE_WIDTH))
void main() {
vec2 offset = fract((tex_coord * rubyTextureSize) - 0.5);
vec3 tempColor = vec3(0.0);
tempColor+=VAL(-1.0);
tempColor+=VAL(0.0);
tempColor+=VAL(1.0);
tempColor+=VAL(2.0);
gl_FragColor = vec4(GAMMAOUT(tempColor), 1.0);
}
]]></fragment>
</shader>