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

A bunch of tweaks! #10

Merged
merged 10 commits into from Apr 12, 2018

Maths: compute -b (nb) not b by flipping vector; this is slightly bet…

…ter. 96 Mrays/s -> 99 Mrays/s
  • Loading branch information...
rygorous committed Apr 11, 2018
commit fc7127c16df47e522e1d139a9279663cbc0d2f90
Copy path View file
@@ -78,21 +78,22 @@ int HitSpheres(const Ray& r, const SpheresSoA& spheres, float tMin, float tMax,
float4 sCenterY = float4(spheres.centerY + i);
float4 sCenterZ = float4(spheres.centerZ + i);
float4 sSqRadius = float4(spheres.sqRadius + i);
float4 ocX = rOrigX - sCenterX;
float4 ocY = rOrigY - sCenterY;
float4 ocZ = rOrigZ - sCenterZ;
float4 b = ocX * rDirX + ocY * rDirY + ocZ * rDirZ;
float4 c = ocX * ocX + ocY * ocY + ocZ * ocZ - sSqRadius;
float4 discr = b * b - c;
// note: we flip this vector and calculate -b (nb) since that happens to be slightly preferable computationally
float4 coX = sCenterX - rOrigX;
float4 coY = sCenterY - rOrigY;
float4 coZ = sCenterZ - rOrigZ;
float4 nb = coX * rDirX + coY * rDirY + coZ * rDirZ;
float4 c = coX * coX + coY * coY + coZ * coZ - sSqRadius;
float4 discr = nb * nb - c;
bool4 discrPos = discr > float4(0.0f);
// if ray hits any of the 4 spheres
if (any(discrPos))
{
float4 discrSq = sqrtf(discr);
// ray could hit spheres at t0 & t1
float4 t0 = -b - discrSq;
float4 t1 = -b + discrSq;
float4 t0 = nb - discrSq;
float4 t1 = nb + discrSq;
bool4 msk0 = discrPos & (t0 > tMin4) & (t0 < hitT);
bool4 msk1 = discrPos & (t1 > tMin4) & (t1 < hitT);
// where sphere is hit at t0, take that; elswhere take t1 hit
ProTip! Use n and p to navigate between commits in a pull request.