Search Unity

Low poly world

Discussion in 'General Graphics' started by IL4Mi3y, Jan 28, 2015.

  1. IL4Mi3y

    IL4Mi3y

    Joined:
    Dec 29, 2014
    Posts:
    38
    I searched over 10 hours and can't find some code or a libary for a low poly game.

    I want to create a low poly world like this http://b.vimeocdn.com/ts/407/486/407486446_640.jpg
    from modifying a terrain.

    I found an expensive asset for low poly. How does he make this? Shaders or Scripts?
    Can someone tell me how I can get a low poly effect on my terrain?

    I despair.

    I don't want to export a model from a 3d program like blender.

    I hope someone can help me.
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    If you want to generate it then you have to write a script to procedurally generate a mesh based on some kind of algorithm. `Poly world` is a good asset on the asset store, check it out.
     
  3. Cpt Chuckles

    Cpt Chuckles

    Joined:
    Dec 31, 2012
    Posts:
    86
    something like that would be accomplished by making a mesh with each triangle "separate" from all others, so that the vertices of each face have normals that match the face normal. it isn't possible to do with a mesh that shares vertices between faces, because each vertex can only have one normal. the lighting is based on the vertex normal.

    i don't know how unity handles terrain objects, or if you could split the vertices to keep separate normals. you may end up having to implement some custom terrain thing yourself in order to generate a mesh with split vertices/normals.
     
    IL4Mi3y likes this.
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    you can create a 'triangle soup' like that from script, with separate vertices/normals for each triangle's corners.
     
    IL4Mi3y likes this.
  5. IL4Mi3y

    IL4Mi3y

    Joined:
    Dec 29, 2014
    Posts:
    38
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    It's just vertex colors. In addition to supplying vertices, you also supply an array of RGBA colors, one for each vertex, so that means you need to repeat the same color 3 times, for 3 vertices of each triangle. It'll then look `flat shaded` because the whole triangle is the same color. The hardware will still interpolate color between the vertices but it will look like it's all the same color.
     
    IL4Mi3y likes this.
  7. IL4Mi3y

    IL4Mi3y

    Joined:
    Dec 29, 2014
    Posts:
    38
    @imaginaryhuman
    But how I can get the colors from my terrain?
    I can't find something useful on the API. Just something about alphamaps. But I don't know how to handle it.

    Here is my mesh.
     
  8. IL4Mi3y

    IL4Mi3y

    Joined:
    Dec 29, 2014
    Posts:
    38
    I tried a bit with coloring the mesh an get this result.


    I do this with this script (random generate)

    Code (CSharp):
    1. Vector3[] vertices = mesh.vertices;
    2. Color[] colors = new Color[vertices.Length];
    3. for (int i = 0; i < vertices.Length; i = i + 3)
    4. {
    5.     if (i + 2 < vertices.Length)
    6.     {
    7.         Color32 color = new Color32((byte) (50 * Random.Range(0.8f, 1.2f)), (byte) (200 * Random.Range(0.8f, 1.2f)),(byte) (50 * Random.Range(0.8f, 1.2f)) ,255);
    8.         colors[i] = color;
    9.         colors[i + 1] = color;
    10.         colors[i + 2] = color;
    11.     }
    12. }
    13.  
    14. mesh.colors = colors;
    And I have a little shader.
    But now I don't know how to get the colors from my terrain.

    I have the idea to iterate through the alpha maps and check wich texture is set and get the color from it but I am not sure how to iterate through because vertices.Length is not equal to d.alphamapHeight * td.alphamapWidth (20.000 : 200.000)

    Has anyone an idea how to deal with it or a solution for my problem describing one post earlier?
     
  9. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Looks like the colors at each of the 3 corners of a triangle are NOT the same, because there is some gauraud shading showing. They don't look flat. I thought you wanted the whole triangle to be the same color? maybe your Triangles array is sharing some vertices? The triangles array must be set as well as the vertices array, so that it doesn't share vertices, each triangle comprising three distinct vertex indexes.

    To get colors from your texture you need to make the texture readable and then use like GetPixel() or something to read the pixel values, and feed them into your mesh.
     
    IL4Mi3y likes this.
  10. IL4Mi3y

    IL4Mi3y

    Joined:
    Dec 29, 2014
    Posts:
    38
    Thank you very much guy!! :)
    I used this code to make an unshared vertex mesh.
    Code (CSharp):
    1. int[] sourceIndices = mesh.GetTriangles(0);
    2. Vector3[] sourceVerts = mesh.vertices;
    3. Vector2[] sourceUVs = mesh.uv;
    4.  
    5. int[] newIndices = new int[sourceIndices.Length];
    6. Vector3[] newVertices = new Vector3[sourceIndices.Length];
    7. Vector2[] newUVs = new Vector2[sourceIndices.Length];
    8.  
    9. // Create a unique vertex for every index in the original Mesh:
    10. for(int i = 0; i < sourceIndices.Length; i++)
    11. {
    12.     newIndices[i] = i;
    13.     newVertices[i] = sourceVerts[sourceIndices[i]];
    14.     newUVs[i] = sourceUVs[sourceIndices[i]];
    15. }
    16.  
    17. Mesh unsharedVertexMesh = new Mesh();
    18. unsharedVertexMesh.vertices = newVertices;
    19. unsharedVertexMesh.uv = newUVs;
    20.  
    21. unsharedVertexMesh.SetTriangles(newIndices, 0);
    With getting the color from my terrain I think you don't understand my problem.
    Width x length of my terrain is = 262144
    The colors and me vertecies length is only = 24576
    So I don't know how to loop to my terrain because I don't know on which xy-coordinate I have to set my color for example at position 100.

    Does anyone have a solution for it here?
    I think what I can do ist to read the value when I'm creating the mesh from the terrain.
    Then I have the exact vertex point on my terrain and mesh and can save the color in a seperate array.
    Is this possible?

    This is how it looks now.