tor-browser

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

glsl-function-smoothstep-float.html (2794B)


      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 <!DOCTYPE html>
      8 <html>
      9 <head>
     10 <meta charset="utf-8">
     11 <title>GLSL smoothstep-float function test</title>
     12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
     13 <link rel="stylesheet" href="../../../resources/glsl-feature-tests.css"/>
     14 <script src="../../../js/js-test-pre.js"></script>
     15 <script src="../../../js/webgl-test-utils.js"> </script>
     16 <script src="../../../js/glsl-generator.js"> </script>
     17 </head>
     18 <body>
     19 <div id="description"></div>
     20 <div id="console"></div>
     21 <script>
     22 "use strict";
     23 
     24 function clamp(value, min, max) {
     25  return Math.max(min, Math.min(value, max));
     26 }
     27 
     28 function smoothstep(edge0, edge1, value) {
     29  var t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
     30  return t * t * (3 - 2 * t);
     31 }
     32 
     33 GLSLGenerator.runReferenceImageTest({
     34  feature: "smoothstep",
     35  args: "float edge0, float edge1, $(type) value",
     36  testFunc: "$(func)(float, float, $(type))",
     37  gridRes: 8,
     38  tolerance: 4,
     39  tests: [
     40    {
     41      source: ["$(output) = vec4(",
     42              "    $(func)(0.3, 0.7, $(input).x),",
     43              "    $(func)(0.2, 0.8, $(input).y),",
     44              "    0,",
     45              "    1);"].join("\n"),
     46      generator: function(x, y, z, w) {
     47        return [ smoothstep(0.3, 0.7, x),
     48                 smoothstep(0.2, 0.8, y),
     49                 0,
     50                 1 ];
     51      },
     52    },
     53    {
     54      source: [ "$(output) = vec4(",
     55                "    $(func)(0.4, 0.8, $(input).xy),",
     56                "    0, 1);"].join("\n"),
     57      generator: function(x, y, z, w) {
     58        return [ smoothstep(0.4, 0.8, x),
     59                 smoothstep(0.4, 0.8, y),
     60                 0,
     61                 1 ];
     62      },
     63    },
     64    {
     65      // FIXME: this test seems to need a higher tolerance when run in a vertex shader.
     66      source: [ "$(output) = vec4(",
     67                "    $(func)(0.3, 0.7, $(input).xyz),",
     68                "    1);"].join("\n"),
     69      generator: function(x, y, z, w) {
     70        return [ smoothstep(0.3, 0.7, x),
     71                 smoothstep(0.3, 0.7, y),
     72                 smoothstep(0.3, 0.7, z),
     73                 1 ];
     74      },
     75      tolerance: 12,
     76      fragmentTolerance: 3,
     77    },
     78    {
     79      // FIXME: this test seems to need a higher tolerance when run in a vertex shader.
     80      source: ["$(output) = ",
     81               "    $(func)(0.3, 0.9, $(input));"].join("\n"),
     82      generator: function(x, y, z, w) {
     83        return [ smoothstep(0.3, 0.9, x),
     84                 smoothstep(0.3, 0.9, y),
     85                 smoothstep(0.3, 0.9, z),
     86                 smoothstep(0.3, 0.9, w) ];
     87      },
     88      tolerance: 7,
     89      fragmentTolerance: 3,
     90    },
     91  ]
     92 });
     93 var successfullyParsed = true;
     94 </script>
     95 </body>
     96 </html>