Example #1
0
 public override bool IntersectP(Ray r)
 {
     float phi;
     Point phit = new Point();
     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;
     }
     return true;
 }
Example #2
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;
 }
Example #3
0
 public Ray(Point orig, Vector dir, Ray parent, float start, float end = float.MaxValue)
 {
     Origin = orig;
     Direction = dir;
     MinT = start;
     MaxT = end;
     Time = parent.Time;
     Depth = parent.Depth + 1;
 }
Example #4
0
 public Ray(Ray ray)
 {
     Origin = ray.Origin;
     Direction = ray.Direction;
     MaxT = ray.MaxT;
     MinT = ray.MinT;
     Time = ray.Time;
     Depth = ray.Depth;
 }
Example #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;
 }
Example #6
0
 public virtual float Pdf(Point p, Vector wi)
 {
     Pointer<DifferentialGeometry> dgLight = new Pointer<DifferentialGeometry>(new DifferentialGeometry());
     Ray ray = new Ray(p, wi, 1e-3f);
     ray.Depth = -1;
     Pointer<float> thit = (Pointer<float>)0, rayEpsilon = (Pointer<float>)0;
     if (!Intersect(ray, thit, rayEpsilon, dgLight)) return 0.0f;
     float pdf = (Point.DistanceSquared(p, ray[thit])) / (Vector.AbsDot((Vector)(~dgLight).nn, -1.0f * wi) * Area);
     if (float.IsInfinity(pdf)) pdf = 0.0f;
     return pdf;
 }
Example #7
0
 public override bool IntersectP(Ray r)
 {
     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;
     return true;
 }
Example #8
0
 public override Point Sample(Point p, float u1, float u2, Pointer<Normal> ns)
 {
     Point Pcenter = (ObjectToWorld)[(new Point(0, 0, 0))];
     Vector wc = Vector.Normalize(Pcenter - p);
     Vector wcX, wcY;
     Extensions.CoordinateSystem(wc, out wcX, out wcY);
     if (Point.DistanceSquared(p, Pcenter) - Radius * Radius < 1e-4f)
         return Sample(u1, u2, ns);
     float sinThetaMax2 = Radius * Radius / Point.DistanceSquared(p, Pcenter);
     float cosThetaMax = MathHelper.Sqrt(MathHelper.Max(0.0f, 1.0f - sinThetaMax2));
     Pointer<DifferentialGeometry> dgSphere = new Pointer<DifferentialGeometry>(new DifferentialGeometry());
     Pointer<float> thit = (Pointer<float>)0, rayEpsilon = (Pointer<float>)0;
     Point ps;
     Ray r = new Ray(p, Extensions.UniformSampleCone(u1, u2, cosThetaMax, wcX, wcY, wc), 1e-3f);
     if (!Intersect(r, thit, rayEpsilon, dgSphere))
         thit[0] = Vector.Dot(Pcenter - p, Vector.Normalize(r.Direction));
     ps = r[thit];
     ns[0] = new Normal(Vector.Normalize(ps - Pcenter));
     if (ReverseOrientation) ns[0] *= -1.0f;
     return ps;
 }
Example #9
0
 public Ray this[Ray ray]
 {
     get
     {
         Ray r = new Ray();
         r.Origin = this[ray.Origin];
         r.Direction = this[ray.Direction];
         return r;
     }
 }
Example #10
0
 public override bool IntersectP(Ray r)
 {
     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;
     }
     return true;
 }
Example #11
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;
 }
Example #12
0
 public override bool IntersectP(Ray r)
 {
     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;
     }
     return true;
 }
Example #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;
 }
Example #14
0
 public RayDifferential(Point orig, Vector dir, Ray parent, float start, float end = float.MaxValue)
     : base(orig, dir, start, end, parent.Time, parent.Depth + 1)
 {
     HasDifferentials = false;
 }
Example #15
0
 public RayDifferential(Ray ray)
     : base(ray)
 {
     HasDifferentials = false;
 }
Example #16
0
 public Ray this[Ray r]
 {
     get
     {
         Ray tr = new Ray();
         if (!actuallyAnimated || r.Time <= startTime)
             tr = (startTransform)[r];
         else if (r.Time >= endTime)
             tr = (endTransform)[r];
         else
         {
             Transform t = new Transform();
             Interpolate(r.Time, t);
             tr = t[r];
         }
         tr.Time = r.Time;
         return tr;
     }
 }
Example #17
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;
 }
Example #18
0
        public bool IntersectRay(Ray ray, ref float hitt0, ref float hitt1)
        {
            float t0 = ray.MinT, t1 = ray.MaxT;
            for (int i = 0; i < 3; ++i)
            {
                float invRayDir = 1.0f / ray.Direction[i];
                float tNear = (Min[i] - ray.Origin[i]) * invRayDir;
                float tFar = (Max[i] - ray.Origin[i]) * invRayDir;

                if (tNear > tFar) MathHelper.Swap<float>(ref tNear,ref tFar);
                t0 = tNear > t0 ? tNear : t0;
                t1 = tFar < t1 ? tFar : t1;
                if (t0 > t1) return false;
            }
            hitt0 = t0;
            hitt1 = t1;
            return true;
        }
Example #19
0
 public virtual bool Intersect(Ray r, Pointer<float> tHit, Pointer<float> rayEpsilon, Pointer<DifferentialGeometry> dg)
 {
     return false;
 }
Example #20
0
 public virtual bool IntersectP(Ray r)
 {
     return false;
 }