Material for mixing / smooth shading

I create and draw a triangular mesh in wpf C # using GeometryModel3D. I was trying to figure out how to create smooth shading over triangles, like the classic smooth openGL shaded triangle.

I would like to define a color for each vertex, and then using colors interpolated over the face like this, assuming three colors in which are red, green and blue.

enter image description here

I suggested that I would need to use a brush, but I could not figure out how to do this. Therefore, any help would be appreciated, or any pointer to a guide that will show me how to achieve this.

EDIT: WPF3D, , , , xaml. , , .

2nd EDIT , RadialGradientBrush. RadiusX RadiusY, ?

3rd EDIT , , RadialGradientBrush. , , RadialGradientBrush RadiusX RadiusY, , . RadialGradientBrush GradientOrigin.

GradientOrigin X, Y , [0,1]. , , X = 0.0 - , X = 1.0 - , Y = 0.0 - , Y = 1.0 - . , , [0,1] x [0,1] , ? [0,1] x [0,1], , .

+3
2
+1

, , , , google, http://www.geeksforgeeks.org/check-whether-a-given-point-lies-inside-a-triangle-or-not/

, . .

float area(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            return (float)Math.Abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
        }

        bool isInside(int x1, int y1, int x2, int y2, int x3, int y3, int x, int y)
        {
            /* Calculate area of triangle ABC */
            float A = area(x1, y1, x2, y2, x3, y3);

            /* Calculate area of triangle PBC */
            float A1 = area(x, y, x2, y2, x3, y3);

            /* Calculate area of triangle PAC */
            float A2 = area(x1, y1, x, y, x3, y3);

            /* Calculate area of triangle PAB */
            float A3 = area(x1, y1, x2, y2, x, y);

            /* Check if sum of A1, A2 and A3 is same as A */
            return (A == A1 + A2 + A3);
        }


 for (int ii = 5; ii < 100; ii++)
          {
               for (int jj = 5; jj < 100; jj++)
                {
                        int distanceRed =0, distanceGreen =0,distanceBlue =0;
                        if (isInside(30, 50, 30, 90, 20, 70, ii, jj))
                        {
                              distanceRed = (int)Math.Sqrt(((ii - 30) * (ii - 30) + (jj - 50) * (jj - 50)));
                              distanceGreen = (int)Math.Sqrt(((ii - 30) * (ii - 30) + (jj - 90) * (jj - 90)));
                              distanceBlue = (int)Math.Sqrt(((ii - 20) * (ii - 20) + (jj - 70) * (jj - 70)));
                          }
                          else
                          {
                               distanceRed = 0; distanceGreen = 0; distanceBlue = 0;
                          }

                              ptr[(((int)jj) * 3) + ((int)ii) * stride] = (byte)(distanceRed % 256);
                              ptr[(((int)jj) * 3) + ((int)ii) * stride + 1] = (byte)(distanceGreen % 256);
                              ptr[(((int)jj) * 3) + ((int)ii) * stride + 2] = (byte)(distanceBlue % 256);

                           }
                       }

:

enter image description here

. , modulo . sqrt .

+1

All Articles