Ejemplo n.º 1
0
        public virtual double GenerateRayDifferential(CameraSample sample, ref RayDifferential rd)
        {
            Ray r = new Ray (rd.Origin, rd.Direction, rd.MinT, rd.MaxT, rd.Time);
            double wt = GenerateRay (sample, ref r);
            rd.Origin = r.Origin;
            rd.Direction = r.Direction;
            rd.MinT = r.MinT;
            rd.MaxT = r.MaxT;
            rd.Time = r.Time;

            CameraSample sshift = sample;
            ++sshift.ImageX;

            Ray rx = new Ray ();
            double wtx = GenerateRay (sshift, ref rx);
            rd.RxOrigin = rx.Origin;
            rd.RxDirection = rx.Direction;

            --sshift.ImageX;
            ++sshift.ImageY;

            Ray ry = new Ray ();
            double wty = GenerateRay (sshift, ref ry);
            rd.RyOrigin = ry.Origin;
            rd.RyDirection = ry.Direction;

            if (wtx == 0.0 || wty == 0.0)
                return 0.0;

            rd.HasDifferentials = true;

            return wt;
        }
Ejemplo n.º 2
0
        public static Spectrum SpecularReflect(RayDifferential ray, BSDF bsdf, Intersection isect, IRenderer renderer, Scene scene, Sample sample)
        {
            Vector wo = -ray.Direction, wi = new Vector ();
            double pdf = 0.0;
            Point p = bsdf.dgShading.p;
            Normal n = bsdf.dgShading.n;

            Spectrum f = bsdf.SampleF (wo, ref wi, new BSDFSample (), ref pdf, BxDFType.BSDF_REFLECTION | BxDFType.BSDF_SPECULAR);
            Spectrum L = new Spectrum ();

            if (pdf > 0.0 && !f.IsBlack && Util.AbsDot (wi, n) != 0.0)
            {
                RayDifferential rd = new RayDifferential (p, wi, ray, isect.RayEpsilon);
                if (ray.HasDifferentials)
                {
                    rd.HasDifferentials = true;
                    rd.RxOrigin = p + isect.dg.dpdx;
                    rd.RyOrigin = p + isect.dg.dpdy;

                    Normal dndx = bsdf.dgShading.dndu * bsdf.dgShading.dudx + bsdf.dgShading.dndv * bsdf.dgShading.dvdx;
                    Normal dndy = bsdf.dgShading.dndu * bsdf.dgShading.dudy + bsdf.dgShading.dndv * bsdf.dgShading.dvdy;
                    Vector dwodx = -ray.RxDirection - wo, dwody = -ray.Direction - wo;
                    double dDNdx = (dwodx ^ n) + (wo ^ dndx);
                    double dDNdy = (dwody ^ n) + (wo ^ dndy);
                    rd.RxDirection = wi - dwodx + 2 * new Vector ((wo ^ n) * dndx + dDNdx * n);
                    rd.RyDirection = wi - dwody + 2 * new Vector ((wo ^ n) * dndy + dDNdy * n);
                }

                Spectrum Li = renderer.Li (scene, rd, sample);
                L = f * Li * Util.AbsDot (wi, n) / pdf;
            }

            return L;
        }
Ejemplo n.º 3
0
        public void Run()
        {
            ISampler sampler = MainSampler.GetSubSampler (TaskNumber, TaskCount);
            if (sampler == null)
            {
                return;
            }

            int maxSamples = sampler.MaximumSampleCount;
            Sample[] samples = OrigSample.Duplicate (maxSamples);
            RayDifferential[] rays = new RayDifferential[maxSamples];
            Spectrum[] Ls = new Spectrum[maxSamples];
            Spectrum[] Ts = new Spectrum[maxSamples];
            Intersection[] isects = new Intersection[maxSamples];

            for (int i = 0; i < maxSamples; ++i)
            {
                samples[i] = new Sample ();
                rays[i] = new RayDifferential ();
                Ls[i] = new Spectrum ();
                Ts[i] = new Spectrum ();
                isects[i] = new Intersection ();
            }

            int sampleCount;

            while ((sampleCount = sampler.GetMoreSamples (samples)) > 0)
            {
                for (int i = 0; i < sampleCount; ++i)
                {
                    double rayWeight = Camera.GenerateRayDifferential (samples[i], ref rays[i]);
                    rays[i].ScaleDifferentials (1.0 / Math.Sqrt (sampler.SamplesPerPixel));

                    if (rayWeight > 0.0)
                        Ls[i] = rayWeight * Renderer.Li (Scene, rays[i], samples[i], ref isects[i], ref Ts[i]);
                    else
                    {
                        Ls[i] = new Spectrum ();
                        Ts[i] = new Spectrum (1.0);
                    }

                    // WARNINGS
                }

                if (sampler.ReportResults (samples, rays, Ls, isects, sampleCount))
                {
                    for (int i = 0; i < sampleCount; ++i)
                        Camera.Film.AddSample (samples[i], Ls[i]);
                }
            }

            Camera.Film.UpdateDisplay (sampler.xPixelStart, sampler.yPixelStart, sampler.xPixelEnd + 1, sampler.yPixelEnd + 1);
            Reporter.Update ();
        }
Ejemplo n.º 4
0
        public static Spectrum SpecularTransmit(RayDifferential ray, BSDF bsdf, Intersection isect, IRenderer renderer, Scene scene, Sample sample)
        {
            Vector wo = -ray.Direction, wi = new Vector ();
            double pdf = 0.0;
            Point p = bsdf.dgShading.p;
            Normal n = bsdf.dgShading.n;
            Spectrum f = bsdf.SampleF (wo, ref wi, new BSDFSample (), ref pdf, BxDFType.BSDF_TRANSMISSION | BxDFType.BSDF_SPECULAR);
            Spectrum L = new Spectrum ();

            if (pdf > 0.0 && !f.IsBlack && Util.AbsDot (wi, n) != 0.0)
            {
                RayDifferential rd = new RayDifferential (p, wi, ray, isect.RayEpsilon);
                if (ray.HasDifferentials)
                {
                    rd.HasDifferentials = true;
                    rd.RxOrigin = p + isect.dg.dpdx;
                    rd.RyOrigin = p + isect.dg.dpdy;

                    double eta = bsdf.Eta;
                    Vector w = -wo;

                    if ((wo ^ n) < 0.0)
                        eta = 1.0 / eta;

                    Normal dndx = bsdf.dgShading.dndu * bsdf.dgShading.dudx + bsdf.dgShading.dndv * bsdf.dgShading.dvdx;
                    Normal dndy = bsdf.dgShading.dndu * bsdf.dgShading.dudy + bsdf.dgShading.dndv * bsdf.dgShading.dvdy;

                    Vector dwodx = -ray.RxDirection - wo, dwody = -ray.RyDirection - wo;
                    double dDNdx = (dwodx ^ n) + (wo ^ dndx);
                    double dDNdy = (dwody ^ n) + (wo ^ dndy);
                    double mu = eta * (w ^ n) - (wi ^ n);
                    double dmudx = (eta - (eta * eta * (w ^ n)) / (wi ^ n)) * dDNdx;
                    double dmudy = (eta - (eta * eta * (w ^ n)) / (wi ^ n)) * dDNdy;

                    rd.RxDirection = wi + eta * dwodx - new Vector (mu * dndx + dmudx * n);
                    rd.RyDirection = wi + eta * dwody - new Vector (mu * dndy + dmudy * n);
                }

                Spectrum Li = renderer.Li (scene, rd, sample);
                L = f * Li * Util.AbsDot (wi, n) / pdf;
            }

            return L;
        }
Ejemplo n.º 5
0
        public override Spectrum Transmittance(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample)
        {
            if (scene.VolumeRegion == null)
                return new Spectrum (1.0);

            double step, offset;
            if (sample != null)
            {
                step = StepSize;
                offset = sample.samples[sample.oneD + TauSampleOffset][0];
            }
            else
            {
                step = 4.0 * StepSize;
                offset = Util.Random.NextDouble ();
            }
            /*Spectrum tau = scene.VolumeRegion.Tau (ray, step, offset);
            return (-tau).Exp;*/
            return null;
        }
Ejemplo n.º 6
0
 public BSDF GetBSDF(RayDifferential ray)
 {
     dg.ComputeDifferentials (ray);
     return Primitive.GetBsdf (dg, ObjectToWorld);
 }
Ejemplo n.º 7
0
 public abstract Spectrum Transmittance(Scene scene, RayDifferential ray, Sample sample);
Ejemplo n.º 8
0
 public Spectrum Li(Scene scene, RayDifferential ray, Sample sample, ref Intersection isect)
 {
     Spectrum T = new Spectrum ();
     return Li (scene, ray, sample, ref isect, ref T);
 }
Ejemplo n.º 9
0
 public abstract Spectrum Li(Scene scene, RayDifferential ray, Sample sample, ref Intersection isect, ref Spectrum T);
Ejemplo n.º 10
0
 public virtual bool ReportResults(Sample[] samples, RayDifferential[] rays, Spectrum[] Ls, Intersection[] isects, int count)
 {
     return true;
 }
Ejemplo n.º 11
0
        public void ComputeDifferentials(RayDifferential ray)
        {
            if (ray.HasDifferentials)
            {
                // Estimate screen space change in $\pt{}$ and $(u,v)$

                // Compute auxiliary intersection points with plane
                double d = -(n ^ new Vector (p.x, p.y, p.z));
                Vector rxv = new Vector (ray.RxOrigin.x, ray.RxOrigin.y, ray.RxOrigin.z);
                double tx = -((n ^ rxv) + d) / (n ^ ray.RxDirection);
                if (double.IsNaN (tx))
                {
                    dudx = dvdx = 0.0;
                    dudy = dvdy = 0.0;
                    dpdx = new Vector ();
                    dpdy = new Vector ();
                }
                Point px = ray.RxOrigin + tx * ray.RxDirection;
                Vector ryv = new Vector (ray.RyOrigin.x, ray.RyOrigin.y, ray.RyOrigin.z);
                double ty = -((n ^ ryv) + d) / (n ^ ray.RyDirection);
                if (double.IsNaN (ty))
                {
                    dudx = dvdx = 0.0;
                    dudy = dvdy = 0.0;
                    dpdx = new Vector ();
                    dpdy = new Vector ();
                }
                Point py = ray.RyOrigin + ty * ray.RyDirection;
                dpdx = px - p;
                dpdy = py - p;

                // Compute $(u,v)$ offsets at auxiliary points

                // Initialize _A_, _Bx_, and _By_ matrices for offset computation
                double[][] A = new double[2][];
                A[0] = new double[2];
                A[1] = new double[2];
                double[] Bx = new double[2], By = new double[2];
                int[] axes = new int[2];
                if (Math.Abs (n.x) > Math.Abs (n.y) && Math.Abs (n.x) > Math.Abs (n.z))
                {
                    axes[0] = 1;
                    axes[1] = 2;
                } else if (Math.Abs (n.y) > Math.Abs (n.z))
                {
                    axes[0] = 0;
                    axes[1] = 2;
                } else
                {
                    axes[0] = 0;
                    axes[1] = 1;
                }

                // Initialize matrices for chosen projection plane
                A[0][0] = dpdu[axes[0]];
                A[0][1] = dpdv[axes[0]];
                A[1][0] = dpdu[axes[1]];
                A[1][1] = dpdv[axes[1]];
                Bx[0] = px[axes[0]] - p[axes[0]];
                Bx[1] = px[axes[1]] - p[axes[1]];
                By[0] = py[axes[0]] - p[axes[0]];
                By[1] = py[axes[1]] - p[axes[1]];
                if (!Util.SolveLinearSystem2x2 (A, Bx[0], Bx[1], out dudx, out dvdx))
                {
                    dudx = 0.0;
                    dvdx = 0.0;
                }
                if (!Util.SolveLinearSystem2x2 (A, By[0], By[1], out dudy, out dvdy))
                {
                    dudy = 0.0;
                    dvdy = 0.0;
                }
            } else
            {
                dudx = dvdx = 0.0;
                dudy = dvdy = 0.0;
                dpdx = new Vector ();
                dpdy = new Vector ();
            }
        }
Ejemplo n.º 12
0
 public virtual Spectrum Le(RayDifferential rd)
 {
     return new Spectrum ();
 }
Ejemplo n.º 13
0
 public override Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample, ref Spectrum transmittance)
 {
     transmittance = new Spectrum (1.0);
     return new Spectrum ();
 }
Ejemplo n.º 14
0
        public override double GenerateRayDifferential(CameraSample sample, ref RayDifferential rd)
        {
            ++NumberOfRays;
            Point pRas = new Point (sample.ImageX, sample.ImageY, 0.0);
            Point pCam = new Point ();
            RasterToCamera.Apply (pRas, ref pCam);
            Vector dir = new Vector (pCam).Normalized;
            rd = new RayDifferential (new Point (), dir, 0.0, double.PositiveInfinity);

            if (LensRadius > 0.0)
            {
                double lensU = 0.0, lensV = 0.0;
                MonteCarlo.ConcentricSampleDisk (sample.LensU, sample.LensV, ref lensU, ref lensV);
                lensU *= LensRadius;
                lensV *= LensRadius;

                double ft = FocalDistance / rd.Direction.z;
                Point pFocus = rd.Apply (ft);

                rd.Origin = new Point (lensU, lensV, 0.0);
                rd.Direction = (pFocus - rd.Origin).Normalized;
            }

            rd.RxOrigin = new Point (rd.Origin);
            rd.RyOrigin = new Point (rd.Origin);
            rd.RxDirection = (new Vector (pCam) + dxCamera).Normalized;
            rd.RyDirection = (new Vector (pCam) + dyCamera).Normalized;
            rd.Time = Util.Lerp (sample.Time, ShutterOpen, ShutterClose);
            CameraToWorld.Apply (rd, ref rd);
            rd.HasDifferentials = true;
            return 1.0;
        }
Ejemplo n.º 15
0
 public void Apply(RayDifferential r, ref RayDifferential tr)
 {
     if (!ActuallyAnimated || r.Time <= StartTime)
         StartTransform.Apply (r, ref tr);
     else if (r.Time >= EndTime)
         EndTransform.Apply (r, ref tr);
     else
     {
         Transform t = new Transform ();
         Interpolate (r.Time, ref t);
         t.Apply (r, ref tr);
     }
     tr.Time = r.Time;
 }
Ejemplo n.º 16
0
 public abstract Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Intersection isect, Sample sample);
Ejemplo n.º 17
0
 public abstract Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample, ref Spectrum transmittance);