tor-browser

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

modulo-arithmetic-accuracy.html (1848B)


      1 <!--
      2 Copyright (c) 2019 The Khronos Group Inc.
      3 Use of this source code is governed by an MIT-style license that can be
      4 found in the LICENSE.txt file.
      5 -->
      6 
      7 <!-- author: Bill Baxter (wbaxter at google.com) -->
      8 
      9 <!DOCTYPE html>
     10 <html>
     11 <head>
     12 <meta charset="utf-8">
     13 <title>Modulo Arithmetic Accuracy Bug</title>
     14 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     15 <script src="../../../js/js-test-pre.js"></script>
     16 <script src="../../../js/webgl-test-utils.js"></script>
     17 <script src="../../../js/glsl-conformance-test.js"></script>
     18 </head>
     19 
     20 <body>
     21 <div id="description"></div>
     22 <div id="console"></div>
     23 
     24 <script id="shader-vs" type="x-shader/x-vertex">
     25 attribute vec4 vPosition;
     26 uniform float divisor;
     27 varying vec4 vColor;
     28 void main(void) {
     29  gl_Position = vPosition;
     30  float index = 9.0;
     31  // mod(x, y) is computed as x-y*floor(x/y).  There are no guarantees on
     32  // the precision of floating point operations in WebGL shaders, but division
     33  // should be accurate to at least 1 part in 10^5.
     34  float value = mod(index * 1.00001, divisor);
     35  vColor = (value < 1.) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
     36 }
     37 </script>
     38 
     39 <script id="shader-fs" type="x-shader/x-fragment">
     40 precision mediump float;
     41 varying vec4 vColor;
     42 void main(void) {
     43  gl_FragColor = vColor;
     44 }
     45 </script>
     46 <script>
     47 "use strict";
     48 
     49 description();
     50 debug("");
     51 // Reproduces bug seen on Mac OS X with AMD Radeon HD 6490 GPU
     52 debug("If things are working correctly, then the square will be green.");
     53 debug("If your card thinks mod(9,3) is not 0, then the square will be red.");
     54 
     55 GLSLConformanceTester.runRenderTests([
     56 {
     57  vShaderId: 'shader-vs',
     58  vShaderSuccess: true,
     59  fShaderId: 'shader-fs',
     60  fShaderSuccess: true,
     61  linkSuccess: true,
     62  passMsg: 'Test that mod(9/3) is 0',
     63  uniforms: [{name: "divisor", functionName: "uniform1f", value: 3}]
     64 }
     65 ]);
     66 </script>
     67 </body>
     68 </html>