Skip to content

Commit

Permalink
Merge pull request #24 from shuding/shu/a3b6
Browse files Browse the repository at this point in the history
Fix Android 12 support
  • Loading branch information
shuding authored Mar 23, 2022
2 parents 891b78b + 5c1a050 commit d2aa139
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
node_modules
.DS_Store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cobe",
"version": "0.4.1",
"version": "0.4.2",
"type": "module",
"main": "./dist/index.esm.js",
"files": [
Expand Down
36 changes: 33 additions & 3 deletions src/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,39 @@ vec3 nearestFibonacciLattice(vec3 p, out float m) {
// float v = idx / kPhi;
// float theta = fract(v) * kTau;

int iFracV = int(idx) * 2654435769; // signed be like nearest-to-zero fmod; 2^32/phi
float fracV = float(iFracV) * by2P32;
float theta = fracV * kTau;
// int iFracV = int(idx) * 2654435769; // signed be like nearest-to-zero fmod; 2^32/phi
// float fracV = float(iFracV) * by2P32;
// float theta = fracV * kTau;

// https://github.com/shuding/cobe/issues/16

float tidx = idx;
float fracV = 0.;

// see codegen

if(tidx >= 524288.) { tidx-=524288.; fracV += 0.8038937048986554; }
if(tidx >= 262144.) { tidx-=262144.; fracV += 0.9019468524493277; }
if(tidx >= 131072.) { tidx-=131072.; fracV += 0.9509734262246639; }
if(tidx >= 65536.) { tidx-=65536.; fracV += 0.4754867131123319; }
if(tidx >= 32768.) { tidx-=32768.; fracV += 0.737743356556166; }
if(tidx >= 16384.) { tidx-=16384.; fracV += 0.868871678278083; }
if(tidx >= 8192.) { tidx-=8192.; fracV += 0.9344358391390415; }
if(tidx >= 4096.) { tidx-=4096.; fracV += 0.46721791956952075; }
if(tidx >= 2048.) { tidx-=2048.; fracV += 0.7336089597847604; }
if(tidx >= 1024.) { tidx-=1024.; fracV += 0.8668044798923802; }
if(tidx >= 512.) { tidx-=512.; fracV += 0.4334022399461901; }
if(tidx >= 256.) { tidx-=256.; fracV += 0.21670111997309505; }
if(tidx >= 128.) { tidx-=128.; fracV += 0.10835055998654752; }
if(tidx >= 64.) { tidx-=64.; fracV += 0.5541752799932738; }
if(tidx >= 32.) { tidx-=32.; fracV += 0.7770876399966369; }
if(tidx >= 16.) { tidx-=16.; fracV += 0.8885438199983184; }
if(tidx >= 8.) { tidx-=8.; fracV += 0.9442719099991592; }
if(tidx >= 4.) { tidx-=4.; fracV += 0.4721359549995796; }
if(tidx >= 2.) { tidx-=2.; fracV += 0.2360679774997898; }
if(tidx >= 1.) { tidx-=1.; fracV += 0.6180339887498949; }

float theta = fract(fracV) * kTau;

float cosphi = 1. - 2. * idx * byDots;
float sinphi = sqrt(1. - cosphi * cosphi);
Expand Down
4 changes: 2 additions & 2 deletions src/shader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2aa139

Please sign in to comment.