Shadow Mapping, part 3

Better use of Cubemap

In my previous post I didn’t fully understand the use of cube maps, and I was just generating the render as if the point light was 5 lights… But code can be a lot easier as OpenGL natively supports Cubemap and the glsl code to check if a point is in shadow or not is actually a lot easier.

Another mistake was to not consider top depth for lights, in most cases they are useless, except when a light is near a wall. In this case the light will “see” the wall when looking up.

Sadly it does not seem Libgdx supports cube map frame buffer, so I copied the FrameBuffer class and modified it to include cube maps.

The code can be download here: FrameBufferCubeMap.java

It might be very dirty, I don’t know… first time getting this deep into OpenGL, FrameBuffer… and I adapted it from C++ source… but it seems to work :)

You need to bind each side of the cubemap differently when rendering to this frame buffer, and don’t forget to change the up of the camera

...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
camera.up.set(0, -1, 0);
...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X);
camera.up.set(0, -1, 0);
...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
camera.up.set(0, 0, -1);
...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
camera.up.set(0, -1, 0);
...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
camera.up.set(0, -1, 0);
...
frameBufferCube.begin(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
camera.up.set(0, 0, 1);
...

 

And now the traditional screenshots

Here is what happens if you don’t change the up property of the camera :

capture_2014-12-16_14-45-40_0548_Alien_Blitz_

 

The up property is not the same for negative/positive Y as the ones I saw on the Internet, don’t know why :

capture_2014-12-16_15-04-55_0665_Alien_Blitz_

 

After correction and adding the bias back

capture_2014-12-16_15-06-54_0310_Alien_Blitz_ capture_2014-12-16_15-07-04_0616_Alien_Blitz_

 

This seems to be a lot quicker than previous method.

 

Multiple lights

Now, trying to render multiple lights, my first approach was to

  • Have one framebuffer per light
  • Generate shadow map for each light on its own framebuffer
  • Generate the final scene, using arrays of samplerCube (for each light) in the fragment shader

capture_2014-12-16_15-31-49_0332_Alien_Blitz_

Problem is it seems only the last shadow texture is used, and I have lots of troubles getting array of samplerCube in the shader.

As of now I can’t seem to get anything to work, so I guess I’m not using the right technique. I’ve read about deferred shading, but I don’t know yet how it works (nor if it can be done with Libgdx / GL 2.0)

Comments are closed.