Exemplo n.º 1
0
 public override Spectrum SampleL(Scene scene, LightSample ls, float u1, float u2, float time, out Ray ray, out Normal ns, out float pdf)
 {
     ray = new Ray(_lightPosition, 
         MonteCarloUtilities.UniformSampleSphere(ls.UPos0, ls.UPos1), 
         0.0f, float.PositiveInfinity, time);
     ns = (Normal) ray.Direction;
     pdf = MonteCarloUtilities.UniformSpherePdf();
     return _intensity;
 }
Exemplo n.º 2
0
 public static Vector Cross(Normal v1, Vector v2)
 {
     float v1x = v1.X, v1y = v1.Y, v1z = v1.Z;
     float v2x = v2.X, v2y = v2.Y, v2z = v2.Z;
     return new Vector(
         (v1y * v2z) - (v1z * v2y),
         (v1z * v2x) - (v1x * v2z),
         (v1x * v2y) - (v1y * v2x));
 }
Exemplo n.º 3
0
 public Bsdf(DifferentialGeometry dgShading, Normal nGeom, float eta = 1.0f)
 {
     _dgShading = dgShading;
     _ng = nGeom;
     _eta = eta;
     _nn = dgShading.Normal;
     _sn = Vector.Normalize(dgShading.DpDu);
     _tn = Normal.Cross(_nn, _sn);
     _bxdfs = new List<Bxdf>();
 }
Exemplo n.º 4
0
        public DifferentialGeometry(Point point, Vector dpdu, Vector dpdv,
            Normal dndu, Normal dndv, float u, float v, Shape shape)
        {
            Point = point;
            Normal = (Normal) Vector.Normalize(Vector.Cross(dpdu, dpdv));
            DpDu = dpdu;
            DpDv = dpdv;
            DnDu = dndu;
            DnDv = dndv;
            U = u;
            V = v;
            Shape = shape;

            if (shape != null && shape.ReverseOrientation != shape.TransformSwapsHandedness)
                Normal *= -1.0f;
        }
Exemplo n.º 5
0
        public override Spectrum SampleL(Scene scene, LightSample ls, float u1, float u2, float time, out Ray ray, out Normal ns, out float pdf)
        {
            // Choose point on disk oriented toward infinite light direction
            Point worldCenter;
            float worldRadius;
            scene.WorldBound.BoundingSphere(out worldCenter, out worldRadius);
            Vector v1, v2;
            Vector.CoordinateSystem(_direction, out v1, out v2);
            float d1, d2;
            MonteCarloUtilities.ConcentricSampleDisk(ls.UPos0, ls.UPos1, out d1, out d2);
            Point Pdisk = worldCenter + worldRadius * (d1 * v1 + d2 * v2);

            // Set ray origin and direction for infinite light ray
            ray = new Ray(Pdisk + worldRadius * _direction, -_direction, 0.0f, float.PositiveInfinity, time);
            ns = (Normal) ray.Direction;

            pdf = 1.0f / (MathUtility.Pi * worldRadius * worldRadius);
            return _radiance;
        }
Exemplo n.º 6
0
 public override Point Sample(float u1, float u2, out Normal ns)
 {
     var p = new Point();
     MonteCarloUtilities.ConcentricSampleDisk(u1, u2, out p.X, out p.Y);
     p.X *= _radius;
     p.Y *= _radius;
     p.Z = _height;
     ns = Normal.Normalize(ObjectToWorld.TransformNormal(new Normal(0, 0, 1)));
     if (ReverseOrientation)
         ns *= -1.0f;
     return ObjectToWorld.TransformPoint(ref p);
 }
Exemplo n.º 7
0
 public static float Dot(Vector v1, Normal v2)
 {
     return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z;
 }
Exemplo n.º 8
0
        public override Point Sample(Point p, float u1, float u2, out Normal ns)
        {
            // Compute coordinate system for sphere sampling
            Point Pcenter = ObjectToWorld.TransformPoint(Point.Zero);
            Vector wc = Vector.Normalize(Pcenter - p);
            Vector wcX, wcY;
            Vector.CoordinateSystem(wc, out wcX, out wcY);

            // Sample uniformly on sphere if $\pt{}$ is inside it
            if (Point.DistanceSquared(p, Pcenter) - _radius * _radius < 1e-4f)
                return Sample(u1, u2, out ns);

            // Sample sphere uniformly inside subtended cone
            float sinThetaMax2 = _radius * _radius / Point.DistanceSquared(p, Pcenter);
            float cosThetaMax = MathUtility.Sqrt(Math.Max(0.0f, 1.0f - sinThetaMax2));
            DifferentialGeometry dgSphere;
            float thit, rayEpsilon;
            Point ps;
            Ray r = new Ray(p, MonteCarloUtilities.UniformSampleCone(u1, u2, cosThetaMax, ref wcX, ref wcY, ref wc),
                1e-3f);
            if (!TryIntersect(r, out thit, out rayEpsilon, out dgSphere))
                thit = Vector.Dot(Pcenter - p, Vector.Normalize(r.Direction));
            ps = r.Evaluate(thit);
            ns = (Normal) Vector.Normalize(ps - Pcenter);
            if (ReverseOrientation)
                ns *= -1.0f;
            return ps;
        }
Exemplo n.º 9
0
 public override Spectrum SampleL(Scene scene, LightSample ls, float u1, float u2, float time, out Ray ray, out Normal ns, out float pdf)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 10
0
 public static Normal FaceForward(Normal n, Normal v)
 {
     return (Dot(n, v) < 0.0f) ? -n : n;
 }
Exemplo n.º 11
0
 public static float Dot(Normal n1, Normal n2)
 {
     return n1.X * n2.X + n1.Y * n2.Y + n1.Z * n2.Z;
 }
Exemplo n.º 12
0
 public virtual Point Sample(Point p, float u1, float u2, out Normal ns)
 {
     return Sample(u1, u2, out ns);
 }
Exemplo n.º 13
0
 public virtual Point Sample(float u1, float u2, out Normal ns)
 {
     throw new InvalidOperationException("Unimplemented Shape.Sample() method called.");
 }
Exemplo n.º 14
0
 public Normal TransformNormal(ref Normal n)
 {
     float x = n.X, y = n.Y, z = n.Z;
     return new Normal(
         _mInv.M[0, 0] * x + _mInv.M[1, 0] * y + _mInv.M[2, 0] * z,
         _mInv.M[0, 1] * x + _mInv.M[1, 1] * y + _mInv.M[2, 1] * z,
         _mInv.M[0, 2] * x + _mInv.M[1, 2] * y + _mInv.M[2, 2] * z);
 }
Exemplo n.º 15
0
 public Normal TransformNormal(Normal n)
 {
     return TransformNormal(ref n);
 }
Exemplo n.º 16
0
 public static Normal Normalize(Normal n)
 {
     return n / n.Length();
 }
Exemplo n.º 17
0
 public abstract Spectrum SampleL(Scene scene, LightSample ls, float u1, float u2,
     float time, out Ray ray, out Normal ns, out float pdf);
Exemplo n.º 18
0
 public static float AbsDot(Normal v1, Normal v2)
 {
     return Math.Abs(Dot(v1, v2));
 }
Exemplo n.º 19
0
 public abstract Spectrum L(Point p, Normal n, Vector w);
Exemplo n.º 20
0
 public override Point Sample(float u1, float u2, out Normal ns)
 {
     var z = MathUtility.Lerp(u1, _zMin, _zMax);
     var t = u2 * _phiMax;
     var p = new Point(_radius * MathUtility.Cos(t), _radius * MathUtility.Sin(t), z);
     ns = Normal.Normalize(ObjectToWorld.TransformNormal(new Normal(p.X, p.Y, 0)));
     if (ReverseOrientation)
         ns *= -1.0f;
     return ObjectToWorld.TransformPoint(ref p);
 }
Exemplo n.º 21
0
 public static Vector FaceForward(Vector n, Normal v)
 {
     return (Dot(n, v) < 0.0f) ? -n : n;
 }
Exemplo n.º 22
0
 public override Spectrum L(Point p, Normal n, Vector w)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 23
0
 public override Point Sample(float u1, float u2, out Normal ns)
 {
     Point p = new Point(0, 0, 0) + _radius * MonteCarloUtilities.UniformSampleSphere(u1, u2);
     ns = Normal.Normalize(ObjectToWorld.TransformNormal(new Normal(p.X, p.Y, p.Z)));
     if (ReverseOrientation)
         ns *= -1.0f;
     return ObjectToWorld.TransformPoint(ref p);
 }