The Watcher on 31/10/2012 at 15:08
[INDENT]
IMPORTANT: What follows applies to light cast from objects with the Renderer -> Light property. Light cast by Renderer -> Anim Light behaves slightly differently, and special notes regarding them are at the bottom of this post. If you find that your lights are behaving differently than the description given here, check whether you are using Renderer -> Light or Renderer -> Anim Light![/INDENT]
I have been trying to work out a number of lighting anomalies in Xavier's over the past few days, and in the end I decided that I had no choice: I needed to sit down and really work at getting a proper handle on the various settings available for lights in a controlled environment. I've spent many hours now in a test map - just me, a light, and an air brush several hundred units wide, high and deep covered in a grid texture - trying an quite obnoxious number of combinations of settings, but I think I finally understand it all.
Note that the discussion that follows only discusses Renderer -> Light and the matching portions of Renderer -> Anim Light (although see "Anim Lights" below!), ie:
Inline Image:
http://thief.starforge.co.uk/images/e/eb/Tutorials-Lighting-Dialogs.pngIt does not go into light colour, or other renderer settings - this is purely an exploration of the effects of the various settings in the above dialogs. I should also point out that this is all the result of tests done in NewDark with 32-bit lightmaps, although some preliminary tests indicate that the general behaviour applies in 1.18 as well.
Getting the easy stuff out of the way first, quad lit softens the edge of any shadows the light creates by calculating the light cast by four slightly-offset points around the light point rather than at a single point. It's an aesthetic thing which you may or may not want to use (and if you do, it increases lighting time, but has no other cost: the lighting data gets baked into the map, so there is no runtime framerate impact from quad lit lights). However, as most sensible people will use NewDark's better shadow softness algorithms, you can probably just ignore quad lit anyway, as noted by ZylonBane:
Quote Posted by ZylonBane
NewDark only pays attention to that setting when using the Standard shadow softness setting in the Build dialog. All other settings override it. QuadLit on object lighting is basically an obsolete, legacy property now.
The offset from object X, Y and Z values are fairly obvious (if not entirely intuitive): they specify the positive or negative offset from the object the light is set on, and they can be used to move the light source around if needed. If you are attaching your light to an object that contains vhot 1, you probably won't need this, as the light will attach to that vhot automagically. Otherwise you generally end up having to muck around with the offset values to get something that looks decent, but there are no real surprises here.
Unfortunately, that's about where the lack of surprises ends. I'm not about to say that
Everything You Know About Lighting Is Wrong, but I'm willing to bet that most people will find some of this illuminating (pun very much intended...)
The most basic light you can have is one with a brightness set and nothing else, no radius, no inner radius or any other settings[1]. If you do that, the light behaves something like this (IMPORTANT: the axes and curve shown here are not to scale, or actually entirely accurate - the curve is not a straight line, for a start! - this is simplified for illustrative purposes):
Inline Image:
http://thief.starforge.co.uk/images/a/a8/Tutorials-Lighting-Infinite.pngEssentially, the farther you get from the light, the darker the surface is, and when you get far enough away the light source contributes no illumination to the surface. This is a simple behaviour that you intuitively understand as being the way that lights work, the only real problems being that Dark abhors lights with no radius, and since light attenuation (the rate at which the light level decreases as you move away from the source) is the same for all infinite-radius lights, it can be difficult to create the areas of brighter light and deep shadow you want in a level.
So, the first thing you want to do is set a radius. And here is where the first really surprising behaviour is encountered, and I only really noticed it initially because of the aforementioned lighting problems in Xavier's. When you set the brightness of a light, and give it a radius
(but do not set an inner radius), you'd expect that the light would start at full brightness at the light source, and decrease to 0 when it gets to the light radius - the graph above, with the 0 point at the light radius. I know I did.
Guess what?
Inline Image:
http://imgs.xkcd.com/comics/duty_calls.pngWhat actually happens is that the attenuation for a light that has its brightness set and a maximum radius (but no inner radius)
is the same as it is for a light with no radius set, so it's possible (if not likely) that the zero point may be outside the radius of the light, and you see a sharp transition[2] from illuminated to dark at the light radius:
Inline Image:
http://thief.starforge.co.uk/images/c/c1/Tutorials-Lighting-Radius.pngHere the red line on the far side of the radius is the curve the light would follow to zero, but Dark simply stops calculating light values when it hits the radius, even if the light value is non-zero. This is potentially useful if you want to create pools of light with hard edges - make your light bright, give it a smallish radius, and there you go.
So, the radius sets the point at which Dark stops calculating, not the radius at which the light reaches 0. Indeed, depending on the brightness, the zero point could potentially be
inside the radius! Regardless of the brightness the radius simply seems to be a way to tell Dark to stop calculating the contribution from a given light beyond a radius from it, and it doesn't have any effect on falloff rate... or does it? You might have noticed above that I was emphasising that no inner radius was set, what happens if you do set one?
Well, this is where things get interesting. The assumption I normally see, and the one I've had for years, is that inner radius is saying "the light is full brightness out to the inner radius, and then it drops off beyond there".
Guess what? Yep:
Inline Image:
http://imgs.xkcd.com/comics/duty_calls.pngThe inner radius is a far more subtle beast than I originally thought. It isn't actually the point out to which the light is full brightness at all, it actually determines the inner edge of a new light curve that ends at zero at the radius. That's a bit of a mouthful, so I'll try to explain - first a diagram:
Inline Image:
http://thief.starforge.co.uk/images/1/1d/Tutorials-Lighting-Inner.pngWhat happens is that, from the light source to the inner radius, the light curve behaves in the same way it does for lights without an inner radius (the black line from the axis to the inner radius above): out to the inner radius, the light curve is identical to that created by infinite lights and lights with just a radius set. However, once you hit the inner radius an entirely new behaviour kicks in - instead of following the 'normal' light curve (the green dashed and dotted line), the curve changes so that the light will hit zero at the light radius (it follows the purple line on the diagram).
By setting a radius for your light, and an inner radius to something small but non-zero (0.1 or less), you get a light that starts off at the expected brightness and smoothly becomes zero at the light radius, with no visible transitions or discontinuities at the inner radius or the radius. By setting a larger inner radius, you get an area of light that follows the normal curve out the inner radius, and then switches to smoothly reach zero at the radius.
What happens if you set an inner radius and no radius? Well, it doesn't seem to break dromed, but I'd really recommend setting a radius if you have an inner radius.
Anim Lights
As noted at the start, Renderer -> Anim Light behaves slightly differently than the above description.
In most respects, the above description applies to Renderer -> Light and Renderer -> Anim Light, but there is one very significant and important difference: when you use Renderer -> Anim Light you will find that, regardless of any settings you may give the Anim Light, there will always be a point at which the light cast by it suddenly drops from quite visible to zero. This drop-off point is not (directly) determined by the Anim Light's radius or inner radius: the drop off is consistently at a specific brightness level. As soon as the light from your Anim Light drops below that brightness level
it stops being included in lighting calculations.
In 1.18 this sudden drop-off was not really noticeable because of the low resolution of the light maps, but the higher resolutions supported by NewDark can make it quite obvious. Early versions of NewDark did not provide a way to change the behaviour, but since v1.22 dromed has supported a set_animlight_cutoff command:
Quote Posted by doc/modders_notes.txt
When calculating lightmaps for regular anim lights, the default intensity cutoff value is 15. That means that surfaces where an anim light's intensity is lower than the cutoff value will be considered as the light not reaching them at all. This is an optimization to reduce the amount of dynamic lightmap updates for surfaces where the anim light contribution is negligible.
There can however be cases where this cutoff can be more noticeable, and if you're really pedantic about quality it's possible to lower this cutoff value for the mission. The command to set the cutoff value is "set_animlight_cutoff". It takes a value between 0 and 15. After changing the cutoff the mission has to be relit for the change to take effect. Note that the value will be reset to 15 when the mission is New:ed in DromEd, and each time a mission is loaded the value will be updated from the loaded mission. Keep in mind that lowering the value may impact performance in particular in larger areas or areas with many anim lights. It doesn't hurt to do some performance testing after lowering it, and not lower it more than necessary to achieve desired results rather than just always set it 0 without reason.
[1] don't do this at home, kids - you should never have a light or anim light with 0 radius, or Dark will try to calculate the light it casts on
every point in your mission. You don't want this.
[2] actually, most of the time, it isn't
that noticeable, especially if the radius is large, you have several other nearby lights, or the light is dim to begin with. However, it can be very noticeable with bright lights that have their radius set fairly small.