Beispiel #1
0
        Color rayTracing(Ray3 ray, int maxReflect)
        {
            IntersectResult result = geometries.Intersect(ray);
            Color           color  = Color.Black;

            if (result.Geometry != null)
            {
                if (depthFlag)
                {
                    color = result.GetDepthColor();
                }
                else if (result.Geometry.Material != null)
                {
                    List <LightSample> lightSamples   = lights.GetLightSample(geometries, result.Position);
                    double             reflectiveness = result.Geometry.Material.Reflectiveness;
                    foreach (LightSample lightSample in lightSamples)
                    {
                        color = color + result.Geometry.Material.Sample(ray, lightSample, result.Normal, result.Position, result.TextureCoordinates);
                    }
                    color = color * (1 - reflectiveness);

                    if (reflectiveness > 0 && maxReflect > 0)
                    {
                        Vector3 r              = result.Normal * (result.Normal ^ ray.Direction * (-2)) + ray.Direction;
                        Ray3    newRay         = new Ray3(result.Position, r);
                        Color   reflectedColor = rayTracing(newRay, maxReflect - 1);
                        color = color + reflectedColor * reflectiveness;
                    }
                }
            }
            return(color);
        }