public Polygon(FloatColor fillColor = null, FloatColor borderColor = null, IEnumerable <FloatPoint> points = null) { if (points == null) { throw new ArgumentNullException(); } Points = points.ToArray(); if (fillColor == null) { this.FillColor = Color.White; } else { this.FillColor = fillColor; } if (borderColor == null) { this.BorderColor = Color.Black; } else { this.BorderColor = borderColor; } }
public static void SetBorder(Figure figure, FloatColor borderColor = null, float borderWidth = 1f) { if (!borderColor.IsTransparent) { GL.Begin(PrimitiveType.LineLoop); GL.Color4(borderColor.R, borderColor.G, borderColor.B, borderColor.A); GL.LineWidth(borderWidth); if ((FigureCheck <Ellipse>(figure) && ((Ellipse)figure).IsCompleted) || !FigureCheck <Ellipse>(figure)) { foreach (var point in figure.Points) { GL.Vertex2(point.X, point.Y); } } else { var points = figure.Points.ToList(); points.Add(((Ellipse)figure).Center); foreach (var point in points) { GL.Vertex2(point.X, point.Y); } } GL.LineWidth(1f); GL.End(); } }
/** * New Text UIElement * @param xOffset * @param yOffset * @param str * @param f * @param size */ public Text(float xOffset, float yOffset, string str, FloatColor f, float size) { label = new GameFont(str, f); this.xOffset = xOffset / 10f; this.yOffset = yOffset / 10f; this.size = size / 10f; }
public static Texture GenerateWith(Func <int, int, FloatColor> colorGenerator) { const int height = 512; const int width = 512; if (Textures.TryGetValue(colorGenerator.ToString(), out var texture)) { return(texture); } var pixels = new FloatColor[width, height]; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { pixels[x, y] = colorGenerator(x, y); } } var result = new Texture(width, height, pixels); Textures.Add(colorGenerator.ToString(), result); return(result); }
/** * * @param xOffset * @param yOffset * @param align * @param str * @param f * @param size */ public Text(float xOffset, float yOffset, Alignment align, string str, FloatColor f, float size) { yOffset /= 20f; size /= 10f; switch (align) { case Alignment.LEFT: xOffset = -1.5f; break; case Alignment.CENTER: xOffset = -0.05f / (0.3f / size); xOffset *= str.Length; break; case Alignment.RIGHT: float characterShift = str.Length * 2f + 1f; xOffset = 1.5f - ((str.Length + str.Length / characterShift) / 10f); break; } label = new GameFont(str, f); this.xOffset = xOffset; this.yOffset = yOffset; this.size = size; this.align = align; }
public Rectangle(float x1 = 0f, float y1 = 0f, float x2 = 0f, float y2 = 0f, float x3 = 0f, float y3 = 0f, float x4 = 0f, float y4 = 0f, FloatColor fillColor = null, FloatColor borderColor = null) { this.Points = new FloatPoint[] { (x1, y1), (x2, y2), (x3, y3), (x4, y4) }; if (fillColor == null) { this.FillColor = Color.White; } else { this.FillColor = fillColor; } if (borderColor == null) { this.BorderColor = Color.Black; } else { this.BorderColor = borderColor; } }
public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing) { var renderTarget = new Framebuffer(width, height); var sampler = new Sampler(new RegularGenerator(), new SquareDistributor(), 25, 1); var camera = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -5), Vector3.Forward, Vector3.Up) { Sampler = sampler, MaxDepth = 5, ColorSpace = ColorSpace.Srgb }; Scene = new Scene(_objects, camera, new List <Light> { new PointLight { Position = new Vector3(0, 0, 0), Color = FloatColor.White, Intensity = 1, Radius = 1, }, new DirectionalLight { Direction = Vector3.Down, Color = FloatColor.Green }, }, FloatColor.Black); }
public ReflectiveMaterial(FloatColor materialColor, float diffuse, float specular, float exponent, float reflectivity, TextureInfo?texture = null) { _direct = new PhongMaterial(materialColor, diffuse, specular, exponent, 1, texture); _reflectivity = reflectivity; _reflectionColor = materialColor; }
public OpenGLWindow ( int width, int height, string title = WindowDefaultSettings.WindowTitle, int updateFrequency = WindowDefaultSettings.WindowUpdateFrequency, int renderFrequency = WindowDefaultSettings.WindowRenderFrequency, FloatColor backgroundColor = null, Picture picture = null ) : base(width, height, GraphicsMode.Default, title) { Graphics.Initialize(this); TargetUpdateFrequency = updateFrequency; TargetRenderFrequency = renderFrequency; if (picture == null) { WindowPicture = Picture.Create(); } else { WindowPicture = picture; } Graphics.SetBackground(backgroundColor); }
public Scene(List <IHittable> objects, Camera camera, List <Light> lights, FloatColor background = default) { Objects = objects; Lights = lights; Camera = camera; camera.Scene = this; Background = background; }
private FloatColor GetResultColor(FloatColor lightColor, float lightIntensity, FloatColor?texelColor, float diffuseFactor) { if (texelColor != null) { return(lightColor * lightIntensity * AmbientPower * texelColor.Value * Color * diffuseFactor * DiffuseCoefficient); } return(lightColor * lightIntensity * AmbientPower * Color * diffuseFactor * DiffuseCoefficient); }
public static Color ToDrawingColor(this FloatColor color) { var a = (color.A * 255).ClampToByte(); var r = (color.R * 255).ClampToByte(); var g = (color.G * 255).ClampToByte(); var b = (color.B * 255).ClampToByte(); return(Color.FromArgb(a, r, g, b)); }
public void InitToMul() { this.diffuse = new FloatColor(1f, 1f, 1f, 1f); this.specular = new FloatColor(1f, 1f, 1f, 1f); this.ambient = new FloatColor(1f, 1f, 1f, 1f); this.edgeColor = new FloatColor(1f, 1f, 1f, 1f); this.specularPower = 1f; this.edgeSize = 1f; }
public Quad(Vector3 q1, Vector3 q2, Vector3 q3, Vector3 q4, FloatColor color = default) { Q1 = q1; Q2 = q2; Q3 = q3; Q4 = q4; Material = new PhongMaterial(color); Normal = (Q2 - Q1).Cross(Q3 - Q1).Normalize(); }
public TransparentMaterial(FloatColor materialColor, float diffuse, float exponent, float reflection, float refraction, float transmission) { _direct = new PhongMaterial(materialColor, diffuse, 0, exponent); _transmission = transmission; _baseColor = materialColor; _reflection = reflection; _refraction = refraction; }
public void InitToAdd() { this.diffuse = new FloatColor(0f, 0f, 0f, 0f); this.specular = new FloatColor(0f, 0f, 0f, 0f); this.ambient = new FloatColor(0f, 0f, 0f, 0f); this.edgeColor = new FloatColor(0f, 0f, 0f, 0f); this.specularPower = 0f; this.edgeSize = 0f; }
public PhongMaterial(FloatColor color, TextureInfo?texture = null) { Color = color; Texture = texture; _diffuseCoefficient = 1; _specular = 0; _specularExponent = 50; _ambientPower = 1f; }
public PhongMaterial(FloatColor color, float diffuseCoefficient, float specular, float specularExponent, float ambientPower = 1f, TextureInfo?texture = null) { Color = color; _diffuseCoefficient = diffuseCoefficient; _specular = specular; _specularExponent = specularExponent; _ambientPower = ambientPower; Texture = texture; }
public static void SetBackground(FloatColor backgroundColor) { if (backgroundColor != null) { BackgroundColor = backgroundColor; } else { BackgroundColor = FloatColor.Create(Color.White); } }
public PbrMaterial(FloatColor color, TextureInfo?texture = null, TextureInfo?emissiveMap = null, TextureInfo?specularMap = null, TextureInfo?normalMap = null) { Color = color; Texture = texture; _emissiveMap = emissiveMap; _specularMap = specularMap; _normalMap = normalMap; DiffuseCoefficient = 1; Specular = 0; SpecularExponent = 50; AmbientPower = 1f; }
public static void UniformColor(uint location, Color color) { unsafe { var fc = new FloatColor { R = color.R / 255f, G = color.G / 255f, B = color.B / 255f, A = color.A / 255f }; Imports.glUniform4fv((int)location, 1, (float *)&fc); } }
public static unsafe Texture LoadFrom(string filename, bool mirrorX = false, bool mirrorY = false) { if (Textures.TryGetValue(filename, out var texture)) { return(texture); } var bitmap = new Bitmap(filename); var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var pixels = new FloatColor[bitmap.Width, bitmap.Height]; const int pixelSize = 4; for (var y = 0; y < data.Height; y++) { var row = (byte *)data.Scan0 + y * data.Stride; for (var x = 0; x < data.Width; x++) { var indexX = x; var indexY = y; if (mirrorY) { indexX = data.Width - 1 - x; } if (mirrorX) { indexY = data.Height - 1 - y; } pixels[indexX, indexY] = FloatColor.FromRgba( row[x * pixelSize + 2], row[x * pixelSize + 1], row[x * pixelSize], row[x * pixelSize + 3]); // row[x * PixelSize] = 0; //Blue 0-255 // row[x * PixelSize + 1] = 255; //Green 0-255 // row[x * PixelSize + 2] = 0; //Red 0-255 // row[x * PixelSize + 3] = 50; //Alpha 0-255 } } bitmap.UnlockBits(data); var result = new Texture(bitmap.Width, bitmap.Height, pixels); Textures.Add(filename, result); return(result); }
public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing) { var renderTarget = new Framebuffer(width, height); renderTarget.Clear(color); var camera = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -10), Vector3.Forward, Vector3.Up); var objects = new List <IHittable>(); var circuitryTexture = Texture.LoadFrom(@"_Resources/Textures/circuitry-albedo.png").ToInfo(3); var sunTexture = Texture.LoadFrom(@"_Resources/Textures/sun.png").ToInfo(); var modelTexture = Texture.LoadFrom(@"_Resources/Textures/texel_density.png").ToInfo(); var crystalTexture = Texture.LoadFrom(@"_Resources/Textures/crystal.png").ToInfo(); var circuitryMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 0.5f, circuitryTexture); var sunMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, sunTexture); var modelMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, modelTexture); var crystalMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, crystalTexture); var circuitry = new Sphere(new Vector3(2.5f, -1, 0), 0.5f, circuitryMaterial); var sun = new Sphere(new Vector3(2.5f, -2.5f, 0), 0.75f, sunMaterial); var model = Model.LoadFromFile("_Resources/Models/lowpolytree_unwrap.obj", modelMaterial, 1, Vector3.Down); var crystal = Model.LoadFromFile("_Resources/Models/crystal.obj", crystalMaterial, 3, Vector3.Left * 2); objects.Add(circuitry); objects.Add(sun); objects.Add(model); objects.Add(crystal); Scene = new Scene(objects, camera, new List <Light> { new PointLight { Position = new Vector3(1, 2f, 0), Color = FloatColor.White }, new PointLight { Position = new Vector3(-2, 2f, 0), Color = FloatColor.Red }, new PointLight { Position = new Vector3(-4, 2f, -3), Color = FloatColor.White }, new PointLight { Position = new Vector3(-2, -1f, 0), Color = FloatColor.Green }, }, FloatColor.Black); }
private FloatColor readColor(BinaryReader br, bool readAlpha) { FloatColor result = default(FloatColor); result.R = br.ReadSingle(); result.G = br.ReadSingle(); result.B = br.ReadSingle(); if (readAlpha) { result.A = br.ReadSingle(); } else { result.A = 1f; } return(result); }
public Line(float x1 = 0f, float y1 = 0f, float x2 = 0f, float y2 = 0f, FloatColor lineColor = null, float lineWidth = 1f) { Points = new FloatPoint[] { (x1, y1), (x2, y2) }; LineWidth = lineWidth; if (lineColor == null) { LineColor = Color.Black; } else { LineColor = lineColor; } }
public static void ToHsv(this FloatColor rgbColor, out float h, out float s, out float v) { // when blue is highest valued if (rgbColor.B > rgbColor.G && rgbColor.B > rgbColor.R) { RgbToHsvHelper(4, rgbColor.B, rgbColor.R, rgbColor.G, out h, out s, out v); } //when green is highest valued else if (rgbColor.G > rgbColor.R) { RgbToHsvHelper(2, rgbColor.G, rgbColor.B, rgbColor.R, out h, out s, out v); } //when red is highest valued else { RgbToHsvHelper(0, rgbColor.R, rgbColor.G, rgbColor.B, out h, out s, out v); } }
public static unsafe Texture CreateFrom(Bitmap bitmap, bool mirrorX = false, bool mirrorY = false) { var hash = bitmap.GetHashCode().ToString(); if (Textures.TryGetValue(hash, out var texture)) { return(texture); } var rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); var data = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var pixels = new FloatColor[bitmap.Width, bitmap.Height]; const int pixelSize = 4; for (var y = 0; y < data.Height; y++) { var row = (byte *)data.Scan0 + y * data.Stride; for (var x = 0; x < data.Width; x++) { var indexX = x; var indexY = y; if (mirrorY) { indexX = data.Width - 1 - x; } if (mirrorX) { indexY = data.Height - 1 - y; } pixels[indexX, indexY] = FloatColor.FromRgba(row[x * pixelSize + 2], row[x * pixelSize + 1], row[x * pixelSize], row[x * pixelSize + 3]); } } bitmap.UnlockBits(data); var result = new Texture(bitmap.Width, bitmap.Height, pixels); Textures.Add(hash, result); return(result); }
public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing) { var renderTarget = new Framebuffer(width, height); renderTarget.Clear(color); var objects = new List <IHittable> { new Plane(new Vector3(0, -2, 0), new Vector3(0, 1, 0), new ReflectiveMaterial(FloatColor.White, 0.4f, 0, 1000, 0.6f, CheckerTexture.Create(FloatColor.Green, FloatColor.Black).ToInfo())), new Sphere(new Vector3(-3.5f, 0, 0), 2, new ReflectiveMaterial(FloatColor.UnityYellow, 0.7f, 0.5f, 1000, 0.3f)), new Sphere(new Vector3(3.5f, 0, 0), 2, new ReflectiveMaterial(Color.GreenYellow.ToFloatColor(), 0.7f, 0.5f, 1000, 0.3f)), new Sphere(new Vector3(0, 0, 3.5f), 2, new ReflectiveMaterial(Color.DeepSkyBlue.ToFloatColor(), 0.7f, 0.5f, 1000, 0.3f)), new Sphere(new Vector3(0, 0, -3.5f), 2, new TransparentMaterial(Color.Red.ToFloatColor(), 0.1f, 0, 0.3f, 1.05f, 0.9f)), }; var sampler = new Sampler(new RegularGenerator(), new SquareDistributor(), 25, 1); var camera = new PinholeCamera(renderTarget, new Vector3(6, 2, -15), new Vector3(0, 0.3f, 0), new Vector3(0, -1, 0), new Vector2(0.7f, 0.7f * height / width), 2) { Sampler = sampler, MaxDepth = 5 }; Scene = new Scene(objects, camera, new List <Light> { new PointLight { Position = new Vector3(-5, 5, -3), Color = FloatColor.White, Intensity = 2 }, }, FloatColor.Black); }
public Ellipse(FloatPoint center = null, float horizontalRadius = 0f, float verticalRadius = 0f, float firstAngle = 0f, float secondAngle = 360f, FloatColor fillColor = null, FloatColor borderColor = null) { if (center == null) { Center = FloatPoint.DefaultPoint; } else { Center = center; } FirstAngle = firstAngle; SecondAngle = secondAngle; if (AngleSum <= 0) { FirstAngle -= 360f; } if (fillColor == null) { this.FillColor = Color.White; } else { this.FillColor = fillColor; } if (borderColor == null) { this.BorderColor = Color.Black; } else { this.BorderColor = borderColor; } HorizontalRadius = horizontalRadius; VerticalRadius = verticalRadius; Points = GetEllipsePoints(); }
private void unifyColors() { Dictionary <string, IList <Color> > labelColors = getSelectedLabelColors(); Dictionary <string, Color> newColors = new Dictionary <string, Color>(); foreach (var pair in labelColors) { if (!pair.Value.All(l => l == pair.Value.First())) { FloatColor[] fColors = pair.Value.Select(c => new FloatColor(c)).ToArray(); FloatColor ret = new FloatColor(); foreach (FloatColor fColor in fColors) { ret = ret.Add(fColor); } ret = ret.Divide(fColors.Length); newColors.Add(pair.Key, ret.ToColor()); } } setColorMap(newColors); }