February 19, 2017

[Week 3] Nature rendering


Hi!
As I said last week, I fixed the fustrum culling system, I had a few problems with the camera planes extraction and also with the bounding geometry. I'll say that in my scene it provides around 50 extra frames (it reduced the number of rendered chunks in half depending on the view point). An oclussion test could improve more the performance as many chunks are ocluded (there are lots of tall mountaings) but for now I'll leave it as it is.

Other big feature that I've implemented this week, is a procedural atmospheric scattering system (O'Neil from gpu gems 2). To simulate the sky, I'm rendering a sphere around the player (atmosphere) and I apply the scattering shader. The terrain has also a scattering effect applied. I have to tweak the shaders as I have some bugs.

I improved the performance of the procedural noise on the gpu by using a 3D lut texture. You can read more about that here: https://www.shadertoy.com/view/4sfGzS.


    // Init lut texture
    mLutColors.resize(256 * 256 * 4);
    for (unsigned int y = 0; y < 256; y++)
    {
        for (unsigned int x = 0; x < 256; x++)
        {
            unsigned int idx = y * 256 + x;
            mLutColors[idx].R = (unsigned char)glm::clamp(int(glm::linearRand(0.0f, 1.0f) * 255.0f), 0, 255);
            mLutColors[idx].B = (unsigned char)glm::clamp(int(glm::linearRand(0.0f, 1.0f) * 255.0f), 0, 255);
        }
    }
    for (unsigned int y = 0; y < 256; y++)
    {
        for (unsigned int x = 0; x < 256; x++)
        {
            int x2 = (x - 37) & 255;
            int y2 = (y - 17) & 255;
            unsigned int idx = y2 * 256 + x2;
            mLutColors[idx].G = mLutColors[idx].R;
            mLutColors[idx].A = mLutColors[idx].B;
        }
    }
I've added a few methods to my Opengl "engine" that allow me to easilly set uniforms (ints,floats,vectors,textures etc) and I updated all the code of the demo with this new system.

Right now, I have a few problems:

  • Depth precission: the water is close to the terrain ground (10-20 meters) and if I move the camera far away from the water I start to see z-fighting. I will investigate on this and try to solve it.
  • Terrain rendering: next week I would like to time the terrain rendering and also implement it with instanced rendering. In total I'm sending 768 drawcalls just for the terrain (256 + 256 + 256). I'm not sure instanced will help with this as some people say that you should only start using instancing with more that 1000 drawcalls.  Anyways I will try it.
  • Clouds: since I've improved  the noise performance I added again my scattering algorithm and it is a bit slow, I'll keep and eye on it.

On the following weeks, I would love to start adding some postprocessing (anti aliasing, god rays etc) and also program a first person controller that will walk over the terrain.