Ejemplo n.º 1
0
        public bool Occluded(V3f rayOrigin, V3f rayDirection, float minT = 0.0f, float maxT = float.MaxValue, RTCFilterFunction filter = null)
        {
            // NOTE: rtcInitIntersectContext is an inline method -> do manually
            var ctx = new RTCIntersectContext()
            {
                instID = unchecked ((uint)-1),
                filter = filter != null?Marshal.GetFunctionPointerForDelegate(filter) : IntPtr.Zero,
            };

            var rtRay = new RTCRay()
            {
                org   = rayOrigin,
                dir   = rayDirection,
                tnear = minT,
                tfar  = maxT,
                flags = 0, // must be initialized with 0
                time  = 0,
                mask  = 0,
                id    = 0,
            };

            unsafe
            {
                var ctxPtr = &ctx;
                var rayPtr = &rtRay;
                EmbreeAPI.rtcOccluded1(Handle, ctxPtr, rayPtr);
            }

            // tfar set to -inf if intersection is found
            return(rtRay.tfar == float.NegativeInfinity);
        }
Ejemplo n.º 2
0
        public bool Intersect(V3f rayOrigin, V3f rayDirection, ref RayHit hit, float minT = 0.0f, float maxT = float.MaxValue, RTCFilterFunction filter = null)
        {
            // NOTE: rtcInitIntersectContext is an inline method -> do manually
            var ctx = new RTCIntersectContext()
            {
                instID = unchecked ((uint)-1), // need to be initialized with RTC_INVALID_GEOMETRY_ID
                filter = filter != null?Marshal.GetFunctionPointerForDelegate(filter) : IntPtr.Zero,
            };

            var rayHit = new RTCRayHit()
            {
                ray = new RTCRay()
                {
                    org   = rayOrigin,
                    dir   = rayDirection,
                    tnear = minT,
                    tfar  = maxT,
                    flags = 0, // must be initialized with 0
                    time  = 0,
                    mask  = 0,
                    id    = 0,
                },
                hit = new RTCHit()
                {
                    geomID = unchecked ((uint)-1), // must be initialized to RTC_INVALID_GEOMETRY_ID
                }
            };

            unsafe
            {
                var ctxPt    = &ctx;
                var rayHitPt = &rayHit;
                EmbreeAPI.rtcIntersect1(Handle, ctxPt, rayHitPt);
            }

            if (rayHit.hit.geomID != unchecked ((uint)-1))
            {
                hit.T           = rayHit.ray.tfar;
                hit.Coord       = rayHit.hit.uv;
                hit.Normal      = rayHit.hit.Ng;
                hit.PrimitiveId = rayHit.hit.primID;
                hit.GeometryId  = rayHit.hit.geomID;
                hit.InstanceId  = rayHit.hit.instID;

                return(true);
            }

            return(false);
        }