Пример #1
0
 public RayDifferential this[RayDifferential r]
 {
     get
     {
         RayDifferential tr = new RayDifferential();
         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;
     }
 }
Пример #2
0
 public void ComputeDifferentials(RayDifferential ray)
 {
     if (ray.HasDifferentials)
     {
         float d = -Vector.Dot((Vector)nn, new Vector(p.X, p.Y, p.Z));
         Vector rxv = new Vector(ray.RXOrigin.X, ray.RXOrigin.Y, ray.RXOrigin.Z);
         float tx = -(Vector.Dot((Vector)nn, rxv) + d) / Vector.Dot((Vector)nn, ray.RXDirection);
         if (float.IsNaN(tx))
         {
             dudx = dvdx = 0.0f;
             dudy = dvdy = 0.0f;
             dpdx = dpdy = new Vector(0, 0, 0);
             goto end;
         }
         Point px = ray.RXOrigin + tx * ray.RXDirection;
         Vector ryv = new Vector(ray.RYOrigin.X, ray.RYOrigin.Y, ray.RYOrigin.Z);
         float ty = -(Vector.Dot((Vector)nn, ryv) + d) / Vector.Dot((Vector)nn, ray.RYDirection);
         if (float.IsNaN(ty))
         {
             dudx = dvdx = 0.0f;
             dudy = dvdy = 0.0f;
             dpdx = dpdy = new Vector(0, 0, 0);
             goto end;
         }
         Point py = ray.RYOrigin + ty * ray.RYDirection;
         dpdx = px - p;
         dpdy = py - p;
         float[][] A = new float[2][];
         float[] Bx = new float[2];
         float[] By = new float[2];
         int[] axes = new int[2];
         if (MathHelper.Abs(nn.X) > MathHelper.Abs(nn.Y) && MathHelper.Abs(nn.X) > MathHelper.Abs(nn.Z))
         {
             axes[0] = 1; axes[1] = 2;
         }
         else if (MathHelper.Abs(nn.Y) > MathHelper.Abs(nn.Z))
         {
             axes[0] = 0; axes[1] = 2;
         }
         else
         {
             axes[0] = 0; axes[1] = 1;
         }
         A[0][0] = dpdu[axes[0]];
         A[0][1] = dpdv[axes[0]];
         A[1][0] = dpdu[axes[1]];
         A[1][1] = dpdv[axes[1]];
         Bx[0] = px[axes[0]] - p[axes[0]];
         Bx[1] = px[axes[1]] - p[axes[1]];
         By[0] = py[axes[0]] - p[axes[0]];
         By[1] = py[axes[1]] - p[axes[1]];
         float a = 0, b = 0, c = 0, f = 0;
         if (!Transform.SolveLinearSystem2x2(A, Bx, ref a, ref b))
         {
             dudx = 0.0f; 
             dvdx = 0.0f;
         }
         else
         {
             dudx = a;
             dvdx = b;
         }
         if (!Transform.SolveLinearSystem2x2(A, By, ref c, ref f))
         {
             dudy = 0.0f; dvdy = 0.0f;
         }
         else
         {
             dudy = c;
             dvdy = f;
         }
     end:
         float j = 0;
     }
     else
     {
         dudx = dvdx = 0.0f;
         dudy = dvdy = 0.0f;
         dpdx = dpdy = new Vector(0, 0, 0);
     }
 }
Пример #3
0
 public RayDifferential this[RayDifferential ray]
 {
     get
     {
         RayDifferential ret = (RayDifferential)this[new Ray(ray)];
         ret.HasDifferentials = ray.HasDifferentials;
         ret.RXOrigin = this[ray.RXOrigin];
         ret.RYOrigin = this[ray.RYOrigin];
         ret.RXDirection = this[ray.RXDirection];
         ret.RYDirection = this[ray.RYDirection];
         return ret;
     }
 }