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
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
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:
And the render becomes :
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 :
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