public RGBColor getIrradiance(Vector3D p, Vector3D n, int depth) { Sample x = new Sample(p, n, depth); double w = root.find(x); //if (first != null) { // System.Diagnostics.Trace.WriteLine ("weight: " + w); } //System.Console.Out.WriteLine (x.irr + " " + w); if (x.irr == null) { return(null); } else { RGBColor a = new RGBColor(x.irr); a.scale(1.0f / (float)w); //x.irr.scale(1.0f / (float) w); return(a); } //return () ? null : x.irr.scaleNew(1.0f / (float) w); }
// Lambertian! Replace with general BSDF. public virtual void radianceEstimate(RGBColor rad, Vector3D position, Vector3D normal, float maxDist, int noPhotons) { //float ALPHA = 0.918f; float MBETA = -1.953f; float DENOMFACTOR = 1.0f / (1.0f - (float)System.Math.Exp(MBETA)); NearestPhotons np = new NearestPhotons(noPhotons, maxDist, position); rad.set(0.0f); // locate the nearest photons locatePhotons(np, 1); // if less than MINPHOTONS return if (np.found < photontracer.SceneConstants.MIN_PHOTONS) { return; } Vector3D direction = new Vector3D(); //float mittrs = MBETA / (2.0f * (float) np.dist2[0]); float kdenom = (float)(1.0 / (1.1 * Math.Sqrt(np.dist2[0]))); // sum irrandiance from all photons for (int i = 1; i <= np.found; i++) { float cosNL; Photon p = getPhoton(np.indices[i]); // the toCartesian call and following if can be omitted (for speed) // if the scene does not have any thin surfaces p.toCartesian(direction); cosNL = (float)direction.dot(normal); //cosNL = -1.0f; if (cosNL < 0.0) { //float gaussWeight = 1.0f - (1.0f - (float) System.Math.Exp((float) p.position.distanceSqr(position) * mittrs)) * DENOMFACTOR; float coneWeight = 1.0f - (float)(p.position.distance(position) * kdenom); //rad.add(p.power.scaleNew((- cosNL) * gaussWeight)); //rad.add(p.power.scaleNew((- cosNL))); rad.add(p.power.scaleNew(coneWeight)); } } // estimate of density //rad.scale(ALPHA / (float) (System.Math.PI * np.dist2[0])); //rad.scale(1.0f / (float) (System.Math.PI * np.dist2[0])); rad.scale(1.0f / (float)((1.0f - 2.0f / (3.0f * 1.1f)) * System.Math.PI * np.dist2[0])); }