Esempio n. 1
0
        public virtual Spectrum GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, Vector view)
        {
            // проверяем что нормали сонаправлены

            var xx = Vector.Dot(normal, this.Direction);

            if (xx > Constants.Epsilon || point.Z > this.Position.Z)
            {
                return(new Spectrum());
            }

            var formFactor = this.GetFormFactor(point);

            // если нет расчетных точек, то генерим их на источнике
            if (this.LightSamplePoints == null)
            {
                this.GenerateLightSamplePoints();
            }

            var result = new Spectrum();

            // цикл по всем расчетным точкам на источнике
            int raysHited = 0;

            foreach (var lightSamplePoint in this.LightSamplePoints)
            {
                var toLight       = lightSamplePoint.Point - point;
                var toLightVector = new Vector(toLight, true);
                //var toLightRay = new Ray( point, lightSamplePoint.Point );
                if (!rayTracer.Occluded(point, toLightVector, Constants.Epsilon, toLight.Length - Constants.Epsilon))
                {
                    // источник косинусный
                    var cosR = Math.Abs(-Vector.Dot(toLightVector, this.Direction));
                    result += material.Reflectance.BRDF(toLightVector.Reverse(), normal, view) * cosR;
                    raysHited++;
                }
            }

            if (raysHited == 0)
            {
                return(new Spectrum());
            }

            // усредняем BRDF
            result = result / (float)raysHited;

            // форм фактор уменьшаяется за счет не попавших лучей
            // (float) Math.PI - из ядра уравнения
            result = this.Illuminance * result * formFactor * (raysHited / (float)(this.Samples));

            //result = result * this.Illuminance / (float)( this.Samples );
            return(result);
        }
Esempio n. 2
0
        public Spectrum GetIlluminance(IRayTracer rayTracer, IMaterial material, Point3D point, Vector normal, Vector view)
        {
            var toLight       = this.Position - point;
            var toLightVector = new Vector(toLight, true);

            //var toLightRay = new Ray( point + normal * Constants.Epsilon, this.Position );

            if (!rayTracer.Occluded(point + normal * Constants.Epsilon, toLightVector, 0, toLight.Length))
            {
                return(this.Intensity * material.Reflectance.BRDF(toLightVector, normal, view) / toLight.Length2);
            }
            else
            {
                return(new Spectrum());
            }
        }