Lighting Explained

From Serious Sam Wiki
Jump to: navigation, search

This article explains the lighting systems used in Serious Engine 3 and also provides some help on creating your own lighting.

(the following is an email quote from Davor Hunski)

The lighting in SED3 is much more advanced than one used in previous engines, so setup can get more difficult. We use full HDR technology what means that light values are not limited to 0..255 range per component, but can be very small and huge (e.g. 0.0001 and 20000), as it happens in real life. In general, we use combination of light maps and dynamic lighting. In lightmaps, we store light bounces (radiosity) that are calculated with separate application called GI baker (GI stands for global illumination). Calling the GI calculator application is seamlessly integrated into SED3, so you have to prepare valid setup and run GI baking. Once GI baker is done, editor will collect the results and apply them automacically. We use remote GI bakers, but you can also use one computer for that. Note that GI baker has special algorithm that we developed that uses power of the gfx card to calculate light bounces extremly faster than CPU would do (still, according to the complexity of the level it can last from several seconds/minutes up to an hour fow higher quality/large level/low powered GPU). Once we calculate HDR light values for the pixels, we have to select right exposure for the scene (the same thing that photo cameras do). You can manually select exposure or let engine to do it for you (there is special entity called postprocessing effect that controls the process). Exposure is controlled via "EV xx.x" menu in the view combo boxes.

To make it short, here is the thing that you have to do:

  • insert the model ("Insert" key)
  • go to mesh editor (E) and create some shapes
  • assign some shaders and textures (GI uses color bleeding, so textures are accounted in light generation-e.g. red carpet will make room a little bit reddish)
  • create "Shadow" UV map (use atlas mapper for simplicity), note that polygons must not overlapp and myst be inside 0..1 UV space
  • exit mesh editor
  • insert distant light and position it right (be careful to adjust range for sun to see the objects-turn on "Selection ranges" view option and select the distant light to check range)
  • <not neccessary step> insert cube background and
   a) browse bcg texture or
   b) select new under "Skylight generator" property and bake the cube background (Shift+B) for skylight generator to generate textures
   Adjust the lightness of the bcg using modulator property (I used skylight generator and 0.05 modifier color lightness)
  • create "Lightmap oven" shader modifier and type 128x128 under the size properties
  • press Alt+G to invoke GI baker dialog. Make sure that it says "Solved on local machine" under "Solving type" property
  • after you confirm the dialog, you shuld be able to see GI progress baking dialog in the rightmost lower part of tge screen. It should take few seconds to bake the solution

Info 16x16.png Note: Cube Background very strongly affects GI Baking. The whole level open-space areas will be colored basing on background texture. You can use that to achieve needed result. For example, if you want greyish level, you set modulator property in cube background to some gray and do GI Baking. Also, after GI Baking is done, you can return the color to default, since it won't affect already baked things (well, unless you bake it again).

(the following is an email quote from Alen Ladavac)

To understand HDR lighting, you hav to know how its rendering exposure adjustments and postprocessing work: The engine first renders everything in full HDR color values (the range is approx. 0.0001 to 10000 in 64 HDR), then determines the average value of the scene then normalizes all values to the average and convert to the standard 0.0-1.0 (0-255) LDR range for display. Any values above 1.0 get cut off in this process, but they contribute to bloom (if enabled). Note that in reality, there is no such thing as a "0% black". Standard black paint, e.g., has reflectance of 5%-10%. Also, if you have some light on the scene, it bounces around, so it is impossible to have one part of the scene lit and one completely unlit.

So, firstly, you should never have full black (0 value) pixels in textures and in the scene. Most "overlit" errors (your example is going towards it, but it can get much worse), are caused by full 0% black pixels. Even a few 0% pixels can cause the average calculations to go awry and make the entire scene too bright. Make sure you have proper lighting with radiosity to bounce the light around properly, and that you never have black pixels in the texture.

Secondly, even with perfect texturing and lighting the end result with complete automatic exposure is not always what you want. (Just like a camera, when set to auto, will sometimes miss what you wanted to achieve in the scene and will burn it or make it too dark.) To combat that, you can use the postprocessing entity to define specific parameters for some parts of the scene. Usually you can clamp the exposure values to an acceptable range, define exposure steps so it doesn't vary too nervously, or do biasing, plus do other kinds of postprocessing adjustments (bloom, DOF, ...).

Note that the models and textures from SamHD are probably not perfect for this, as the entire SamHD is made to use mostly SS:FE and SS:SE lighting, so the exposure is fixed to 0 in all levels. You will be able to see real HDR lighting only in Sam3. So, the textures in SamHD are not adjusted, and you can probably find too dark/too bright values in them.

Regarding it appearing in dim in the editor, you are probably viewing it with Tone Mapping disabled (which is default for edit mode). That gives some more visibility for editing as it compresses the range differently, but is not very attractive for viewing. Compare the default view modes Num6 and Num9 to see the difference. The 9 is for editing, 6 is for game. Camera Effects, Image processing and Tonemapping have to be on for full effect.