Example #1
0
        public ColorIntensity RayIntensity(SDScene scene, RayData data)
        {
            ColorIntensity color = new ColorIntensity();

            float lightPass = LightPassValue(scene.ClosestDistance, data.Pos);

            if (lightPass == 0f)
            {
                return(color);
            }

            Vec3f dir = (Pos - data.Pos).Normalized();

            float diffuseDot = dir.Dot(data.Normal);

            if (diffuseDot > 0f)
            {
                color += data.Mat.DiffuseIntensity * DiffuseIntensity * diffuseDot * lightPass;

                Vec3f reflectionDir = 2f * dir.Dot(data.Normal) * data.Normal - dir;
                Vec3f viewerDir     = (data.RayOrigin - data.Pos).Normalized();
                float specularDot   = reflectionDir.Dot(viewerDir);
                if (specularDot > 0f)
                {
                    color += SpecularIntensity * data.Mat.Specular
                             * MathF.Pow(specularDot, data.Mat.Shininess) * lightPass;
                }
            }

            return(color.AtDistance((Pos - data.Pos).Magnitude));
        }
Example #2
0
        public ColorIntensity RayIntensity(RayData data)
        {
            if (Scene == null)
            {
                throw new MemberAccessException("A scene must be stored in Lighting.Scene");
            }

            ColorIntensity color = new ColorIntensity();

            foreach (ILight light in Lights)
            {
                color += light.RayIntensity(Scene, data);
            }

            return(color + data.Mat.AmbientIntensity * AmbientIntensity);
        }