Пример #1
0
 public PhongShading(IObject obj, Vector3 hit, Ray ray, RayTracing rayTracing)
 {
     _hit              = hit;
     _n                = obj.GetNorm(hit);
     _mat              = obj.Material;
     _eh               = ray.Direction;
     _rayTracing       = rayTracing;
     _localCoordinates = obj.ToLocalNormalized(hit);
     _isLightProbe     = obj is LightProbe;
 }
Пример #2
0
            private float Shadow(RayTracing rayTracing)
            {
                if (_isLightProbe || !rayTracing.UseShadows)
                {
                    return(1f);
                }

                var shadowMultiplier = 1f;

                var sPoint = _hit + Vector3.Normalize(_light.Position - _hit) * 0.0001f + _n * 0.0001f;

                (var lHit, _, var lambda) = rayTracing.FindClosestHitPoint(new Ray(sPoint, _l));

                if (lHit.HasValue && lambda * lambda < (_light.Position - _hit).LengthSquared())
                {
                    shadowMultiplier = 0.2f;
                }

                return(shadowMultiplier);
            }