git.y1.nz

SameBoy

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

Shaders/MasterShader.fsh

      1 #version 150
      2 uniform sampler2D image;
      3 uniform sampler2D previous_image;
      4 uniform int frame_blending_mode;
      5 
      6 uniform vec2 output_resolution;
      7 uniform vec2 origin;
      8 
      9 #define equal(x, y) ((x) == (y))
     10 #define inequal(x, y) ((x) != (y))
     11 #define STATIC
     12 #define GAMMA (2.2)
     13 
     14 out vec4 frag_color;
     15 
     16 vec4 _texture(sampler2D t, vec2 pos)
     17 {
     18     return pow(texture(t, pos), vec4(GAMMA));
     19 }
     20 
     21 vec4 texture_relative(sampler2D t, vec2 pos, vec2 offset)
     22 {
     23     vec2 input_resolution = textureSize(t, 0);
     24     return _texture(t, (floor(pos * input_resolution) + offset + vec2(0.5, 0.5)) / input_resolution);
     25 }
     26 
     27 #define texture _texture
     28 
     29 #line 1
     30 {filter}
     31 
     32 
     33 #define BLEND_BIAS (1.0/3.0)
     34 
     35 #define DISABLED 0
     36 #define SIMPLE 1
     37 #define ACCURATE 2
     38 #define ACCURATE_EVEN ACCURATE
     39 #define ACCURATE_ODD 3
     40 
     41 void main()
     42 {
     43     vec2 position = gl_FragCoord.xy - origin;
     44     position /= output_resolution;
     45     position.y = 1 - position.y;
     46     vec2 input_resolution = textureSize(image, 0);
     47 
     48     float ratio;
     49     switch (frame_blending_mode) {
     50         default:
     51         case DISABLED:
     52             frag_color = pow(scale(image, position, input_resolution, output_resolution), vec4(1.0 / GAMMA));
     53             return;
     54         case SIMPLE:
     55             ratio = 0.5;
     56             break;
     57         case ACCURATE_EVEN:
     58             if ((int(position.y * input_resolution.y) & 1) == 0) {
     59                 ratio = BLEND_BIAS;
     60             }
     61             else {
     62                 ratio = 1 - BLEND_BIAS;
     63             }
     64             break;
     65         case ACCURATE_ODD:
     66             if ((int(position.y * input_resolution.y) & 1) == 0) {
     67                 ratio = 1 - BLEND_BIAS;
     68             }
     69             else {
     70                 ratio = BLEND_BIAS;
     71             }
     72             break;
     73     }
     74 
     75     frag_color = pow(mix(scale(image, position, input_resolution, output_resolution),
     76                          scale(previous_image, position, input_resolution, output_resolution), ratio), vec4(1.0 / GAMMA));
     77 
     78 }

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