Ejemplo n.º 1
0
        public Color getColor(Vec2D v)
        {
            // simple interpolation
            // int col = (int)(v.u * this.image.width);
            // int row = (int)(v.v * this.image.height);

            // if (col >= this.image.width) col = this.image.width - 1;
            // if (row >= this.image.height) row = this.image.height - 1;

            // return image.getPixel(col, row);

            // elegant bilinear interpolation

            float x = v.u * (this.image.width - 1);
            int x1 = (int)Math.Floor(v.u * (this.image.width - 1));
            if (x1 >= this.image.width - 1) x1 = (int)v.u * (this.image.width - 2);
            int x2 = x1 + 1;

            float y = v.v * (this.image.height - 1);
            int y1 = (int)Math.Floor(v.v * (this.image.height - 1));
            if (y1 >= this.image.height - 1) y1 = (int)v.v * (this.image.height - 2);
            int y2 = y1 + 1;

            Color c11 = this.image.getPixel(x1, y1);
            Color c12 = this.image.getPixel(x1, y2);
            Color c21 = this.image.getPixel(x2, y1);
            Color c22 = this.image.getPixel(x2, y2);

            float den = 1.0f / ((x2 - x1) * (y2 - y1));

            return (x2 - x) * (c11 * (y2 - y) + c12 * (y - y1)) + (x - x1) * (c21 * (y2 - y) + c22 * (y - y1)) * den;

        }
Ejemplo n.º 2
0
        public Color getColor(Vec2D uv)
        {

            int u = (int)Math.Floor(uv.u * this.nSteps);
            int v = (int)Math.Floor(uv.v * this.nSteps);
            return (u + v) % 2 == 0 ? this.color1 : this.color2;
        }
Ejemplo n.º 3
0
 public HitRecord(Point wp, Normal nm, Vec2D sp, float tt, Ray r, Shape? shape = null)
 {
     this.worldPoint = wp;
     this.normal = nm;
     this.surfacePoint = sp;
     this.t = tt;
     this.ray = r;
     this.shape = shape;
 }
Ejemplo n.º 4
0
        public override Color Eval(Normal normal, Vec inDir, Vec outDir, Vec2D uv)
        {
            float thetaIn = MathF.Acos(Utility.NormalizedDot(normal.ToVec(), inDir));
            float thetaOut = MathF.Acos(Utility.NormalizedDot(normal.ToVec(), outDir));

            if (MathF.Abs(thetaIn - thetaOut) < this.thresholdAngleRad)
                return this.pigment.getColor(uv);
            else
                return new Color(0f, 0f, 0f);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Method that checks if two <see cref="Vec2D"/> objects
 /// are approximately equal.
 /// </summary>
 /// <param name="vector"> The Vec2D to be compared to</param>
 /// <returns> True if the two vecs are equal</returns>
 public bool isClose(Vec2D vector)
    => Utility.areClose(this.u, vector.u) && Utility.areClose(this.v, vector.v);
Ejemplo n.º 6
0
 public Color getColor(Vec2D vec)
 {
     return this.c;
 }
Ejemplo n.º 7
0
 public override Color Eval(Normal normal, Vec inDir, Vec outDir, Vec2D uv)
 {
     return this.pigment.getColor(uv) * (this.reflectance / Constant.PI);
 }
Ejemplo n.º 8
0
 public abstract Color Eval(Normal normal, Vec inDir, Vec outDir, Vec2D uv);