git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

Shaders/Scale2x.fsh

      1 /* Shader implementation of Scale2x is adapted from https://gist.github.com/singron/3161079 */
      2 
      3 STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
      4 {
      5     // texel arrangement
      6     // A B C
      7     // D E F
      8     // G H I
      9     
     10     vec4 B = texture_relative(image, position, vec2(  0,  1));
     11     vec4 D = texture_relative(image, position, vec2( -1,  0));
     12     vec4 E = texture_relative(image, position, vec2(  0,  0));
     13     vec4 F = texture_relative(image, position, vec2(  1,  0));
     14     vec4 H = texture_relative(image, position, vec2(  0, -1));
     15     vec2 p = position * input_resolution;
     16     // p = the position within a pixel [0...1]
     17     p = fract(p);
     18     if (p.x > .5) {
     19         if (p.y > .5) {
     20             // Top Right
     21             return equal(B, F) && inequal(B, D) && inequal(F, H) ? F : E;
     22         } else {
     23             // Bottom Right
     24             return equal(H, F) && inequal(D, H) && inequal(B, F) ? F : E;
     25         }
     26     } else {
     27         if (p.y > .5) {
     28             // Top Left
     29             return equal(D, B) && inequal(B, F) && inequal(D, H) ? D : E;
     30         } else {
     31             // Bottom Left
     32             return equal(D, H) && inequal(D, B) && inequal(H, F) ? D : E;
     33         }
     34     }
     35 }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.