-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.glsl
127 lines (103 loc) · 3.37 KB
/
template.glsl
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
#version 120
#if defined(VERTEX)
#if __VERSION__ >= 130
#define COMPAT_VARYING out
#define COMPAT_ATTRIBUTE in
#define COMPAT_TEXTURE texture
#else
#define COMPAT_VARYING varying
#define COMPAT_ATTRIBUTE attribute
#define COMPAT_TEXTURE texture2D
#endif
#ifdef GL_ES
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif
uniform vec2 rubyTextureSize;
uniform vec2 rubyInputSize;
uniform vec2 rubyOutputSize;
COMPAT_ATTRIBUTE vec4 a_position;
COMPAT_VARYING vec2 v_texCoord;
void main()
{
gl_Position = a_position;
v_texCoord = vec2(a_position.x + 1.0, 1.0 - a_position.y) / 2.0 * rubyInputSize / rubyTextureSize;
}
#elif defined(FRAGMENT)
#if __VERSION__ >= 130
#define COMPAT_VARYING in
#define COMPAT_TEXTURE texture
out vec4 FragColor;
#else
#define COMPAT_VARYING varying
#define FragColor gl_FragColor
#define COMPAT_TEXTURE texture2D
#endif
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#define COMPAT_PRECISION highp
#else
#define COMPAT_PRECISION
#endif
uniform vec2 rubyTextureSize;
uniform sampler2D rubyTexture;
/*
The following code allows the shader to override any texture filtering
configured in DOSBox. if 'output' is set to 'opengl', bilinear filtering
will be enabled and OPENGLNB will not be defined, if 'output' is set to
'openglnb', nearest neighbour filtering will be enabled and OPENGLNB will
be defined.
If you wish to use the default filtering method that is currently enabled
in DOSBox, use COMPAT_TEXTURE to lookup a texel from the input texture.
If you wish to force nearest-neighbor interpolation use NN_TEXTURE.
If you wish to force bilinear interpolation use BL_TEXTURE.
If DOSBox is configured to use the filtering method that is being forced,
the default hardware implementation will be used, otherwise the custom
implementations below will be used instead.
These custom implemenations rely on the `rubyTextureSize` uniform variable.
The code could calculate the texture size from the sampler using the
textureSize() GLSL function, but this would require a minimum of GLSL
version 130, which may prevent the shader from working on older systems.
*/
#if defined(OPENGLNB)
#define NN_TEXTURE COMPAT_TEXTURE
#define BL_TEXTURE blTexture
vec4 blTexture(in sampler2D sampler, in vec2 uv)
{
// subtract 0.5 here and add it again after the floor to centre the texel
vec2 texCoord = uv * rubyTextureSize - vec2(0.5);
vec2 s0t0 = floor(texCoord) + vec2(0.5);
vec2 s0t1 = s0t0 + vec2(0.0, 1.0);
vec2 s1t0 = s0t0 + vec2(1.0, 0.0);
vec2 s1t1 = s0t0 + vec2(1.0);
vec2 invTexSize = 1.0 / rubyTextureSize;
vec4 c_s0t0 = COMPAT_TEXTURE(sampler, s0t0 * invTexSize);
vec4 c_s0t1 = COMPAT_TEXTURE(sampler, s0t1 * invTexSize);
vec4 c_s1t0 = COMPAT_TEXTURE(sampler, s1t0 * invTexSize);
vec4 c_s1t1 = COMPAT_TEXTURE(sampler, s1t1 * invTexSize);
vec2 weight = fract(texCoord);
vec4 c0 = c_s0t0 + (c_s1t0 - c_s0t0) * weight.x;
vec4 c1 = c_s0t1 + (c_s1t1 - c_s0t1) * weight.x;
return (c0 + (c1 - c0) * weight.y);
}
#else
#define BL_TEXTURE COMPAT_TEXTURE
#define NN_TEXTURE nnTexture
vec4 nnTexture(in sampler2D sampler, in vec2 uv)
{
vec2 texCoord = floor(uv * rubyTextureSize) + vec2(0.5);
vec2 invTexSize = 1.0 / rubyTextureSize;
return COMPAT_TEXTURE(sampler, texCoord * invTexSize);
}
#endif
COMPAT_VARYING vec2 v_texCoord;
void main()
{
FragColor = COMPAT_TEXTURE(rubyTexture, v_texCoord);
}
#endif