public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) { p.set(lightPoint); float phi = (float)(2 * Math.PI * randX1); float s = (float)Math.Sqrt(randY1 * (1.0f - randY1)); dir.x = (float)Math.Cos(phi) * s; dir.y = (float)Math.Sin(phi) * s; dir.z = (float)(1 - 2 * randY1); power.set(this.power); }
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) { float phi = (float)(2 * Math.PI * randX1); float s = (float)Math.Sqrt(1.0f - randY1); dir.x = r * (float)Math.Cos(phi) * s; dir.y = r * (float)Math.Sin(phi) * s; dir.z = 0; basis.transform(dir); Point3.add(src, dir, p); dir.set(this.dir); power.set(radiance).mul((float)Math.PI * r2); }
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) { float z = (float)(1 - 2 * randX2); float r = (float)Math.Sqrt(Math.Max(0, 1 - z * z)); float phi = (float)(2 * Math.PI * randY2); float x = r * (float)Math.Cos(phi); float y = r * (float)Math.Sin(phi); p.x = center.x + x * radius; p.y = center.y + y * radius; p.z = center.z + z * radius; OrthoNormalBasis basis = OrthoNormalBasis.makeFromW(new Vector3(x, y, z)); phi = (float)(2 * Math.PI * randX1); float cosPhi = (float)Math.Cos(phi); float sinPhi = (float)Math.Sin(phi); float sinTheta = (float)Math.Sqrt(randY1); float cosTheta = (float)Math.Sqrt(1 - randY1); dir.x = cosPhi * sinTheta; dir.y = sinPhi * sinTheta; dir.z = cosTheta; basis.transform(dir); power.set(radiance); power.mul((float)(Math.PI * Math.PI * 4 * r2)); }
public void precomputeRadiance() { if (storedPhotons == 0) return; // precompute the radiance for all photons that are neither // leaves nor parents of leaves in the tree. int quadStoredPhotons = halfStoredPhotons / 2; Point3 p = new Point3(); Vector3 n = new Vector3(); Point3 ppos = new Point3(); Vector3 pdir = new Vector3(); Vector3 pvec = new Vector3(); Color irr = new Color(); Color pow = new Color(); float maxDist2 = gatherRadius * gatherRadius; NearestPhotons np = new NearestPhotons(p, numGather, maxDist2); Photon[] temp = new Photon[quadStoredPhotons + 1]; UI.taskStart("Precomputing radiance", 1, quadStoredPhotons); for (int i = 1; i <= quadStoredPhotons; i++) { UI.taskUpdate(i); Photon curr = photons[i]; p.set(curr.x, curr.y, curr.z); Vector3.decode(curr.normal, n); irr.set(Color.BLACK); np.reset(p, maxDist2); locatePhotons(np); if (np.found < 8) { curr.data = 0; temp[i] = curr; continue; } float invArea = 1.0f / ((float)Math.PI * np.dist2[0]); float maxNDist = np.dist2[0] * 0.05f; for (int j = 1; j <= np.found; j++) { Photon phot = np.index[j]; Vector3.decode(phot.dir, pdir); float cos = -Vector3.dot(pdir, n); if (cos > 0.01f) { ppos.set(phot.x, phot.y, phot.z); Point3.sub(ppos, p, pvec); float pcos = Vector3.dot(pvec, n); if ((pcos < maxNDist) && (pcos > -maxNDist)) irr.add(pow.setRGBE(phot.power)); } } irr.mul(invArea); // compute radiance irr.mul(new Color(curr.data)).mul(1.0f / (float)Math.PI); curr.data = irr.toRGBE(); temp[i] = curr; } UI.taskStop(); // resize photon map to only include irradiance photons numGather /= 4; maxRadius = 1.4f * (float)Math.Sqrt(maxPower * numGather); if (gatherRadius > maxRadius) gatherRadius = maxRadius; storedPhotons = quadStoredPhotons; halfStoredPhotons = storedPhotons / 2; log2n = (int)Math.Ceiling(Math.Log(storedPhotons) / Math.Log(2.0)); photons = temp; hasRadiance = true; }