// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader
test (float angle = 10, float inscale = 20,
      float offset = 0, float scale = 1,
      output color Cout = 0)
{
   // setup some coordinates
   float theta = radians(angle);
   float s = mod(u,0.25) - 0.125;
   float t = mod(v,0.5) - 0.25;
   float cos_theta;
   float sin_theta;
   if (angle == 10) {
       // hard code values for expected case of angle 10
       // to avoid issue of OSL constant folding 
       // producing slightly differnt values which 
       // create vastly different results due to 
       // aliasing in hashnoise.  
       cos_theta = 0.984807729721069335;
       sin_theta = 0.173648148775100708;
   } else {
       cos_theta = cos(theta);
       sin_theta = sin(theta);
   }
   float ru = cos_theta * s + sin_theta * t;
   float rv = sin_theta * s - cos_theta * t;
   ru *= inscale;
   rv *= inscale;
   float rz = (inscale * (s + t)) / M_SQRT2;
   float ttime = s*inscale;
   
   float pru = int(64*u);
   float prv = int(64*v);
   float prz = int(32*(u + v));
   float ptime = 64 - pru;

   string noisetypes[7] = {
       "perlin",
       "uperlin",
       "gabor",
       "snoise",
       "cell",
       "noise",
       "hash"
   };
   
   int noiseIndex = int(v*2*7)%7;
   string noisetype = noisetypes[noiseIndex];
   
   Cout = 0;
   if (v < 0.49) {
       // float noise in 1,2,3,4 dimensions
       if (u < 0.24)
           Cout = offset + scale * (float) pnoise(noisetype, ru, pru);
       else if (u > 0.26 && u < 0.49)
           Cout = offset + scale * (float) pnoise(noisetype, ru, rv, pru, prv);
       else if (u > 0.51 && u < 0.74)
           Cout = offset + scale * (float) pnoise(noisetype, point(ru, rv, rz), point(pru, prv, prz));
       else if (u > 0.76)
           Cout = offset + scale * (float) pnoise(noisetype, point(ru, rv, rz), ttime, point(pru, prv, prz), ptime);
   } else if (v > 0.51) {
       // color noise in 1,2,3,4 dimensions
       if (u < 0.24)
           Cout = offset + scale * pnoise(noisetype, ru, pru);
       else if (u > 0.26 && u < 0.49)
           Cout = offset + scale * pnoise(noisetype, ru, rv, pru, prv);
       else if (u > 0.51 && u < 0.74)
           Cout = offset + scale * pnoise(noisetype, point(ru, rv, rz), point(pru, prv, prz));
       else if (u > 0.76)
           Cout = offset + scale * pnoise(noisetype, point(ru, rv, rz), ttime, point(pru, prv, prz), ptime);
   }
}
