Пример #1
0
    static private Color color(Ray r, hitable_list world, int depth)
    {
        hit_record rec;

        UnityEngine.Profiling.Profiler.BeginSample("hit");
        var isHit = world.hit(r, 0.001f, float.MaxValue, out rec);

        UnityEngine.Profiling.Profiler.EndSample();

        if (isHit)
        {
            Ray   scatteded;
            Color attenuation;
            if (depth < 50)
            {
                UnityEngine.Profiling.Profiler.BeginSample("scattter");
                var b = rec.mat.scatter(r, rec, out attenuation, out scatteded);
                UnityEngine.Profiling.Profiler.EndSample();

                if (b)
                {
                    return(attenuation * color(scatteded, world, depth + 1));
                }
                else
                {
                    return(Color.black);
                }
            }
            else
            {
                return(Color.black);
            }
        }
        else
        {
            var unit_direction = r.direction().normalized;
            var t = 0.5f * (unit_direction.y + 1.0f);
            return((1.0f - t) * (new Color(1, 1, 1)) + t * (new Color(0.5f, 0.7f, 1.0f)));
        }
    }
Пример #2
0
    static private Color color(Ray r, hitable_list world, int depth)
    {
        hit_record rec;

        if (world.hit(r, 0.001f, float.MaxValue, out rec))
        {
            Ray   scatteded;
            Color attenuation;
            if (depth < 50 && rec.mat.scatter(r, rec, out attenuation, out scatteded))
            {
                return(attenuation * color(scatteded, world, depth + 1));
            }
            else
            {
                return(Color.black);
            }
        }
        else
        {
            var unit_direction = r.direction().normalized;
            var t = 0.5f * (unit_direction.y + 1.0f);
            return((1.0f - t) * (new Color(1, 1, 1)) + t * (new Color(0.5f, 0.7f, 1.0f)));
        }
    }