Wednesday, January 11, 2012

Shader Tech Demo

Since my last post, I've decided to include above-ground in Project Vox too. Caves, albeit interesting, can get pretty dreary after a while. So, I spent a few days optimizing the shader and got the calculation time down to about 2 seconds (for a 200x200 map). I'll still need to get it further down to be able to do calculations in real-time (when chunk loading is implemented) but I'm getting there.

There are many tutorials and explanations of ambient occlusion on the net but, for those of you who don't know how it works, the algorithm (in a nutshell) is:
For every surface (Quads in my case), calculate whether a ray sent out from each vertex collides with any other surface. The amount of rays that are occluded are then interpreted in relation to the total amount of rays to establish how dark/light that vertex should appear.
It is important to note that the rays sent out from a surface should be distributed uniformly on the unit sphere. There are many algorithms you could use to calculate the points the rays should pass through (Personally I prefer the Golden Section Spiral).

While messing around with different ideas I just lumped a lot of the code into the graphics library, which now looks really messy. And there are much more optimal ways of doing the calculations involved. Hence, I will be refactoring most of the code into proper libraries, this should take about a week.

Here are some screenshots, a video and for the executable, you can go here. Sorry about the quality of the video, I don't have fast enough internet to upload a proper one.






Lastly, generating terrain with simplex rather than perlin noise.




4 comments:

  1. I really like where you are going with this, I'd love to see the shader in action in real time.

    Some more suggestions:
    1. Day night cycle (would be nice to see how the shader reacts to that).
    2. Some environmental objects, like generated trees, and perhaps animals.
    3. a HUD (player info) or/and a menu system for settings/game start, and perhaps even a stats or inventory page.
    4. I want to see that player swim!
    5. Sky, some generated clouds, perhaps even some kind of weather system (I'd be happy with clouds for now).

    The above in no particular order.

    ReplyDelete
  2. Awesome work, I love the new direction this project is going.

    Can't wait to see what happens next.

    ReplyDelete
  3. I am glad I found your blog. I am looking at writing my own Voxel engine in XNA. I would be interested in hearing what your coding environment is.

    ReplyDelete
    Replies
    1. Hi there. Thanks for taking the time to comment. I'm writing mine with c++ and OpenGL.

      Delete