Exemplo n.º 1
0
        private bool IsVisible(HitRecord record, ILight light)
        {
            Vector3 lightDirection = light.GetLightDirection(record.IntersectionPoint);
            Vector3 hitPos         = record.IntersectionPoint;
            Vector3 offset         = record.RayDirection;

            offset  = -offset;
            offset *= 0.001f;
            hitPos += offset;
            Ray       shadowRay = new Ray(hitPos, lightDirection);
            HitRecord shadowHit = objects.Intersect(shadowRay);
            Vector3   distance  = Vector3.Subtract(light.Position, hitPos);

            return(shadowHit != null && (shadowHit.Distance > distance.Length));
        }
Exemplo n.º 2
0
        public bool IsShadowed(ILight light, Tuple4 pointOverSurface)
        {
            var lightDir = light.GetLightDirection(pointOverSurface);

            if (!lightDir.Equals(Tuple4.ZeroVector))
            {
                var lh = CalculateIntersection(Tuple4.Add(pointOverSurface, Tuple4.Scale(lightDir, Constants.Epsilon)), lightDir);
                if (lh.IsHit)
                {
                    var distance = light.GetLightDistance(pointOverSurface);
                    if (lh.Distance < distance)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }