Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precision problem, take 2 (partially) #9

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ uniform sampler2D uTexture;
// const float twoPiOnPhi = kTau/kPhi;
// const float phiMinusOne = kPhi-1.;
// const float r = .8;
// const float by2P32 = 1./4294967296.;

const float sqrt5 = 2.23606797749979;
const float PI = 3.141592653589793;
Expand All @@ -36,6 +37,7 @@ const float byLogPhiPlusOne = 0.7202100452062783;
const float twoPiOnPhi = 3.8832220774509327;
const float phiMinusOne = .618033988749895;
const float r = .8;
const float by2P32 = 2.3283064365386963e-10;

float byDots = 1./dots;

Expand Down Expand Up @@ -72,8 +74,13 @@ vec3 nearestFibonacciLattice(vec3 p, out float m) {
float idx = dot(f, c + o);
if (idx > dots) continue;

float v = idx / kPhi;
float theta = (v - floor(v/3000.)*3000.)*kTau;
// float v = idx / kPhi;
// float theta = fract(v) * kTau;

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

float cosphi = 1. - 2. * idx * byDots;
float sinphi = sqrt(1. - cosphi * cosphi);
vec3 sample = vec3(cos(theta) * sinphi, sin(theta) * sinphi, cosphi);
Expand Down