Пример #1
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            // Generate raster and camera samples
            Point Pras    = new Point(sample.ImageX, sample.ImageY, 0);
            Point Pcamera = RasterToCamera.TransformPoint(ref Pras);

            ray = new RayDifferential(new Point(0, 0, 0), Vector.Normalize((Vector)Pcamera), 0.0f);
            // Modify ray for depth of field
            if (LensRadius > 0.0f)
            {
                // Sample point on lens
                float lensU, lensV;
                MonteCarloUtilities.ConcentricSampleDisk(sample.LensU, sample.LensV, out lensU, out lensV);
                lensU *= LensRadius;
                lensV *= LensRadius;

                // Compute point on plane of focus
                float ft     = FocalDistance / ray.Direction.Z;
                Point Pfocus = ray.Evaluate(ft);

                // Update ray for effect of lens
                ray.Origin    = new Point(lensU, lensV, 0.0f);
                ray.Direction = Vector.Normalize(Pfocus - ray.Origin);
            }
            // Compute offset rays for _PerspectiveCamera_ ray differentials
            ray.RxOrigin    = ray.RyOrigin = ray.Origin;
            ray.RxDirection = Vector.Normalize((Vector)Pcamera + _dxCamera);
            ray.RyDirection = Vector.Normalize((Vector)Pcamera + _dyCamera);
            ray.Time        = sample.Time;
            ray             = CameraToWorld.TransformRayDifferential(ray);
            return(1.0f);
        }
Пример #2
0
 public Spectrum Transmittance(Scene scene, Renderer renderer,
                               Sample sample, Random rng)
 {
     return(renderer.Transmittance(
                scene, RayDifferential.FromRay(Ray),
                sample, rng));
 }
Пример #3
0
        public virtual float GenerateRayDifferential(CameraSample sample, out RayDifferential rd)
        {
            Ray   ray;
            float wt = GenerateRay(sample, out ray);

            rd = RayDifferential.FromRay(ray);

            // Find ray after shifting one pixel in the $x$ direction
            CameraSample sshift = sample;

            ++(sshift.ImageX);
            Ray   rx;
            float wtx = GenerateRay(sshift, out rx);

            rd.RxOrigin    = rx.Origin;
            rd.RxDirection = rx.Direction;

            // Find ray after shifting one pixel in the $y$ direction
            --(sshift.ImageX);
            ++(sshift.ImageY);
            Ray   ry;
            float wty = GenerateRay(sshift, out ry);

            rd.RyOrigin    = ry.Origin;
            rd.RyDirection = ry.Direction;

            if (wtx == 0.0f || wty == 0.0f)
            {
                return(0.0f);
            }

            rd.HasDifferentials = true;
            return(wt);
        }
Пример #4
0
        public Spectrum Li(Scene scene, RayDifferential ray, Sample sample, Random rng)
        {
            Intersection intersection = null;
            Spectrum     t;

            return(Li(scene, ray, sample, rng, ref intersection, out t));
        }
Пример #5
0
 public void ComputeScatteringFunctions(
     RayDifferential ray,
     bool allowMultipleLobes = false,
     TransportMode mode      = TransportMode.Radiance)
 {
     ComputeDifferentials(ray);
     Primitive.ComputeScatteringFunctions(this, mode, allowMultipleLobes);
 }
Пример #6
0
        public Spectrum SpecularTransmit(
            RayDifferential ray,
            SurfaceInteraction isect,
            Scene scene,
            Sampler sampler,
            int depth)
        {
            Vector3D wo = isect.Wo;
            double   pdf;
            Point3D  p    = isect.P;
            Normal3D ns   = isect.ShadingN;
            Bsdf     bsdf = isect.Bsdf;
            Spectrum f    = bsdf.Sample_f(wo, out Vector3D wi, sampler.Get2D(), out pdf,
                                          out BxdfType sampledType, BxdfType.Transmission | BxdfType.Specular);
            Spectrum L = Spectrum.Create(0.0);

            if (pdf > 0.0 && !f.IsBlack() && wi.AbsDot(ns) != 0.0)
            {
                // Compute ray differential _rd_ for specular transmission
                RayDifferential rd = new RayDifferential(isect.SpawnRay(wi));
                if (ray.HasDifferentials)
                {
                    rd.HasDifferentials = true;
                    rd.RxOrigin         = p + isect.Dpdx.ToPoint3D();
                    rd.RyOrigin         = p + isect.Dpdy.ToPoint3D();

                    double   eta = bsdf.Eta;
                    Vector3D w   = -wo;
                    if (wo.Dot(ns) < 0.0)
                    {
                        eta = 1.0 / eta;
                    }

                    Normal3D dndx = isect.ShadingDndu * isect.Dudx +
                                    isect.ShadingDndv * isect.Dvdx;
                    Normal3D dndy = isect.ShadingDndu * isect.Dudy +
                                    isect.ShadingDndv * isect.Dvdy;

                    Vector3D dwodx = -ray.RxDirection - wo,
                             dwody = -ray.RyDirection - wo;
                    double dDNdx   = dwodx.Dot(ns) + wo.Dot(dndx);
                    double dDNdy   = dwody.Dot(ns) + wo.Dot(dndy);

                    double mu    = eta * w.Dot(ns) - wi.Dot(ns);
                    double dmudx =
                        (eta - (eta * eta * w.Dot(ns)) / wi.Dot(ns)) * dDNdx;
                    double dmudy =
                        (eta - (eta * eta * w.Dot(ns)) / wi.Dot(ns)) * dDNdy;

                    rd.RxDirection =
                        wi + eta * dwodx - (mu * dndx + dmudx * ns).ToVector3D();
                    rd.RyDirection =
                        wi + eta * dwody - (mu * dndy + dmudy * ns).ToVector3D();
                }
                L = f * Li(rd, scene, sampler, depth + 1) * wi.AbsDot(ns) / pdf;
            }
            return(L);
        }
Пример #7
0
        /// <inheritdoc />
        public override double GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            //ProfilePhase prof(Prof::GenerateCameraRay);
            // Compute raster and camera sample positions
            Point3D  pFilm   = new Point3D(sample.FilmPoint.X, sample.FilmPoint.Y, 0.0);
            Point3D  pCamera = RasterToCamera.ExecuteTransform(pFilm);
            Vector3D dir     = new Vector3D(pCamera.X, pCamera.Y, pCamera.Z).Normalize();

            ray = new RayDifferential(new Point3D(0.0, 0.0, 0.0), dir);
            // Modify ray for depth of field
            if (LensRadius > 0.0)
            {
                // Sample point on lens
                Point2D pLens = LensRadius * Sampling.ConcentricSampleDisk(sample.LensPoint);

                // Compute point on plane of focus
                double  ft     = FocalDistance / ray.Direction.Z;
                Point3D pFocus = ray.AtPoint(ft);

                // Update ray for effect of lens
                ray.Origin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.Direction = (pFocus - ray.Origin).ToVector3D().Normalize();
            }

            // Compute offset rays for _PerspectiveCamera_ ray differentials
            if (LensRadius > 0.0)
            {
                // Compute _PerspectiveCamera_ ray differentials accounting for lens

                // Sample point on lens
                Point2D  pLens  = LensRadius * Sampling.ConcentricSampleDisk(sample.LensPoint);
                Vector3D dx     = (pCamera.ToVector3D() + _dxCamera).Normalize();
                double   ft     = FocalDistance / dx.Z;
                Point3D  pFocus = new Point3D(0.0, 0.0, 0.0) + (ft * dx).ToPoint3D();
                ray.RxOrigin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.RxDirection = (pFocus - ray.RxOrigin).ToVector3D().Normalize();

                Vector3D dy = (pCamera.ToVector3D() + _dyCamera).Normalize();
                ft              = FocalDistance / dy.Z;
                pFocus          = new Point3D(0.0, 0.0, 0.0) + (ft * dy).ToPoint3D();
                ray.RyOrigin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.RyDirection = (pFocus - ray.RyOrigin).ToVector3D().Normalize();
            }
            else
            {
                ray.RxOrigin    = ray.RyOrigin = ray.Origin;
                ray.RxDirection = (pCamera.ToVector3D() + _dxCamera).Normalize();
                ray.RyDirection = (pCamera.ToVector3D() + _dyCamera).Normalize();
            }
            ray.Time   = PbrtMath.Lerp(sample.Time, ShutterOpen, ShutterClose);
            ray.Medium = Medium;
            ray        = new RayDifferential(CameraToWorld.ExecuteTransform(ray))
            {
                HasDifferentials = true
            };
            return(1.0);
        }
Пример #8
0
        public virtual double GenerateRayDifferential(CameraSample sample, out RayDifferential rd)
        {
            double wt = GenerateRay(sample, out Ray r);

            rd = new RayDifferential(r);
            if (wt == 0.0)
            {
                return(0.0);
            }

            // Find camera ray after shifting a fraction of a pixel in the $x$ direction
            double wtx = 0.0;

            foreach (double eps in new List <double> {
                0.5, -0.5
            })
            {
                CameraSample sshift = sample;
                sshift.FilmPoint = new Point2D(sshift.FilmPoint.X + eps, sshift.FilmPoint.Y);
                wtx            = GenerateRay(sshift, out Ray rx);
                rd.RxOrigin    = rd.Origin + (rx.Origin - rd.Origin) / eps;
                rd.RxDirection = rd.Direction + (rx.Direction - rd.Direction) / eps;
                if (wtx != 0.0)
                {
                    break;
                }
            }
            if (wtx == 0.0)
            {
                return(0.0);
            }

            // Find camera ray after shifting a fraction of a pixel in the $y$ direction
            double wty = 0.0;

            foreach (double eps in new List <double> {
                0.5, -0.5
            })
            {
                CameraSample sshift = sample;
                sshift.FilmPoint = new Point2D(sshift.FilmPoint.X, sshift.FilmPoint.Y + eps);
                wty            = GenerateRay(sshift, out Ray ry);
                rd.RyOrigin    = rd.Origin + (ry.Origin - rd.Origin) / eps;
                rd.RyDirection = rd.Direction + (ry.Direction - rd.Direction) / eps;
                if (wty != 0.0)
                {
                    break;
                }
            }
            if (wty == 0.0)
            {
                return(0.0);
            }

            rd.HasDifferentials = true;
            return(wt);
        }
Пример #9
0
 public new RayDifferential Clone()
 {
     var result = new RayDifferential(Origin, Direction, MinT, MaxT, Time, Depth);
     result.HasDifferentials = HasDifferentials;
     result.RxOrigin = RxOrigin;
     result.RyOrigin = RyOrigin;
     result.RxDirection = RxDirection;
     result.RyDirection = RyDirection;
     return result;
 }
Пример #10
0
        public new RayDifferential Clone()
        {
            var result = new RayDifferential(Origin, Direction, MinT, MaxT, Time, Depth);

            result.HasDifferentials = HasDifferentials;
            result.RxOrigin         = RxOrigin;
            result.RyOrigin         = RyOrigin;
            result.RxDirection      = RxDirection;
            result.RyDirection      = RyDirection;
            return(result);
        }
Пример #11
0
        /// <inheritdoc />
        public override Spectrum Li(RayDifferential ray, Scene scene, Sampler sampler, int depth = 0)
        {
            Spectrum L = Spectrum.Create(0.0);

            // Find closest ray intersection or return background radiance
            if (!scene.Intersect(ray, out SurfaceInteraction isect))
            {
                foreach (var light in scene.Lights)
                {
                    L += light.Le(ray);
                }
                return(L);
            }

            // Compute emitted and reflected light at ray intersection point

            // Initialize common variables for Whitted integrator
            Normal3D n  = isect.ShadingN;
            Vector3D wo = isect.Wo;

            // Compute scattering functions for surface interaction
            isect.ComputeScatteringFunctions(ray);
            if (isect.Bsdf == null)
            {
                return(Li(new RayDifferential(isect.SpawnRay(ray.Direction)), scene, sampler, depth));
            }

            // Compute emitted light if ray hit an area light source
            L += isect.Le(wo);

            // Add contribution of each light source
            foreach (var light in scene.Lights)
            {
                Spectrum Li =
                    light.Sample_Li(isect, sampler.Get2D(), out Vector3D wi, out double pdf, out VisibilityTester visibility);
                if (Li.IsBlack() || pdf == 0.0)
                {
                    continue;
                }

                Spectrum f = isect.Bsdf.f(wo, wi);
                if (!f.IsBlack() && visibility.Unoccluded(scene))
                {
                    L += f * Li * wi.AbsDot(n) / pdf;
                }
            }
            if (depth + 1 < _maxDepth)
            {
                // Trace rays for specular reflection and refraction
                L += SpecularReflect(ray, isect, scene, sampler, depth);
                L += SpecularTransmit(ray, isect, scene, sampler, depth);
            }
            return(L);
        }
Пример #12
0
        public static Spectrum SpecularTransmit(RayDifferential ray, Bsdf bsdf,
                                                Random rng, Intersection isect, Renderer renderer,
                                                Scene scene, Sample sample)
        {
            Vector   wo = -ray.Direction, wi;
            float    pdf;
            Point    p = bsdf.DgShading.Point;
            Normal   n = bsdf.DgShading.Normal;
            Spectrum f = bsdf.SampleF(wo, out wi, new BsdfSample(rng), out pdf,
                                      BxdfType.Transmission | BxdfType.Specular);
            Spectrum L = Spectrum.CreateBlack();

            if (pdf > 0.0f && !f.IsBlack && Vector.AbsDot(wi, n) != 0.0f)
            {
                // Compute ray differential _rd_ for specular transmission
                var rd = new RayDifferential(p, wi, ray, isect.RayEpsilon);
                if (ray.HasDifferentials)
                {
                    rd.HasDifferentials = true;
                    rd.RxOrigin         = p + isect.DifferentialGeometry.DpDx;
                    rd.RyOrigin         = p + isect.DifferentialGeometry.DpDy;

                    float  eta = bsdf.Eta;
                    Vector w   = -wo;
                    if (Vector.Dot(wo, n) < 0)
                    {
                        eta = 1.0f / 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;
                    float  dDNdx = Vector.Dot(dwodx, n) + Vector.Dot(wo, dndx);
                    float  dDNdy = Vector.Dot(dwody, n) + Vector.Dot(wo, dndy);

                    float mu    = eta * Vector.Dot(w, n) - Vector.Dot(wi, n);
                    float dmudx = (eta - (eta * eta * Vector.Dot(w, n)) / Vector.Dot(wi, n)) * dDNdx;
                    float dmudy = (eta - (eta * eta * Vector.Dot(w, n)) / Vector.Dot(wi, n)) * dDNdy;

                    rd.RxDirection = wi + eta * dwodx - (Vector)(mu * dndx + dmudx * n);
                    rd.RyDirection = wi + eta * dwody - (Vector)(mu * dndy + dmudy * n);
                }
                Spectrum Li = renderer.Li(scene, rd, sample, rng);
                L = f * Li * Vector.AbsDot(wi, n) / pdf;
            }
            return(L);
        }
Пример #13
0
        public override Spectrum Li(RayDifferential ray, Scene scene, Camera camera, Sampler sampler, int depth = 0)
        {
            // If the ray doesn't intersect the scene, return black
            if (!scene.Intersect(ray, out SurfaceInteraction inter))
            {
                return(Spectrum.Zero);
            }

            // Otherwise return a greyscale level that corresponds to
            // the object's distance from the camera
            float c = (inter.P - camera.Position).Length() / 10.0f;

            return(new Spectrum(c));
        }
Пример #14
0
        public override Spectrum Li(RayDifferential ray, Scene scene, Camera camera, Sampler sampler, int depth = 0)
        {
            var L = Spectrum.Zero;

            // If the ray doesn't intersect the scene, return the background radiance
            if (!scene.Intersect(ray, out SurfaceInteraction inter) || inter == null)
            {
                foreach (var light in scene.Lights)
                {
                    L += light.Le(ray);
                }
                //return new Spectrum(0, 0, 1);
                return(L);
            }

            // If the ray intersects something, compute how the light is scattered
            inter.ComputeScatteringFunctions(ray);

            // Add the emissive contribution of the intersected object
            L += inter.Le(inter.Wo);

            if (inter.Bsdf == null)
            {
                return(L);
            }

            // Add the direct lighting contribution
            if (scene.Lights.Any())
            {
                if (strategy == LightStrategy.SampleAll)
                {
                    L += UniformSampleAllLights(inter, scene, sampler);
                }
                else
                {
                    L += UniformSampleOneLight(inter, scene, sampler);
                }
            }

            // Recursively trace new rays
            if (depth + 1 < maxDepth)
            {
                L += SpecularReflect(ray, inter, scene, camera, sampler, depth);
                //L += SpecularTransmit(ray, inter, scene, sampler, depth);
            }

            return(L);
        }
Пример #15
0
        public Spectrum SpecularReflect(
            RayDifferential ray,
            SurfaceInteraction isect,
            Scene scene,
            Sampler sampler,
            int depth)
        {
            // Compute specular reflection direction _wi_ and BSDF value
            Vector3D wo   = isect.Wo;
            BxdfType type = BxdfType.Reflection | BxdfType.Specular;
            Spectrum f    = isect.Bsdf.Sample_f(wo, out Vector3D wi, sampler.Get2D(), out double pdf, out BxdfType sampledType, type);

            // Return contribution of specular reflection
            Normal3D ns = isect.ShadingN;

            if (pdf > 0.0 && !f.IsBlack() && wi.AbsDot(ns) != 0.0)
            {
                // Compute ray differential _rd_ for specular reflection
                RayDifferential rd = new RayDifferential(isect.SpawnRay(wi));
                if (ray.HasDifferentials)
                {
                    rd.HasDifferentials = true;
                    rd.RxOrigin         = isect.P + isect.Dpdx.ToPoint3D();
                    rd.RyOrigin         = isect.P + isect.Dpdy.ToPoint3D();
                    // Compute differential reflected directions
                    Normal3D dndx = isect.ShadingDndu * isect.Dudx +
                                    isect.ShadingDndv * isect.Dvdx;
                    Normal3D dndy = isect.ShadingDndu * isect.Dudy +
                                    isect.ShadingDndv * isect.Dvdy;
                    Vector3D dwodx = -ray.RxDirection - wo,
                             dwody = -ray.RyDirection - wo;
                    double dDNdx   = dwodx.Dot(ns) + wo.Dot(dndx);
                    double dDNdy   = dwody.Dot(ns) + wo.Dot(dndy);
                    rd.RxDirection =
                        wi - dwodx + 2.0 * (wo.Dot(ns) * dndx + dDNdx * ns).ToVector3D();
                    rd.RyDirection =
                        wi - dwody + 2.0 * (wo.Dot(ns) * dndy + dDNdy * ns).ToVector3D();
                }
                return(f * Li(rd, scene, sampler, depth + 1) * wi.AbsDot(ns) /
                       pdf);
            }
            else
            {
                return(Spectrum.Create(0.0));
            }
        }
Пример #16
0
        public override Spectrum Li(Scene scene, Renderer renderer, RayDifferential ray, Intersection intersection,
                                    Sample sample, Random rng)
        {
            Spectrum L = Spectrum.CreateBlack();
            // Compute emitted and reflected light at ray intersection point

            // Evaluate BSDF at hit point
            var bsdf = intersection.GetBsdf(ray);

            // Initialize common variables for Whitted integrator
            Point  p  = bsdf.DgShading.Point;
            Normal n  = bsdf.DgShading.Normal;
            Vector wo = -ray.Direction;

            // Compute emitted light if ray hit an area light source
            L += intersection.Le(wo);

            // Add contribution of each light source
            foreach (var light in scene.Lights)
            {
                Vector           wi;
                float            pdf;
                VisibilityTester visibility;
                Spectrum         Li = light.SampleL(p, intersection.RayEpsilon,
                                                    new LightSample(rng), ray.Time, out wi, out pdf, out visibility);
                if (Li.IsBlack || pdf == 0.0f)
                {
                    continue;
                }
                Spectrum f = bsdf.F(wo, wi);
                if (!f.IsBlack && visibility.Unoccluded(scene))
                {
                    L += f * Li * Vector.AbsDot(wi, n)
                         * visibility.Transmittance(scene, renderer, sample, rng)
                         / pdf;
                }
            }
            if (ray.Depth + 1 < _maxDepth)
            {
                // Trace rays for specular reflection and refraction
                L += IntegratorUtilities.SpecularReflect(ray, bsdf, rng, intersection, renderer, scene, sample);
                L += IntegratorUtilities.SpecularTransmit(ray, bsdf, rng, intersection, renderer, scene, sample);
            }
            return(L);
        }
Пример #17
0
        public override float GenerateRay(CameraSample sample, out Ray ray)
        {
            // Transform the film position from raster space to camera space
            var posFilm   = new Point3 <float>(sample.PosFilm.X, sample.PosFilm.Y, 0);
            var posCamera = RasterToCamera * posFilm;

            // Create a ray coming from the center of the view
            ray = new RayDifferential(Point3 <float> .Zero, new Vector3 <float>(posCamera).Normalized());

            // TODO DoF

            //ray.time = ...
            //ray.medium = ...

            ray = CameraToWorld * ray;

            return(1);
        }
Пример #18
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential rayDiff)
        {
            // Transform the film position from raster space to camera space
            var posFilm   = new Point3 <float>(sample.PosFilm.X, sample.PosFilm.Y, 0);
            var posCamera = RasterToCamera * posFilm;

            // Create a ray coming from the center of the view
            rayDiff     = new RayDifferential(Point3 <float> .Zero, new Vector3 <float>(posCamera).Normalized());
            rayDiff.RxO = rayDiff.O + dxCamera;
            rayDiff.RyO = rayDiff.O + dyCamera;
            rayDiff.RxD = rayDiff.RyD = rayDiff.D;

            // TODO time, medium
            rayDiff.HasDifferentials = true;

            // Transform the ray from camera space to world space
            rayDiff = CameraToWorld * rayDiff;

            return(1);
        }
Пример #19
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential rayDiff)
        {
            // Transform the film position from raster space to camera space
            var posFilm   = new Point3 <float>(sample.PosFilm.X, sample.PosFilm.Y, 0);
            var posCamera = RasterToCamera * posFilm;

            // Create a ray directed towards the camera's Z-axis
            rayDiff     = new RayDifferential(posCamera, new Vector3 <float>(0, 0, 1));
            rayDiff.RxO = rayDiff.O + dxCamera;
            rayDiff.RyO = rayDiff.O + dyCamera;
            rayDiff.RxD = rayDiff.RyD = rayDiff.D;

            // TODO time, medium
            rayDiff.HasDifferentials = true;

            // Transform the ray from camera space to world space
            rayDiff = CameraToWorld * rayDiff;

            return(1);
        }
Пример #20
0
        private Spectrum SpecularReflect(RayDifferential ray, SurfaceInteraction inter, Scene scene, Camera camera, Sampler sampler, int depth)
        {
            // Sample a direction with the BSDF
            var type = BxDFType.Reflection | BxDFType.Specular;
            var f    = inter.Bsdf.Sample_f(inter.Wo, out Vector3 <float> wi, sampler.Get2D(), out float pdf, type, out BxDF.BxDFType sampledType);

            // Add the contribution of this reflection
            if (pdf > 0 && !f.IsBlack() && Vector3 <float> .AbsDot(wi, inter.Shading.N) != 0)
            {
                var newRay = inter.SpawnRay(wi).ToDiff();

                if (ray.HasDifferentials)
                {
                    // TODO
                }

                return(f * Li(newRay, scene, camera, sampler, depth + 1) * Vector3 <float> .AbsDot(wi, inter.Shading.N) * (1.0f / pdf));
            }

            return(Spectrum.Zero);
        }
Пример #21
0
        public override Spectrum Li(Scene scene, RayDifferential ray, Sample sample, Random rng, ref Intersection intersection, out Spectrum t)
        {
            Debug.Assert(ray.Time == sample.Time);
            Spectrum Li = Spectrum.CreateBlack();

            if (scene.TryIntersect(ray, ref intersection))
            {
                Li = _surfaceIntegrator.Li(scene, this, ray, intersection, sample, rng);
            }
            else
            {
                // Handle ray that doesn't intersect any geometry
                foreach (var light in scene.Lights)
                {
                    Li += light.Le(ray);
                }
            }
            Spectrum Lvi = _volumeIntegrator.Li(scene, this, ray, sample, rng, out t);

            return(t * Li + Lvi);
        }
Пример #22
0
 public override Spectrum Transmittance(Scene scene, Renderer renderer, RayDifferential ray, Sample sample, Random rng)
 {
     // TODO
     return(new Spectrum(1.0f));
 }
Пример #23
0
 public override Spectrum Li(Scene scene, Renderer renderer, RayDifferential ray, Sample sample, Random rng, out Spectrum transmittance)
 {
     // TODO
     transmittance = new Spectrum(1.0f);
     return(Spectrum.CreateBlack());
 }
Пример #24
0
 public void ComputeScatteringFunctions(RayDifferential ray, bool allowMultipleLobes = false /*, TransportMode mode*/)
 {
     // TODO for texture aliasing ComputeDifferentials(ray);
     Primitive.ComputeScatteringFunctions(this, allowMultipleLobes);
 }
Пример #25
0
 public virtual Spectrum Le(RayDifferential r)
 {
     return(Spectrum.CreateBlack());
 }
Пример #26
0
 public override bool Intersect(RayDifferential ray, out float dist)
 {
     throw new System.NotImplementedException();
 }
Пример #27
0
        private Task CreateRenderTask(
            Scene scene, Sample origSample, CancellationToken cancellationToken,
            int taskNumber, int taskCount)
        {
            return(new Task(() =>
            {
                var sampler = _sampler.GetSubSampler(taskNumber, taskCount);
                if (sampler == null)
                {
                    return;
                }

                var rng = new Random(taskNumber);

                // Allocate space for samples and intersections
                int maxSamples = _sampler.MaximumSampleCount;
                var samples = origSample.Duplicate(maxSamples);
                var rays = new RayDifferential[maxSamples];
                var Ls = new Spectrum[maxSamples];
                var Ts = new Spectrum[maxSamples];
                var isects = new Intersection[maxSamples];

                // Get samples from _Sampler_ and update image
                int sampleCount;
                while ((sampleCount = sampler.GetMoreSamples(samples, rng)) > 0)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    // Generate camera rays and compute radiance along rays
                    for (int i = 0; i < sampleCount; ++i)
                    {
                        // Find camera ray for _sample[i]_
                        float rayWeight = _camera.GenerateRayDifferential(samples[i], out rays[i]);
                        rays[i].ScaleDifferentials(1.0f / MathUtility.Sqrt(sampler.SamplesPerPixel));

                        // Evaluate radiance along camera ray
                        if (rayWeight > 0.0f)
                        {
                            Ls[i] = rayWeight * Li(scene, rays[i], samples[i], rng, ref isects[i], out Ts[i]);
                        }
                        else
                        {
                            Ls[i] = new Spectrum(0.0f);
                            Ts[i] = new Spectrum(1.0f);
                        }
                    }

                    // Report sample results to _Sampler_, add contributions to image
                    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.XStart, sampler.YStart,
                    sampler.XEnd + 1, sampler.YEnd + 1);
            }, cancellationToken));
        }
Пример #28
0
 public override Spectrum Transmittance(Scene scene, RayDifferential ray, Sample sample, Random rng)
 {
     return(_volumeIntegrator.Transmittance(scene, this, ray, sample, rng));
 }
Пример #29
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            Point3 Pras    = new Point3(sample.imageX, sample.imageY);
            Point3 Pcamera = RasterToCamera.Caculate(Pras);

            ray = new RayDifferential(Pcamera, new Vector(0, 0, 1), 0, 1.0f / 0);

            #region Modify ray for depth of field
            if (lensRadius > 0.0)
            {
                // Sample point on lens
                float lensU = 0, lensV = 0;
                LR.ConcentricSampleDisk(sample.lensU, sample.lensV, ref lensU, ref lensV);
                lensU *= lensRadius;
                lensV *= lensRadius;

                // Compute point on plane of focus
                float  ft     = focalDistance / ray.d.z;
                Point3 Pfocus = ray.Transfer(ft);

                // Update ray for effect of lens
                ray.o = new Point3(lensU, lensV, 0.0f);
                ray.d = LR.Normalize(Pfocus - ray.o);
            }
            #endregion
            ray.time = sample.time;

            #region Compute ray differentials for _OrthoCamera_
            if (lensRadius > 0)
            {
                // Compute _OrthoCamera_ ray differentials with defocus blur

                // Sample point on lens
                float lensU = 0, lensV = 0;
                LR.ConcentricSampleDisk(sample.lensU, sample.lensV, ref lensU, ref lensV);
                lensU *= lensRadius;
                lensV *= lensRadius;

                float ft = focalDistance / ray.d.z;

                Point3 pFocus = Pcamera + dxCamera + (ft * new Vector(0, 0, 1));
                ray.rxOrigin    = new Point3(lensU, lensV, 0.0f);
                ray.rxDirection = LR.Normalize(pFocus - ray.rxOrigin);

                pFocus          = Pcamera + dyCamera + (ft * new Vector(0, 0, 1));
                ray.ryOrigin    = new Point3(lensU, lensV, 0.0f);
                ray.ryDirection = LR.Normalize(pFocus - ray.ryOrigin);
            }
            else
            {
                ray.rxOrigin    = ray.o + dxCamera;
                ray.ryOrigin    = ray.o + dyCamera;
                ray.rxDirection = ray.ryDirection = ray.d;
            }
            #endregion

            ray.hasDifferentials = true;
            ray = CameraToWorld.Caculate(ray);

            return(1.0f);
        }
Пример #30
0
 override public float GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
 {
     // Generate raster and camera samples
     ray = new RayDifferential(new Point3(), new Vector());
     return(0.0f);
 }
Пример #31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="r"></param>
 /// <returns></returns>
 public virtual Spectrum Le(RayDifferential r)
 {
     return new Spectrum ();
 }
Пример #32
0
 public abstract Spectrum Li(RayDifferential ray, Scene scene, Sampler sampler, int depth = 0);
Пример #33
0
 public Bssrdf GetBssrdf(RayDifferential ray)
 {
     _dg.ComputeDifferentials(ray);
     return(_primitive.GetBssrdf(_dg, ObjectToWorld));
 }
Пример #34
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ray"></param>
        public void ComputeDifferentials(RayDifferential ray)
        {
            if (!ray.HasDifferentials)
            {
                dudx = dvdx = 0.0;
                dudy = dvdy = 0.0;
                dpdx = dpdy = new Vector (0, 0, 0);
                return;
            }

            var d = -Util.Dot (nn, new Vector (p.x, p.y, p.z));
            var rxv = new Vector (ray.rxOrigin.x, ray.rxOrigin.y, ray.rxOrigin.z);
            var tx = -(Util.Dot (nn, rxv) + d) / Util.Dot (nn, ray.rxDirection);

            if (double.IsNaN (tx))
            {
                dudx = dvdx = 0.0;
                dudy = dvdy = 0.0;
                dpdx = dpdy = new Vector (0, 0, 0);
                return;
            }

            var px = ray.rxOrigin + tx * ray.rxDirection;
            var ryv = new Vector (ray.ryOrigin.x, ray.ryOrigin.y, ray.ryOrigin.z);
            var ty = -(Util.Dot (nn, ryv) + d) / Util.Dot (nn, ray.ryDirection);

            if (double.IsNaN (ty))
            {
                dudx = dvdx = 0.0;
                dudy = dvdy = 0.0;
                dpdx = dpdy = new Vector (0, 0, 0);
                return;
            }

            var py = ray.ryOrigin + ty * ray.ryDirection;
            dpdx = px - p;
            dpdy = py - p;

            var A = new double[2][] { new double[2], new double[2] };
            var Bx = new double[2];
            var By = new double[2];
            var axes = new int[2];

            if (Math.Abs (nn.x) > Math.Abs (nn.y) && Math.Abs (nn.x) > Math.Abs (nn.z))
            {
                axes[0] = 1; axes[1] = 2;
            }
            else if (Math.Abs (nn.y) > Math.Abs (nn.z))
            {
                axes[0] = 0; axes[1] = 2;
            }
            else
            {
                axes[0] = 0; axes[1] = 1;
            }

            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, ref dudx, ref dvdx))
            {
                dudx = 0.0; dvdx = 0.0;
            }
            if (!Util.SolveLinearSystem2x2 (A, By, ref dudy, ref dvdy))
            {
                dudy = 0.0; dvdy = 0.0;
            }
        }