Jump to content

[PLUGIN][0.21.x][ALPHA] Kerbopolis - Procedurally Generated Cities


tobyb121

Recommended Posts

EDIT: 0.1 ALPHA Release

Finally got round to releasing v0.1 ALPHA

The main features I wanted working, the city generation, road generation, day/night animation, config file is all working and I've got lots of ideas for a future release. The performance impact seems to be negligable, I can't notice a difference with/without the mod (once the city has finished generating).

Please let me know what you think and if there are any issues that you are having with the mod.

Download:

http://www./download/6rfsjer4oeozh1y/Kerbopolis+v0.1_alpha.zip

Source Code:

https://github.com/tobyb121/Kerbopolis

************************************************** ******************

For the last couple of days I've been working on developing procedural cities that can be placed in the game.

The mod isn't using Kerbtown, but these cities could work alongside it.

Each city has a random seed value and then a set of parameters that control the size of the city, minimum size for blocks, and the way that the city is split up, building sizes etc.

The basic algorithm for generating the city is that it starts with a single city block, this is then subdivided into a random number of smaller blocks. Each of these blocks is then subdivided again etc. upto the specified number of subdivision passes. The corners of the buildings are calculated and used to identify each road intersection. These intersections are then connected with road sections. Finally the blocks are filled with buildings (with their height scaled according to how close they are to the city centre).

Everything has a simple box collider on it at the moment so there is only a small impact on performance, but you can of course crash planes into the buildings.

I'm planning to create some random roof decoration for the buildings, fire escapes, radio towers, etc. and just need to fix all the road intersections before releasing anything.

Let me know what you think

tobyb121

Javascript is disabled. View full album
Edited by tobyb121
Link to comment
Share on other sites

Excellent! Do you plan on creating cities all over Kerbin with this? If you hard-coded the seed and released a cities of Kerbin mod, it would greatly enhance the game for everyone! :) Keep up the good work!

That's what I'm planning to do in the end, the only other slight limitation that I hadn't mentioned is that the ground underneath the city needs to be flat, so that might limit where such cities can be placed, I may also build an artifical lump of terrain that the city sits on.

Are you going to release a alpha?

Once I've fixed the road layout issue, it will be very alpha-y though.

I will look into having lighting at night, I'm focusing more on the geometry and layout generation at the moment.

Edited by tobyb121
Link to comment
Share on other sites

Haha, great minds think alike!

http://forum.kerbalspaceprogram.com/threads/49982-Kerbin-Real-Estate-Procedural-Cities

I noticed that your blocks are missing centers... do you plan on resolving that? I found the best way was to sub divide blocks into a grid, and then randomly connect building footprints, fixing corners and connecting the inside blocks to the outside if not.

Where did you find your textures?

What is your plan to ensure that the city is always on the ground level?

P.S. Your scale is MUCH better than mine :)

EDIT:

I also wanted to know if you were using UnityEngine.Random or System.Random ? I found the UnityEngine Random was not that at all... in my class that referenced it, it seemed to reset the seed every time the class methods were called.

Edited by rbray89
Link to comment
Share on other sites

Anything like this built anywhere but right by KSC is gonna need a terrain bed. This is something we found out very early on developing KerbolQuests...and the proc terrain of 0.21 makes the issue more prominent. I been making statics with 15meter thick terrain base, and then adjusting as needed from there, though 15m is good for most spots not right by a mountain. (fyi...building things INTO the side of a mountain suuuucks!)

Really not sure why yall are not using KerbTown for this...its based on PQSCity and already has other functionality to it as well (like triggered animations, fuel storage and transfer, nighttime lighting and more). Its also rather open-ended so that developers like yourselfs can add namespaces/modules to it to suit your needs....just a thought =)

Link to comment
Share on other sites

The GameObjects we are using (ie. Meshes, UV maps, Colliders, etc.) are being created on the fly. Kerbtown doesn't allow this without modification, plus, it is nice to get terrain information (ie, if the ground level is 0, we know there is water there and know not to build there)

Link to comment
Share on other sites

Anything like this built anywhere but right by KSC is gonna need a terrain bed. This is something we found out very early on developing KerbolQuests...and the proc terrain of 0.21 makes the issue more prominent. I been making statics with 15meter thick terrain base, and then adjusting as needed from there, though 15m is good for most spots not right by a mountain. (fyi...building things INTO the side of a mountain suuuucks!)

Really not sure why yall are not using KerbTown for this...its based on PQSCity and already has other functionality to it as well (like triggered animations, fuel storage and transfer, nighttime lighting and more). Its also rather open-ended so that developers like yourselfs can add namespaces/modules to it to suit your needs....just a thought =)

Kerbtown doesn't allow this kind of dynamically generated model, it uses the built in KSP mesh loading, but I'm using the same PQSCity stuff to position the city. As I've said as well this doesn't interfere with kerbtown so you could use Kerbtown to create your landmarks etc. and then use Kerbopolis to fill in the city.

@rbray89: I hadn't seen your project, looking good, you've got some interesting geometries being formed.

I got all my textures from http://www.cgtextures.com/ I literally just copied the thumbnails because I'm trying to limit all the textures to 128x128 max so don't need their full high res stuff. These are only temporary textures just to get the look right, though I'm quite pleased with the effect.

In terms of keeping the city on the ground, while I agree that the terrain info can be obtained, I don't think the road system I'm using will adapt well to uneven terrain, especially if it is not an exact N-S or E-W slope. A terrain bed will most likely be the solution I go for but I'll try and keep it as low as possible and find the flattest terrain I can.

Link to comment
Share on other sites

I noticed that your blocks are missing centers... do you plan on resolving that?

It was actually intentional for the centres of the blocks to be empty. If you have a look at a city like New York, which uses a very regular "blocks" structure you find that the blocks do not actually have buildings in the middle:

KvQWz3J.png

That said I agree that my blocks don't look right at the moment, I think this is because I just don't have enough building density.

Edited by tobyb121
Link to comment
Share on other sites

I think I figured out a good way to emulate areal city lights at night... it also has the bonus effect of creating a "light pollution" effect when looking up from within a city. I'll be posting it when I'm done working everything out, but essentially it is a custom distance-sensitive emissive/transparent shader that fades as the camera nears it. What I hope to do is place two quad planes above the city. One at ~200m and the other at ~800m. The lower one would be the exact size of the city, maybe a little bit extra to provide a good "higher res" "light source" at lower altitudes. The upper layer would have a circular gradient texture and would cover ~2x the size of the city to provide a "light dot" that would be seen at much higher altitudes.

ie.

_   _   _  _ _______ _  _   _    _



----------------
..|..(CITY)|..|.

Link to comment
Share on other sites

One thing I did notice is that all the buildings are edge to edge. Is this also intentional? You don't have any alleyways, and you generally don't see taller buildings right up next to each-other. I do like how the smaller buildings are connected though. That is closer to reality then having those all separated.

Link to comment
Share on other sites

Yeah, at the moment there are no alleys between buildings, but it's very easy to add, and in my working copy the smaller blocks do have alleyways because they couldn't fit building in fully.

At the moment my block filling algorithm is pretty basic. I've just finished off the visibility range stuff, and am just finishing off the last bits of code to make a usable mod, which I'll hopefully release along with the source code this weekend

Link to comment
Share on other sites

Thats sounds like an interesting method to do it, I would be interested to see how it works.

It looks like it will work well for above views:

Javascript is disabled. View full album

I still have to tweak the render distance and the values i'm using in the shader. If you are interested, this is it:

	Shader "AlphaSelfIllum" {

Properties {
_Color ("Color Tint", Color) = (1,1,1,1)
_MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
}

Category {

Lighting On
ZWrite Off
Cull Back
Blend SrcAlpha OneMinusSrcAlpha

Tags {Queue=Transparent}
SubShader {

Material {
Emission [_Color]
}

CGPROGRAM
#pragma surface surf Lambert vertex:vert

sampler2D _MainTex;
fixed4 _Color;

struct Input {
float2 uv_MainTex;
float3 fooAlpha;
};

void vert (inout appdata_full v, out Input o) {
// Transform to camera space
float dist = distance(float3(0,0,0), mul(UNITY_MATRIX_MVP, v.vertex));
float alpha = dist * .00005;
alpha = alpha*alpha;
alpha = min(.85,alpha);
o.fooAlpha = alpha;
}

void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgba;
o.Alpha = min(c.a, IN.fooAlpha);
o.Emission = c.rgba;
}
ENDCG

Pass {
SetTexture [_MainTex] {
Combine Texture * Primary, Texture * Primary
}
}
}
}
Fallback "Self-Illumin/VertexLit"
}

I'm not using any texture with it, but eventually it will be a halogen lamp color with a conical shape. It works fairly well with varying from distance, but it could be better. It is mostly the

float alpha = dist * .00005;

line I'm tweaking at this point. Though I may make it a cubic distance function instead of a square.

Link to comment
Share on other sites

Any updates/news on a alpha?

I should have something to post today that will be very simple. I was hoping to get a night/day animation working, but it's not working as expected, so I'll probably leave that for the moment, just need to add a terrain bed and then I'll post it.

Link to comment
Share on other sites

I should have something to post today that will be very simple. I was hoping to get a night/day animation working, but it's not working as expected, so I'll probably leave that for the moment, just need to add a terrain bed and then I'll post it.

Id be interested in seeing how you handle day/night transition. Right now the lights I posted stay up in daylight as well...

Link to comment
Share on other sites

I was hoping to use the built-in TimeOfDayAnimation component, but I'm having some trouble getting it to work.

Just as a quick update I'm not able to release an alpha today, as I've found a problem with setting the altitude of the city, which I hadn't noticed before because I've just been testing at the KSC.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...