You can get Voxel Farm now. For more information click here.

Wednesday, April 10, 2013

The sun rises in ProcWorld, again

Last week I posted some early screenshots of the nigh-day cycle. There was a lot going wrong in them and you guys were very helpful in pointing out solutions.

I did another iteration on this, while not everything is as it should, I think there was some improvement. This time I have captured a video. The transitions are better appreciated like this. Again let me know what you think.

The main issues with the previous iteration were the brightness of the sky (or lack of it), and how the distant features failed to blend with the sky. This time I made sure there was enough atmosphere so more light was trapped between the horizon and the eye. The distance to the sky is also consistent with the terrain dimensions, now the colors in terrain and sky match better.

A few comments in the previous post suggested a different method called "Precomputed Atmospheric Scattering". It certainly produces better results than the method I am using here, which is the one from O'Neil in GPU Gems 2.

I had a quick look at the method and saw that in its vanilla form it could run slower than what I have now. While the method uses precomputed tables as textures to accelerate rendering, all the work is done in the fragment shader. That means every pixel on screen now had to perform two or three additional texture fetches.

The method from O'Neil does all the heavy lifting in the vertex shader. Consider this scene:

The sky, even if it appears softly shaded, has only a few vertices:

I think in this case it makes a big difference.

The precomputed method could also run in the vertex shader, but then it would take some time to port the tables, which now are in pixel formats that cannot be read by the vertex shader.

Of course there is a chance I am reading this wrong. If you have worked in this area before and see what I am missing please let me know.


  1. Can't help you on the technical side, sorry, I'll just leave a subjective opinion.

    It still looks kinda fake but definitely much better than before. More realistic gradients and hues would help a lot but I doubt it will ever get as good as PAS so I'm wondering how much it impacts on performances: I'd gladly sacrifice a few FPS to get a realistic sky (not to mention a less evident LOD switch).

  2. I think the method that you using is enought for now, but maybe with some fixes, for example in the colors, because maybe you should make sunset and sunrise a bit more reddish :)

    Anyway i like so much sun's effect, pretty good :D

  3. I tried physics-based sky in Arcane Worlds at first, but it had a lot of problems. Here's the description of what I use instead.

  4. Great stuff as always Miguel, I implemented the Precomputed Atmospheric Scattering algorithm in my own project ( and you are absolutely correct, it's a fairly hefty per-pixel cost.

    I applied it as a post process to avoid additional cost from overdraw and didn't do any timings to see how much it was adding but it is fairly intensive.

    Doing it as a post-process though causes problems with alpha areas such as water where the ground visible through the water isn't affected by the scattering as the pixel depth is coming from the water - you end up having to apply the scattering twice once for solid and again for alpha which makes it even more expensive in these areas.

    The positive of course though is that you don't have to do anything to all your other shaders - as long as they output depth it just works.

  5. Looks much better than the last version and I have no ideas for improvement regarding the overall lightning transition beside one point: the night seems for me to be a little too bright. As I mentioned in an older anonymous post I am used to the enviroment in the German alps. When you stand in such a mountain landscape without much or any light sources (like houses, citys, streets etc.) it is mostly pitch black at night - beside a beautiful night sky full of stars. Of course I understand gameplay wise it can be quite annoying when you have to stumble through the night without seeing anything. The same goes for wandering in a deep cave. But if you aim for realism or plan to implent torches as a important part in your game like they did in Minecraft I would think about a darker night sky.

    1. Seconded. I live in the Austrian alps (in a sparsely populated area) and would love to see realistic darkness.

      Don't go for the Hollywood torches as in Minecraft tough.
      This guy makes some good points about authentic uses of fire as a light source:

    2. You mean he should go for smoky, short lived fires which need to be re-fuelled every so often?

  6. Wow. That looks a lot better than before. My biggest issue with it is that the orange lighting from sunrise seems to show up after the orange sky is already gone. It seemed a bit strange.

    I also think the sunset could do with some pink/purple shades when the sun is around the horizon, at least in the area between the orange and the dark blue/black parts of the sky. That might depend on the time of year or something, though. I don't know.

    Will you be doing any motion smoothing of the shadows from the sunlight? What I mean is that in most games with short enough day-night cycles, you can see the real-time shadows jump forward every second or two (presumably because of precision issues) instead of it being a smooth motion. I find that it really ruins my immersion level, but I don't think I've seen anyone do it better yet.

  7. This one is looking much better than last weeks! I really like the effect that is going on here. Like others mentioned, the bright orange is a bit too saturated, it looks like there is a nuclear bomb going off every morning! That is all a matter of tweaking values, I'm sure, and the general feel of it is very nice. I especially liked at dawn how the sun had a sort of meta-ball effect.
    I can't wait to see what you do with the smaller details in the sky, like weather patterns and stars. Is the system you've built going to be capable of producing a flat-bottomed overcast cloudscape, or is that going to be a different system?
    As always, fantastic work and I look forward to seeing more.

  8. Omg... Dynamic shadows...
    Miguel, make weather in procworld

  9. It looks really great and you should add clouds, weather and seasons to make it look more realistic.
    Also, will you sold a game, a engine, both ?
    I would love to make a 3D terraria-like using this engine that have crysis 1 graphism (wich is really good).

  10. As previous people have said, it all looks really quite good, except the sunrise and sunset, to me it seems not so much like an atomic bomb, but more like giant forest fires or something, as, if I am not mistaken, the sky turns black (Darker than at midnight) at sunset, and then it sort of goes over to the Dark Blue of the sky, it almost seems like the sun DID indeed set in 10 seconds or so and your eyes are adjusting, even though in reality this wouldnt be the case I believe.

    Also, the article I send in last post, I found that through the Infinite: The Quest for Earth website, perhaps you could try and ask the developers of that game some questions about it?
    Other than that, I cant help you with this =/ heres a link:

  11. Still looks great to me. :P

    Vegetation looks way more natural now as opposed to being almost self-lit.

    What really jarred me though were the LOD transitions! Was I just missing them in your previous videos or have you changed something? They are REALLY immersion-breaking.

    Finally and this is just a suggestion for future videos, but walkovers are nice. FLYOVERS are awesome! Consider this in official fan request for more flyover footage (and don't forget to look at the horizon several times so we can see sweeping vistas).

    Really appreciate your efforts and as always, looking forward to your next blog.

    Take care.

    1. "Vegetation looks way more natural now as opposed to being almost self-lit."

      I realise this isn't entirely on topic, but feel compelled to ask - would it be possible, to de-synchronize the animations for vegetation in some capacity? For example, when you look at a valley, and all the plants wiggle in time with one another, it's slightly visually disconcerting. If there was some method where a random variable might be introduced, the scene might read as more visually 'real'. I know it's a small quibble, but think it would be a high reward/minimal work type scenario.

      On topic, I *love* the day/night transitions. The night stars seem fairly muted tho, is this just a placeholder/template type thing, or do you think you'll maintain them at this low light level intensity? Great work tho, thanks for the post! :)

    2. For the Vegetation, I think he actually said that currently he is just using a sine wave, and will find a proper thing to do eventually. From my understanding of programming however, I believe it should totally be possible to make them move asynchronous.

  12. Looks good!, Id be tempted to use some more dense fogging on the distant terrain using some sort of averaged color from the sky. It softens the transition from horizon line to sky

    I cheat terribly in our Day Night Cycle.
    I basically lerp through a set of colors (fog,lighting/skyboxbackground) for each part of the 24hr cycle and then apply these to the appropriate objects.
    The biggest cheat is that I have a hour or so of just ambient light at dawn/dusk. This allows me to get away with using only 1 directional light source for both the sun and moon, otherwise you need 2 since they will crossover. I don't do enough to get an atmopsheric scattering effect though :(

  13. Definitely a big improvement - much more natural looking. I agree with the overly saturated orange comments though. How hard it would be to get some pink/lilac colours into the sunset? That would look quite cool - see for the kind of effect I'm talking about.

  14. There are some realy great procedural skies the the Terragen 2 galery....

    maybe it will give you some ideas.
    (probaly woth checking out their forum as well)

  15. It really looks great. It already looks like a world I could blow hours in. So, any chance you could tell us what's the plan is? What are the next steps? how far will you take it? I'd love to see clouds and weather, maybe coastlines and plains. Jungle would be a challenge, but fun. Are you planning a road/trail generator? How about wildlife?

    1. I actually wonder if jungle would really be that much of a challenge, he's got the tree algorithm, he's got the undergrowth, what else is there really? I think the greatest challenge (besides things which are alive other than plants and fungus) would be animated water, in other words, things like streams and waves.

    2. From his earlier comments, miguel has said he's done some work on water and it's on his radar for inclusion, but he has other priorities at the moment. We'll just have to wait and see!

    3. I always wonder, why everyone is so eager to see water be implemented. Of course rivers, lakes etc. increase realism and atmosphere. But I always find water in games as a little bit boring. Spontanously I can't recall any game that has used water as a relevant gameplay element in a fun way (expect some Minecraft mods maybe). Regarding Miguel's work I am more fascinated by his procedural architectur system. I would love to see more complex buildings, maybe procedural towns (like he showed in rough version in an earlier post) or procedural interiors.

    4. Well, the thing about water is, its pwetty =D. For some reason, adding water to a landscape just does something to it, sure not every inch will have to have water, in a desert you wouldnt want to find water every kilometre or so... Still, Water is of great importance to humans and all life we know actually, so it would be slightly strange to not have water...

      Anyway, Rivers, like trees, are just one of those landscape defining things, which add to the uniqueness of a landscape... And theyre fun to follow.
      Just out of curiosity, have you ever played a game where there was no liquid bodies (like rivers and stuff, be they water, lava, poison or whatever), if so, did you enjoy walking around in them?

  16. Would the moon have been full like that with the sun rising more or less behind it?

    1. As said before, the moon is a place-holder, it will be changed to a more realistic one in the future.

  17. Just going through the video again, the forest edge scene at 2:00 gets the dawn to daytime colors. and transition. pretty darn realistic!

    I've camped out in many similar situations and I think it's pretty right on for a couple reasons:

    - that section displayed far less of the super saturated orange and other colors that other sections did. Probably due to the view angle. I agree with others that in some other parts of the video the highly saturated orange was too much.

    - I think someone mentioned that both dust and water in the air significantly affect the amazing dusk/sunsets that we sometimes see, vs. the blah ones we also often see.

    If it is possible, I's suggest adding bit of little randomness to the color intensity settings 'day to day' and 'night to night' so that sometimes you get that feeling that "this sunset is truly magnificent! I HAVE to find the perfect spot to get a screen cap of this."

    Great stuff!

  18. On the multi scatter side, you're exactly right ... it's constructing a ray and doing a heap of texture fetches against it.

    It's nothing too crazy (there are no for loops etc.), but there is quite a healthy dose of texture fetches, just look at the "inscatter" fragment shader function.

    If you can get your current single scatter method to work for you (which I think is pretty clear from this post that you can), then stick with it. It doesn't take a very detailed sphere mesh (with per vertex calculations) to get a good looking sky.

    Using *extremely* unscientific tests, toggling the multi scatter on/off on my GTX580 represents almost exactly 10% of GPU usage with a 1600*1000 ish window (running at 60fps).

    So it's neither ridiculously expensive, nor is it free. I think you're taking the right path. If you're ever burnt out on whatever you're developing at the time, it'll only take you a day worth of dev to satisfy your curiosity.

  19. I guess replies to this post are long due, but still... It looks great, except that the colors during sunset and sunrise are unnatural. It's too brown! I already noticed it in the pictures in the previous post, but it makes everything look dead. Brown light is unnatural. I don't know how to fix it though ;)
    There are loads of sunset videos on Youtube that show the "right" colors.