Showing posts with label Exposure. Show all posts
Showing posts with label Exposure. Show all posts

2008-02-19

Why does mental ray Render (my background) Black? Undestanding the new Physical Scale settings

The most common "complaints" I get about mental ray rendering in 3ds Max 2008 is "it's washed out" and "it Renders black". The answer to the former is "you are not handling your gamma correctly", and will be thorougly covered in the future. The answer to the latter is "You are not understanding the Physical Scale" settings. Which is what we're going to talk about now.

Color and Color



Without going too deep into the physics of photometric units (we did that already) we must understand that a normal color, an RGB value, i.e. a pixel color of some sort, can, fundamentally represent one of two different things:


  • A reflectance value
  • A luminance (radiance) measurement


The "luminance" of something is simply how bright it looks. It's probably the most intuitively understandable lighting unit. Basically, you can say that when you are looking at the pixels your digital camera spit out on your computer, you are looking at pixels as individual luminance measurements, converted back to luminance variations by your screen.

I.e. a given luminance of some real world object flows in through the lens of your camera, hits the imaging surface (generally a CCD of some kind) and gets converted to some value. This value (for the moment ignoring things like transfer curves, gamma, spectral responses and whatnot) is, in principle, proportional to the luminance of the pixel.

Now "reflectance" is how much something reflects. It is often also treated in computer graphics as a "color". Your "diffuse color" is really a "diffuse reflectance". It's not really a pixel value (i.e. a "luminance") until you throw some light at it to reflect.

And herein lies the problem; traditionally, computer graphics has been very lax with treating luminance and reflectance as interchangeable properties, and it's gotten away with this because it has ignored "exposure", and instead played with light intensity. You can tell you are working with "oldschool" rendering if your lights is of intensities like "1.0" or "0.2" or something like that, in some vague, unit-less property.

So when working "oldschool" style, if you took an image (some photo of a house, for example) and applied as a "background", this image was just piped through as is, black was black, white was white, and the pixels came through as before. Piece of cake.

Also, if you took a light of intensity "1.0" that shone perpendicular on a diffuse texture map (some photo of wood, I gather) will yield exactly those pixels back in the final render.

Basically, the wood "photo" was treated as "reflectance", which was then lit with something arbitrary ("1.0") and treated on screen as luminance. The house photo, however, was treated as luminance values directly.


But here's the problem: Reflectance is inherently limited in range from 0.0 to 1.0... i.e. a surface can never reflect more than 100% of the light it receives (ignoring fluorescence, bioluminescence, or other self-emissive properties), whereas actual real-world luminance knows no such bounds.

Now consider a photograph... a real, hardcopy, printed photograph. It actually reflects the light you shine on it. You can't watch a photograph in the dark. So what a camera does is to take values that are luminances, take it through some form of exposure (using different electronic gains, chemical responses, irises to block light, and modulating the amount of time the imaging surfaces is subjected to the available luminances). Basically, what the camera does, is to take a large range (0-to-infinity, pretty much) and convert it down to a low rang (0-to-1, pretty much).

When this is printed as a hardcopy, it indeed is basically converting luminances, via exposure, into a reflectance (of the hardcopy paper). But this is just a representation. How bright (actual luminance) the "white" part of the photographic hardcopy will be depends on how much light you shine on the photograph when you view it - just like how bright (actual lumiance) the "white" part of the softcopy viewed on the computer depends on the brighness knob of the monitor, the monitors available emissive power, etc.

The funny thing with the human visual system is that it is really adaptive, and can view this image and fully understand and decode the picture even though the absolute luminance of the "white" part of the image varies like that. Our eyes are really adaptive things. Spiffy, cool things.

So, the flow of data is:

  • Actual luminance in the scene (world)
  • going through lens/film/imaging surface and is "exposed" (by the various camera attributes) and
  • becomes a low dynamic range representation on the screen, going from 0-to-1 (i.e. from 0% to 100% at whatever max brightness the monitor may have for the day).



So, now the problem.



In the oldschool world we could draw a near equivalence between the "reflectance" interpretation and the "luminance" interpretation of a color. Our "photo of wood" texture looked the same as "photo of house" background.

What if we use a physical interpretation?

What about our "photo of wood"? Well, if we ignore the detail of the absolute reflectance not necessarily being correct due to us not knowing the exposure or lighting whtn the "photo of wood" being taken, it is still a rather useful way to reperesent wood reflectance.

So, if we shine some 1000's of lux of light onto a completely white surface, and expose the camera such that this turns into a perfectly white (without over-exposure) pixel on the screen, then applying this "photo of wood" as a texture map will yeild exactly the same result as the "oldschool" method. Basically, our camera exposure simply counter-acted the absolute luminance introduced by the light intensity.

So, in short, the "photo of wood" used interpreted as "reflectance" still works fine (well, no less "fine" than before).

What about us placing our "photo of house" as the background?

Well, now things start to change... we threw some thousands of lux onto the photo, creating a luminance likely in the thousands as well.... these values "in the thousands" was then converted to a range from black-to-white by the exposure.

So what happens with our "photo of house"? Nothing has told it to be anything than a 0-to-1 range thing. Basically, if interpreted strictly as luminance values, the exposure we are using (the one converting something in the thousands to white) will covert something in the range of 0-1 to.... pitch black. It won't even be enough to wiggle the lowest bit on your graphics card.

You will see nothing. Nada. Zip. BLACKNESS!

So, assuming you interpret oldschool "0-to-1" values directly as luminance, you will (for most common exposures) not see anything.

Now this is the default behaviour of the mr Photographic Exposure control!!



This setting (pictured above) from the mr Photographic Exposure will interpret any "oldschool" value directly as a cd/m^2 measurement. And will, with most useful exposures used for most scenes, result in the value "1" representing anything from complete blackness to near-imperceptible-near-blackness.

(I admit, I've considered many a time that making this mode the default was perhaps not the best choice)

So how do we fix it



Simple. There are two routes to take:


  • Simply "know what you are doing" and take into account that you need to apply the "luminance" interpretation at certain points, and scale the values accordingly.
  • Play with the "Physical Scale" setting


Both of these methods equate to roughly the same result, but the former is a bit more "controlled". I.e. for a "background photo" you will need to boost it's intensity to be in the range of the "thousands" that may be necessary to show up for your current exposure. In the Output rollout, turn up "RGB Level" very high.

Of course, in an ideal world you would have your background photo taken at a known exposure, or where you had measured the luminance of some known surface in the photo, and you would set the scaling accordingly. Or even better, your background image is already a HDR image calibrated directly in cd/m^2.

But what of the other method?

Undersanding the 'Physical Scale' in 3ds Max



When you are using the mr Phogographic Exposure control, and you switch to the "Unitless" mode...



...one can say that this parameter now is a "scale factor" between any "oldschool" value and physical values. So you can think of it as if any non-photometric value (say, pixel values of a background image, or light intensities of non-photometric lights) were roughly multiplied by this value before being interpreted as physical values. (This, however, is a simplification; under the hood it actually does the opposite, it is the physical values that are scaled in relation to the "oldschool" values, but since the exposure control exactly "undoes" this in the opposite direction, the apparent practical result of this is that it seems to "scale" any oldschool-0-1 values)


When to use which mode



Which method to use is up to you. You may need to know a few things, though: The "cd/m^2" mode is a bit more controllable and exact. However, the "Unitless" mode is how the other Exposure controls, such as the Logarithmic, work by default. Hence, for a scene created with a logarithmic exposure, to get the same lighting balance between photometric things and "oldschool" things, you must use the unitless mode.

Furthermore, certain features of 3DS Max actually works incorrectly, indeed limiting their output to a "0-1" range. Notable here is many of the volumetric effects like fog. Hence, if the "cd/m^2 mode" is used, it blocks fog intensity to max out at "1 cd/m^2". This causes things like fog or volume light cones to appear black! That is bad.

Whereas in the "Unitless" mode, the value of "Physical Scale" basically defines how bright the "1.0" color "appears", and this gets around any limitation of the (unfortunately) clamping volume shaders.


BTW: I actually already covered this topic in an earlier post, but it seems that I needed to go into a bit more detail, since the question still arise quite often on various fora.

Hope this helps...

/Z

2007-10-25

Max 2008: Physical Camera with DOF and motion blur

So, does anyone want a Physical Camera for mental ray in 3ds Max 2008? Read on...



The Photographic Exposure Control (mia_exposure_photographic) gives you values in f-stops and shutter speeds like in a real camera. However, it only applies to the exposure of the image (i.e. the brightness, basically).

In a real camera, the above mentioned parameters affect the depth of field and the motion blur of the camera.

This isn't supported out-of-the-box - the exposure control really only deals with the exposure.

A second thing is that the exposure knobs being "camera oriented", but they are not ON the actual Camera object. Whereas it would make more sense if these parameters "lived" in the UI of the Camera.

To try to solve these issues, I wrote a little "proof of concept" script to test out what such a UI would perhaps look like. It's very clumsy in many ways and an ugly hack, because it's just a "scriptable plugin", and scriptable plugins has a ton of limitations in max.

First of all, a scriptable plugin can only extend an existing object, not make a "new" one. Secondly, scriptable camera can only extend the "free" camera due to technical limitations of MaxScript (well, the MaxScript docs tell me so anyway), but most people "want" to use a "Target" camera.

Due to this limitation, the camera always gets created in "Free" mode, but after it has been created, you can switch it to "Target" mode. Ugly, but... livable.


How to use this plugin hack



1. Download this plugin and save into the "plugins" directory under your 3ds Max main directory.

2. Now, either restart max, or just load the plugin manually as well from the MaxScript menu.

3. Now, under your "cameras" you have a new "mr Camera" item.

4. Insert it - unfortunately always comes in as a "Free Camera". The UI at this point will look like the old camera.

5. Go to the "Modify" tab to see the "new" UI.

6. Play, rejoice, etc.

Remember, this is an ugly unsupported quick hack. The "mr Camera" simply "feeds" other existing plugins with value (mr Photographic Exposure, mental ray Depth of Field, motion blur, etc.) and doesn't really "do" anything by itself.

And it probably has more bugs than you can shake a stick at... but is provided here "for fun".

Enjoy.

/Z

2007-10-23

3ds Max 2008 released: Some Known Issues

Or "Why do my brand new 3ds Max 2008 render black when I choose a mental ray render preset"?



3ds Max 2008 has been released, and as always, some things sneak in the wasn't really intended in the final version.

Here, a "minor edit" to the rendering presets became less minor than was intended;

Since 3ds Max 2008 contains the new mr Photographic Exposure control, the rendering presets (y'know, the ones down at the bottom of the render dialog) for daylight was supposed to be changed from the old Log exposure to the new Photographic exposure set for "sunny day" lighting.

The problem? That this was done.... but by accident all mental ray render presets got this setting.

Yes, even the "plain old" settings got, by mistake, a setting suitable for a superbright sunny day enabled:



The setting accidentally put in


But a sunny day can easily be lit by 100000 lux. And your average interior surely is not. So out of the box, starting up max and putting in some photometric lights (try to use the photometric lights as often as possible, btw) you would get a really dark scene.

And even worse, putting in some non-photometric scene would yield a pretty much completely BLACK scene. Why?

Well, the new mr Photographic Exposure Control has a 2nd feature; The feature of treating any "oldschool" value as real, physical cd/m^2 values (if you wonder about what a "candela per square meter" is, go back to the "Gnomes and Basketballs" post).



The Units Setting


This means that if an "oldschool" light of the arbitrary intensity value "1.0" shines perpendicular to a white (100% reflective) lambertian surface (i.e. plain old white diffuse thingamabob), this will emit light that is interpreted as 1 cd/m^2.

Now that is really really really really REALLY really dark.

I.e. turning on max, loading a mental ray render preset, and putting in and oldschool "Omni" light gives you a black render. Not good.

The fix? Easy.

Do one of three things:

Either:

1: Turn it off altogether

Hit "8" to bring up the "Environment/Effects" dialog and do as follows:


Exposure Control Turned Off


By simply turning off the exposure control, you are back to a "known" behavior. However the exposure control is really neat and gives very nice images... so I don't really recommend that method!


2: Use the exposure controls "non physical" mode


Exposure Control in "Non Physical" mode


This is better; it still gives you all the nice image control of crushing blacks, taming highlights, camera vignetting and saturation controls, but it uses a fixed unity gain, i.e. the intensity of the pixels does not change (except it applies a gamma correction if the 3ds Max gamma is disabled, if the 3ds Max gamma is enabled, that gamma is used).

However, it is not perfect just because of the fact that you lack any control over exposure; the "non physical mode" is locked to unity gain with no control over it.

There is, however, a third variant:

3: Use the exposure control with an EV=0.0


Exposure Control with an EV of 0.0


It so happens that when using the "oldschool pixels equal cd/m^2 mode" (pictured above) the EV value of zero (0.0) is very close to the "unity gain" mode set by the "Non Physical" mode. But you can change it up or down to re-expose the scene.

So for a scene lit completely with "oldschool" lights (non photometric), that is the easiest setting with the greatest control.


A further note on the units / physical scale



Now if you have an old scene with a blend of photometric and non-photometric lights, you may want to revert to the old behavior of using the "physical scale" setting, which exists in the old Logarithmic exposure control.



Using a "Physical Scale" like in the past



In this mode you cannot use the "EV=0" setting, you probably need to pick one of the "indoor" presets, or just play with the EV until you get a "nice" image, because this means that now an oldschool light of intensity "1.0" will equate to an illuminance of ~1500 lux when perpendicular to a surface, so an exposure "suitable" for that amount of light must be used.


Hope this helps!


/Z