Ejemplo n.º 1
0
        // Lambertian! Replace with general BSDF.
        public virtual void  radianceEstimatePrecomputed(RGBColor rad, Vector3D position, Vector3D normal, float initialDist, float maxDist)
        {
            NearestPhotons np;

            // locate the nearest photon
            float r = initialDist;

            do
            {
                np = new NearestPhotons(1, r, position);

                locatePhotonsPrecomputed(normal, np, 1);

                r = (float)(r * 2.0);
            }while (np.found == 0 && r < maxDist);

            if (np.found > 0)
            {
                Photon p = getPhoton(np.indices[1]);

                rad.set(p.accumPower);
            }
            else
            {
                rad.set(0.0f);
            }
        }
Ejemplo n.º 2
0
        // 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 < RaytracerPhotonmapping.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(1.0f / (float)((1.0f - 2.0f / (3.0f * 1.1f)) * System.Math.PI * np.dist2[0]));
        }