Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

After playing minecraft...

Discussion in 'General Discussion' started by jc_lvngstn, Oct 8, 2010.

Thread Status:
Not open for further replies.
  1. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Ah cool. I guess it could always be a bug. ;)
     
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I could create a sample project but not on this weekend. Monday evening maybe.
     
  3. Windexglow2

    Windexglow2

    Joined:
    Sep 23, 2012
    Posts:
    90
    Question: If a renderer is built for it, wouldn't a quad render nearly as fast as 1 triangle? Or is there more going on behind the scenes?
    [I know very little about the technical parts of rendering]
     
  4. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I already made a project as an example. You could try it and see if I'm even recreating the problem correctly.

    http://www.mediafire.com/download.php?nnr3njcotic5hyb

    If you want to modify it and send it as a bug report once you've gotten it to... stop working.. then go ahead.
     
    Last edited: Oct 27, 2012
  5. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    I can't get it to misbehave, I have upped the numbers and toggle between quads and triangles. There is absolutely no effect in FPS or performance. The only change that happens is that the triangle count go down by half. This is what I would expect.

    This is on a macbook pro.
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    That example on my pc,
    triangles mainthread: 1.1-1.3ms (~800fps), quads: 1.7-1.9ms (~600fps)
    (not optimized)
     
  7. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    ^ that was in dx11 mode, if use opengl:

    triangles mainthread:0.4ms (~2600fps), quads: 0.4ms (~2600fps)
    (not optimized)

    Then dx9:
    triangles mainthread:4.6ms (~220fps), quads: 1.8ms (~530fps)
    (not optimized)
     
  8. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    It suprises me that directX9 handles quads better then dX11, while you would say quads is more, well, new, so dX11 should be better at handling those. Looks pretty strange to me...
     
  9. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Hey guys, a bit off topic.... Yet a bit on topic.

    My voxel engine is working well, however how am I supposed to texture each voxel differently? Do I need to make a atlas of triangles and apply them to that or what?

    I'm guessing it's pretty simple, I just haven't done much work with textures before
     
  10. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    You could try finding out how MinePackage does this
     
  11. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I just do it how minecraft does it. Slap all your blocks into one texture and change the uv of block based on which type of block it is. I think alexzzzzzz...zzzz...z...etc. may use one submesh per block type and just assign a new material for each.
     
  12. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    I'm planning on implement a marching cubes algorythm with triplanar texturing. So that would probably be the way to do this too. I'm still a bit confused on the submesh thing though. How does it exactly work?
     
  13. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I find that submeshes are easier to use than atlases, but they are slower due to higher number of drawcalls. For 16x16x16 chunks, I think, it's better to use atlases.

    Actually I'm trying to implement atlases even though I use 32x32x32 chunks. Not one big atlas that contains all the textures, but a set of atlases that contain 4 or 9 high-resolution textures. Right now I'm fighting with pixel bleeding effect:

    Debug atlas texture (2x2)


    Pixel bleeding
     
  14. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    While building a mesh, instead of one list of indices you should have multiple lists - one per material. And then instead of calling
    Code (csharp):
    1. mesh.triangles = indices.ToArray();
    you use
    Code (csharp):
    1.  
    2. for (int i = 0; i < numberOfMaterials; i++)
    3. {
    4.     var listOfIndicesForCurrentMaterial = listOfListsOfIndices[i];
    5.     mesh.SetTriangles(triangles: listOfIndicesForCurrentMaterial.ToArray(), submesh: i);
    6. }
    and MeshRenderer should have several materials instead of the only one.
     
    Last edited: Oct 29, 2012
  15. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    A submesh is when you take your big chunk, and draw different triangle indexes for the different parts of it. For example, you can draw your water in a submesh, your leafs in another and your ground in another. Each submesh can have it's own material, so you can have different shaders and textures. You end up with 1 mesh, where different triangles can be rendered with different materials.

    The problem is performance. If you have say 100 different block types, you don't want to do 100 submeshes, because each submesh is done in a separate draw call. Draw calls is the main driver for FPS (more so than triangle count).

    Atlases have pixel bleeding problems, and are much harder to use, but they allow you to have all your different blocks in just 1 submesh.

    There is no perfect solution, just tradeoffs.
     
  16. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Ok thanks, that's exactly what I was wondering




    Thanks for your explanation :D

    Would it also be possible to figure out if, for example, there is no iron in the specific chunk, so don't create a submesh for it and dont store a material for it either? How would you go about that?


    Alexzzz just mentioned the pixel bleeding effect. How does that arise? I also noticed myself the terrain was looking different at a specific distance:
     
    Last edited: Oct 29, 2012
  17. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    I forgot one more thing. Do this before any mesh.SetTriangles calls:
    Code (csharp):
    1. mesh.subMeshCount = numberOfMaterials;
    I did it exactly this way. If the list of indices for iron is empty, skip that submesh and don't add iron material to the chunk's MeshRenderer.

    http://www.realitymod.com/forum/f189-modding-tutorials/90244-uv-texture-info-pixel-bleeding.html

    On mipmaps the edge pixels of any two adjacent atlas tiles bleed into each other. The further the distance, the higher level of mipmaps is used, the more the bleeding.
     
    Last edited: Oct 29, 2012
  18. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    By the way, is it possible to limit a texture's mipmap level count? In case of atlases the highest levels, where the mipmap size is 1x1 or 2x2, have absolutely no sense.
     
  19. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Hmmm... Still don't quite explain the submesh thing.. Will do with time and investigation.

    Would it be better for me to just jump straight into atlasing? Because with 60+ blocks....... Yeah

    Anyone care to run me through it or give me some links?
     
  20. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    How about making a seperate mesh for every material, so very rare materials may have only 1 big mesh for the entire currently loaded world. More common materials may be seperated in chunks, depending on its rarity. The rarer it is, the bigger the mesh will span, the more common, the smaller the chunks it is divided in
     
  21. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    So I found out in the lighting calculations, the / and % operators are used. So to start I switched the % with ( chunkwidth - 1), and this simple change, reduced the total generation time for a 512x128x512 world of 32x128x32 blocks from ~40,8 seconds to a stunning ~36,1 seconds. With the >> operator added, it is reduced to 29 seconds! That's halve of the total ligh calculation process! Thanks for the tip!
     
  22. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Thank you for this information. I updated the article with it. This is what the article was missing, some real world numbers. These numbers are also consistent with what I found.

    Anybody that knows anything about performance analysis will tell you microoptimizations are useless in 99% of the cases. I agree, but this is that other 1% :)
     
  23. Krileon

    Krileon

    Joined:
    Oct 30, 2012
    Posts:
    642
    Is there a collaborated system being used for this? Maybe it'd be a good idea to take the latest modified and put on github so others can contribute to a singular package for providing a voxel implementation. Getting hard to follow the thread, lol.
     
    Last edited: Oct 31, 2012
  24. ApplezGaming

    ApplezGaming

    Joined:
    Sep 24, 2012
    Posts:
    3
    i have a destroying and building script but when i place a block on the side of another it then place it on top of the block i clicked to place it next to and also i can place blocks in side each other and the placement is dodgy would some one be able to try and help sort my script out please. This is the script :
    using UnityEngine;
    using System.Collections;

    public class BuildScript : MonoBehaviour {

    public Transform prefab1;
    public Transform prefab2;
    public Transform prefab3;
    public Transform prefab4;
    public Transform prefab5;
    public Transform prefab6;
    public Transform prefab7;
    public Transform prefab8;
    public Transform currentPrefab;
    RaycastHit hit;

    void Awake() {
    currentPrefab = prefab1;
    }
    // Update is called once per frame
    void Update () {


    Ray ray = camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

    Vector3 G = new Vector3(Mathf.Round(hit.point.x), Mathf.Ceil(hit.point.y), Mathf.Round(hit.point.z));

    if (Input.GetKeyDown(KeyCode.Alpha1))
    {
    currentPrefab = prefab1;
    print("Grass");
    }
    if (Input.GetKeyDown(KeyCode.Alpha2))
    {
    currentPrefab = prefab2;
    print("Mud");
    }
    if (Input.GetKeyDown(KeyCode.Alpha3))
    {
    currentPrefab = prefab3;
    print("Stone");
    }
    if (Input.GetKeyDown(KeyCode.Alpha4))
    {
    currentPrefab = prefab4;
    print("Cobblestone");
    }
    if (Input.GetKeyDown(KeyCode.Alpha5))
    {
    currentPrefab = prefab5;
    print("Leaves");
    }
    if (Input.GetKeyDown(KeyCode.Alpha6))
    {
    currentPrefab = prefab6;
    print("Logs");
    }
    if (Input.GetKeyDown(KeyCode.Alpha7))
    {
    currentPrefab = prefab7;
    print ("Wood");
    }
    if (Input.GetKeyDown(KeyCode.Alpha8))
    {
    currentPrefab = prefab8;
    print("Bedrock");
    }
    if(Input.GetMouseButtonDown(1)){
    Instantiate(currentPrefab, G, Quaternion.identity);
    }

    if(Physics.Raycast(ray, out hit)){

    if(Input.GetMouseButtonDown(0)){
    Destroy(hit.collider.gameObject);
    }



    }

    }
    }
     
  25. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    First off, next time you post code here on the forum, would you please enclose it in a CODE tag, that way it is easier to read and follow for us. :)

    Second, I'd want to say that the way you are doing this now is very inefficient, and will lag you to death after a decent amount of prefabs have been placed ( let alone a complete world )

    Are you a beginner in programming? If you are ( which I'm assuming from the code you show us ), I would recommend learning a bit more tips tricks and some better programming habbits, before continueing with Voxel terrain.

    I would advice downloading the MinePackage jc_ made, which you can find on this forum. It's a great place to start off :D
     
  26. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I think it's fine the way he's starting out right now. That's how I learned to do terrain generation. Start simple then break it down and build it back up stronger/better/faster than it was before. You really have to learn as you go or else you risk just quitting all together. If you tell someone to start with complex code they may not ever figure out what's going on.
     
  27. HelloTherePeople

    HelloTherePeople

    Joined:
    Sep 9, 2012
    Posts:
    56
    I have finished my voxel engine. Terrain generation is rather boring, as it generates a flat plane. Stay tuned, I will post some code soon, and release my games source code.
     
  28. ApplezGaming

    ApplezGaming

    Joined:
    Sep 24, 2012
    Posts:
    3
    i have the terrain generation but i carnt get the placing of the block part to work properly
     
  29. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    To dig a block:

    1. Cast a ray in the direction you're looking to the center of the screen.
    2. Determine which block you have hit by using the distance and the normal of the hit (this gives you the face you've hit).
    3. Find the block in your array and change it to whatever.
    4. Redraw the mesh.

    To place a block:

    Do the same thing as digging but offset the block by 1 in whichever direction the normal is pointing at.
     
  30. ApplezGaming

    ApplezGaming

    Joined:
    Sep 24, 2012
    Posts:
    3
    i have the placeing and digging script but sometimes the block gets placed on top or inside the block i want to place the block next to so please could some one help and try and get my script to work please?
     
  31. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    /edit Nevermind, I figured it out.

    Is anyone here using LibNoiseDotNet? I'm having all sorts of trouble with getting Boo to recognize that SimplexPerlinNoise has members such as OctaveCount and such.

    I'm sure it's just a major brain fart on my part.​
     
    Last edited: Nov 2, 2012
  32. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    This may not apply to you but when I was doing this I noticed that sometimes the calculations ended up being, say, 1.0000000000000001 instead of 1. So I would get the wrong block (off by 1). I never found out why but my solution was to round the raycast results, I believe.
     
  33. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    BTW does anyone have an idea of the overhead involved in calling binaries (like, compiled C++ dlls) from Unity? Currently I'm just using .NET stuff directly (source code) as I don't have Pro but eventually I'd like to move to there and I am wondering, with the ten zillion calls that would be made to LibNoise to generate the voxel data, if that will have a negative impact?

    I'd imagine the overhead is minimal compared to the speed up from using "native" compiled code?
     
  34. HelloTherePeople

    HelloTherePeople

    Joined:
    Sep 9, 2012
    Posts:
    56
    Words of wisdom right here :)
     
  35. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    I'm curious have people thought about looking at the source for Minecraft and take notes of how the game is officially built?
     
  36. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    So in order to show textures would it be best to make a texture atlas for each chunk gradually?

    Not sure on this
     
  37. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,447
    One atlas per chunk? It's definitely not an option for hi-res atlases.
     
  38. XavLar

    XavLar

    Joined:
    Feb 14, 2012
    Posts:
    143
    If the source was availible we would, although there would be SO MANY MORE Minecraft Clones if the source was released.
     
  39. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Well, check the main Minecraft wikis. I'm pretty sure most of the algorithms and data structures have been figured out, and, in fact, were used in this thread as a starting point.
     
  40. Sequence

    Sequence

    Joined:
    Feb 4, 2012
    Posts:
    44
    Whoa, this thread is still alive? I read this a while ago to try to make a minecraft game. Such a good thread.
     
  41. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    The greatest thread on the forums. This baby will never die.
     
  42. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    I can get the source easily, im not supposed to i know but I can. Its how people mod the game. I can open modify the source and run the game in the Eclipse IDE
     
  43. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Any idea where to start then :p
     
  44. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    I'm confused as to what you're asking for here or what the issue is. We're talking about texturing the blocks, right?

    You only need 1 material---to start just take the texture file from Minecraft. I think it's made up of 16x16 pixel blocks with 16x16 blocks in the image.

    So your UVs are just whatever the block coordinate is divided by 16 and then offset it for each vertex.
     
  45. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    I understand this much, however each chunk is one single mesh.
     
  46. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Well, don't hold back... what is the secret?
     
  47. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    So? I don't understand what the issue is.
     
    Last edited: Nov 2, 2012
  48. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    You can decompile most Java stuff... Google it.
     
  49. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    How do I apply the texture in accordance to the block co-ords in the chunk.

    My "worldData" is a 3-Dimensional Array of a custom class I created called ChunkBlock

    Code (csharp):
    1.  
    2. class   ChunkBlock
    3. {
    4. var isShown = false;
    5. var isTransparent = true;
    6. var name:String;
    7. var texture:Texture2D;
    8. var breakTime:int;
    9. }
    10.  
    Each potential "block"(Which is really just co-ordinates for the single mesh) in the chunk has one of these

    Im going to change the texture variable to co-ords of the big texture atlas but how do I apply them seperatley, as in how do i determine and tell the renderer "On this part of the mesh, the texture should be this"

    Thanks Foam :)
     
  50. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    yeah also look for minecraft specifically it easy it takes like 5 mins
     
Thread Status:
Not open for further replies.