Search Unity

After playing minecraft...

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

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

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Finally got caves to work! Photo taken on my iPhone 5
     
  2. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    Nice! How have you implemented them?
     
  3. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
  4. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    :D Good to see! Congratulations.
     
  5. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Umm, I basically use simplex noise to carve out the caves. (Sorry I'm really bad at explaining how I do things :/)
     
  6. Lumos

    Lumos

    Joined:
    Feb 11, 2013
    Posts:
    49
    Greetings!
    This is my first post on this thread, and though I've looked at a lot of the stuff on it, I've not read though all of it, so please excuse me if I'm asking something that's already been discussed thoroughly.
    So, I've been dabbling into Minecraft-style terrain as well. It seems to be pretty much working, despite the fact that my attempt to create the lighting failed miserably. In any case, I got around to working on the block placing/removal mechanics, and while the first is simple enough (and direct removal is as well), I'm having trouble with displaying the damage.
    My blocks consist of a byte for the ID and a byte for the health (no light data included (for now)). Basically, I intend to have a few "permanent" damage states which are stored in the block (opening up the possibility of block repairing and whatnot), and I - naturally - want the damage states to be displayed on the blocks. The logical way to do that would seem to be overlaying the damage texture on top of the regular one through a shader. But how?
    As usual, I'm using a tilesheet, and the UVs for the default texture are set through Mesh.uv. Assuming my damage state textures are in a tilesheet as well, how would I go about getting and combining the two? I know of the existence of Mesh.uv2, though, to be honest, I have no idea what a "second texture coordinate set" is. I guess I could set these, then modify the regular Diffuse shader to combine the two (probably multiplying, don't know how to make the second one overwrite the first one). Is that the way to go?

    Thanks for any replies in advance. I'm pretty new to the whole Unity stuff, and I've never written (or modified) a shader before, so my knowledge on the subject is a bit wonky, but bear wih me, please...
     
  7. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I also have a small question. I understand that Unity can only manage meshes with up to ~65k vertices. That means that a chunk can't be much larger than 16x10x16 (*24 maximum vertices per cube = ~61k). I have read a lot about Minecraft using 16x128x16 chunks. Does this mean Unity users just use smaller chunks?
     
  8. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Well actually IIRC Minecraft organizes their chunks into 16x128x16, but those are further subdivided into a stack of 8 cubic sections (each one is 16x16x16). Remember, that vertex limit isn't a Unity specific limitation - see here: https://www.opengl.org/discussion_boards/showthread.php/143425-Vertex-Array-Limit
    It's a limitation of how much a 16-bit unsigned integer can store.
    Minecraft therefore has to deal with the same limitation, which is why chunks are further subdivided into multiple sections (and therefore multiple meshes).
     
  9. sandboxgod

    sandboxgod

    Joined:
    Sep 27, 2013
    Posts:
    366
    @jordantotty, Nice screenshots. I especially liked that view from inside the cave
     
  10. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Thanks. I assume that means that Minecraft uses 8 vertices per cell?
     
  11. Ellandar

    Ellandar

    Joined:
    Jan 5, 2013
    Posts:
    207
    Hi All,

    I've been a long time lurker here, very cool stuff happening!
    First off, congratulations Goldbug on going live in steam!! Very impressive mate.

    I've been following these voxel engines for quite a while, some pop up and show good promise then die away, whilst other long stayers stick around and get better and better. I've been a little envious as I don't really have the chops to build my own, yet.

    I thought I'd tackle a different problem that I'm quite sure I can deliver on - generic water.

    I've got a WIP thread going over here: Liquid Voxels for ...
    It's a generic water implementation that can be added to voxel engines with a fairly limited amount of effort.
    I'm still quite a way from release/completion but I will be releasing beta versions for people to try out.

    I'll start getting it going with Cubiquity, then I'll probably throw out an open invitation for people to vote on applying it to other voxel engines. To be honest, I believe I've made it simple enough to implement in most of your engines already, barring peculiar game-play situations.

    I'll leave you with a couple of videos. Feel free to drop me a line, twitter, ask a question on the blog etc. Happy to answer questions.

    - Ell



     
  12. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Nice work on the water animation. Coincidentally, today I have started working on my own water animation, although a lot simpler. I have a water chunk and I created a list of all vertices that make up the chunk's top triangles by adding the current vertexIndex to the list while creating faces. Now I try to use this information to animate the mesh's top vertices up and down to simulate waves. It's not working right so far, it runs at less than 30 fps and somehow not all vertices move when they should.

    Has anyone successfully done something like this? In essence, continually moving a select number of verticess of a mesh?
     
  13. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Have a look at Mr Wishmaster's engine, he has moving water :)
     
  14. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Coming to iOS and android soon!


    (Photo taken on iPhone 5)
     
    Last edited: May 3, 2014
  15. Spiderbean

    Spiderbean

    Joined:
    Nov 12, 2012
    Posts:
    6
    Hello Guys,

    I am trying to follow this thread a bit and you guys have been a great help. I am at the moment developing a marching cubes terrain. I started off with a normal Voxel Minecraft terrain, which worked out perfecly well. It is hard for me to read through this entire thread, so I thought I would post my problem: My terrain engine is supposed to help edit chunks, which worked perfectly well on my blocky version of it. Although now if I click often nothing happens and the chunks appear to be edited only sometimes(only if the colliders have a certain shape). I've tried everything I could think of. Subtracting the hit.normal didnt work. Tell me if you need more scripts.

    $terrain.png

    View attachment $PlayerIO.cs
     
  16. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Kinda hard to see the problem when we don't have the source :) If I were you I would just use some Debug.Log("Here")'s to work out what parts of the code are actually being executed.
     
  17. Spiderbean

    Spiderbean

    Joined:
    Nov 12, 2012
    Posts:
    6
    Last edited: May 8, 2014
  18. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I'm still having troubles with my animated water. I just want the top vertices of the water cube mesh to go up and down to simulate tidal waves.

    So far, this is what I have done.

    When generating the face of a water block, I check if the vertex is one the water level, and if yes, add it to a list that stores the Vertex Indices as ints.

    Code (csharp):
    1.  
    2. waveVertices.Add(vertexIndex);
    3. waveVertices.Add(vertexIndex + 1);
    4. waveVertices.Add(vertexIndex + 2);
    5. waveVertices.Add(vertexIndex + 3);
    6.  
    Then, I just use the Update function to check if any the waveVertices list contains anything, and if yes, create a new mesh using the stored Vertex Indices, find out how low and high the vertices should go, and change their positions accordingly.

    Code (csharp):
    1.  
    2.  
    3. public float lvl;
    4. public int waveDir;
    5. public float waveSpeed = 0.2f;
    6.  
    7. void Update() {
    8.         if(tidalWaves == true) {
    9.             if(waveVertices.Count > 0) {
    10.  
    11.                 Mesh mesh = GetComponent<MeshFilter>().mesh;
    12.                 Vector3[] vertices = mesh.vertices;
    13.  
    14.                 min = waterLevel + waterHeight;
    15.                 max = waterLevel + waveHeight;
    16.                 lvl = vertices[waveVertices[0]].y;
    17.  
    18.                 if(waveDir == 1  vertices[waveVertices[0]].y >= max) {
    19.                     waveDir = 0;
    20.                 }
    21.                 if(waveDir == 0  vertices[waveVertices[0]].y <= min) {
    22.                     waveDir = 1;
    23.                 }
    24.  
    25.                 foreach(int i in waveVertices) {
    26.                     if(waveDir == 0) {
    27.                         vertices[i] -= Vector3.up * Time.deltaTime * waveSpeed / 5;
    28.                     }
    29.                     else {
    30.                         vertices[i] += Vector3.up * Time.deltaTime * waveSpeed / 5;
    31.                     }
    32.                 }
    33.                 mesh.vertices = vertices;
    34.                 mesh.RecalculateBounds();
    35.             }
    36.         }
    37.     }
    38.  
    However, the major problem here is that when I modify the mesh (adding or deleting water blocks) while the vertices are moving, the wave vertices go up and down faster and faster! I have absolutely no idea how that could be :(
     
  19. jordantotty

    jordantotty

    Joined:
    Dec 15, 2011
    Posts:
    77
    Have you tried this shader?


    It is from Mr Wishmaster/Demi's source. :)
     
  20. Badreend

    Badreend

    Joined:
    Apr 15, 2014
    Posts:
    2
    I've tried some examples/tutorials, but what I already got at the moment is still beter what i've tried meanwhile. All those examples are made for making as much as possible voxels vissible on screen. But the voxels need to be also dynamic resizeable. And that is still the problem i'm struggling with.

     
  21. Spiderbean

    Spiderbean

    Joined:
    Nov 12, 2012
    Posts:
    6
    I started debugging and using all sorts of normals and other stuff to correct the raycasting. It just doesn´t work! Here I use the Debug.DrawLine . You can clearly see that the Mathf.FloorToInt works(in order to get 3D array index). But it still randomly not work there.
    $terrain.png
     
  22. Philpratt

    Philpratt

    Joined:
    Mar 16, 2014
    Posts:
    2
    Wow there are some impressive projects in this thread!

    I've also just started a similar project, more to improve my coding skills than anything else, but I'm currently stuck trying to figure out the lighting and shader.
    My current lighting is using a flood fill approach where I start at the top of my chunk and fill light until I finally hit a solid block, which appears to be similar to the way a number of other have done their lighting. What I don't quite understand how you can adjust the daylight level without recalculating every mesh and killing your fps?

    It feels like I must be missing a trick here because everything else seems to be working ok, but day/night cycles are killing me.

    Thanks
     
  23. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Do it in the shader. Encode light level in the vertex colors, and then have your shader multiply light amount from vertices with a light color param. That way you can just change the light color with different times of day.
     
  24. Philpratt

    Philpratt

    Joined:
    Mar 16, 2014
    Posts:
    2
    Thanks for the quick reply, I'll have to take a look at my code tonight. I'm probably overdue a bit of a refactor for my code as it isn't very efficient at the moment.

    Wouldn't recalculating all the vertex colors still be quite expensive as you would still need to visit each visible block in each chunk?
     
  25. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    No you wouldn't be recalculating the vertex colors at all. Like I said, do it in the vertex shader - the shader itself multiplies incoming vertex color by light color.
     
  26. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Hey guys,

    I've been working on a voxel engine for some time now. And I have all kinds of functionality in it. Terrain generation, all kinds of block types, block functionality, and a bunch of unique things.

    But one thing I absolutely can't seem to get my mind wrapped around is lighting. And by that I mean I can't even figure it out at the most basic level.

    I think I'm stuck with the wrong perspective on this. I don't see how I'd even begin going about lighting. I hear about using vertices, shaders, etc. But how do you actually use vertices and shaders to make a block light up, so that you can begin a flood-fill type thing?

    So basically, I'm not sure where you even start. I'm pretty new with that kind of thing.

    And if this was mentioned somewhere, I wasn't able to read every one of the 119 pages... that's a lot!

    Thanks in advance if you can point me in the right direction.
     
  27. jevin05

    jevin05

    Joined:
    Apr 7, 2013
    Posts:
    5
    Nice Thread!!!

    thx a lot!

    I'm having a bit of trouble with this thread. when i click mouse button,nothing happened But.... I found RemoveBlock function in World.cs. and it works. I don't know what happened. And "Player" GameObject miss Mono Script. Anyone know ?
     
  28. wuqiudongonmyway

    wuqiudongonmyway

    Joined:
    Dec 1, 2012
    Posts:
    2
    Hi,all :mrgreen:
    I have a big problem: how to build the special block, such as stair, chair, fence and so on.
    It's so difficult for me to add vertices/triangles for such special block.
    Can any one give some advices to handle those special block in the voxel engine?
     
  29. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    I'm kind of wondering about the above question as well. I mean, do you just make vertices like you do with the cubes? I imagine you would have to make all the vertices like you do cubes. I'm just wondering if there's some trick I'm unaware of, given how new I am to voxel engines.

    I'm also still wondering about lighting. I heard I'm to use vertex colors. How do I do this? Do I make a list of vertex colors, just like I do with vertices and triangles and all that? And how exactly do I apply it to each face in code?

    I'm learning... but much to go still.

    Thanks in advance.
     
  30. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    You can of course just create chairs, stairs etc. by maunally creating meshes as with the main cube chunks, you just have to carefully plan where each vertiex will go for a chair's legs and so on. However, as long as you don't need thousands of objects, I would think that adding such decorative objects as prefabs would be far easier.
     
  31. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Of course, how many you need is entirely up to the player who is building the world. So that gets kind of tricky...
     
  32. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    You could probably just have a mesh for the object, and then grab the mesh data and add it to your chunk mesh pretty much as-is (perhaps map the UVs to the appropriate tile of the atlas, and maybe rotate the vertices but not much else needed I think)
     
  33. wuqiudongonmyway

    wuqiudongonmyway

    Joined:
    Dec 1, 2012
    Posts:
    2
    Hi, PhobicGunner,
    1. When I get the object mesh data, I can't split the mesh data into 6 different faces.
    this result I can't use the same way with cube block, and voxel engine may have much more draw call.

    2. if current special block is a stair,and the bottom block is a dirt, what I should do with the shared face. if this two block are independent, the performance will decrease.

    any other idea will welcome, Thanks!
     
  34. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    After accepting that our terrain generation sucked, we spent a few neurons and made a new terrain generator for block story. Here are some screenshots:


    Here is a "hobbit house"


    A couple houses generated in the forest


    Sinkholes with waterfalls


    pretty volcanoes


    Oasis in the desert
     
    magic9cube likes this.
  35. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    First off, I'd like to extend a big thank you to everyone that has contributed in the glorious thread!

    My first asset on the Unity Asset store was just accepted. I call it Voxmodule. It all started months ago when I wanted to make a voxel engine. After having success I went on to make a voxel game. Several months were put in by the team on design alone. Unfortunately, the team fell apart in the beginning of the project. :(



    Around the same time frame I was without a job, and figured I would try something different. I spend 4-8 hours every day doing game dev. I figured I may be able to eek out a living doing this. Unfortunately I need money now, and I don't have enough savings to last until I am able to release a game.



    My decision was simple, I will try to sell different things I've created over the years to help fund my indie game dev mission. This finally brings my back to my original point! I am trying to make just a little bit of money off of Voxmodule, so that all the time and energy that went into it is not wasted.



    You can check out a demo here

    If you like what you see, I would greatly appreciate it if you considered a purchase. The engine is multi-threaded, runs very well, and has procedural infinite terrain. If sales go well then I plan to continue working on the engine, adding a few more planned features as well as implementing user suggested features.

    Link to asset store

    Once again, thank you to everyone in this thread!
     
  36. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    It's my MineCraft clone.


    Unfortunately, I came to the conclusion that Unity is poorly suited for such games.
    Unity mesh contains a fixed set of data. Vertex position, UV, Normal consists of float types. But for MineCraft possible store all data as bytes. It would be a good memory savings.
     
  37. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    Indeed, storing vertex, uv and normals as bytes would be massive memory savings. Do you know of a game engine that allows for doing this?
     
  38. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    I was wondering the very same thing. I'm especially curious about how storing some of these as bytes would even work?

    (BTW, great job on Block Story!)
     
  39. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    there are only 6 normals in the blocky terrain. You can encode that in 3 bits,
    if all the sprites in your atlas (assuming you are using atlas), are the same size, then you can pack 256 uvs in 1 byte (4 bits x and 4 bits y).

    If you have ambient light, say you only have 16 values for each RGBS (full color + sun) then you can pack that into 2 bytes.

    so uv + normal + color can easily fit into 4 bytes and still have some spare space. One would need a specialized shader that can decode this information, here is an example of doing something like that:

    http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/

    Another simpler option is to encode this into a Color32 structure (bytes), and then in the shader multiply the color components by 255 to decode the bytes.
     
  40. Threepwood

    Threepwood

    Joined:
    Jul 23, 2009
    Posts:
    95
    Memory is always an issue, but is it a big deal here? Even if a game takes 1g or so of memory, it will be fine. Don't these games generally delete chunks from memory as you get far away (and cache to disk if changed), then just re-generate them as you get near again? So you only have X chunks in memory at any given time? So while packing stuff smaller is a good idea, you can certainly ship commercial stuff without it here, right?
     
  41. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    Yes, I saw such way to optimize memory.
    But why should I bother with the encoding and decoding float, if there is a low-level API allows you to add any data with any type?
    Especially as float decoding takes time.
     
  42. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    It depends. My game is a mobile game, memory is a BIG deal to me. From my calculations, this will save me 5 - 10 MB of ram at maximum view distance, which is significant for mobile, and it is relatively speaking a small change.

    Because as far as I am aware there is no such low-level API. If there is, kindly let me know.
     
  43. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    I see SharpDX exampe http://sharpdx.org/forum/5-api-usage/241-d3d11-indexbuffer
    Look at: new InputElement("POSITION",0, Format.R32G32B32_Float,0,0),
    And here is list of formats: http://sharpdx.org/documentation/api/t-sharpdx-dxgi-format
    Large list.
    Why even Aras uses encode, decode of float, if it can be done so simply?
    Also this http://feedback.unity3d.com/suggestions/get-values-from-render-texture is very strange limitation.
     
  44. Threepwood

    Threepwood

    Joined:
    Jul 23, 2009
    Posts:
    95
    Goldbug, 100% granted for mobile but I think games of this type are generally the domain of pc or console :)
     
  45. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    That looks interesting, it would be very nice if it was available for unity. That said, it looks like it is a DX feature, is there something available for android and iphone (opengl es 2) ?

    Until it is available for unity and for phones, that is why Aras uses encode and decode for float.
     
  46. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767
    About 80% of my revenue comes from mobile. I would not even think of doing a PC-first game anymore :)
     
  47. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    Of course Android has such function. All API can setup type of input data.
    I am looking at my very old code for Android \ OpenGL ES 1.0.
    There is such methods:
    glVertexPointer (int size, int type, int stride, Buffer pointer)
    glNormalPointer(int type, int stride, Buffer pointer)
    glTexCoordPointer(int size, int type, int stride, Buffer pointer)
    they take the types of data.
    http://developer.android.com/reference/javax/microedition/khronos/opengles/GL10.html


    Such feature would be very useful for us.
     
  48. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    767

    I posted the feature request for textcoord and normals, kindly vote for them here:
    http://feedback.unity3d.com/suggestions/support-textcoords-with-shorts
    http://feedback.unity3d.com/suggestions/specify-normals-with-bytes
     
  49. Deni35

    Deni35

    Joined:
    Jul 10, 2012
    Posts:
    43
    No. Necessary not only to have textcoords with shorts and normals with bytes. I want a full control.
    Would be much better if Mesh could be created with ANY data. I.e. any formats, semantics and any number of buffers.
    I.e. fully customise mesh.
    It would be very interesting. And it is good for learning low-level API.

    I would even like to get access to OpenGL and DirectX. Of course, the programmer will have problems with crossplatform. But he can learn low-level API. And do whatever he wants.
     
  50. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    For those who say that Unity is not suited for Minecraft or if it is not possible to recreate minecraft in unity, here ya go:


    Pretty impressive eh?
     
Thread Status:
Not open for further replies.