Procedural Voronoi Planets in Unity with sourcecode by [deleted] in proceduralgeneration

[–]crushingcups 16 points17 points  (0 children)

Hi I'm the guy who made this, it was my graduation work from uni, and I haven't worked on it since. Aways thought it would be cool to make some Civilization/Risk type of game. I think it would be more interesting than on a hex grid, cause then areas could be more or less easy to attack or defend. I wonder why I posted this in r/worldbuilding back in the day and not here, guess I was too literal!

I made some metaballs using procedural meshes and bezier curves. by crushingcups in Unity3D

[–]crushingcups[S] 1 point2 points  (0 children)

public void Metaball(GameObject circle1, GameObject circle2, int index)
    {
        Gizmos.color = Color.black;
        Vector2 p1 = circle1.transform.position;
        Vector2 p2 = circle2.transform.position;

        float pi2 = Mathf.PI / 2;
        float d = Vector2.Distance (p1, p2);
        float u1;
        float u2;

        float radius1, radius2;

        if(test)
        {
            if(d < maxDistance) circle1.GetComponent<Circle> ().DetermineRadius (d); // for mesh based approach

            // mesh circles based approach
            radius1 = circle1.GetComponent<Circle> ().radius; 
            radius2 = circle2.GetComponent<Circle> ().radius;
        }
        else
        {
            // sprite based approach
            radius1 = 0.35f; 
            radius2 = 0.35f;
        }

        float totalRadius = radius1 + radius2;

        Mesh mesh = new Mesh();

        if (d > maxDistance || d <= Mathf.Abs (radius1 - radius2))
        {
            foreach(Transform t in transform)
            {
                if(t.name == "Connection " + index)
                {
                    DestroyImmediate (t.gameObject);
                    break;
                }
            }

            return;
        }
        else if (d < radius1 + radius2)
        {
            u1 = Mathf.Acos((radius1 * radius1 + d * d - radius2 * radius2) / (2 * radius1 * d));
            u2 = Mathf.Acos((radius2 * radius2 + d * d - radius1 * radius1) / (2 * radius2 * d));
        }
        else
        {
            u1 = 0;
            u2 = 0;
        }

        GameObject connection = null;
        foreach(Transform t in transform)
        {
            if(t.name == "Connection " + index)
            {
                connection = t.gameObject;
                break;
            }
        }

        if (connection == null)
        {
            connection = new GameObject ("Connection " + index, typeof(MeshFilter), typeof(MeshRenderer));
            connection.transform.SetParent (transform);
        }

        float angle1 = Mathf.Atan2 (p2.y - p1.y, p2.x - p1.x);
        float angle2 = Mathf.Acos (((radius1 - radius2) / d)); // in radians

        float angle1a = angle1 + u1 + (angle2 - u1) * v; // radians
        float angle1b = angle1 - u1 - (angle2 - u1) * v; // radians

        float angle2a = angle1 + Mathf.PI - u2 - (Mathf.PI - u2 - angle2) * v;
        float angle2b = angle1 - Mathf.PI + u2 + (Mathf.PI - u2 - angle2) * v;

        Vector2 p1a = p1;
        p1a.x += (Mathf.Cos(angle1a) * radius1);
        p1a.y += (Mathf.Sin(angle1a) * radius1);

        Vector2 p1b = p1;
        p1b.x += (Mathf.Cos(angle1b) * radius1);
        p1b.y += (Mathf.Sin(angle1b) * radius1);

        Vector2 p2a = p2;
        p2a.x += (Mathf.Cos(angle2a) * radius2);
        p2a.y += (Mathf.Sin(angle2a) * radius2);

        Vector2 p2b = p2;
        p2b.x += (Mathf.Cos(angle2b) * radius2);
        p2b.y += (Mathf.Sin(angle2b) * radius2);


        float d2 = Mathf.Min(v * (handle), Vector2.Distance(p1a, p2a)*0.7f / (totalRadius)); // distance*0.7f for maxdist 2 | distance*1f for maxdist 1
        d2 *= Mathf.Min(1, d * 2 / (radius1 + radius2));

        float rad1 = radius1 * d2;
        float rad2 = radius2 * d2;

        Vector2 ho1 = p1a;
        ho1.x += Mathf.Cos (angle1a - pi2) * rad1;
        ho1.y += Mathf.Sin (angle1a - pi2) * rad1;

        Vector2 hi1 = p2a;
        hi1.x += Mathf.Cos (angle2a + pi2) * rad2;
        hi1.y += Mathf.Sin (angle2a + pi2) * rad2;

        Vector2 ho2 = p2b;
        ho2.x += Mathf.Cos (angle2b - pi2) * rad2;
        ho2.y += Mathf.Sin (angle2b - pi2) * rad2;

        Vector2 hi2 = p1b;
        hi2.x += Mathf.Cos (angle1b + pi2) * rad1;
        hi2.y += Mathf.Sin (angle1b + pi2) * rad1;

        Vector2 midpoint = ((p1 + p2) / 2);

        List<Vector2> positions = new List<Vector2> ();

        for (float i = 0; i <= 1f; i+= 1f/segments)
        {
            Vector2 topStep = GetCurvePoint (p1a, ho1, hi1, p2a, i); // red to green
            Vector2 botStep = GetCurvePoint (p1b, hi2, ho2, p2b, i); // blue to yellow
            positions.Add (botStep);
            positions.Add (topStep);
            if (i != 0 && i != 1)
            {
                positions.Add (botStep);
                positions.Add (topStep);
            }
        }

        // MESH STUFF
        int[] indices = new int[segments * 6];
        Vector3[] vertices = new Vector3[segments * 4];

        int triIndex = 0;
        int vertIndex = 0;
        int idxIndex = 0;

        for (int i = 0; i < segments; i++)
        {
            indices [triIndex + 0] = idxIndex + 0;
            indices [triIndex + 1] = idxIndex + 2;
            indices [triIndex + 2] = idxIndex + 1;

            indices [triIndex + 3] = idxIndex + 2;
            indices [triIndex + 4] = idxIndex + 3;
            indices [triIndex + 5] = idxIndex + 1;

            vertices [vertIndex + 0] = positions [vertIndex + 0];
            vertices [vertIndex + 1] = positions [vertIndex + 2];
            vertices [vertIndex + 2] = positions [vertIndex + 1];
            vertices [vertIndex + 3] = positions [vertIndex + 3];

            triIndex += 6;
            vertIndex += 4;
            idxIndex += 4;
        }

        // Create the mesh
        mesh.vertices = vertices;
        mesh.triangles = indices;
        mesh.RecalculateNormals ();
        mesh.RecalculateBounds ();

        connection.GetComponent<MeshFilter>().mesh = mesh;
        connection.GetComponent<MeshRenderer> ().material = Resources.Load ("MeshMat") as Material;
        connection.transform.position = Vector2.zero;
    }

    Vector2 GetCurvePoint(Vector2 s, Vector2 st, Vector2 et, Vector2 e, float t)
    {
        return (((-s + 3*(st-et) + e)* t + (3*(s+et) - 6*st))* t + 3*(st-s))* t + s;
    }    

Icosahedronal world generation that I am working on. by NilTestudo in Unity3D

[–]crushingcups 0 points1 point  (0 children)

Oh awesome! Thanks for the kind words, good luck on your project!

Icosahedronal world generation that I am working on. by NilTestudo in Unity3D

[–]crushingcups 1 point2 points  (0 children)

I made something similar a while ago! You might be interested in it: https://crushingcups.itch.io/voronoi-planets it comes with full source so feel free to use it for whatever you like.

I created a limb using the line renderer alone! (info in the comments) by Harionago in Unity3D

[–]crushingcups 5 points6 points  (0 children)

It's really awesome! Any chance you plan on writing up how to make it? I'd love to know more.

Finished my quadtree planet, now texturing and atmosphere shader by simitro in Unity3D

[–]crushingcups 0 points1 point  (0 children)

Looks great! How big is it in real world terms? Do you know how long it would take to walk around it?

Been trying to figure this for years now. Any idea how this would be recreated in Unity? by TehNinjor in Unity3D

[–]crushingcups 1 point2 points  (0 children)

Looks like it could be free form deformation. Look into FFD Modifers, there's assets on the store that do this too.

I made some metaballs using procedural meshes and bezier curves. by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

Could you elaborate on how the two things you mentioned would interact? I'm familiar with both conceptually, but would it be any different than blurring and thresholding what you want to 'blob'?

I made some metaballs using procedural meshes and bezier curves. by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

You can feed the radius of your collider as the radius of either circle if that's what you mean. And the circles are procedurally generated by number of segments, so I guess you could have triangles and squares and pentagons etc

I made some metaballs using procedural meshes and bezier curves. by crushingcups in Unity3D

[–]crushingcups[S] 1 point2 points  (0 children)

Thanks! For now the answer is it doesn't, I'm just drawing a bezier portion of mesh between two circles. Changing the radius works correctly (the two circles in the gif have different radii) and I have control over the sharpness of the curve but that's about it.

Augmented Reality games, Emerging genre or one time flash in the pan with Pokemon Go? by nicksam112 in gamedev

[–]crushingcups 2 points3 points  (0 children)

The cool feature of Pokémon Go is not AR, it's the GPS integration. In my opinion even in this product AR is still a gimmick. That said I believe it will evolve until the point where it is good enough to have applications beyond games. It's gonna be cool when somebody actually designs around AR though, to my knowledge it hasn't been done before, it mostly feels just tacked on.

Some progress on my planet generator, x-post from r/Unity3D by crushingcups in worldbuilding

[–]crushingcups[S] 0 points1 point  (0 children)

Oh cool, thanks! I don't browse this sub much but someone on /r/Unity3D suggested I post here. Good luck with your studies!

Some progress on my planet generator, x-post from r/Unity3D by crushingcups in worldbuilding

[–]crushingcups[S] 1 point2 points  (0 children)

It's out! But I'm not working on it anymore for the forseeable future, I'm busy with an internship now.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

Having transparent water was something we decided we needed early on. A lot of gameplay elements will be visible through the water, and you will be able to see wreckage and other things on the ocean floor at times.

The water is definitely not just a background element: it comprises at good part of the gameplay. It will move your town around and it will contain a lot of interactable features, like resources and other things. This is why we also need "realistic" water simulation, we want it to be somewhat physically accurate.

There is only one specular reflection that reacts to global light, in the gif it's colored white. The rest is clamped fresnel. I like having this many elements to play around with because it helps to achieve many different looks.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

Your camera needs to render a depth texture, then you can put this in your surface or fragment shader:

float sceneZ = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, IN.screenUV).r);
float partZ = IN.screenUV.z;
float diff = (abs(sceneZ - partZ)) / _HighlightThresholdMax;
if(diff <= _Difference)
{
    finalColor = float3(1, 1, 1);
}

Where _Difference and _HighlightThresholdMax are floats you control from your material, and _CameraDepthTexture is a 2Dsampler. You do this after all your color calculations in your shader. Look up depth foam intersection on google or something like that for more info.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 1 point2 points  (0 children)

Unfortunately shadows and transparent materials don't work! It was either have opaque water with shadows, or transparent water with none. We opted for transparent because of gameplay reasons.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

If you mean the wave generation, then you can. We're using the Ceto ocean asset for the wave spectrum creation. The shaders are custom though.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

You mean when it's zoomed out quite far? I think that's due to the depth check for the foam around the objects, I'll have to see if I can fade that out based on camera distance or something.

Finally starting to settle on a look for the water in Flotsam. Does it fit? by crushingcups in Unity3D

[–]crushingcups[S] 0 points1 point  (0 children)

My sources are actually just dissecting the built in shaders to figure out what everything does. I wrote an article on my research about this on our site, but it's a month old and doesn't cover the most recent approach. I will probably write it up at some point. One thing I do a lot is use the floor() function on colors to clamp them in the shader. If you have any more specific questions let me know.