Shadow mapping, part 4

Deferred rendering

My fear in previous post were justified, in order to use deferred rendering I need to use OpenGL Multiple Render Targets (MRT), and this is not available in Libgdx as it uses OpenGL 2.0

I tried enabling OpenGL 3 but I think it’s just some preliminary work as it justs crashes the game, something to do with shaders apparently.

Basically from what I understand :

  • MRT is used on frame buffer to render to multiple textures instead of just one (you get access to an array of gl_FragColor in the fragment shader instead of just one)
  • A few textures are saved containing data : colors, positions, normals,…
  • Then next passes will use these textures to just render on the screen space using what was previously calculated, and each pass blends a new light.

This saves a lot of calculations as no unnecessary lights calculations are made, only what is visible on screen is computed.

 

Multi pass rendering

So I tried something else, render the terrain multiple times

  • First time just rendering the terrain without lighting
  • Render one more time per light, each time blending the shadows from the light

The bad thing is that the fragment shader is called multiple times, so it’s not very efficient…

I first tried with a simple approach, just adding a soft shadow on each light

capture_2014-12-18_13-29-20_0506_Alien_Blitz_

I have lots of problems when lights have a limited range, I don’t know why. So I set a very high range for the moment

capture_2014-12-18_18-49-58_0476_Alien_Blitz_

Of course this is not at all a correct result, but at least I can now see that all lights and frame buffers are taken into account.

Now to correct the process :

  • Render all lights (viewed from the usual camera) on a Frame Buffer, each new render just adds its data above the previous one
  • Render the terrain full light, and multiply each fragment with the color from the frame buffer

Basically the frame buffer contains:

screenshot112

And the render becomes :

capture_2014-12-18_21-31-05_0299_Alien_Blitz_

This seems a bit better but I still run into troubles when adding more lights…

In the above example there are 3 lights activated, if I activate the one in the center of the big room the render becomes :

capture_2014-12-18_21-31-34_0105_Alien_Blitz_

It seems the new lights takes the frame buffer of the right light… which doesn’t make sense… it needs more investigation.
*edit* it works better with my nvidia card instead of the integrated intel one, so I must be hitting a limit somewhere

Comments are closed.