Пример #1
0
        public void At(Surface.Intersection intersection, ref Surface.Attributes attributes)
        {
            Triangle tri = triangles[intersection.PrimitiveID];

            if (smoothNormals)
            {
                // barycentric interpolation
                Vector smoothed = tri.V1.Normal * intersection.LocalU
                                  + tri.V2.Normal * intersection.LocalV
                                  + tri.V0.Normal * (1 - intersection.LocalU - intersection.LocalV);

                attributes.Basis = new Basis(smoothed.Normalize());
            }
            else
            {
                attributes.Basis = new Basis(tri.FaceNormal);
            }
        }
Пример #2
0
        public unsafe Boolean Intersect(Ray ray, float near, float far, out Surface.Intersection intersection)
        {
            var ptr = stackalloc byte[Marshal.SizeOf(typeof(Embree.RayStruct1))
                                      + Embree.RayStruct1.Alignment];
            var rs = (Embree.RayStruct1 *)(Align(ptr, Embree.RayStruct1.Alignment));

            rs->orgX = ray.Origin.X;
            rs->orgY = ray.Origin.Y;
            rs->orgZ = ray.Origin.Z;

            rs->dirX = ray.Direction.X;
            rs->dirY = ray.Direction.Y;
            rs->dirZ = ray.Direction.Z;

            rs->tnear = near;
            rs->tfar  = far;
            rs->time  = 0.0f;

            rs->geomID = Embree.RTC.InvalidID;
            rs->primID = Embree.RTC.InvalidID;
            rs->instID = Embree.RTC.InvalidID;
            rs->mask   = 0xFFFFFFFF;

            scene.Intersection(rs);

            if (rs->geomID != Embree.RTC.InvalidID)
            {
                intersection = new Surface.Intersection()
                {
                    Distance    = rs->tfar,
                    SurfaceID   = rs->instID,
                    PrimitiveID = rs->primID,
                    LocalU      = rs->u,
                    LocalV      = rs->v
                };
                return(true);
            }
            else
            {
                intersection = default(Surface.Intersection);
                return(false);
            }
        }
Пример #3
0
 public void At(Surface.Intersection intersection, ref Surface.Attributes attributes)
 {
     attributes.Material = Material;
 }