Tuesday 9 February 2016

Coding Features - How the Lighting is Setup In Space

Coding Features - How the Lighting is Setup in Space

Star Dancer is set in Space. It uses a fake phong shader for the lighting with fake bump mapping.

The fake phong shader uses diffuse and specular components for lighting the space ship (per pixel) using the standard lighting equations for diffuse and specular components. However I ignore the ambient term.  Bump mapping is faked by taking the color map and extracting an average brightness value of the texel for two points - the current actual texel and a slightly offset texel and then using the difference in these to calculate a heightmap that alters the diffuse and specular components as a minor perturbation to the normal for the bumpmap..it is a crude but effective method when applied lightly (the bump mapping is very light - mostly not noticeable).

Given that this is a game not reality I had a bit of creative leeway with the positions of the lights.  In the game I use two light sources to represent a key and a fill light.  I would have liked to have had a back light as well as in a traditional 3 point lighting set up but getting the faint glow around the edges of the ships was going to prove a little difficult in a real time setup for me.  

The key and fill lights are oriented almost 180 degrees apart - slightly off from that, with the fill light being of lesser intensity. Both are white lights.  Because I have only two lights and because they are both static directional lights I include their position directly within the shader itself.  

Typically with game engines lights are expressed as parameters to a shader but because I am not making an engine but am making a game with a specific lighting setup that is unchanging I had no worries about simply expressing these lights as constant light source values in the game that could be built directly into the shader.  Not recommended for a more general purpose lighting solution but for a space environment it works.


No comments:

Post a Comment