Saturday, July 24, 2010

Let Your Eyes Adjust

This is a feature I looked at putting into X-Plane 9, but it turned out that it affects so many different parts of the sim (and has to be done all-or-nothing) that it got kicked to v10. Consider these two pictures of the default B777 (the lighting was not adjusted, only the time of day):



The night image looks pretty, but what's wrong with the day image? The answer is: the small panel post lights in the night image are still casting a fair amount of light in the day image. And the result looks silly. But why?

The answer is: in real life your pupils would contract in the sun, letting in less light. The sun is really rather bright, so the daytime panel would still look normal, but the apparent power of those posts lights would be a lot less, because your eyes are less sensitive. In other words, the relative strength of the sun and post lights is wrong in the second image.

Computer monitors don't have a huge dynamic range for how much brightness they can put out. So we can't hope to display the absolute brightness of the scene correctly. Instead we need to make everything brighter at night (to simulate your night vision) and dimmer during the day, like this:




In this set of images, the night image is matched precisely to the previous one, but as the sun comes out, the apparent brightness of all lit textures has been scaled down to simulate the effect of your eye becoming less sensitive due to the flood of sunlight.

What's good about the compensated image is that the weird artifacts from the post lights are gone; the relative strength of the post lights is really low in relative terms.

What happened to the EFIS and moving map? The answer is that they too are not as apparently bright relative to the sun as they would be at night.

There is one hitch here: plenty of real airplanes have light sensors for various avionics; the avionics will automatically turn up their brightness during the day. So it is possible (I am no expert on the 777) that in the real plane, as the sun rises, you might not have to adjust your instrument brightness; the sensor would do it for you. The pictures above illustrate what you would see if no automatic adjustment is made.

Auto-adjustment presents a challenge: currently two wrongs make a right. We don't auto-adjust the brightness of instruments, but we don't simulate the apparent visual brightness relative to the sun, and the result are instruments that look adequately bright at all times of day without user adjustment.

I think in the productized version of this feature, authors will have two options for anything lit:
  • Tie the lit instrument/texture to an auto-adjusting rheostat (e.g. brightness 1 + auto adjustment) or
  • Tie the lit instrument to the "raw" rheostat (e.g. brightness 1).
The tricky part will be finding the right mapping for legacy airplanes into the new system.

8 comments:

Steve said...

Subtle. Slick. Looking forward to v10, Ben.

vonhinx said...

Well, I've already invested equivalent-months time in an object-based 3D panel to replace a temporary 2D panel, which must be eliminated as it is totally different. The problem is that without the latter, I've just realized I'm going to struggle to get the post lights to work. Is there a FAQ anywhere as to how to do post lights for a pure 3D panel? Is it even possible?

Benjamin Supnik said...

Vonhinx,

I'm not sure I understand the question, and writing a tutorial or providing tech support is beyond the scope of this blog.

Most of the specific details of lighting in cockpits is on the wiki, but there isn't much on integration.

I can tell you one thing: the most 'modern' technique I have seen from users for doing post lights is as follows:
- They use their rendering tools to create a _LIT texture with the post lights drawn in; this implies that the post lights are lighting up non-cockpit texture.
- They use ATTR_lit_level to tie the light level of the mesh (for only the areas affected by post lights) to a dataref from one of the lighting rheostats (e.g. panel_brightness_ratio[n] or instrument_brightness_ratio[n]).
- They also add one global 3-d cockpit light at very low intensity NEAR the center of the post lights. This 3-d light casts just a liiiittle bit of 'extra' light all over the 3-d parts to make the look a little bit more convincing, particularly for moving animated elements like switches and throttles.

This technique requires very careful planning of how the mesh UV map is created.

vonhinx said...

Thanks for that, I'll be digesting that for a while. Best post lighting I ever saw was in Morten's Piper Archer III - 2D only - and none of what I've read in the docs or blog about how to achieve that in 3D has stuck in my brain. Every clue helps. At least I know what direction to pull the reins when I flog my dead horse.

Anonymous said...

I think in the productized version of this feature, authors will have two options for anything lit:

"Productized"? Really?

Ugh.

Benjamin Supnik said...

"Anonymous"? Really?

Ugh.

:-)

productized = tech demo + all the details for backward compatibility, bug fixes, etc.

sgabriel said...

This looks to be a feature that will enhance the "feel" of the simulator a great deal. Wonderful stuff. Will the principal also apply to the outside world in v10?

IMO, it would be a big step up in both the feel and the utility of X-Plane if the environment reflected (no pun intended) the same visual effects. Improved daytime vibrancy and a greater range of light qualities depending on atmospheric conditions would be great. But night lighting effects! Currently there's no discernible moon illumination, which is unfortunate. It would be neat/useful/realistic if a full moon night seemed almost as bright as day, in that wonderful way it does in the real world.

Thanks for the great work and the great (articulate, engaging) blog.

Benjamin Supnik said...

Yes - the scaling applies to scenery too.