private void RasterizeAndFragmentShader() { var usingPass = UsingPass; var drawState = usingPass.State; switch (drawState.PolygonMode) { case PolygonMode.Triangle: var len = trianglePrimitiveHelper.Count; for (int i = 0; i < len; i++) { var t = trianglePrimitiveHelper[i]; //if (t.clip) continue; // 光栅化成片段 Rasterizer.GenFragInfo(t, genShadedFragHelper, genWireframeFragHelper, genNormalLineFragHelper); // 处理片段 InnerFragmentShader(genShadedFragHelper, genWireframeFragHelper, genNormalLineFragHelper); } break; case PolygonMode.Line: throw new Exception($"not implements polygonMode:{drawState.PolygonMode}"); case PolygonMode.Point: throw new Exception($"not implements polygonMode:{drawState.PolygonMode}"); default: throw new Exception($"not implements polygonMode:{drawState.PolygonMode}"); } }
protected void FromDungeonGen(int seed, DungeonTemplate template) { Log.InfoFormat("Loading template for world {0}({1})...", Id, Name); var gen = new Generator(seed, template); gen.Generate(); var ras = new Rasterizer(seed, gen.ExportGraph()); ras.Rasterize(); var dTiles = ras.ExportMap(); if (Map == null) { Map = new Wmap(Manager.Resources.GameData); Interlocked.Add(ref _entityInc, Map.Load(dTiles, _entityInc)); if (Blocking == 3) { Sight.CalcRegionBlocks(Map); } } else { Map.ResetTiles(); } InitMap(); }
private void InitRenderer() { m_Rasterizer = new Rasterizer(Screen.width, Screen.height); m_Models = new List <BufferMeshMap>(); m_Camera = GetComponent <Camera>(); // Generate Resources m_BlitMaterial = new Material(Shader.Find("RasterUtility/Blit")); m_FullScreenTriangle = new Mesh(); // Drawing a big triangle is faster than drawing a quad. m_FullScreenTriangle.SetVertices(new List <Vector3>() { new Vector3(-1, -1, 0), new Vector3(-1, 3, 0), new Vector3(3, -1, 0) }); m_FullScreenTriangle.SetUVs(0, new List <Vector2>() { new Vector2(0, 0), new Vector2(0, 2), new Vector2(2, 0) }); m_FullScreenTriangle.SetIndices(new[] { 0, 1, 2 }, MeshTopology.Triangles, 0, false); m_FullScreenTriangle.UploadMeshData(false); // Init CommandBuffer m_Cmd = new CommandBuffer() { name = "RasterCmd" }; m_Cmd.SetGlobalTexture("_MainTex", m_Rasterizer.GetOutputTexture()); m_Cmd.DrawMesh(m_FullScreenTriangle, Matrix4x4.identity, m_BlitMaterial); m_Camera.AddCommandBuffer(CameraEvent.AfterEverything, m_Cmd); }
/// <summary> /// Function to clean up the categorized interfaces. /// </summary> private void DestroyInterfaces() { if (Fonts != null) { Fonts.CleanUp(); } Fonts = null; if (Textures != null) { Textures.CleanUp(); } Textures = null; if (Shaders != null) { Shaders.CleanUp(); } Shaders = null; if (Output != null) { Output.CleanUp(); } Output = null; if (Rasterizer != null) { Rasterizer.CleanUp(); } }
public void GenerateColliders() { // Remove any previous foreach (var collider in _colliders) { RemoveComponent(collider); } // _colliders.Clear(); // foreach (var co in Rasterizer.Rectangle(0, 0, Width, Height)) { var tile = GetTile(co.X, co.Y); if (tile.IsSolid) { var bounds = ComputeCollisionBounds(co.X, co.Y); var collider = AddComponent(new Collider(bounds)); _colliders.Add(collider); } } }
public void RedrawObjects() { View.Clear(); //curSel = null; CurEditing = null; View.Tool = View.Tool; // this deactivates + reactivates the current tool to reset its status... TODO: does this really work? //TopLevelItems = new List<OverlayShapeVM>(); DisplayTree.ParseTree = ParseTree; //DisplayTree.RecreateDisplayTree(); if (ParseTree == null) { Rasterizer.ResetRaster(); return; // nothing to display } try { SetCorrectRaster((TikzParseItem)null); } catch (Exception e) { // we should really not come here.... but there are conceivable tex files with cyclic references that might // produce errors. Clear(); View.AllowEditing = false; GlobalUI.UI.AddStatusLine(this, "Error in Overlay rendering: '" + e.Message + "' Overlay disabled for now.", true); } }
public void RedrawObjects() { View.Clear(); //curSel = null; CurEditing = null; View.Tool = View.Tool; // this deactivates + reactivates the current tool to reset its status TopLevelItems = new List <OverlayShape>(); if (ParseTree == null) { Rasterizer.ResetRaster(); return; // nothing to display } try { DrawObject(ParseTree, TopLevelItems); BindControlPointsToOrigins(); SetCorrectRaster((TikzParseItem)null); } catch (Exception e) { // we should really not come here.... but there are conceivable tex files with cyclic references that might // produce errors. Clear(); View.AllowEditing = false; MainWindow.AddStatusLine("Error in Overlay rendering: '" + e.Message + "' Overlay disabled for now.", true); } }
public virtual ActionResult Img(int id, int imageSize, int penSizePerc, int rotation, bool normalized, bool decorated) { var sd = db.SymbolDrawings.FirstOrDefault(x => x.SymbolDrawingId == id); if (sd == null) { return(HttpNotFound()); } string fileName = string.Format("{0}-s{1}-p{2}-r{3}-d{4}-n{5}.png", id, imageSize, penSizePerc, rotation, decorated ? 1 : 0, normalized ? 1 : 0); string filePath = Path.Combine(appSettingsProvider.SymbolDrawingsCacheDirAbsolute, fileName); if (!System.IO.File.Exists(filePath)) { var drawing = sd.GetRawDrawing(); if (rotation != 0) { new RawDataProcessor().RotateInPlace(drawing, rotation); } if (normalized) { new RawDataProcessor().NormalizeInPlace(drawing); } var img = new Rasterizer().Rasterize(drawing, imageSize, penSizePerc / 100f, normalized, decorated); img.Save(filePath, ImageFormat.Png); } return(File(filePath, "image/png")); }
public static unsafe void TestRasterize() { Rasterizer.StartRasterize(CRenderSettings.ResolutionF); RenderBuffer <float> tex0 = new RenderBuffer <float>(CRenderSettings.Resolution, 3); CharRenderBuffer <float> texChar = new CharRenderBuffer <float>(tex0); Vector2 *points = stackalloc Vector2[4]; for (float i = 0; i < JMath.PI_TWO; i += .02f) { Vector2 dir = new Vector2(MathF.Cos(i) * .3f, MathF.Sin(i) * .3f); Vector2 orthoDir = new Vector2(-dir.Y, dir.X); points[0] = new Vector2(.5f, .5f) + dir; points[1] = new Vector2(.5f, .5f) - dir; points[2] = new Vector2(.5f, .5f) + orthoDir; points[3] = new Vector2(.5f, .5f) - orthoDir; LinePrimitive *line = stackalloc LinePrimitive[1] { new LinePrimitive(points, null, 0) }; Rasterizer.Rasterize <Line, LinePrimitive>(line); tex0.WritePixel(Rasterizer.ContriveResult(), new GenericVector <float>(3) { 1f, 1f, 1f }); CRenderer.Render(texChar); tex0.Clear(); Thread.Sleep(16); } Rasterizer.EndRasterize(); }
void Update() { if (check || Input.GetKeyDown(KeyCode.Space)) { check = false; Triangle3D t = testPlane.triangle; Camera camera = cam; float theta_Y = camera.fieldOfView * 0.5f; float theta_X = Mathf.Atan(Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad) * camera.aspect) * Mathf.Rad2Deg; Plane left = new Plane(0, new Vector3(-Mathf.Cos((theta_X) * Mathf.Deg2Rad), 0, -Mathf.Sin((theta_X) * Mathf.Deg2Rad))); Plane right = new Plane(0, new Vector3(-Mathf.Cos((180 - theta_X) * Mathf.Deg2Rad), 0, -Mathf.Sin((180 - theta_X) * Mathf.Deg2Rad))); Plane near = new Plane(-camera.nearClipPlane, Vector3.back); Plane far = new Plane(camera.farClipPlane, Vector3.forward); Plane top = new Plane(0, new Vector3(0, -Mathf.Sin((-theta_Y + 90) * Mathf.Deg2Rad), -Mathf.Cos((-theta_Y + 90) * Mathf.Deg2Rad))); Plane buttom = new Plane(0, new Vector3(0, -Mathf.Sin((theta_Y - 90) * Mathf.Deg2Rad), -Mathf.Cos((theta_Y - 90) * Mathf.Deg2Rad))); List <Triangle3D> ts = Rasterizer.ViewSpaceFrustrumClipping(t, cam); print(buttom.Point(p1.position)); foreach (var go in ts) { TrianglePainter.CreateTrianglePainter(go); } } }
void Step_Click(object sender, EventArgs e) { if (((Button)sender).Tag is GenerationStep) { var step = (GenerationStep)((Button)sender).Tag; gen.Generate(step + 1); } else { gen.Generate(); if (ras == null) { ras = new Rasterizer(seed, gen.ExportGraph()); } var step = (RasterizationStep)((Button)sender).Tag; ras.Rasterize(step + 1); } Render(); foreach (var btn in btns) { if (btn.Tag is GenerationStep) { btn.Enabled = (GenerationStep)btn.Tag >= gen.Step; } else { btn.Enabled = ras == null || (RasterizationStep)btn.Tag >= ras.Step; } } }
public static void TestRasterizerStartEnd() { Rasterizer.StartRasterize(new Vector2(100, 100)); Assert.Catch(() => Rasterizer.StartRasterize(new Vector2(100, 100))); Rasterizer.EndRasterize(); Assert.Catch(() => Rasterizer.EndRasterize()); }
/// <summary> /// Application for testing purposes. /// </summary> public Game1() { // Set necessary values. graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 512; graphics.PreferredBackBufferHeight = 512; this.IsFixedTimeStep = false; graphics.SynchronizeWithVerticalRetrace = false; // Create as many threads as you have cores. // Used for rendering - greatly enhances performance. JobCenter.initializeWorkers(6); // Initialize the software-rasterizer. testRasterizer = new Rasterizer( graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight ); // Initialize the virtual camera. cam = new Camera(10, 200, new Vector3(0, 25, 80), new Vector3(0, 0, 0), ((float)graphics.PreferredBackBufferWidth) / graphics.PreferredBackBufferHeight); }
public virtual ActionResult Img(int id, int imageSize, int penSizePerc, bool normalized, bool decorated) { var sd = db.Drawings.FirstOrDefault(x => x.DrawingId == id); if (sd == null) { return(HttpNotFound()); } string filePath = getCachePath(id, imageSize, penSizePerc, normalized, decorated); if (!System.IO.File.Exists(filePath)) { var drawing = sd.GetRawDrawing(); if (normalized) { new RawDataProcessor().NormalizeInPlace(drawing); } var img = new Rasterizer().Rasterize(drawing, imageSize, penSizePerc / 100f, normalized, decorated); img.Save(filePath, ImageFormat.Png); } return(File(filePath, "image/png")); }
public void Dispose() { GC.SuppressFinalize(this); if (frontBuffer != null) { frontBuffer.Dispose(); frontBuffer = null; } if (FrameBuffer != null) { FrameBuffer.Dispose(); FrameBuffer = null; } if (Rasterizer != null) { Rasterizer.Dispose(); Rasterizer = null; } if (ShaderData != null) { ShaderData.Dispose(); ShaderData = null; } if (ShaderMgr != null) { ShaderMgr.Dispose(); ShaderMgr = null; } Shader = null; UsingSubShader = null; UsingPass = null; }
void BuildRecursivly(BinNode <List <Triangle3D> > node) { if (node.data.Count <= 1) { return; } Triangle3D main = node.data[0]; Plane plane = new Plane(main.a, main.normal); for (int i = 1; i < node.data.Count; i++) { Triangle3D go = node.data[i]; float fa = Helper.SnapToZero(plane.Point(go.a)); float fb = Helper.SnapToZero(plane.Point(go.b)); float fc = Helper.SnapToZero(plane.Point(go.c)); if (fa >= 0 && fb >= 0 && fc >= 0) { if (node.right == null) { node.right = new BinNode <List <Triangle3D> >(new List <Triangle3D>()); node.right.data = new List <Triangle3D>(); } node.right.data.Add(go); } else if (fa <= 0 && fb <= 0 && fc <= 0) { if (node.left == null) { node.left = new BinNode <List <Triangle3D> >(new List <Triangle3D>()); node.left.data = new List <Triangle3D>(); } node.left.data.Add(go); } else { List <Triangle3D> ts = Rasterizer.ClipTriangle(go, plane); node.data.AddRange(ts); node.data.RemoveAt(i); i--; } } node.data.RemoveRange(1, node.data.Count - 1); if (node.left != null) { BuildRecursivly(node.left); } if (node.right != null) { BuildRecursivly(node.right); } }
public override void Rasterize() { var tile = new DungeonTile { TileType = PirateCaveTemplate.ShallowWater }; Rasterizer.Clear(tile); }
public static void Compute(IEnumerable <Point> polyline, double[,] transform) { var width = transform.GetLength(0); var height = transform.GetLength(1); var raster = Rasterizer.Rasterize(polyline, width, height); Compute(raster, transform); }
/// <summary> /// Clears all items from the canvas. /// </summary> public void Clear() { View.Clear(); CurEditing = null; ParseTree = null; View.Tool = View.Tool; // this deactivates + reactivates the current tool to reset its status... e.g., it might contain links to some selected objects etc. TopLevelItems = new List <OverlayShape>(); Rasterizer.ResetRaster(); }
/// <summary> /// Clears all items from the canvas. /// </summary> public void Clear() { View.Clear(); CurEditing = null; ParseTree = null; View.Tool = View.Tool; // this deactivates + reactivates the current tool to reset its status... e.g., it might contain links to some selected objects etc. //DisplayTree.Clear(); Rasterizer.ResetRaster(); }
public Bitmap Run() { var bitmap = new Bitmap(640, 480, PixelFormat.Format32bppArgb); var r = new Rasterizer(); var v = new VertexProcessor(r); var pixelShader = new PixelShader(); var vertexShader = new VertexShader(); r.SetScissorRect(0, 0, 640, 480); v.SetViewport(100, 100, 640 - 200, 480 - 200); v.SetCullMode(CullMode.None); var indices = new List <int> { 0, 1, 2 }; var vertices = new List <VertexData>(); var vertex = new VertexData(); vertex.x = 0.0f; vertex.y = 0.5f; vertex.z = 0.0f; vertex.r = 1.0f; vertex.g = 0.0f; vertex.b = 0.0f; vertices.Add(vertex); vertex = new VertexData(); vertex.x = -1.5f; vertex.y = -0.5f; vertex.z = 0.0f; vertex.r = 0.0f; vertex.g = 1.0f; vertex.b = 0.0f; vertices.Add(vertex); vertex = new VertexData(); vertex.x = 1.5f; vertex.y = -0.5f; vertex.z = 0.0f; vertex.r = 0.0f; vertex.g = 0.0f; vertex.b = 1.0f; vertices.Add(vertex); pixelShader.Bitmap = bitmap; vertexShader.VertexData = vertices; r.SetPixelShader(pixelShader); v.SetVertexShader(vertexShader); v.DrawElements(DrawMode.Triangle, 3, indices); return(bitmap); }
/// <summary> /// Adds game-components. /// </summary> private void AddComponents() { this.Rasterizer = new Rasterizer(); this.Game.Components.Add(new InputManager(this.Game)); this.Game.Components.Add(new AssetManager(this.Game)); #if XNA //this.Game.Components.Add(new Sky(this.Game)); #endif this.Game.Components.Add(new NewSky(this.Game)); this.Game.Components.Add(new Fogger(this.Game)); var chunkStorage = new ChunkStorage(this.Game); this.Game.Components.Add(chunkStorage); var vertexBuilder = new VertexBuilder(this.Game); this.Game.Components.Add(vertexBuilder); var chunkCache = new ChunkCache(this.Game); this.Game.Components.Add(chunkCache); var blockStorage = new BlockStorage(this.Game); this.Game.Components.Add(blockStorage); var world = new World(this.Game, chunkStorage, chunkCache); this.Game.Components.Add(world); this.Game.Components.Add(new Player(this.Game, world)); this.Game.Components.Add(new Camera(this.Game)); this.Game.Components.Add(new UserInterface(this.Game)); this.Game.Components.Add(new InGameDebugger(this.Game)); this.Game.Components.Add(new DebugBar(this.Game)); this.Game.Components.Add(new GraphManager(this.Game)); #if XNA this.Game.Components.Add(new AudioManager(this.Game)); #endif var spriteBatch = new SpriteBatch(this.Game.GraphicsDevice); Console = new GameConsole(this.Game, spriteBatch, new GameConsoleOptions { Font = Game.Content.Load <SpriteFont>(@"Fonts/Verdana"), FontColor = Color.LawnGreen, Prompt = ">", PromptColor = Color.Crimson, CursorColor = Color.OrangeRed, BackgroundColor = Color.Black * 0.8f, PastCommandOutputColor = Color.Aqua, BufferColor = Color.Gold }); }
public void Run() { var r = new Rasterizer(); var v = new VertexProcessor(r); var pixelShader = new PixelShader(); var vertexShader = new VertexShader(); r.SetScissorRect(0, 0, 640, 480); v.SetViewport(0, 0, 640, 480); v.SetCullMode(CullMode.None); var indices = new List <int>(); var vertices = new List <VertexData>(); var random = new Random(0); for (int i = 0; i < 4096 * 10; i++) { VertexData CreateVertex() { var vertex = new VertexData(); vertex.x = (float)random.NextDouble(); vertex.y = (float)random.NextDouble(); vertex.z = (float)random.NextDouble(); vertex.r = (float)random.NextDouble(); vertex.g = (float)random.NextDouble(); vertex.b = (float)random.NextDouble(); return(vertex); } var offset = vertices.Count; vertices.Add(CreateVertex()); vertices.Add(CreateVertex()); vertices.Add(CreateVertex()); indices.Add(offset + 0); indices.Add(offset + 1); indices.Add(offset + 2); } pixelShader.Buffer = new int[640 * 480]; pixelShader.Width = 640; pixelShader.Height = 480; vertexShader.VertexData = vertices; r.SetPixelShader(pixelShader); v.SetVertexShader(vertexShader); var sw = Stopwatch.StartNew(); v.DrawElements(DrawMode.Triangle, indices.Count, indices); Console.WriteLine(sw.ElapsedMilliseconds); }
public void Clear() { if (_disposed) { throw new ObjectDisposedException(this.GetType().ToString()); } TextOutput.Clear(); Rasterizer.Clear(); }
void RenderVertices() { vecTrianglesToRaster = vecTrianglesToRaster.OrderByDescending(a => a.averageZ).ToList(); foreach (RenderTriangle tri in vecTrianglesToRaster) { // tri.lightValue = 1f; Rasterizer.FillTriangle(tri.points[0], tri.points[1], tri.points[2], new Color(tri.faceColor.r * tri.lightValue, tri.faceColor.g * tri.lightValue, tri.faceColor.b * tri.lightValue, 1), screentex); //Rasterizer.DrawTriangle(tri.points[0], tri.points[1], tri.points[2], Color.black,screentex); } screentex.Apply(); }
public async Task ShouldCreatePngFromPdf() { var actualImagePath = Path.Combine(Path.GetTempPath(), "ActualShouldCreatePngFromPdf"); using var rasterizer = new Rasterizer(); var actualImages = await rasterizer.ConvertToPngAsync(@"../../../SourceTest.pdf", actualImagePath); Assert.Equal(1, actualImages.Count); Assert.True(File.Exists(actualImages.Single()), "Actual output file not found"); Assert.True(ImageSharpCompare.ImageAreEqual(actualImages.Single(), @"../../../ExpectedImages/ExpectedShouldCreatePngFromPdf1.png"), "Actual and expected image do differ"); File.Delete(actualImages.Single()); }
void OnEnable() { var time = Time.realtimeSinceStartup; var rasterizer = new Rasterizer(resolution.x, resolution.y); rasterizer.Draw(camera, models, reversedZ); Debug.LogFormat("Time spent: {0:0.000} s", Time.realtimeSinceStartup - time); colorBuffer = rasterizer.ExportColorBuffer(); depthBuffer = rasterizer.ExportDepthBuffer(); }
static void draw_ellipse(Rasterizer ras, double x, double y, double rx, double ry) { int i; ras.MoveToD(x + rx, y); // Here we have a fixed number of approximation steps, namely 360 // while in reality it's supposed to be smarter. for (i = 1; i < 360; i++) { double a = (double)i * 3.1415926 / 180.0; ras.LineToD(x + Math.Cos(a) * rx, y + Math.Sin(a) * ry); } }
void RenderLavaGround(Point a, Point b) { Rasterizer.DrawLine(a, b, (x, y) => { if (Rasterizer.Bitmap[x, y].TileType == AbyssTemplate.Lava) { return new DungeonTile { TileType = AbyssTemplate.Lava, Object = Floor } } ; return(Rasterizer.Bitmap[x, y]); }, 1); }
public static unsafe void TestRasterizerLine() { Vector2 *line = stackalloc Vector2[2] { Vector2.Zero, Vector2.One }; Rasterizer.StartRasterize(new Vector2(100, 100)); Rasterizer.SetPoints(line); Rasterizer.Line(); var resultArr = Rasterizer.ContriveResult(); Assert.AreEqual(resultArr.Length, 100, 1); Rasterizer.EndRasterize(); }
static void draw_line(Rasterizer ras, double x1, double y1, double x2, double y2, double width) { double dx = x2 - x1; double dy = y2 - y1; double d = Math.Sqrt(dx * dx + dy * dy); dx = width * (y2 - y1) / d; dy = width * (x2 - x1) / d; ras.MoveToD(x1 - dx, y1 + dy); ras.LineToD(x2 - dx, y2 + dy); ras.LineToD(x2 + dx, y2 - dy); ras.LineToD(x1 + dx, y1 - dy); }
void Start() { rasterizer = new Rasterizer(); referencePlaneMesh = MeshCreator.CreatePlane(); // rasterizedPlaneMesh = MeshCreator.CreatePlane(1f, 1f, 0.3343f, 0.6345f); currentMesh = new MMesh(rasterizedPlaneMesh); referenceGameObject = CreateGameobjectWithMesh("ReferenceObject", referencePlaneMesh); rasterizedGameObject = CreateGameobjectWithMesh("RasterizedObject", rasterizedPlaneMesh); currentMesh.ApplyPadding((1f / 512) * 8f); referenceGameObject.renderer.material.mainTexture = rasterizer.RasterizeMesh(currentMesh, 512); rasterizedGameObject.renderer.material.mainTexture = referenceGameObject.renderer.material.mainTexture; }
static TerrainTile[,] CreateTerrain(int seed, PolygonMap map) { Rasterizer<TerrainTile> rasterizer = new Rasterizer<TerrainTile>(Size, Size); //Set all to ocean rasterizer.Clear(new TerrainTile() { PolygonId = -1, Elevation = 0, Moisture = 1, TileId = TileTypes.DeepWater, TileObj = null }); //Render lands poly foreach (var poly in map.Polygons.Where(_ => !_.IsWater)) { uint color = 0x00ffffff; color |= (uint)(poly.DistanceToCoast * 255) << 24; rasterizer.FillPolygon( poly.Nodes.SelectMany(_ => { return new[]{ (_.X + 1) / 2 * Size, (_.Y + 1) / 2 * Size}; }).Concat(new[]{ (poly.Nodes[0].X + 1) / 2 * Size, (poly.Nodes[0].Y + 1) / 2 * Size}).ToArray(), new TerrainTile() { PolygonId = poly.Id, Elevation = (float)poly.DistanceToCoast, Moisture = -1, TileId = TileTypes.Grass, TileObj = null }); } MapFeatures fea = new MapFeatures(map, seed); //Render roads var roads = fea.GenerateRoads(); foreach (var i in roads) { rasterizer.DrawClosedCurve(i.SelectMany(_ => new[] { (_.X + 1) / 2 * Size, (_.Y + 1) / 2 * Size }).ToArray(), 1, t => { t.TileId = TileTypes.Road; return t; }, 3); } //Render waters poly foreach (var poly in map.Polygons.Where(_ => _.IsWater)) { var tile = new TerrainTile() { PolygonId = poly.Id, Elevation = (float)poly.DistanceToCoast, TileObj = null }; if (poly.IsCoast) { tile.TileId = TileTypes.MovingWater; tile.Moisture = 0; } else { tile.TileId = TileTypes.DeepWater; tile.Moisture = 1; } rasterizer.FillPolygon( poly.Nodes.SelectMany(_ => { return new[]{ (_.X + 1) / 2 * Size, (_.Y + 1) / 2 * Size}; }).Concat(new[]{ (poly.Nodes[0].X + 1) / 2 * Size, (poly.Nodes[0].Y + 1) / 2 * Size}).ToArray(), tile); } //Render rivers var rivers = fea.GenerateRivers(); Dictionary<Tuple<MapNode, MapNode>, int> edges = new Dictionary<Tuple<MapNode, MapNode>, int>(); foreach (var i in rivers) { for (int j = 1; j < i.Length; j++) { Tuple<MapNode, MapNode> edge = new Tuple<MapNode, MapNode>(i[j - 1], i[j]); int count; if (edges.TryGetValue(edge, out count)) count++; else count = 1; edges[edge] = count; } } foreach (var i in edges) { i.Key.Item1.IsWater = true; i.Key.Item1.RiverValue = i.Value + 1; i.Key.Item2.IsWater = true; i.Key.Item2.RiverValue = i.Value + 1; rasterizer.DrawLineBresenham( (i.Key.Item1.X + 1) / 2 * Size, (i.Key.Item1.Y + 1) / 2 * Size, (i.Key.Item2.X + 1) / 2 * Size, (i.Key.Item2.Y + 1) / 2 * Size, t => { t.TileId = TileTypes.Water; t.Elevation = (float)(i.Key.Item1.DistanceToCoast + i.Key.Item2.DistanceToCoast) / 2; t.Moisture = 1; return t; }, 3 * Math.Min(2, i.Value)); } return rasterizer.Buffer; }
/// <summary> /// Creates a new merge depth buffer job. When executed, /// it will merge the depth buffer of the given rasterizer. /// </summary> /// <param name="rasterizer">The rasterizer whoose depth buffer shall /// be merged.</param> public MergeDepthBufferJob(Rasterizer rasterizer) { _rasterizer = rasterizer; }
/// <summary> /// Creates a render object job. When executed it will render <paramref name="object3D"/> from /// <paramref name="cam"/>'s point of view with <paramref name="rasterizer"/>. /// </summary> /// <param name="object3D">The 3d object to be rendered.</param> /// <param name="camera">The camera from which object3d shall be rendered.</param> /// <param name="rasterizer">The rasterizer to use for the /// rendering process.</param> public RenderObjectJob(Object3D object3D, Camera camera, Rasterizer rasterizer) { _object3D = object3D; _camera = camera; _rasterizer = rasterizer; }