Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

After playing minecraft...

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

Thread Status:
Not open for further replies.
  1. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Sadly, CombineMeshes don't work for meshCollider(
    I can't create liquid and grass (
     
    Last edited: Jul 18, 2013
  2. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I made some logic improvement to code posted by alezzz in this thread. Vertex displacement now. I think i should apply displacement not for all block types (eg bricks)
    $vertex_displacement_2.JPG
     
  3. Titan8190

    Titan8190

    Joined:
    Feb 16, 2013
    Posts:
    29
    Why don't you use an atlas instead of bothering with tons of submeshes and mandatory optimizations coming with it ? but your mesh collider can't be the same than your rendered mesh so I don't really see the problem with your combine mesh stuff, it's supposed to be 2 seperate things.
    your displacement look nice but you are still missing lightning :), or there is a weird glitch, I don't know.
    Differentiate block type for displacement sound heavy since you'll have to add a lot of checks for each vertex to avoid gaps, basically 3 additional by vertex to know if an adjacent cell can't move + the current one.

    I would have liked more thought on chunk data structure.
     
  4. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Why don't you use an atlas instead of bothering with tons of submeshes and mandatory optimizations coming with it
    eg different shader for material

    My mesh collider problem:
    What i do now:
    generate geometry -> combine into 1 mesh -> assing to mesh filter -> render - mesh count equals to chunks count

    If i want to have some submesh without collider (eg grass or liquid sumbesh) i should creating one more mesh for collider.
    And mesh count in 2 times more than chunks count - uses more memory, but it's not problem, problem is destroing it after.
    It can be avoided by using CombineMeshes for MeshCollider, but it's impossible :(:(:(


    Sorry for my ugly english
     
  5. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    Can anyone tell me what the best way to overlay a cracked texture on a block is? I know you can create a temporary box around whatever block you're breaking, but is there a way to put the damaged texture onto the mesh?
     
  6. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Add over damaged side(or block) texture with alpha cutout shader
     
  7. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I figured out that i have a lot of draw calls due to using Transparent\Cutout soft edge for glasses. There is stats from editor and game

    With cutout shader
    $cutout_soft_edge.JPG
    $cutout_soft_edge_stats.JPG

    Without
    $without_cutout_soft_edge.JPG
    $without_cutout_soft_edge_stats.JPG


    Guys, what shader do you use for glass?
     
  8. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    Do you mean instantiate a new gameobject on the block's position with the damaged texture? Because what I want to know if there is a way to put the damaged texture onto the mesh of the chunk itself.
     
  9. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I think there is a way to add textute_2 over texture_1.
    Or you can write shader with 2 texture - block texture (eg grass) and damage texture.
     
  10. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    But how could you tell the shader use one set of uv coords for texture 1 and another set for texture 2?
     
  11. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Use submeshes
     
  12. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    What kind of a performance hit would this incur? And what about z-fighting?
     
  13. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    The z-fighting would depend on how far you put the crack-texture submesh from the terrain submesh and possibly the shader. It's up to you.
     
  14. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I spend 4 hours creating water block with wave and nothing. How do you creating liquid wave: Shader? Script ?
     
  15. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    https://dl.dropboxusercontent.com/u/17783172/Farm Me Now/Farm Me Now.html

    In that I had just used a submesh with Unity's water shaders. I had to fiddle with the shader settings until the waves only waved up and down, then I made them not as rough (you can't really see them at all at this point). The collisions remain the same as if it were any other shader/material though. My thinking would be that you if you are using MeshColliders for everything then you could try to build a seperate water mesh and assign it to a different GameObject somehow. Maybe have an object parented to the chunk's GameObject that is only there for holding water mesh.
     
  16. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Or just do something like this

    HasCollider return true for collide-able block type such as liquid(lava, water), grass bilboard.
    But with this an implementation meshes will be 2 times more: one render mesh, 1 collider mesh => little more RAM using. As with the separate gameobject for water)

    Code (csharp):
    1.     public void BuildMesh(Chunk chunk)
    2.     {
    3.         if (chunk == null)
    4.             throw new ArgumentNullException("chunk");
    5.  
    6.         MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
    7.         MeshCollider meshCollider = gameObject.GetComponent<MeshCollider>();
    8.  
    9.         List<CombineInstance> draw = new List<CombineInstance>(8);
    10.         List<CombineInstance> collider = new List<CombineInstance>(8);
    11.  
    12.         for (int i = 0; i < 6; ++i)
    13.         {
    14.             Geometry geometry = chunk.Geometry[i + 1];
    15.             CombineInstance instance = new CombineInstance
    16.             {
    17.                 mesh = geometry.ConvertToUnityMesh(),
    18.                 subMeshIndex = 0,
    19.             };
    20.  
    21.             if (geometry.HasCollider)
    22.                 collider.Add(instance);
    23.             draw.Add(instance);
    24.         }
    25.  
    26.         UnityEngine.Object.Destroy(meshFilter.mesh);
    27.         UnityEngine.Object.Destroy(meshCollider.sharedMesh);
    28.  
    29.         Mesh mesh = new Mesh();
    30.         mesh.CombineMeshes(draw.ToArray(), false, false);
    31.  
    32.         meshFilter.sharedMesh = null;
    33.         meshFilter.sharedMesh = mesh;
    34.  
    35.         mesh = new Mesh();
    36.         mesh.CombineMeshes(collider.ToArray(), false, false);
    37.  
    38.         meshCollider.sharedMesh = null;
    39.         meshCollider.sharedMesh = mesh;
    40.  
    41.         Debug.LogError(collider.Count);
    42.         for (int i = 0; i < draw.Count; ++i)
    43.         {
    44.             UnityEngine.Object.Destroy(draw[i].mesh);
    45.         }
    46.         draw.Clear();
    47.  
    48.         for (int i = 0; i < collider.Count; ++i)
    49.         {
    50.             UnityEngine.Object.Destroy(collider[i].mesh);
    51.         }
    52.         collider.Clear();
    53.  
    54.         //UnityEngine.Object.Destroy(mesh);
    55.  
    56.         for (int i = 0; i < 6; ++i)
    57.         {
    58.             PoolGeometry.AddObject(chunk.Geometry[i]);
    59.         }
    60.  
    61.         chunk.SwitchJob(Job.Finish);
    62.     }
     
  17. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    "Another rendering optimization that you can do is merge triangle faces for neighbour blocks that share the same block type or block colour. This optimization is a little more involved because you have to come up with a looping algorithm that will check each block neighbour in sequence and merge any faces which share common properties. This can become quite complex depending on the type of algorithm you use. And in some cases you might not get the most optimum face merge output. This is an area for further investigation."

    Has anyone do this?
     
  18. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    That's exactly what I've been doing the past for weeks/months. My new problem though is that I have to account for blocks that have been rotated. The uvs will be rotated and won't be able to share the same faces unless it's next to another block that is rotated similarly.

    Edit:
    Look what I found http://unitycoder.com/blog/2012/10/18/voxel-resources-engines-for-unity/
    They've got a list of voxel related projects, one of them being InfiChunk (my terrain generator)(also just noticed Free Terrain 3 on the list at #10).
     
    Last edited: Jul 21, 2013
  19. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    I figured out a way using shaders to show a cracked texture on the side. This only works with vertex lighting, a texture atlas, the cracks use uv2, and needs the mesh to be updated everytime a block is damaged but it works well enough for what I wanted.
    Code (csharp):
    1.  
    2. Shader "Vertex Colored" {    Properties {
    3.          //_Color ("Main Color", Color) = (1,1,1,1)
    4.          _MainTex ("Base (RGBA)", 2D) = "white" {}
    5.     }
    6.  
    7.  
    8.     SubShader {
    9.         Pass {
    10.             BindChannels {
    11.                 Bind "Color", Color
    12.                 Bind "texcoord", texcoord0
    13.             }
    14.            
    15.             SetTexture [_MainTex] {
    16.                 Combine texture * primary//, texture * primary
    17.             }
    18.         }
    19.         Pass{
    20.             BindChannels{
    21.                 Bind "texcoord1", texcoord0
    22.             }
    23.             AlphaTest Equal 1
    24.             //ZWrite off
    25.             SetTexture [_MainTex]{
    26.                 combine texture
    27.             }
    28.         }
    29.     }
    30.    
    31.     Fallback " VertexLit", 1
    32. }
    33.  
     
    Last edited: Jul 21, 2013
  20. Nightmare Games

    Nightmare Games

    Joined:
    Sep 5, 2012
    Posts:
    201
  21. Nightmare Games

    Nightmare Games

    Joined:
    Sep 5, 2012
    Posts:
    201
    screen shot please? would be appreciated
     
  22. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Last edited: Jul 21, 2013
  23. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    I do this in block story. It is tricky, because in order to get an atlas to work with this, you need to write your own shader that will repeat a texture when a triangle spawns several blocks. It also has the issue that it can produce artifacts at the edges of blocks because of floating point precision errors in the vertex shader, since now adjacent triangles may not have the same length.

    There is absolutely no way block story would work in mobile without this optimization.
     
  24. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    780
    Thanks for the tip on mobile. Your 'Block Engine Demystified' articles was a great read, and has been a great help!
     
  25. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    After some tests i figured out, that i have problem with circular array.
    http://forum.unity3d.com/threads/63...craft/page75?p=1179343&viewfull=1#post1179343

    I thought alezzzzz use shift by 10 coz width of him world is 32 (chunk block width) * 32 (chunks in width count) = 1024 == 1 << 10
    I replace 10 by 9, coz width of my world is 16 (chunk block width) * 32 (chunks in width count) = 512 = 1 << 9, but this change lead to error. Using shift by 10 help me to avoid this problem, but use in 4 times more RAM for array.
    Old: 370mb
    New (1 << 9): 350mb
    New (1 << 10): 505mb

    $Capture.JPG

    solved
     
    Last edited: Jul 22, 2013
  26. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I have a questions for you: how you save chunk to file? How long does the saving and loading for one chunk in ms??? And what dimension of your chunk?
     
  27. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    I just do a dump of the data from memory. Data in memory can be stored compressed or uncompressed, depending on how recently it has been accessed. If it's compressed then I use RLE for 'cubic' style data and DEFLATE for smooth (Marching Cubes) data.

    Unfortunately I haven't timed this but I do need to profile at some point.

    I make a distinction between the size of a chunk which is stored on disk/memory, and the size of the meshes which are generated from the data. Conceptually there is no reason why these need to be the same (though it may be easier if they are).

    In disk/memory I store the data in a chunk of 64x64x64 for cubic data and 32x32x32 for density data. The density data is bigger per voxel which is why the chunk size is smaller.

    For generating the meshes I find it depends on the size of the scene and the target hardware, to balance batch count against extraction time. On my desktop I find I can regenerate 64x64x64 meshes in real time, whereas my laptop can only manage 16x16x16 meshes in real time.
     
  28. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I thought of how to implement a Oclussion Culling system. Just need to build list of visible chunks using player position and camera view direction, and after just set not active all chunks that not present in this list.
     
  29. Joel-Huenink

    Joel-Huenink

    Joined:
    Dec 3, 2012
    Posts:
    7
    I thought I would share our project with everyone here. And if you are a talented programmer with a passion for voxel technology we could use another coder to help.

    http://7daystodie.com/

    Edit: I tried embedding a youtube video but it didn't work for some reason, what am I doing wrong?
     
  30. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    A working occlusion culling system would be the holy grail of voxel engines. I have not come up with anything that would work fast enough. I think it is doable if your terrain is octree based, but that has a lot of performance issues in other areas.
     
  31. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    @Joel Huenink - I remember seeing your game when it launched on Kickstarter, looks like a nice project.
     
  32. Joel-Huenink

    Joel-Huenink

    Joined:
    Dec 3, 2012
    Posts:
    7
    Thanks!
     
  33. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    Same, looks like a really good project to be on. Hopefully you guys do well with the kickstarter since you have a nice prototype to show the community. I think with time it will definitely become a polished product if you guys can get the funding you are seeking.

    -Dane
     
  34. scipiothegreat

    scipiothegreat

    Joined:
    Mar 12, 2012
    Posts:
    19
    $cracks.png
     
  35. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    Are you guys aware that dynamic shadows are now available in Unity Free? They're a great solution for lighting voxel-based worlds. Much easier than baking shadows into the mesh (though not so cheap to render of course).



     
  36. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Isn't not very expensive?
     
  37. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    No, dynamic shadows are now free! See the Unity 4.2 release notes.

    It's hard shadows only and for just a single directional light, but still a big step forward :)
     
  38. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    No, no, i'm about GPU and CPU usage
     
  39. DavidWilliams

    DavidWilliams

    Joined:
    Apr 28, 2013
    Posts:
    522
    Ah, sorry! Of course that's what you meant :)

    Yes, there is some cost to real-time shadows, but I have not profiled it so I don't know how significant it is. I didn't notice any performance impact on my desktop but that is a fairly powerful machine.

    For real-time shadows you basically have to render the scene twice (once is into the shadowmap), so this is some extra work for both the CPU and the GPU. You also have the overhead of reading from and comparing to the shadowmap when doing the main render, so this is some extra work for the GPU.

    At some point I'll try it on my laptop to see how it performs there...
     
  40. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    780
    Realtime shadows is working out great for me so far, but ive yet to try this in a larger world and see what the performance hit is. In a smaller level though, its marginal it seems. No performance loss that I can tell.
     
  41. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Finaly i reduce memory usage of my game to 300mb for 32*32 chunks, each chunk store 16*16*64 blocks. Without tangents and normals.
    With normals: 330 - 340mb

    2 weeks ago, the game required more than 1 gigabyte. 330mb is not a chapel.
     
    Last edited: Jul 24, 2013
  42. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    I think i can reduce memory usage by using 1 submesh per shader, instead 1 submesh per material
     
  43. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    But what about if you're using, let's say, two materials with the diffuse shader. One uses a grass texture and the other uses a dirt texture. How will it account for the two different textures?
     
  44. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    Texture atlas

    "I think i can reduce memory usage by using 1 submesh per shader, instead 1 submesh per material "

    After tests i figured out that it is not
     
  45. Captain Morgan

    Captain Morgan

    Joined:
    May 12, 2013
    Posts:
    144
    1 submesh per material: 330mb cold start
    1 submesh per shader (unoptimized) 640mb cold start
    1 submesh per shader (optimized) 630mb cold start
     
    Last edited: Jul 26, 2013
  46. Titan8190

    Titan8190

    Joined:
    Feb 16, 2013
    Posts:
    29
    why would the size double when you merge your submeshes, it don't make any sense...
     
  47. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Lovely post!

    Just wanted to share a video of the "voxel engine" we created in unity for a game project! Ask away if you want to know anything ;)

     
  48. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
  49. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
  50. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    I really like the concept you got going here and it looks really fun! How long have you guys been working on this project and when are you looking to finish/release it? :)

    -Dane
     
Thread Status:
Not open for further replies.