Example #1
0
        public Tuple ShadeHit(World w, Computation comps, int remaining)
        {
            Tuple surface = Tuple.Color(0, 0, 0);

            foreach (var light in w.Lights)
            {
                bool shadowed = w.IsShadowed(light, comps.OverPoint);
                surface += Lighting(comps.Material,
                                    comps.Object,
                                    light,
                                    comps.Point,
                                    comps.Eyev,
                                    comps.Normalv,
                                    shadowed);
            }

            Tuple reflected = ReflectedColor(w, comps, remaining);
            Tuple refracted = RefractedColor(w, comps, remaining);

            Material material = comps.Material;

            if (material.Reflective > 0 && material.Transparency > 0)
            {
                float reflectance = Fresnel.Schlick(comps);
                return(surface + reflected * reflectance + refracted * (1 - reflectance));
            }

            return(surface + reflected + refracted);
        }
Example #2
0
        public double IntensityAt(Point point, World world)
        {
            var total = 0.0;

            for (int v = 0; v < this.VSteps; v++)
            {
                for (int u = 0; u < this.USteps; u++)
                {
                    var light_position = this.PointOnLight(u, v);
                    if (!world.IsShadowed(light_position, point))
                    {
                        total = total + 1.0;
                    }
                }
            }

            return(total / this.Samples);
        }