public Material()
 {
     Color     = new RtColor(1, 1, 1);
     Ambient   = 0.1;
     Diffuse   = 0.9;
     Specular  = 0.9;
     Shininess = 200.0;
 }
Exemple #2
0
        public Canvas(int width, int height, RtColor background)
        {
            Width  = width;
            Height = height;
            canvas = new RtColor[width, height];

            Clear(background);
        }
Exemple #3
0
 private void Clear(RtColor RtColor)
 {
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             canvas[x, y] = RtColor;
         }
     }
 }
Exemple #4
0
        public AreaLight(RtPoint corner, RtVector uVector, int uSteps, RtVector vVector, int vSteps, RtColor intensity)
        {
            Corner    = corner;
            UVector   = uVector / uSteps;
            USteps    = uSteps;
            VVector   = vVector / vSteps;
            VSteps    = vSteps;
            Intensity = intensity;

            var middle = (uVector / 2) + (vVector / 2);

            Position = new RtPoint(middle.X, middle.Y, middle.Z);
            Samples  = uSteps * vSteps;
        }
        public RtColor Lighting(Computations computations, Light light, double intensity)
        {
            var color = Color;

            if (Pattern != null)
            {
                color = Pattern.PatternAtShape(computations.Shape, computations.OverPosition);
            }

            var effectiveColor = color * light.Intensity;
            var ambient        = effectiveColor * Ambient;

            // var lightPosition = light.Position;

            RtColor sum = RtColor.Black;

            foreach (var lightPosition in light.GetSamples())
            {
                var lightVector    = (lightPosition - computations.Position).Normalize();
                var lightDotNormal = lightVector.Dot(computations.NormalVector);

                if (lightDotNormal < 0 || intensity == 0)
                {
                    continue;
                }

                sum += effectiveColor * Diffuse * lightDotNormal;

                var reflectVector = lightVector.Negate().Reflect(computations.NormalVector);
                var reflectDotEye = reflectVector.Dot(computations.EyeVector);

                if (reflectDotEye > 0)
                {
                    var factor = Math.Pow(reflectDotEye, Shininess);
                    sum += light.Intensity * Specular * factor;
                }
            }

            var results = ambient + (sum / light.Samples) * intensity;

            return(results);
        }
 public GradientPattern(RtColor white, RtColor black)
 {
     ColorB = black;
     ColorA = white;
 }
Exemple #7
0
 public StripePattern(RtColor colorA, RtColor colorB)
 {
     ColorA = colorA;
     ColorB = colorB;
 }
Exemple #8
0
 public PointLight(RtPoint position, RtColor color)
 {
     Position  = position;
     Intensity = color;
     Samples   = 1;
 }
 public GradientRingPattern(RtColor colorA1, RtColor colorA2, RtColor colorB)
 {
     ColorA1 = colorA1;
     ColorA2 = colorA2;
     ColorB  = colorB;
 }
Exemple #10
0
 public RingPattern(RtColor colorA, RtColor colorB)
 {
     ColorA = colorA;
     ColorB = colorB;
 }
 public CheckersPattern(RtColor colorA, RtColor colorB)
 {
     ColorB = colorB;
     ColorA = colorA;
 }