示例#1
0
 public static Point4D WeightedSum(Point4D p1, Point4D p2, Weights weights)
 {
     System.Diagnostics.Debug.Assert(weights.W3 == 0, "Two component interpolation must be done with Weight3 == 0");
     return(WeightedSum(p1, p2, new Point4D(), weights));
 }
示例#2
0
 public static Color WeightedSum(Color c1, Color c2, Weights weights)
 {
     System.Diagnostics.Debug.Assert(weights.W3 == 0, "Two component interpolation must be done with Weight3 == 0");
     return(WeightedSum(c1, c2, new Color(), weights));
 }
示例#3
0
 public static Point WeightedSum(Point p1, Point p2, Point p3, Weights weights)
 {
     return(new Point(
                WeightedSum(p1.X, p2.X, p3.X, weights),
                WeightedSum(p1.Y, p2.Y, p3.Y, weights)));
 }
示例#4
0
 public static double WeightedSum(double d1, double d2, double d3, Weights weights)
 {
     return(d1 * weights.W1 + d2 * weights.W2 + d3 * weights.W3);
 }
示例#5
0
 public static double WeightedSum(double d1, double d2, Weights weights)
 {
     System.Diagnostics.Debug.Assert(weights.W3 == 0, "Two component interpolation must be done with Weight3 == 0");
     return(WeightedSum(d1, d2, 0, weights));
 }
示例#6
0
        /// <summary>
        /// Does a perspective-correct, 3-way interpolation of vertex data based on projected point.
        /// Subclasses provide their own implementation.
        /// </summary>
        /// <param name="x">2D Screen-Space pixel X coordinate</param>
        /// <param name="y">2D Screen-Space pixel Y coordinate</param>
        /// <returns>Perspective-correct interpolated Vertex value for this point.</returns>
        public virtual Vertex GetVertex(double x, double y)
        {
            Vertex interpolation = new Vertex();

            Point3D currRasterPoint = new Point3D(x, y, 0);
            Weights screenWeights   = ComputeScreenWeights(currRasterPoint);
            // Use screen weights to find current Z
            Point3D currProjectedPoint = new Point3D(x, y, WeightedSum(
                                                         vertex1.ProjectedPosition.Z,
                                                         vertex2.ProjectedPosition.Z,
                                                         vertex3.ProjectedPosition.Z,
                                                         screenWeights));

            interpolation.ProjectedPosition = currProjectedPoint;
            // Now that we have currProjectedPoint, we can go ahead and compute other weights
            Weights homogeneousWeights = ComputeHomogeneousWeights(currProjectedPoint);
            // Now we can use the perspectiveCorrectionFactor and the homogeneousWeights to
            // find the perspective-correct weights.
            Weights pcWeights = ComputePerspectiveCorrectWeights(homogeneousWeights);

            interpolation.W = 1.0 / WeightedSum(
                vertex1.OneOverW,
                vertex2.OneOverW,
                vertex3.OneOverW,
                homogeneousWeights);

            // Position ( Eye Space )
            interpolation.Position = WeightedSum(vertex1.Position, vertex2.Position, vertex3.Position, pcWeights);

            // Normal ( Eye Space )
            interpolation.Normal = MathEx.Normalize(
                pcWeights.W1 * vertex1.Normal +
                pcWeights.W2 * vertex2.Normal +
                pcWeights.W3 * vertex3.Normal);

            // Color
            interpolation.Color = WeightedSum(vertex1.Color, vertex2.Color, vertex3.Color, pcWeights);

            // Color Error
            interpolation.ColorTolerance = WeightedSum(
                vertex1.ColorTolerance,
                vertex2.ColorTolerance,
                vertex3.ColorTolerance,
                pcWeights);

            if (pixelOnEdge)
            {
                // Since numerical precision makes these borderline cases inaccurate,
                // we set the tolerance of this pixel to ignore it.
                interpolation.ColorTolerance = ColorOperations.Add(
                    interpolation.ColorTolerance,
                    Color.FromArgb(0x00, 0xFF, 0xFF, 0xFF));
            }

            // NOTE:
            //      x and y may not actually be contained by this triangle
            //      This can get us texture coordinates that are outside the [0,1] range

            // Texture Coordinates
            interpolation.TextureCoordinates = WeightedSum(
                vertex1.TextureCoordinates,
                vertex2.TextureCoordinates,
                vertex3.TextureCoordinates,
                pcWeights);

            // Precomputed Lighting for each material on this triangle
            if (vertex1.PrecomputedLight != null)
            {
                int materialCount = vertex1.PrecomputedLight.Length;

                interpolation.PrecomputedLight = new Color[materialCount];
                for (int i = 0; i < materialCount; i++)
                {
                    interpolation.PrecomputedLight[i] = WeightedSum(
                        vertex1.PrecomputedLight[i],
                        vertex2.PrecomputedLight[i],
                        vertex3.PrecomputedLight[i],
                        pcWeights);
                }
            }

            // Precomputed Lighting tolerance for each material on this triangle
            if (vertex1.PrecomputedLightTolerance != null)
            {
                int materialCount = vertex1.PrecomputedLight.Length;

                interpolation.PrecomputedLightTolerance = new Color[materialCount];
                for (int i = 0; i < materialCount; i++)
                {
                    interpolation.PrecomputedLightTolerance[i] = WeightedSum(
                        vertex1.PrecomputedLightTolerance[i],
                        vertex2.PrecomputedLightTolerance[i],
                        vertex3.PrecomputedLightTolerance[i],
                        pcWeights);
                }
            }

            return(interpolation);
        }
示例#7
0
 public static HdrColor WeightedSum(HdrColor c1, HdrColor c2, HdrColor c3, Weights weights)
 {
     return((c1 * weights.W1) + (c2 * weights.W2) + (c3 * weights.W3));
 }