Tuesday, April 24, 2012

Windows

Added windows (coloring the box inside each building blue) and some geometry variation. Think I'm going to call it a day. Code can be found here.


We have bricks

Bricks!

Added bricks. The code is referenced from The Orange Book.

Saturday, April 21, 2012

Small Update


Added a taller building type with a different mod value.



With more types of buildings it should be easy to achieve a believable city. However, since there isn't much time left, I'm considering focusing more on texturing and making what I have look pretty.

Wednesday, April 18, 2012

Progress

Riccardo (aka h3r3) kindly helped me out with generating random heights for the buildings, and it worked great (thanks again!) What he suggested was to create a position vector (pos) that remained the same for each building/cell:
vec2 pos = vec2(ceil(p.x/c.x), ceil(p.z/c.z));
 The idea behind this is: Using the mod function for repetition is like dividing the space into individual cells. By dividing p by c, you get the 2D position of the cell in this "checkerboard". The ceil function serves to ensure each cell is represented by only one (int) value, since the rand function always returns the same output when given the same input.

While I was trying to think of ways around generating random heights, Gabe suggested to try using multiple repetition patterns to simulate a varied but modular city. I think combining both these methods would produce good results, and I will be working on this this week.

I've been experimenting with adding details to buildings, and I decided to use IQ's method in his menger fractals to create windows. The basic idea is to create a cross that extends infinitely, and subtract it from the rectangular building bodies repeatedly to create window spaces. The rand function from before also resulted in some "free" variations, as seen below:

Windows and Ledges

I guess these buildings can be considered generic residential ones. I'll be experimenting with some more different types this week to add variation to the city. You can see the current work in progress here.

Wednesday, April 11, 2012

Running into Trouble

I've been trying to implement the procedural generation part of the project the past few days, but so far things haven't been looking that great. My first approach was to use IQ's repetition function (which is basically a modulo function) to duplicate one building infinitely. The idea was to assign each drawn building a random attribute (starting with height). However, the distance function, which is where the height would be determined, operates on each point of the ray, and there is no unifying "seed" I can pass to the random function that would return a height that would be the same for points hitting the same building. As such, all the available things I can pass into the random function (it takes in a vec2 and returns a float) result in flickering static at the tops of the buildings. I think the reason this isn't working is because the distance function is impartial to what object is being hit and describes the entire scene instead, and because there's no way to tell if the hits are landing on the same object, there is no way to set attributes for individual objects.

My backup plan was to individually construct buildings on an i by j grid that fills up the screen, and add/remove buildings to the scene as the camera moves. However, because the distance function for this implementation involves taking the union of all the objects, and the union is finding the smallest distance to the camera among all the objects, each pass of the fragment shader has to loop through every object in the scene to find the smallest distance. With the number of objects (around 255 in the sreenshot) in the scene, the lag became unbearably slow (and this is on the machine with the Fermi card).

Variation at the price of speed

I wasn't expecting something like this to happen, and I'm kind of out of ideas at this point. I've been reading on terrain ray marching to see if there's anything useful, since that was what inspired this project. What I noticed was in terrain ray marching, there is no need to differentiate between individual objects (the terrain is basically one big fractal field), so it never runs into my problem. Right now I'm emailing some people for advice. In the meantime I'll be thinking of other ways around this (hopefully) and looking into geometry.

Sunday, April 8, 2012

Repeating City

After I decided to ignore the camera messing up, I happened to have to restart glsl sandbox, and found that the same code from my previous session produced scene at a different angle. I tried setting the cos and sin inputs to constants this time and it works now. Go figure.


I have a rudimentary infinite city with the camera continuously panning backwards here, and I'll be building the geometry this week. I'm still not happy with the shading (still can't figure out why dark lines are showing up at the edges of some of the buildings, I'm guessing its some kind of problem with the normal), but I'm a bit behind schedule with the geometry so it's time to move along.