SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Shaders/Scale4x.fsh
1 STATIC vec4 scale2x(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
2 {
3 // texel arrangement
4 // A B C
5 // D E F
6 // G H I
7 vec4 B = texture_relative(image, position, vec2( 0, 1));
8 vec4 D = texture_relative(image, position, vec2( -1, 0));
9 vec4 E = texture_relative(image, position, vec2( 0, 0));
10 vec4 F = texture_relative(image, position, vec2( 1, 0));
11 vec4 H = texture_relative(image, position, vec2( 0, -1));
12 vec2 p = position * input_resolution;
13 // p = the position within a pixel [0...1]
14 p = fract(p);
15 if (p.x > .5) {
16 if (p.y > .5) {
17 // Top Right
18 return equal(B, F) && inequal(B, D) && inequal(F, H) ? F : E;
19 } else {
20 // Bottom Right
21 return equal(H, F) && inequal(D, H) && inequal(B, F) ? F : E;
22 }
23 } else {
24 if (p.y > .5) {
25 // Top Left
26 return equal(D, B) && inequal(B, F) && inequal(D, H) ? D : E;
27 } else {
28 // Bottom Left
29 return equal(D, H) && inequal(D, B) && inequal(H, F) ? D : E;
30 }
31 }
32 }
33
34 STATIC vec4 scale2x_wrapper(sampler2D t, vec2 pos, vec2 offset, vec2 input_resolution, vec2 output_resolution)
35 {
36 vec2 origin = (floor(pos * input_resolution * 2.0)) + vec2(0.5, 0.5);
37 return scale2x(t, (origin + offset) / input_resolution / 2.0, input_resolution, output_resolution);
38 }
39
40 STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
41 {
42 // texel arrangement
43 // A B C
44 // D E F
45 // G H I
46 vec4 B = scale2x_wrapper(image, position, vec2( 0, 1), input_resolution, output_resolution);
47 vec4 D = scale2x_wrapper(image, position, vec2( -1, 0), input_resolution, output_resolution);
48 vec4 E = scale2x_wrapper(image, position, vec2( 0, 0), input_resolution, output_resolution);
49 vec4 F = scale2x_wrapper(image, position, vec2( 1, 0), input_resolution, output_resolution);
50 vec4 H = scale2x_wrapper(image, position, vec2( 0, -1), input_resolution, output_resolution);
51
52 vec2 p = position * input_resolution * 2.;
53 // p = the position within a pixel [0...1]
54 p = fract(p);
55 if (p.x > .5) {
56 if (p.y > .5) {
57 // Top Right
58 return equal(B, F) && inequal(B, D) && inequal(F, H) ? F : E;
59 } else {
60 // Bottom Right
61 return equal(H, F) && inequal(D, H) && inequal(B, F) ? F : E;
62 }
63 } else {
64 if (p.y > .5) {
65 // Top Left
66 return equal(D, B) && inequal(B, F) && inequal(D, H) ? D : E;
67 } else {
68 // Bottom Left
69 return equal(D, H) && inequal(D, B) && inequal(H, F) ? D : E;
70 }
71 }
72 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.