Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

119 Neutral

About GameObject

  • Rank
  1. In my voxel game I am running into an issue in drawing the chunks where there is a lot of memory problems when it comes to building the mesh, so I'm looking for a new design model to base this on. Currently my design model is non-existent and kind of a mishmash/mess. I'm using Unity 5.x, essentially I've tried this approach so far: First attempt tried: Every Chunk GameObject has a meshcreator script on it. However, I've learned this can be a problem when you have 2k+ chunks and leads to wasted memory because that would also be 2k+ meshcreator scripts. That in and of itself isn't really a problem if they aren't doing anything most of the time, but I feel like this leads to less control and more of a mess to have so many scripts like that. The meshcreator script uses Lists to build Faces, Verticies, UVs, ColliderVerticies, and ColliderFaces. The lists are then converted to an array and applied to the mesh. Presto, the chunk shows up. But the downside with this is that 1) it is using List which in Unity is poorly managed in memory. 2) With each chunk having over 4k of voxels, to be calling List.Add() that many times is very inefficient because you are resizing an array thousands of times and adds garbage collection overhead. Second attempt tried: So I went ahead and converted them to arrays instead, predefining a large array size and reusing the array. It has an indexHeight so that every time we add something to the array, the position is increased for the next item to be added. But, as you can guess, when you have 2k+ chunks and each one has several arrays of 65k items, that creates HUGE memory footprint.   private Vector3[] Verticies = new Vector3[65530]; private int verticiesIndexHeight = 0; private void AddVertex(Vector3 vertex) { Verticies[verticiesIndexHeight] = vertex; verticiesIndexHeight += 1; } Third attempt: Here is where I'm wondering what the best approach might be. Is it feasable to add a mesh creating script to each chunk? Or would it be better to just have one ChunkMeshCreator script that handles all the work? So instead of having thousands of meshcreator scripts on each chunk, instead a single main script renders them? What have other people done? What might be most efficient for Unity?
  2. How might I add 2 px or any pixel amount of padding into this when getting the texture from atlas and applying to UV? I've updated my original post to include the code when getting atlas pos. Just a little thrown off on when to add vs subtract for padding.
  3. The following code maps the texture from a texture atlas to a UV. The problem is I'm having texture bleeding issues due to rounding (what I suspect anyway).   Does anyone know how to overcome this problem and have any suggestions? Here is the code I have, all images are point filtered and **no mipmapping** is used.              for (int i = 0; i < mesh.uv.Length; i++) { UVs.Add(GetUVTextureFromAtlas(mesh.uv[i].x, mesh.uv[i].y, voxel, 0)); } [...] Vector2 GetUVTextureFromAtlas(float x, float y, ushort voxel, Facing side) { Rect rect = GetVoxelTextureRect(voxel, side); float xout = UVLerp(rect.x, rect.x + rect.width, x); float yout = UVLerp(rect.y, rect.y + rect.height, y); return new Vector2(xout, yout); } float UVLerp(float from, float to, float t) { float difference = to - from; return from + (difference * t); } Rect GetVoxelTextureRect(ushort voxel, Facing s) { int side = Convert.ToInt32(s); Rect rect = new Rect(VoxelArray[voxel].TextureAtlasPos[side].x, VoxelArray[voxel].TextureAtlasPos[side].y, VoxelArray[voxel].TextureAtlasPos[side].width, VoxelArray[voxel].TextureAtlasPos[side].height); return rect; }   Notice the tearing along the triangle lines of the mesh:   [attachment=29524:texturebleeding.png]
  4. Yes that's it, thanks. Unfortunately the Unity SSAO is almost useless so I'll have to find another solution or write my own Minecraft like AO.   Was reading through this, http://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/, looks like it isn't too hard but within Unity sort of stuck on how to us a shader to go through the voxels or somehow join my chunkmeshcreator with the shader(?) 
  5. I'm working with Unity 5.x and trying create a shader that creates shadows at the edges of voxels similar to games like Trove and CubeWorld. You can see in this image below from my game (first image) that the shading between voxels is simply not there even with additional light sources. I believe that games like trove (second image) and cube world (third image) use a shader that creates a shadow between two voxels based on whether the two surfaces are meeting on converging right angles. Does anyone know how one would attain this effect in writing a unity shader? Right now I'm using the unity standard shader. [attachment=29376:shadbetweenboxes.png]   Notice the shadow at the corner of two voxel surfaces, there is always a fading shadow at each voxel on two different planes. [attachment=29377:shader2.png] Here you can see two the same effect, there is a shadow at the edge of two different angles as the shadow fades. [attachment=29378:shader3.png]
  6. Thanks, I've updated my railsystem to do this. That was my initial approach but I just rewrote it today, seems to be working better now. Still a few kinks to work out but overall it's OK.
  7. I've been working on a railroad system for a voxel game I'm making but pretty much starting over from scratch again after my previous system has caused so many head aches. In my previous setup, user places voxel rails and as the train engine moved from one to the next, every time train ran it would scan several blocks ahead and built a list of rails. Each rail stored a list of coordinates that were open for connecting to other rails. The train engine would check to make sure each rail was connected by checking these coordinates between two rails to see if they match  (two rails facing each other properly side by side) and if they do, the rail is connected so the train could move forward. I ran into problems when the rails were at higher or lower elevations which added more complexity.   I was thinking of adding some sort of waypoint system instead but I'm having trouble wrapping my head around this insofar of making sure the next waypoint is correct facing track to the previous waypoint. Essentially each track in the railroad would be a waypoint but the voxel rails need to be correct facing ones, otherwise for example you may have problems like a front facing track and left/right turn track which might not connect but the waypoint system would still flow forward.   Has anyone ever done anything similar or can provide any tips or an overview on what the best approach might be? The railway system is 3d space, modifiable, and the tracks can be placed and destroyed any time.
  8. GameObject

    Creating a filled Bresenham's ellipse

    Thanks Mark! I'll have a look at this shortly, been a busy week this week! Can't wait to test out this code.
  9. I have the following code to create a Bresenham's ellipse for a voxel game. While this is complete and works great to create nice ellipse outlines, I'm struggling to figure out how I might convert this to create a filled ellipse. I was thinking of perhaps doing some sort of flood fill, but not entirely sure how I might implement it. I thought maybe I will save the map points and do a line scan across from left to right boundary and fill in between.   I was hoping someone might have an example of something more efficient and working. The code below is C# but more interested in how it will work and I can just convert to c#.  void DrawEllipse(int xc, int yPos, int zc, int width, int height, VoxelInfo voxelInfo) { int a2 = width * width; int b2 = height * height; int fa2 = 4 * a2, fb2 = 4 * b2; int x, z, sigma; for (x = 0, z = height, sigma = 2 * b2 + a2 * (1 - 2 * height); b2 * x <= a2 * z; x++) { voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true); voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true); voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true); voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true); if (sigma >= 0) { sigma += fa2 * (1 - z); z--; } sigma += b2 * ((4 * x) + 6); } for (x = width, z = 0, sigma = 2 * a2 + b2 * (1 - 2 * width); a2 * z <= b2 * x; z++) { voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true); voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true); voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true); voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true); if (sigma >= 0) { sigma += fb2 * (1 - x); x--; } sigma += a2 * ((4 * z) + 6); } }
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!