示例#1
0
        public void AbsDotProduct()
        {
            var a = new Vector(1, 2, 3);
            var b = new Vector(2, 3, 4);

            Vector.AbsDot(a, b).Should().BeApproximately(20f, 0.00001f);
            b = new Vector(-2, 3, -4);
            Vector.Dot(a, b).Should().BeApproximately(-8f, 0.00001f);
            Vector.AbsDot(a, b).Should().BeApproximately(8f, 0.00001f);
        }
示例#2
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);
        }
示例#3
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);
        }