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.