tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

dithering.glsl (894B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2  * License, v. 2.0. If a copy of the MPL was not distributed with this
      3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifdef WR_FRAGMENT_SHADER
      6 
      7 #ifdef WR_FEATURE_DITHERING
      8 
      9 // A 8x8 texture producing values in the range [0, 64/255].
     10 uniform sampler2D sDither;
     11 
     12 vec4 dither(vec4 color) {
     13     const int matrix_mask = 7;
     14 
     15     ivec2 pos = ivec2(gl_FragCoord.xy) & ivec2(matrix_mask);
     16     float noise_normalized = texelFetch(sDither, pos, 0).r * 255.0 / 64.0;
     17     // Center the range around zero and scale it down by some amount to
     18     // avoid hardware-specific rounding differences.
     19     float noise = (noise_normalized - 0.5) / 256.0 * 0.87;
     20 
     21     return color + vec4(noise, noise, noise, 0);
     22 }
     23 
     24 #else
     25 
     26 vec4 dither(vec4 color) {
     27     return color;
     28 }
     29 
     30 #endif //WR_FEATURE_DITHERING
     31 
     32 #endif //WR_FRAGMENT_SHADER