Пример #1
0
 public Spectrum Transmittance(Scene scene, Renderer renderer,
     Sample sample, Random rng)
 {
     return renderer.Transmittance(
         scene, RayDifferential.FromRay(Ray),
         sample, rng);
 }
Пример #2
0
        public static void Read(TextReader reader, out Scene scene, out Renderer renderer)
        {
            var sceneFile = Parser.Parse(reader.ReadToEnd());

            var context = new SceneReaderContext();
            foreach (var directive in sceneFile)
                directive.Process(context);

            renderer = context.RenderOptions.MakeRenderer();
            scene = context.RenderOptions.MakeScene();
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
0
 public abstract Spectrum Li(Scene scene, Renderer renderer, RayDifferential ray,
     Sample sample, Random rng, out Spectrum transmittance);
Пример #6
0
 public abstract Spectrum Li(Scene scene, Renderer renderer, RayDifferential ray,
     Intersection intersection, Sample sample, Random rng);
Пример #7
0
 public override Spectrum Transmittance(Scene scene, Renderer renderer, RayDifferential ray, Sample sample, Random rng)
 {
     // TODO
     return new Spectrum(1.0f);
 }
Пример #8
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();
 }
Пример #9
0
 public virtual void PreProcess(Scene scene, Camera camera, Renderer renderer)
 {
     
 }