Esempio n. 1
0
        /*public ColorRgb Radiance(PointLight light, HitInfo hit)
         * {
         *  Vector3 inDirection = (light.Position - hit.HitPoint).Normalised;
         *  double diffuseFactor = inDirection.Dot(hit.Normal);
         *
         *  if (diffuseFactor < 0) { return ColorRgb.Black; }
         *
         *  ColorRgb result = light.Color * materialColor * diffuseFactor * diffuseCoeff;
         *  double phongFactor = PhongFactor(inDirection, hit.Normal, -hit.Ray.Direction);
         *
         *  if(phongFactor != 0)
         *  { result += materialColor * specular * phongFactor; }
         *
         *  return result;
         * }*/

        public ColorRgb Shade(Raytracer tracer, HitInfo hit)
        {
            ColorRgb totalColor = ColorRgb.Black;

            foreach (var light in hit.World.Lights)
            {
                Vector3 inDirection   = (light.Position - hit.HitPoint).Normalised;
                double  diffuseFactor = inDirection.Dot(hit.Normal);
                if (diffuseFactor < 0)
                {
                    return(ColorRgb.Black);
                }
                if (hit.World.AnyObstacleBetween(hit.HitPoint, light.Position))
                {
                    continue;
                }
                ColorRgb result = light.Color * materialColor * diffuseFactor * diffuseCoeff; double phongFactor = PhongFactor(inDirection, hit.Normal, -hit.Ray.Direction);
                if (phongFactor != 0)
                {
                    result += materialColor * specular * phongFactor;
                }
                totalColor += result;
            }
            return(totalColor);
        }
Esempio n. 2
0
 Color StripColor(ColorRgb colorInfo)
 {
     colorInfo.R = colorInfo.R < 0 ? 0 : colorInfo.R > 1 ? 1 : colorInfo.R;
     colorInfo.G = colorInfo.G < 0 ? 0 : colorInfo.G > 1 ? 1 : colorInfo.G;
     colorInfo.B = colorInfo.B < 0 ? 0 : colorInfo.B > 1 ? 1 : colorInfo.B;
     return(Color.FromArgb((int)(colorInfo.R * 255), (int)(colorInfo.G * 255), (int)(colorInfo.B * 255)));
 }
Esempio n. 3
0
 public Phong(ColorRgb materialColor, double diffuse, double specular, double specularExponent)
 {
     this.materialColor    = materialColor;
     this.diffuseCoeff     = diffuse;
     this.specular         = specular;
     this.specularExponent = specularExponent;
 }
        public ColorRgb Shade(Raytracer tracer, HitInfo hit)
        {
            Vector3  toCameraDirection   = -hit.Ray.Direction;
            ColorRgb radiance            = direct.Shade(tracer, hit);
            Vector3  reflectionDirection = Vector3.Reflect(toCameraDirection, hit.Normal);
            Ray      reflectedRay        = new Ray(hit.HitPoint, reflectionDirection);
            ColorRgb reflected           = tracer.ShadeRay(hit.World, reflectedRay, hit.Depth) * reflectionColor * reflectivity;

            radiance += tracer.ShadeRay(hit.World, reflectedRay, hit.Depth) * reflectionColor * reflectivity;
            return(radiance);
        }
Esempio n. 5
0
        /*public ColorRgb Radiance(PointLight light, HitInfo hit) {
         *  Vector3 inDirection = (light.Position - hit.HitPoint).Normalised;
         *  double diffuseFactor = inDirection.Dot(hit.Normal);
         *  if (diffuseFactor < 0) { return ColorRgb.Black; }
         *  return light.Color * materialColor * diffuseFactor;
         * }*/

        public ColorRgb Shade(Raytracer tracer, HitInfo hit)
        {
            ColorRgb totalColor = ColorRgb.Black;

            foreach (var light in hit.World.Lights)
            {
                Vector3 inDirection   = (light.Position - hit.HitPoint).Normalised;
                double  diffuseFactor = inDirection.Dot(hit.Normal);
                if (diffuseFactor < 0)
                {
                    continue;
                }
                if (hit.World.AnyObstacleBetween(hit.HitPoint, light.Position))
                {
                    continue;
                }
                totalColor += light.Color * materialColor * diffuseFactor;
            }
            return(totalColor);
        }
Esempio n. 6
0
 public PointLight(Vector3 position, ColorRgb color)
 {
     this.Position = position;
     this.Color    = color;
 }
Esempio n. 7
0
 public Light(Vector3 vector, bool Directed, ColorRgb color)
 {
     this.Vector   = vector;
     this.Directed = Directed;
     this.Color    = color;
 }
Esempio n. 8
0
 public PerfectDiffuse(ColorRgb materialColor)
 {
     this.materialColor = materialColor;
 }
 public Reflective(ColorRgb materialColor, double diffuse, double specular, double exponent, double reflectivity)
 {
     this.direct          = new Phong(materialColor, diffuse, specular, exponent);
     this.reflectivity    = reflectivity;
     this.reflectionColor = materialColor;
 }