/// <summary>
 /// Constructs the point light.
 /// </summary>
 /// <param name="pos">The position.</param>
 /// <param name="radius">The radius.</param>
 /// <param name="col">The color.</param>
 public PointLight(Location pos, float radius, Color3F col)
 {
     EyePos = pos;
     Radius = radius;
     Color  = col;
     for (int i = 0; i < 6; i++)
     {
         Light li = new Light();
         li.Create(pos.ToOpenTK3D(), (pos + Location.UnitX).ToOpenTK3D(), 90f, Radius, Color.ToOpenTK());
         InternalLights.Add(li);
     }
     InternalLights[4].up = new Vector3(0, 1, 0);
     InternalLights[5].up = new Vector3(0, 1, 0);
     Reposition(EyePos);
     MaxDistance = radius;
     GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
 }
Beispiel #2
0
        static int[] GradientMap(Dictionary <int, Color3F> colorsDict)
        {
            var colors = colorsDict.OrderBy(x => x.Key).ToArray();
            int min    = colors.Min(x => x.Key);
            int max    = colors.Max(x => x.Key);
            var output = new int[max - min + 1];

            var lastC = colors.First().Value;
            int lastP = colors.First().Key;

            foreach (var c in colors.Skip(1))
            {
                for (int p = lastP; p < c.Key; p++)
                {
                    output[p - min] = Color3F.Mix(lastC, c.Value, 1f / (c.Key - lastP) * (p - lastP)).Int32;
                }
                lastP = c.Key;
                lastC = c.Value;
            }
            output[output.Length - 1] = colors.Last().Value.Int32;
            return(output);
        }
Beispiel #3
0
 /// <summary>
 /// Converts a Color3F to an OpenTK Vector3.
 /// </summary>
 /// <param name="l">The color.</param>
 /// <returns>The OpenTK Vector3.</returns>
 public static Vector3 ToOpenTK(this Color3F l)
 {
     return(new Vector3(l.R, l.G, l.B));
 }
 /// <summary>
 /// Converts a <see cref="Color3F"/> to an OpenTK <see cref="Vector3"/> as R,G,B.
 /// </summary>
 /// <param name="color">The <see cref="Color3F"/>.</param>
 /// <returns>The OpenTK <see cref="Vector3"/>.</returns>
 public static Vector3 ToOpenTK(this Color3F color)
 {
     return(new Vector3(color.R, color.G, color.B));
 }
Beispiel #5
0
        public static Bitmap GradientTest(int width, int height, int gradientType, int resolution)
        {
            int resValue = 1 << resolution;
            int resMask  = resValue - 1;

            var colors = new Dictionary <int, Color3F>
            {
                { 0, new Color3F(0, 0, 0) },                    // black
                { resValue / 4 * 1 - 1, new Color3F(0, 0, 1) }, // blue
                { resValue / 4 * 2 - 1, new Color3F(0, 1, 0) }, // gree
                { resValue / 4 * 3 - 1, new Color3F(1, 0, 0) }, // red
                { resValue / 4 * 4 - 1, new Color3F(1, 1, 1) } // white
            };

            var gradientMap = GradientMap(colors);

            var gradientTest = new Bitmap(width, height, PixelFormat.Format32bppRgb);
            var gradientPix  = new int[width * height];

            switch (gradientType)
            {
                #region # case 0:// --- simple Linear ---
            case 0:
            {
                for (int x = 0; x < width; x++)
                {
                    int pos    = (x << resolution) / width;
                    var gColor = gradientMap[pos];
                    for (int y = 0; y < height; y++)
                    {
                        gradientPix[x + y * width] = gColor;
                    }
                }
            } break;

                #endregion
                #region # case 1:// --- 2D Linear ---
            case 1:
            {
                var black = new Color3F(0x000000); // top color
                var white = new Color3F(0xffffff); // bottom color
                for (int x = 0; x < width; x++)
                {
                    int pos    = (x << resolution) / width;
                    var gColor = new Color3F(gradientMap[pos]);
                    for (int y = 0; y < height / 2; y++)
                    {
                        gradientPix[x + y * width] = Color3F.Mix(black, gColor, y / (height / 2f)).Int32;
                    }
                    for (int y = height / 2; y < height; y++)
                    {
                        gradientPix[x + y * width] = Color3F.Mix(gColor, white, (y - height / 2) / (height / 2f)).Int32;
                    }
                }
            } break;

                #endregion
            case 2:
            {
                int max = (int)(width / 2f * (width - width / 2f) / resValue + height / 2f * (height - height / 2f) / resValue + 1f);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        gradientPix[x + y * width] = gradientMap[(uint)(x * (width - x) + y * (height - y)) / max & resMask];
                    }
                }
            } break;

            default: throw new Exception("unknown gradientType: " + gradientType);
            }

            var bdata = gradientTest.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
            Marshal.Copy(gradientPix, 0, bdata.Scan0, gradientPix.Length);
            gradientTest.UnlockBits(bdata);

            return(gradientTest);
        }