git.y1.nz

SameBoy

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

Shaders/MonoLCD.fsh

      1 #define SCANLINE_DEPTH 0.25
      2 #define BLOOM 0.4
      3 
      4 STATIC vec4 scale(sampler2D image, vec2 position, vec2 input_resolution, vec2 output_resolution)
      5 {
      6     vec2 pixel = position * input_resolution - vec2(0.5, 0.5);
      7 
      8     vec4 q11 = texture(image, (floor(pixel) + 0.5) / input_resolution);
      9     vec4 q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / input_resolution);
     10     vec4 q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / input_resolution);
     11     vec4 q22 = texture(image, (ceil(pixel) + 0.5) / input_resolution);
     12 
     13     vec2 s = smoothstep(0., 1., fract(pixel));
     14 
     15     vec4 r1 = mix(q11, q21, s.x);
     16     vec4 r2 = mix(q12, q22, s.x);
     17     
     18     vec2 pos = fract(position * input_resolution);
     19     vec2 sub_pos = pos * 6.0;
     20 
     21     float multiplier = 1.0;
     22     
     23     if (sub_pos.y < 1.0) {
     24         multiplier *= sub_pos.y * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH);
     25     }
     26     else if (sub_pos.y > 5.0) {
     27         multiplier *= (6.0 - sub_pos.y) * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH);
     28     }
     29     
     30     if (sub_pos.x < 1.0) {
     31         multiplier *= sub_pos.x * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH);
     32     }
     33     else if (sub_pos.x > 5.0) {
     34         multiplier *= (6.0 - sub_pos.x) * SCANLINE_DEPTH + (1.0 - SCANLINE_DEPTH);
     35     }
     36 
     37     vec4 pre_shadow = mix(texture(image, position) * multiplier, mix(r1, r2, s.y), BLOOM);
     38     pre_shadow.a = 1.0;
     39     pixel += vec2(-0.6, -0.8);
     40     
     41     q11 = texture(image, (floor(pixel) + 0.5) / input_resolution);
     42     q12 = texture(image, (vec2(floor(pixel.x), ceil(pixel.y)) + 0.5) / input_resolution);
     43     q21 = texture(image, (vec2(ceil(pixel.x), floor(pixel.y)) + 0.5) / input_resolution);
     44     q22 = texture(image, (ceil(pixel) + 0.5) / input_resolution);
     45    
     46     r1 = mix(q11, q21, fract(pixel.x));
     47     r2 = mix(q12, q22, fract(pixel.x));
     48     
     49     vec4 shadow = mix(r1, r2, fract(pixel.y));
     50     return mix(min(shadow, pre_shadow), pre_shadow, 0.75);
     51 }

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