Ejemplo n.º 1
0
        public override T Evaluate(DifferentialGeometry dg)
        {
            T   t1 = _tex1.Evaluate(dg), t2 = _tex2.Evaluate(dg);
            var amt = _amount.Evaluate(dg);

            return(Operators.Add(Operators.Multiply(t1, (1f - amt)), Operators.Multiply(t2, amt)));
        }
Ejemplo n.º 2
0
        public override Bsdf GetBsdf(DifferentialGeometry dgGeom, DifferentialGeometry dgShading)
        {
            // Allocate _BSDF_, possibly doing bump mapping with _bumpMap_
            var dgs = (_bumpMap != null)
                ? Bump(_bumpMap, dgGeom, dgShading)
                : dgShading;

            var bsdf = new Bsdf(dgs, dgGeom.Normal);

            // Evaluate textures for _MatteMaterial_ material and allocate BRDF
            Spectrum r   = Spectrum.Clamp(_kd.Evaluate(dgs));
            float    sig = MathUtility.Clamp(_sigma.Evaluate(dgs), 0.0f, 90.0f);

            if (!r.IsBlack)
            {
                if (sig == 0.0f)
                {
                    bsdf.Add(new Lambertian(r));
                }
                else
                {
                    bsdf.Add(new OrenNayar(r, sig));
                }
            }
            return(bsdf);
        }
Ejemplo n.º 3
0
 public override bool Intersect(Ray r, Pointer<float> tHit, Pointer<float> rayEpsilon, Pointer<DifferentialGeometry> dg)
 {
     Ray ray = (WorldToObject)[r];
     if (MathHelper.Abs(ray.Direction.Z) < 1e-7) return false;
     float thit = (Height - ray.Origin.Z) / ray.Direction.Z;
     if (thit < ray.MinT || thit > ray.MaxT)
         return false;
     Point phit = ray[thit];
     float dist2 = phit.X * phit.X + phit.Y * phit.Y;
     if (dist2 > Radius * Radius || dist2 < InnerRadius * InnerRadius)
         return false;
     float phi = MathHelper.Atan2(phit.Y, phit.X);
     if (phi < 0) phi += 2.0f * MathHelper.PI;
     if (phi > PhiMax)
         return false;
     float u = phi / PhiMax;
     float oneMinusV = ((MathHelper.Sqrt(dist2) - InnerRadius) /
                        (Radius - InnerRadius));
     float invOneMinusV = (oneMinusV > 0.0f) ? (1.0f / oneMinusV) : 0.0f;
     float v = 1.0f - oneMinusV;
     Vector dpdu = new Vector(-PhiMax * phit.Y, PhiMax * phit.X, 0);
     Vector dpdv = new Vector(-phit.X * invOneMinusV, -phit.Y * invOneMinusV, 0);
     dpdu *= PhiMax * MathHelper.InvTwoPI;
     dpdv *= (Radius - InnerRadius) / Radius;
     Normal dndu = new Normal(0, 0, 0), dndv = new Normal(0, 0, 0);
     Transform o2w = ObjectToWorld;
     dg[0] = new DifferentialGeometry(o2w[phit], o2w[dpdu], o2w[dpdv],
                                o2w[dndu], o2w[dndv], u, v, this);
     tHit[0] = thit;
     rayEpsilon[0] = 5e-4f * ~tHit;
     return true;
 }
Ejemplo n.º 4
0
        public override bool Intersect(Ray ray, ref DifferentialGeometry dg)
        {
            float A = ray.d.x * ray.d.x + ray.d.y * ray.d.y + ray.d.z * ray.d.z;
            float B = 2 * (ray.d.x * ray.o.x + ray.d.y * ray.o.y + ray.d.z * ray.o.z);
            float C = ray.o.x * ray.o.x + ray.o.y * ray.o.y +
                      ray.o.z * ray.o.z - radius * radius;


            float[] t;
            if (!LR.Quadratic(A, B, C, out t))
            {
                return(false);
            }


            if (t[0] > ray.maxt || t[1] < ray.mint)
            {
                return(false);
            }
            float thit = t[0];

            if (t[0] < ray.mint)
            {
                thit = t[1];
                if (thit > ray.maxt)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
 public override bool Intersect(Ray r, Pointer<float> tHit, Pointer<float> rayEpsilon, Pointer<DifferentialGeometry> dg)
 {
     float phi;
     Point phit;
     Ray ray = (WorldToObject)[r];
     float A = ray.Direction.X * ray.Direction.X + ray.Direction.Y * ray.Direction.Y;
     float B = 2 * (ray.Direction.X * ray.Origin.X + ray.Direction.Y * ray.Origin.Y);
     float C = ray.Origin.X * ray.Origin.X + ray.Origin.Y * ray.Origin.Y - Radius * Radius;
     float t0 = 0, t1 = 0;
     if (!MathHelper.Quadratic(A, B, C, ref t0, ref t1))
         return false;
     if (t0 > ray.MaxT || t1 < ray.MinT)
         return false;
     float thit = t0;
     if (t0 < ray.MinT)
     {
         thit = t1;
         if (thit > ray.MaxT) return false;
     }
     phit = ray[thit];
     phi = MathHelper.Atan2(phit.Y, phit.X);
     if (phi < 0) phi += 2.0f * MathHelper.PI;
     if (phit.Z < ZMin || phit.Z > ZMax || phi > PhiMax)
     {
         if (thit == t1) return false;
         thit = t1;
         if (t1 > ray.MaxT) return false;
         phit = ray[thit];
         phi = MathHelper.Atan2(phit.Y, phit.X);
         if (phi < 0) phi += 2.0f * MathHelper.PI;
         if (phit.Z < ZMin || phit.Z > ZMax || phi > PhiMax)
             return false;
     }
     float u = phi / PhiMax;
     float v = (phit.Z - ZMin) / (ZMax - ZMin);
     Vector dpdu = new Vector(-PhiMax * phit.Y, PhiMax * phit.X, 0);
     Vector dpdv = new Vector(0, 0, ZMax - ZMin);
     Vector d2Pduu = -PhiMax * PhiMax * new Vector(phit.X, phit.Y, 0);
     Vector d2Pduv = new Vector(0, 0, 0), d2Pdvv = new Vector(0, 0, 0);
     float E = Vector.Dot(dpdu, dpdu);
     float F = Vector.Dot(dpdu, dpdv);
     float G = Vector.Dot(dpdv, dpdv);
     Vector N = Vector.Normalize(Vector.Cross(dpdu, dpdv));
     float e = Vector.Dot(N, d2Pduu);
     float f = Vector.Dot(N, d2Pduv);
     float g = Vector.Dot(N, d2Pdvv);
     float invEGF2 = 1.0f / (E * G - F * F);
     Normal dndu = new Normal((f * F - e * G) * invEGF2 * dpdu + (e * F - f * E) * invEGF2 * dpdv);
     Normal dndv = new Normal((g * F - f * G) * invEGF2 * dpdu + (f * F - g * E) * invEGF2 * dpdv);
     Transform o2w = ObjectToWorld;
     dg[0] = new DifferentialGeometry(o2w[phit], o2w[dpdu], o2w[dpdv],
                                o2w[dndu], o2w[dndv], u, v, this);
     tHit[0] = thit;
     rayEpsilon[0] = 5e-4f * ~tHit;
     return true;
 }
Ejemplo n.º 6
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>();
 }
Ejemplo n.º 7
0
 public Intersection(DifferentialGeometry dg, Primitive primitive,
                     Transform objectToWorld, Transform worldToObject,
                     float rayEpsilon)
 {
     _dg           = dg;
     _primitive    = primitive;
     WorldToObject = worldToObject;
     ObjectToWorld = objectToWorld;
     _rayEpsilon   = rayEpsilon;
 }
Ejemplo n.º 8
0
 public override void Map(DifferentialGeometry dg, ref float s, ref float t, ref float dsdx, ref float dtdx,
                          ref float dsdy,
                          ref float dtdy)
 {
     s    = _su * dg.U + _du;
     t    = _sv * dg.V + _dv;
     dsdx = _su * dg.dudx;
     dtdx = _sv * dg.dvdx;
     dsdy = _su * dg.dudy;
     dtdy = _sv * dg.dvdy;
 }
Ejemplo n.º 9
0
        protected static DifferentialGeometry Bump(Texture <float> d,
                                                   DifferentialGeometry dgGeom,
                                                   DifferentialGeometry dgs)
        {
            // Compute offset positions and evaluate displacement texture
            DifferentialGeometry dgEval = dgs;

            // Shift _dgEval_ _du_ in the $u$ direction
            float du = .5f * (Math.Abs(dgs.DuDx) + Math.Abs(dgs.DuDy));

            if (du == 0.0f)
            {
                du = .01f;
            }
            dgEval.Point  = dgs.Point + du * dgs.DpDu;
            dgEval.U      = dgs.U + du;
            dgEval.Normal = Normal.Normalize((Normal)Vector.Cross(dgs.DpDu, dgs.DpDv) +
                                             du * dgs.DnDu);
            float uDisplace = d.Evaluate(dgEval);

            // Shift _dgEval_ _dv_ in the $v$ direction
            float dv = .5f * (Math.Abs(dgs.DvDx) + Math.Abs(dgs.DvDy));

            if (dv == 0.0f)
            {
                dv = .01f;
            }
            dgEval.Point  = dgs.Point + dv * dgs.DpDv;
            dgEval.U      = dgs.U;
            dgEval.V      = dgs.V + dv;
            dgEval.Normal = Normal.Normalize((Normal)Vector.Cross(dgs.DpDu, dgs.DpDv) + dv * dgs.DnDv);
            float vDisplace = d.Evaluate(dgEval);
            float displace  = d.Evaluate(dgs);

            // Compute bump-mapped differential geometry
            var dgBump = dgs.Clone();

            dgBump.DpDu = dgs.DpDu + (uDisplace - displace) / du * (Vector)dgs.Normal +
                          displace * (Vector)dgs.DnDu;
            dgBump.DpDv = dgs.DpDv + (vDisplace - displace) / dv * (Vector)dgs.Normal +
                          displace * (Vector)dgs.DnDv;
            dgBump.Normal = (Normal)Vector.Normalize(Vector.Cross(dgBump.DpDu, dgBump.DpDv));
            if (dgs.Shape.ReverseOrientation ^ dgs.Shape.TransformSwapsHandedness)
            {
                dgBump.Normal *= -1.0f;
            }

            // Orient shading normal to match geometric normal
            dgBump.Normal = Normal.FaceForward(dgBump.Normal, dgGeom.Normal);

            return(dgBump);
        }
Ejemplo n.º 10
0
        public override bool Intersect(Ray ray, ref DifferentialGeometry dg)
        {
            Point3 p1 = m.P[v[0]];
            Point3 p2 = m.P[v[1]];
            Point3 p3 = m.P[v[2]];

            Vector e1 = p2 - p1;
            Vector e2 = p3 - p1;
            Vector s1 = LR.Cross(ray.d, e2);

            float divisor = LR.Dot(s1, e1);

            if (divisor == 0.0f)
            {
                return(false);
            }
            float invDivisor = 1.0f / divisor;

            // Compute first barycentric coordinate
            Vector s  = ray.o - p1;
            float  b1 = LR.Dot(s, s1) * invDivisor;

            if (b1 < 0.0f || b1 > 1.0f)
            {
                return(false);
            }

            // Compute second barycentric coordinate
            Vector s2 = LR.Cross(s, e1);
            float  b2 = LR.Dot(ray.d, s2) * invDivisor;

            if (b2 < 0.0f || b1 + b2 > 1.0f)
            {
                return(false);
            }

            // Compute _t_ to intersection point
            float t = LR.Dot(e2, s2) * invDivisor;

            if (t < ray.mint || t > ray.maxt)
            {
                return(false);
            }


            return(false);
        }
Ejemplo n.º 11
0
 public abstract Bssrdf GetBssrdf(DifferentialGeometry dg, Transform objectToWorld);
Ejemplo n.º 12
0
 public abstract T Evaluate(DifferentialGeometry dg);
Ejemplo n.º 13
0
 public override bool Intersect(Ray r, Pointer<float> tHit, Pointer<float> rayEpsilon, Pointer<DifferentialGeometry> dg)
 {
     float phi;
     Point phit = new Point();
     Ray ray = (WorldToObject)[r];
     float A = ray.Direction.X * ray.Direction.X + ray.Direction.Y * ray.Direction.Y + ray.Direction.Z * ray.Direction.Z;
     float B = 2 * (ray.Direction.X * ray.Origin.X + ray.Direction.Y * ray.Origin.Y + ray.Direction.Z * ray.Origin.Z);
     float C = ray.Origin.X * ray.Origin.X + ray.Origin.Y * ray.Origin.Y +
               ray.Origin.Z * ray.Origin.Z - Radius * Radius;
     float t0 = 0, t1 = 0;
     if (!MathHelper.Quadratic(A, B, C, ref t0, ref t1))
         return false;
     if (t0 > ray.MaxT || t1 < ray.MinT)
         return false;
     float thit = t0;
     if (t0 < ray.MinT)
     {
         thit = t1;
         if (thit > ray.MaxT) return false;
     }
     phit = ray[thit];
     if (phit.X == 0.0f && phit.Y == 0.0f) phit.X = 1e-5f * Radius;
     phi = MathHelper.Atan2(phit.Y, phit.X);
     if (phi < 0.0f) phi += 2.0f * MathHelper.PI;
     if ((zmin > -Radius && phit.Z < zmin) ||
         (zmax < Radius && phit.Z > zmax) || phi > phiMax)
     {
         if (thit == t1) return false;
         if (t1 > ray.MaxT) return false;
         thit = t1;
         phit = ray[thit];
         if (phit.X == 0.0f && phit.Y == 0.0f) phit.X = 1e-5f * Radius;
         phi = MathHelper.Atan2(phit.Y, phit.X);
         if (phi < 0.0f) phi += 2.0f * MathHelper.PI;
         if ((zmin > -Radius && phit.Z < zmin) ||
             (zmax < Radius && phit.Z > zmax) || phi > phiMax)
             return false;
     }
     float u = phi / phiMax;
     float theta = MathHelper.Acos(MathHelper.Clamp(phit.Z / Radius, -1.0f, 1.0f));
     float v = (theta - thetaMin) / (thetaMax - thetaMin);
     float zradius = MathHelper.Sqrt(phit.X * phit.X + phit.Y * phit.Y);
     float invzradius = 1.0f / zradius;
     float cosphi = phit.X * invzradius;
     float sinphi = phit.Y * invzradius;
     Vector dpdu = new Vector(-phiMax * phit.Y, phiMax * phit.X, 0);
     Vector dpdv = (thetaMax - thetaMin) *
         new Vector(phit.Z * cosphi, phit.Z * sinphi,
                -Radius * MathHelper.Sin(theta));
     Vector d2Pduu = -phiMax * phiMax * new Vector(phit.X, phit.Y, 0);
     Vector d2Pduv = (thetaMax - thetaMin) * phit.Z * phiMax *
                     new Vector(-sinphi, cosphi, 0.0f);
     Vector d2Pdvv = -(thetaMax - thetaMin) * (thetaMax - thetaMin) *
                     new Vector(phit.X, phit.Y, phit.Z);
     float E = Vector.Dot(dpdu, dpdu);
     float F = Vector.Dot(dpdu, dpdv);
     float G = Vector.Dot(dpdv, dpdv);
     Vector N = Vector.Normalize(Vector.Cross(dpdu, dpdv));
     float e = Vector.Dot(N, d2Pduu);
     float f = Vector.Dot(N, d2Pduv);
     float g = Vector.Dot(N, d2Pdvv);
     float invEGF2 = 1.0f / (E * G - F * F);
     Normal dndu = new Normal((f * F - e * G) * invEGF2 * dpdu + (e * F - f * E) * invEGF2 * dpdv);
     Normal dndv = new Normal((g * F - f * G) * invEGF2 * dpdu + (f * F - g * E) * invEGF2 * dpdv);
     Transform o2w = ObjectToWorld;
     dg[0] = new DifferentialGeometry(o2w[phit], o2w[dpdu], o2w[dpdv], o2w[dndu], o2w[dndv], u, v, this);
     tHit[0] = thit;
     rayEpsilon[0] = 5e-4f * ~tHit;
     return true;
 }
Ejemplo n.º 14
0
 public override bool Intersect(Ray r, Pointer<float> tHit, Pointer<float> rayEpsilon, Pointer<DifferentialGeometry> dg)
 {
     float phi, v;
     Point phit;
     Ray ray = (WorldToObject)[r];
     float A = a * ray.Direction.X * ray.Direction.X +
               a * ray.Direction.Y * ray.Direction.Y -
               c * ray.Direction.Z * ray.Direction.Z;
     float B = 2.0f * (a * ray.Direction.X * ray.Origin.X +
                      a * ray.Direction.Y * ray.Origin.Y -
                      c * ray.Direction.Z * ray.Origin.Z);
     float C = a * ray.Origin.X * ray.Origin.X +
               a * ray.Origin.Y * ray.Origin.Y -
               c * ray.Origin.Z * ray.Origin.Z - 1;
     float t0 = 0, t1 = 0;
     if (!MathHelper.Quadratic(A, B, C, ref t0, ref t1))
         return false;
     if (t0 > ray.MaxT || t1 < ray.MinT)
         return false;
     float thit = t0;
     if (t0 < ray.MinT)
     {
         thit = t1;
         if (thit > ray.MaxT) return false;
     }
     phit = ray[thit];
     v = (phit.Z - p1.Z) / (p2.Z - p1.Z);
     Point pr = (1.0f - v) * p1 + v * p2;
     phi = MathHelper.Atan2(pr.X * phit.Y - phit.X * pr.Y,
         phit.X * pr.X + phit.Y * pr.Y);
     if (phi < 0)
         phi += 2 * MathHelper.PI;
     if (phit.Z < zmin || phit.Z > zmax || phi > phiMax)
     {
         if (thit == t1) return false;
         thit = t1;
         if (t1 > ray.MaxT) return false;
         phit = ray[thit];
         v = (phit.Z - p1.Z) / (p2.Z - p1.Z);
         Point pr2 = (1.0f - v) * p1 + v * p2;
         phi = MathHelper.Atan2(pr2.X * phit.Y - phit.X * pr2.Y,
             phit.X * pr2.X + phit.Y * pr2.Y);
         if (phi < 0)
             phi += 2 * MathHelper.PI;
         if (phit.Z < zmin || phit.Z > zmax || phi > phiMax)
             return false;
     }
     float u = phi / phiMax;
     float cosphi = MathHelper.Cos(phi), sinphi = MathHelper.Sin(phi);
     Vector dpdu = new Vector(-phiMax * phit.Y, phiMax * phit.X, 0);
     Vector dpdv = new Vector((p2.X - p1.X) * cosphi - (p2.Y - p1.Y) * sinphi,
         (p2.X - p1.X) * sinphi + (p2.Y - p1.Y) * cosphi,
         p2.Z - p1.Z);
     Vector d2Pduu = -phiMax * phiMax *
                     new Vector(phit.X, phit.Y, 0);
     Vector d2Pduv = phiMax *
                     new Vector(-dpdv.Y, dpdv.X, 0);
     Vector d2Pdvv = new Vector(0, 0, 0);
     float E = Vector.Dot(dpdu, dpdu);
     float F = Vector.Dot(dpdu, dpdv);
     float G = Vector.Dot(dpdv, dpdv);
     Vector N = Vector.Normalize(Vector.Cross(dpdu, dpdv));
     float e = Vector.Dot(N, d2Pduu);
     float f = Vector.Dot(N, d2Pduv);
     float g = Vector.Dot(N, d2Pdvv);
     float invEGF2 = 1.0f / (E * G - F * F);
     Normal dndu = new Normal((f * F - e * G) * invEGF2 * dpdu +
                          (e * F - f * E) * invEGF2 * dpdv);
     Normal dndv = new Normal((g * F - f * G) * invEGF2 * dpdu +
                          (f * F - g * E) * invEGF2 * dpdv);
     Transform o2w = ObjectToWorld;
     dg[0] = new DifferentialGeometry(o2w[phit], o2w[dpdu], o2w[dpdv],
                                o2w[dndu], o2w[dndv], u, v, this);
     tHit[0] = thit;
     rayEpsilon[0] = 5e-4f * tHit;
     return true;
 }
Ejemplo n.º 15
0
        public override Bssrdf GetBssrdf(DifferentialGeometry dg, Transform objectToWorld)
        {
            var dgs = _shape.GetShadingGeometry(objectToWorld, dg);

            return(_material.GetBssrdf(dg, dgs));
        }
Ejemplo n.º 16
0
 public abstract Bsdf GetBsdf(DifferentialGeometry dgGeom, DifferentialGeometry dgShading);
Ejemplo n.º 17
0
        public override void GetShadingGeometry(Transform obj2world, DifferentialGeometry dg, Pointer<DifferentialGeometry> dgShading)
        {
            if (mesh.n == null && mesh.s == null)
            {
                dgShading[0] = dg;
                return;
            }
            float[] b = new float[3];
            float[][] uv = new float[3][];
            uv[0] = new float[2];
            uv[1] = new float[2];
            uv[2] = new float[2];
            GetUVs(uv);
            float[][] A = { new float[2]
    { uv[1][0] - uv[0][0], uv[2][0] - uv[0][0] },
    new float[2]
    { uv[1][1] - uv[0][1], uv[2][1] - uv[0][1] } 
    };
            float[] C = { dg.u - uv[0][0], dg.v - uv[0][1] };
            if (!Transform.SolveLinearSystem2x2(A, C, ref b[1], ref b[2]))
            {
                b[0] = b[1] = b[2] = 1.0f / 3.0f;
            }
            else
                b[0] = 1.0f - b[1] - b[2];
            Normal ns;
            Vector ss, ts;
            if (mesh.n != null) ns = Normal.Normalize(obj2world[b[0] * mesh.n[v[0]] +
                                                  b[1] * mesh.n[v[1]] +
                                                  b[2] * mesh.n[v[2]]]);
            else ns = dg.nn;
            if (mesh.s != null) ss = Vector.Normalize(obj2world[b[0] * mesh.s[v[0]] +
                                                  b[1] * mesh.s[v[1]] +
                                                  b[2] * mesh.s[v[2]]]);
            else ss = Vector.Normalize(dg.dpdu);

            ts = Vector.Cross(ss, ns);
            if (ts.SquaredMagnitude > 0.0f)
            {
                ts = Vector.Normalize(ts);
                ss = Vector.Cross(ts, ns);
            }
            else
                Extensions.CoordinateSystem((Vector)ns, out ss, out ts);
            Normal dndu, dndv;
            if (mesh.n != null)
            {
                float[][] uvs = new float[3][];
                uvs[0] = new float[2];
                uvs[1] = new float[2];
                uvs[2] = new float[2];
                GetUVs(uvs);
                float du1 = uvs[0][0] - uvs[2][0];
                float du2 = uvs[1][0] - uvs[2][0];
                float dv1 = uvs[0][1] - uvs[2][1];
                float dv2 = uvs[1][1] - uvs[2][1];
                Normal dn1 = mesh.n[v[0]] - mesh.n[v[2]];
                Normal dn2 = mesh.n[v[1]] - mesh.n[v[2]];
                float determinant = du1 * dv2 - dv1 * du2;
                if (determinant == 0.0f)
                    dndu = dndv = new Normal(0, 0, 0);
                else
                {
                    float invdet = 1.0f / determinant;
                    dndu = ((dv2 * dn1 - dv1 * dn2) * invdet);
                    dndv = ((-du2 * dn1 + du1 * dn2) * invdet);
                }
            }
            else
                dndu = dndv = new Normal(0, 0, 0);
            dgShading[0] = new DifferentialGeometry(dg.p, ss, ts, (ObjectToWorld)[dndu], (ObjectToWorld)[dndv],
                dg.u, dg.v, dg.shape);
            dgShading[0].Setdudx(dg.dudx); 
            dgShading[0].Setdvdx(dg.dvdx);
            dgShading[0].Setdudy(dg.dudy); 
            dgShading[0].Setdvdy(dg.dvdy);
            dgShading[0].Setdpdx(dg.dpdx); 
            dgShading[0].Setdpdy(dg.dpdy);
        }
Ejemplo n.º 18
0
 public override TU Evaluate(DifferentialGeometry dg)
 {
     return(Operators.Multiply(_tex2.Evaluate(dg), _tex1.Evaluate(dg)));
 }
Ejemplo n.º 19
0
 public override Bssrdf GetBssrdf(DifferentialGeometry dg, Transform objectToWorld)
 {
     throw new InvalidOperationException("Aggregate.GetBssrdf() method called; should have gone to GeometricPrimitive.");
 }
Ejemplo n.º 20
0
 public virtual void GetShadingGeometry(Transform obj2world, DifferentialGeometry dg, Pointer<DifferentialGeometry> dgShading)
 {
     dgShading[0] = dg;
 }
Ejemplo n.º 21
0
 public virtual Bssrdf GetBssrdf(DifferentialGeometry dgGeom, DifferentialGeometry dgShading)
 {
     return(null);
 }
Ejemplo n.º 22
0
 public abstract void Map(DifferentialGeometry dg, ref float s, ref float t, ref float dsdx, ref float dtdx,
                          ref float dsdy, ref float dtdy);
Ejemplo n.º 23
0
 public override bool IntersectP(Ray ray)
 {
     Point p1 = mesh.p[v[0]];
     Point p2 = mesh.p[v[1]];
     Point p3 = mesh.p[v[2]];
     Vector e1 = p2 - p1;
     Vector e2 = p3 - p1;
     Vector s1 = Vector.Cross(ray.Direction, e2);
     float divisor = Vector.Dot(s1, e1);
     if (divisor == 0.0f)
         return false;
     float invDivisor = 1.0f / divisor;
     Vector d = ray.Origin - p1;
     float b1 = Vector.Dot(d, s1) * invDivisor;
     if (b1 < 0 || b1 > 1)
         return false;
     Vector s2 = Vector.Cross(d, e1);
     float b2 = Vector.Dot(ray.Direction, s2) * invDivisor;
     if (b2 < 0 || b1 + b2 > 1)
         return false;
     float t = Vector.Dot(e2, s2) * invDivisor;
     if (t < ray.MinT || t > ray.MaxT)
         return false;
     if (ray.Depth != -1 && mesh.alphaTexture != null)
     {
         Vector dpdu, dpdv;
         float[][] uvs = new float[3][];
         uvs[0] = new float[2];
         uvs[1] = new float[2];
         uvs[2] = new float[2];
         GetUVs(uvs);
         float du1 = uvs[0][0] - uvs[2][0];
         float du2 = uvs[1][0] - uvs[2][0];
         float dv1 = uvs[0][1] - uvs[2][1];
         float dv2 = uvs[1][1] - uvs[2][1];
         Vector dp1 = p1 - p3, dp2 = p2 - p3;
         float determinant = du1 * dv2 - dv1 * du2;
         if (determinant == 0.0f)
         {
             Extensions.CoordinateSystem(Vector.Normalize(Vector.Cross(e2, e1)), out dpdu, out dpdv);
         }
         else
         {
             float invdet = 1.0f / determinant;
             dpdu = (dv2 * dp1 - dv1 * dp2) * invdet;
             dpdv = (-du2 * dp1 + du1 * dp2) * invdet;
         }
         float b0 = 1 - b1 - b2;
         float tu = b0 * uvs[0][0] + b1 * uvs[1][0] + b2 * uvs[2][0];
         float tv = b0 * uvs[0][1] + b1 * uvs[1][1] + b2 * uvs[2][1];
         DifferentialGeometry dgLocal = new DifferentialGeometry(ray[t], dpdu, dpdv, new Normal(0,0,0), new Normal(0,0,0), tu, tv, this);
         if (mesh.alphaTexture.Evaluate(dgLocal) == 0.0f)
             return false;
     }
     return true;
 }
Ejemplo n.º 24
0
 public override Bssrdf GetBssrdf(DifferentialGeometry dg, Transform objectToWorld)
 {
     return(null);
 }
 public override T Evaluate(DifferentialGeometry dg)
 {
     return(_value);
 }